Skip to content

Instantly share code, notes, and snippets.

@mvodep
Last active March 2, 2019 07:58
Show Gist options
  • Save mvodep/4bd3b4685a77a426cdd1 to your computer and use it in GitHub Desktop.
Save mvodep/4bd3b4685a77a426cdd1 to your computer and use it in GitHub Desktop.
currentEvolutionBoard.ForAllCells(
(cell, nextEvolutionBoard) =>
{
// Any live cell with fewer than two live neighbours dies, as if caused by under-population.
if (cell.IsAlive() && cell.AmountOfNeighbours() < 2)
{
nextEvolutionBoard.CopyCellFromTemplate(cell).Dies();
}
// Any live cell with two or three live neighbours lives on to the next generation.
if (cell.IsAlive() && (cell.AmountOfNeighbours() == 2 || cell.AmountOfNeighbours() == 3))
{
nextEvolutionBoard.CopyCellFromTemplate(cell);
}
// Any live cell with more than three live neighbours dies, as if by over-population.
if (cell.IsAlive() && cell.AmountOfNeighbours() > 3)
{
nextEvolutionBoard.CopyCellFromTemplate(cell).Dies();
}
// Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
if (cell.IsDead() && cell.AmountOfNeighbours() == 3)
{
nextEvolutionBoard.CopyCellFromTemplate(cell).Reproduction();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment