high life rule

This commit is contained in:
2022-12-18 13:50:21 +01:00
parent 6c72a497c7
commit e03f7db3ba
3 changed files with 24 additions and 0 deletions

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,
};