Class: Threesmodel::BaseGameAutomation
- Inherits:
-
Object
- Object
- Threesmodel::BaseGameAutomation
show all
- Defined in:
- lib/threesmodel.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BaseGameAutomation.
21
22
23
24
25
26
27
28
|
# File 'lib/threesmodel.rb', line 21
def initialize
@game_controller = Threesmodel::GameController.new
@game_board_folder = GameBoardFolder.new
@score_calculator = ScoreCalculator.new
@scores = []
@highest_cell_value_histogram = { c3: 0, c6: 0, c12: 0, c24: 0, c48: 0, c96: 0, c192: 0, c384: 0, c768: 0, c1536: 0, c3072: 0, c6144:0}
@best_game = nil
end
|
Instance Method Details
#play ⇒ Object
30
31
32
|
# File 'lib/threesmodel.rb', line 30
def play;
raise 'Method missing - please implement "play" method.';
end
|
#play_many(times = 100) ⇒ Object
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
|
# File 'lib/threesmodel.rb', line 38
def play_many(times=100)
max_score = 0
iteration = 1
times.times do
@game = @game_controller.start_new_game
score = play
if score > max_score then
max_score = score
@best_game = @game[:game]
end
@scores << score
print "." if iteration % 1000 == 0
update_highest_value_histogram(@game[:game])
end
puts "Done!"
puts max_score
puts @highest_cell_value_histogram
File.open(score_filename, "w+") do |f|
f.puts(@scores)
end
puts "Best game is:"
puts @best_game
end
|
#score_filename ⇒ Object
34
35
36
|
# File 'lib/threesmodel.rb', line 34
def score_filename
self.class.name + ".txt"
end
|
#update_highest_value_histogram(game_board) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/threesmodel.rb', line 64
def update_highest_value_histogram(game_board)
highest_cell_value = 0
game_board.each { |val|
highest_cell_value = val if val > highest_cell_value
}
key = ("c" + highest_cell_value.to_s).to_sym
@highest_cell_value_histogram[key] += 1
end
|