Class: Lifelike::LifelikeCellularAutomaton::World
- Inherits:
-
Object
- Object
- Lifelike::LifelikeCellularAutomaton::World
- Defined in:
- lib/lifelike/lifelike_cellular_automaton/world.rb
Instance Attribute Summary collapse
-
#cell_grid ⇒ Object
readonly
Returns the value of attribute cell_grid.
Instance Method Summary collapse
-
#initialize(cell_grid) ⇒ World
constructor
A new instance of World.
- #tick(generations) ⇒ Object
- #tick_once ⇒ Object
Constructor Details
#initialize(cell_grid) ⇒ World
Returns a new instance of World.
5 6 7 |
# File 'lib/lifelike/lifelike_cellular_automaton/world.rb', line 5 def initialize(cell_grid) @cell_grid = cell_grid end |
Instance Attribute Details
#cell_grid ⇒ Object (readonly)
Returns the value of attribute cell_grid.
4 5 6 |
# File 'lib/lifelike/lifelike_cellular_automaton/world.rb', line 4 def cell_grid @cell_grid end |
Instance Method Details
#tick(generations) ⇒ Object
9 10 11 12 13 |
# File 'lib/lifelike/lifelike_cellular_automaton/world.rb', line 9 def tick(generations) (1..generations).reduce(self) do |world, _| world.tick_once end end |
#tick_once ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/lifelike/lifelike_cellular_automaton/world.rb', line 15 def tick_once self.class.new( @cell_grid.map_with_neighbors do |cell, neighbors| cell.tick(neighbors) end ) end |