overpopulation rules

This commit is contained in:
2022-12-15 16:18:57 +01:00
parent 8cf9252779
commit 81b9320452
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,
};

View File

@ -92,4 +92,18 @@ const initialStates = [
},
];
export { presetRuleset, initialStates };
const preset2dRules = [
{
id: "conway",
name: "Conway's Game of Life",
description: "The most popular 2d automata",
},
{
id: "overpopulation",
name: "Overpopulation variation",
description:
"Variation on Conway's Game of Life *without* the overpopulation rule",
},
];
export { presetRuleset, initialStates, preset2dRules };