Game of life algo
Note: See example here
<script src="https://cdn.jsdelivr.net/gh/yoannchb-pro/game-of-life/index.min.js"></script>
There are two arguments nbCelssWidth
and nbCellsHeight
(by default 50 and 50) for the number of cells you want on the width and on the height
const handler = new GameOfLife(3, 3);
console.log(handler.game);
//[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
There is one argument factor
(by default 0.2) between 0 and 1 that determine the probability of a cell to be alive
handler.randomGeneration();
//[[0, 0, 1], [1, 0, 1], [1, 0, 0]]
Evoluate the environment
//[[0, 1, 0], [0, 1, 0], [0, 1, 0]]
handler.evoluate();
//[[0, 0, 0], [1, 1, 1], [0, 0, 0]]
There are two arguments line
and column
handler.hydratate(1, 2);
//[[0, 0, 0], [0, 0, 1], [0, 0, 0]]
There are two arguments line
and column
//[[0, 0, 0], [0, 0, 1], [0, 0, 0]]
handler.deshydratate(1, 2);
//[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
Clear the whole environment
//[[0, 1, 0], [0, 1, 0], [0, 1, 0]]
handler.clear();
//[[0, 0, 0], [0, 0, 0], [0, 0, 0]]