update last board, new rules

This commit is contained in:
2022-12-15 21:24:17 +01:00
parent 81b9320452
commit 90e81c661e
3 changed files with 46 additions and 4 deletions

View File

@ -91,6 +91,28 @@ function conwayRules(cell, neighbors) {
return cell;
}
// variation on the game of life's rules,
// where the "three live neighbors" rule is ignored
function threebornRules(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
return cell;
}
// variation on the game of life's rules,
// where the loneliness rule is ignored
function lonelinessRules(cell, neighbors) {
// overpopulation rule
if (cell === 1 && neighbors > 3) 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;
}
// variation on the game of life's rules,
// where the overpopulation rule is ignored
function overpopulationRules(cell, neighbors) {
@ -160,6 +182,8 @@ export {
create1dStateOneCell,
conwayRules,
overpopulationRules,
lonelinessRules,
threebornRules,
evolve1d,
evolve2d,
};