Created
January 20, 2011 21:25
-
-
Save rdammkoehler/788712 to your computer and use it in GitHub Desktop.
This is a good compromise, even though it has redundancy, less DRY, more intent revealing.
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
public boolean willBeAliveInTheNextGeneration() { | |
return shouldLiveOnToNextGeneration() || shouldBeCreatedByReproduction(); | |
} | |
private boolean shouldLiveOnToNextGeneration() { | |
return cell.isAlive() && ( cellHasTwoNeighbors() || cellHasThreeNeighbors()); | |
} | |
private boolean shouldBeCreatedByReproduction() { | |
return cell.isDead() && cellHasThreeNeighbors(); | |
} | |
private boolean cellHasTwoNeighbors() { | |
return cell.numberOfLiveNeighbors == 2; | |
} | |
private boolean cellHasThreeNeighbors() { | |
return cell.numberOfLiveNeighbors == 3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment