Class: World
- Inherits:
-
Object
- Object
- World
- Defined in:
- lib/life/world.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
Instance Method Summary collapse
-
#initialize(x, y, seed = []) ⇒ World
constructor
A new instance of World.
- #tick ⇒ Object
- #to_s(live, dead) ⇒ Object
Constructor Details
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
3 4 5 |
# File 'lib/life/world.rb', line 3 def current @current end |
Instance Method Details
#tick ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/life/world.rb', line 10 def tick current.each do |row| x = current.index(row) row.each do |cell| y = row.index(cell) if cell.live? case @current.live_neighbor_count_for(x,y) when 0..1 then @next[x][y].kill when 2..3 then @next[x][y].live when 4..8 then @next[x][y].kill end elsif cell.dead? && @current.live_neighbor_count_for(x,y) == 3 @next[x][y].live end end end @current = @next.deep_copy end |
#to_s(live, dead) ⇒ Object
29 30 31 |
# File 'lib/life/world.rb', line 29 def to_s(live, dead) @current.to_s(live, dead) end |