overpopulation rules
This commit is contained in:
@ -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,
|
||||
};
|
||||
|
||||
@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user