Class: Golr::Game
- Inherits:
-
Object
- Object
- Golr::Game
- Defined in:
- lib/golr/game.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#grid ⇒ Object
readonly
Returns the value of attribute grid.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #alive?(key) ⇒ Boolean
- #evolve ⇒ Object
-
#initialize(columns, rows, living_cells = []) ⇒ Game
constructor
A new instance of Game.
Constructor Details
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/golr/game.rb', line 4 def columns @columns end |
#grid ⇒ Object (readonly)
Returns the value of attribute grid.
4 5 6 |
# File 'lib/golr/game.rb', line 4 def grid @grid end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
4 5 6 |
# File 'lib/golr/game.rb', line 4 def rows @rows end |
Instance Method Details
#alive?(key) ⇒ Boolean
33 34 35 |
# File 'lib/golr/game.rb', line 33 def alive?(key) @grid[key] == true end |
#evolve ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/golr/game.rb', line 24 def evolve next_grid = init_grid @grid.each_key do |key| next_grid[key] = @rules.evaluate(living_neighbors(key), alive?(key)) end @grid = next_grid self end |