Skip to content

Instantly share code, notes, and snippets.

@rdammkoehler
Created January 20, 2011 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdammkoehler/788712 to your computer and use it in GitHub Desktop.
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.
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