Skip to content

Instantly share code, notes, and snippets.

@coreyhaines
Created November 6, 2010 11:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save coreyhaines/665346 to your computer and use it in GitHub Desktop.
Save coreyhaines/665346 to your computer and use it in GitHub Desktop.
Can you spot all the SRP violations? Can you spot the abstractions that are screaming to come out? There's at least one OCP violation, too.
def tick(cell, number_of_neighbors)
if number_of_neighbors < 2 || number_of_neighbors > 3
cell.setAlive false
end
if number_of_neighbors == 3
cell.setAlive true
end
end
@JonKernPA
Copy link

context? shoot, that makes it too easy .

Essentially, this code is invoked for each "tick" of the clock to see what the next "generation" looks like for each cell.

You can see my first (well, second) Game of Life code -- and you can run it locally to watch each tick: https://github.com/JonKernPA/gol-2

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