Class: Grid
- Inherits:
-
Array
- Object
- Array
- Grid
- Defined in:
- lib/life/grid.rb
Instance Method Summary collapse
- #deep_copy ⇒ Object
-
#initialize(x, y, seed = []) ⇒ Grid
constructor
A new instance of Grid.
- #live_neighbor_count_for(x, y) ⇒ Object
Constructor Details
Instance Method Details
#deep_copy ⇒ Object
10 11 12 |
# File 'lib/life/grid.rb', line 10 def deep_copy Marshal.load(Marshal.dump(self)) end |
#live_neighbor_count_for(x, y) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/life/grid.rb', line 14 def live_neighbor_count_for(x, y) count = 0 x_range(x).each do |curr_x| y_range(y).each do |curr_y| unless (curr_x == x && curr_y == y) count += 1 if self[curr_x][curr_y].live? end end end count end |