Class: Gol
- Inherits:
-
Object
- Object
- Gol
- Defined in:
- lib/gol.rb
Constant Summary collapse
- GRID_SIZE =
16
- SPEED_LIMIT =
1
Instance Method Summary collapse
- #draw(grid) ⇒ Object
-
#initialize(grid_size: GRID_SIZE, speed_limit: SPEED_LIMIT) ⇒ Gol
constructor
A new instance of Gol.
Constructor Details
#initialize(grid_size: GRID_SIZE, speed_limit: SPEED_LIMIT) ⇒ Gol
Returns a new instance of Gol.
10 11 12 13 14 15 16 17 |
# File 'lib/gol.rb', line 10 def initialize(grid_size: GRID_SIZE, speed_limit: SPEED_LIMIT) grid = Grid.new(size: grid_size, speed: speed_limit) while(true) draw(grid) grid.iterate() end end |
Instance Method Details
#draw(grid) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/gol.rb', line 19 def draw(grid) puts "Generation: #{grid.generation}, Speed: #{grid.speed} (lower is faster), Stop with CTRL+C\n" grid.cells.each do |row| graph = row.map {|item| item.alive == true ? "X" : " "} p graph end end |