high life rule

This commit is contained in:
Ali Gator 2022-12-18 13:50:21 +01:00
parent bce0f39aff
commit 61846b88a5
3 changed files with 24 additions and 0 deletions

View File

@ -24,6 +24,7 @@
overpopulationRules,
lonelinessRules,
threebornRules,
highLifeRules,
evolve2d,
} from "../modules/automata.js";
import { getRandomInt, sleep } from "../modules/common.js";
@ -42,6 +43,7 @@
overpopulation: overpopulationRules,
loneliness: lonelinessRules,
threeborn: threebornRules,
highlife: highLifeRules,
},
};
},

View File

@ -91,6 +91,21 @@ function conwayRules(cell, neighbors) {
return cell;
}
// variation of the game of life where a
// cell comes to live if 6 neigbor cells are alive
function highLifeRules(cell, neighbors) {
// loneliness rule
if (cell === 1 && neighbors < 2) return 0;
// overpopulation rule
if (cell === 1 && neighbors > 3) return 0;
// born when three live neighbors rule
if (cell === 0 && neighbors === 2) return 1;
// highlife rules
if ((cell === 0 && neighbors === 3) || neighbors === 6) return 1;
// the cell remains the same if none apply
return cell;
}
// variation on the game of life's rules,
// where the "three live neighbors" rule is ignored
function threebornRules(cell, neighbors) {
@ -184,6 +199,7 @@ export {
overpopulationRules,
lonelinessRules,
threebornRules,
highLifeRules,
evolve1d,
evolve2d,
};

View File

@ -116,6 +116,12 @@ const preset2dRules = [
description:
"Variation on Conway's Game of Life *without* the 'three live neighbors' rule",
},
{
id: "highlife",
name: "HighLife variation",
description:
"Variation on Conway's Game of Life where a cell live if the six neighbor cells are alive",
},
];
export { presetRuleset, initialStates, preset2dRules };