-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.rb
executable file
·69 lines (56 loc) · 1.5 KB
/
test.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
#!/usr/bin/env ruby
require_relative 'window'
require_relative 'reference_game'
srand(42)
class Main
def run
@fields = random_field(30, 0.5)
@fields_cloned = @fields.map { |arr| arr.clone }
window = Window.new
game = load_game(ENV['GAME_PATH'])
reference_game = ReferenceGame.new(@fields_cloned)
game_loop(window, game, reference_game)
end
def game_loop(window, game, reference_game)
100.times do
compare_games(window, game, reference_game)
game.tick
reference_game.tick
end
puts 'All went well (probably), congrats!'
end
def compare_games(window, game, reference_game)
start_compare_loop(window, game, reference_game) if game.fields != reference_game.fields
end
def start_compare_loop(window, game, reference_game)
show_reference_game = true
loop do
if show_reference_game
print_game('Reference Game', reference_game, window)
else
print_game('Your Implementation', game, window)
end
show_reference_game = !show_reference_game
end
window.print(game)
end
def print_game(game_name, game_to_print, window)
window.print(game_to_print)
puts ''
puts game_name
puts ''
puts 'Press <enter> to continue'
gets
end
def load_game(path)
real_game(path)
end
def real_game(path)
require_relative(path)
Game.new(@fields)
end
def random_field(size, alive_ratio)
size.times.to_a.map { size.times.to_a.map { rand < alive_ratio } }
end
end
Main.new.run