Skip to content

Instantly share code, notes, and snippets.

@elikem
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save elikem/9557884 to your computer and use it in GitHub Desktop.

Select an option

Save elikem/9557884 to your computer and use it in GitHub Desktop.
create a board with all the cells you need
class Board
attr_reader :all_cells
def initialize
@all_cells = []
(0..99).each do |x|
(0..99).each do |y|
@all_cells << Cell.new(x, y)
end
end
end
end
@elikem
Copy link
Author

elikem commented Mar 14, 2014

find the neighbors of the ...it... cell

if cell.x_coord == x && cell.y_coord == x
(x - 1..x + 1).each do |i|
(y - 1..y + 1).each do |j|

          @another_arr << cell
        end
  end

Find the neighbors and sum their true states - 1.
The rules...

Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:
Any live cell with fewer than two live neighbours dies, as if caused by under-population.
Any live cell with two or three live neighbours lives on to the next generation.
Any live cell with more than three live neighbours dies, as if by overcrowding.
Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment