Last active
March 2, 2019 07:58
-
-
Save mvodep/4bd3b4685a77a426cdd1 to your computer and use it in GitHub Desktop.
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
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