overpopulation rules

This commit is contained in:
Gator
2022-12-15 16:18:57 +01:00
parent c847e6c218
commit beab487429
5 changed files with 73 additions and 5 deletions

View File

@ -91,6 +91,17 @@ function conwayRules(cell, neighbors) {
return cell;
}
// variation on the game of life's rules,
// where the overpopulation rule is ignored
function overpopulationRules(cell, neighbors) {
// loneliness rule
if (cell === 1 && neighbors < 2) return 0;
// born when three live neighbors rule
if (cell === 0 && neighbors === 3) return 1;
// the cell remains the same if none apply
return cell;
}
// get the next evolution of a 2D CA initial state
// Rules : Moore neighborhood
function evolve2d(board, rulesFn) {
@ -148,6 +159,7 @@ export {
createBoard,
create1dStateOneCell,
conwayRules,
overpopulationRules,
evolve1d,
evolve2d,
};