Class: GameOfLife::Game
- Inherits:
-
Object
- Object
- GameOfLife::Game
- Defined in:
- lib/game_of_life/game.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
the Game Board.
Instance Method Summary collapse
-
#seed(formatted_input) ⇒ Object
Takes the formatted input data and seeds the Board with it.
-
#tick ⇒ Object
The event by which the board transitions from the current to the next generation/state.
Instance Attribute Details
#board ⇒ Object (readonly)
the Game Board
4 5 6 |
# File 'lib/game_of_life/game.rb', line 4 def board @board end |
Instance Method Details
#seed(formatted_input) ⇒ Object
Takes the formatted input data and seeds the Board with it
13 14 15 |
# File 'lib/game_of_life/game.rb', line 13 def seed(formatted_input) @board = Board.new(formatted_input) end |
#tick ⇒ Object
The event by which the board transitions from the current to the next generation/state. There are three stages in the process:
-
reformat the board: Each tick can make the neighboring dead cells (which are not technically in the board now) cells alive. So reformat the board to add a new row at the top and bottom an a column at the left and right (all dead cells)
-
mark and sweep for the next generation
-
shed the dead weight: In stage 1, we added a layer of dead cells around the current board. If the whole layer is still dead, just remove it as we don’t want to keep adding layers of dead weight on every tick.
27 28 29 30 31 |
# File 'lib/game_of_life/game.rb', line 27 def tick @board.reformat_for_next_generation! @board.mark_and_sweep_for_next_generation! @board.shed_dead_weight! end |