-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.rb
executable file
·78 lines (61 loc) · 1.98 KB
/
run.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'optparse'
require 'active_support/all'
require 'colorize'
require './lib/human_player'
require './lib/q_player'
require './lib/game'
# Run game with different options...
Options = Struct.new(:player, :runs, :map_size, :player_pos, :cheese_pos, :pit_pos, :max_score)
args = Options.new('HumanPlayer', 10, 12, 3, 10, 0, 5)
parser =
OptionParser.new do |opts|
opts.banner = 'Run the game in different modes. Usage: run.rb [options]'
opts.on('-pPLAYER', '--player=PLAYER', String, 'Used player', %w[ HumanPlayer QPlayer ]) do |player|
args.player = player
end
opts.on('-rRUNS', '--runs=RUNS', Integer, 'Total runs to to play') do |runs|
args.runs = runs
end
opts.on('-mMAPSIZE', '--map-size=MAPSIZE', Integer, 'The size of the map') do |map_size|
args.map_size = map_size
end
opts.on('--player-pos=PLAYERPOS', Integer, 'The players start position (must fit map size)') do |player_pos|
args.player_pos = player_pos
end
opts.on('--cheese-pos=CHEESEPOS', Integer, 'The cheese position (must fit map size)') do |cheese_pos|
args.cheese_pos = cheese_pos
end
opts.on('--pit-pos=PITPOS', Integer, 'The pit position (must fit map size)') do |pit_pos|
args.pit_pos = pit_pos
end
opts.on('-sMAXSCORE', '--max-score=MAXSCORE', Integer, 'The maximum score needed to win a run') do |max_score|
args.max_score = max_score
end
opts.on('-h', '--help', 'Prints this help') do
puts opts
exit
end
end
parser.parse!
# Initialize game
player_klass = args.player.constantize
begin
game = Game.new(
player_klass,
args.to_h.slice(:map_size, :player_pos, :cheese_pos, :pit_pos, :max_score),
)
# Run
game.start
args.runs.times do
game.run
game.reset
end
game.stop
rescue ArgumentError => e
puts "[ArgumentError] #{e.message}".red
rescue NotImplementedError => e
puts "[NotImplemeted] #{e.message}".red
end