high life rule
This commit is contained in:
parent
bce0f39aff
commit
61846b88a5
@ -24,6 +24,7 @@
|
|||||||
overpopulationRules,
|
overpopulationRules,
|
||||||
lonelinessRules,
|
lonelinessRules,
|
||||||
threebornRules,
|
threebornRules,
|
||||||
|
highLifeRules,
|
||||||
evolve2d,
|
evolve2d,
|
||||||
} from "../modules/automata.js";
|
} from "../modules/automata.js";
|
||||||
import { getRandomInt, sleep } from "../modules/common.js";
|
import { getRandomInt, sleep } from "../modules/common.js";
|
||||||
@ -42,6 +43,7 @@
|
|||||||
overpopulation: overpopulationRules,
|
overpopulation: overpopulationRules,
|
||||||
loneliness: lonelinessRules,
|
loneliness: lonelinessRules,
|
||||||
threeborn: threebornRules,
|
threeborn: threebornRules,
|
||||||
|
highlife: highLifeRules,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -91,6 +91,21 @@ function conwayRules(cell, neighbors) {
|
|||||||
return cell;
|
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,
|
// variation on the game of life's rules,
|
||||||
// where the "three live neighbors" rule is ignored
|
// where the "three live neighbors" rule is ignored
|
||||||
function threebornRules(cell, neighbors) {
|
function threebornRules(cell, neighbors) {
|
||||||
@ -184,6 +199,7 @@ export {
|
|||||||
overpopulationRules,
|
overpopulationRules,
|
||||||
lonelinessRules,
|
lonelinessRules,
|
||||||
threebornRules,
|
threebornRules,
|
||||||
|
highLifeRules,
|
||||||
evolve1d,
|
evolve1d,
|
||||||
evolve2d,
|
evolve2d,
|
||||||
};
|
};
|
||||||
|
@ -116,6 +116,12 @@ const preset2dRules = [
|
|||||||
description:
|
description:
|
||||||
"Variation on Conway's Game of Life *without* the 'three live neighbors' rule",
|
"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 };
|
export { presetRuleset, initialStates, preset2dRules };
|
||||||
|
Loading…
Reference in New Issue
Block a user