Created
November 6, 2010 11:19
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sorry about that. This is a method for handling the ruleset for conway's game of life (GoL): http://en.wikipedia.org/wiki/Conway's_game_of_life
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
I'm a little lost on this - maybe a little more context is needed for me to understand what is going on.
My initial thought would be to change it into:
def tick(cell, number_of_neighbors)
cell.setAlive number_of_neighbors == 3 #pull out 3 into some meaningful name
end
But I don't understand what the tick method is for ... tick and setAlive don't go well for me. I might also pull the boolean expression out into its own method so it would read something like:
cell.setAlive ifCloseNeighbors
But in doing this, setAlive and ifCloseNeighbors don't meld well for me either.
I would like to hear other peoples interpretation.