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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user