using yarn:
yarn add gameoflife.js
using npm:
npm i gameoflife.js
import { GameOfLife } from "gameoflife.js"
const initialCell = [
{
width: 1,
height: 0,
},
{
width: 2,
height: 1,
},
{
width: 0,
height: 2,
},
{
width: 1,
height: 2,
},
{
width: 2,
height: 2,
},
]
const game = new GameOfLife({ width: 5, height: 10, initialCell })
Input
game.cells
Output:
[
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[1, 1, 1, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
]
Input
game.next()
Output:
[
[0, 0, 0, 0, 0],
[1, 0, 1, 0, 0],
[0, 1, 1, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
]
input
game.add([{ width: 0, height: 0 }])
output
[
[1 /* added */, 0, 0, 0, 0],
[1, 0, 1, 0, 0],
[0, 1, 1, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
]
input
game.remove([{ width: 0, height: 0 }])
output
[
[0 /* removed */, 0, 0, 0, 0],
[1, 0, 1, 0, 0],
[0, 1, 1, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
]
input
game.toogle([{ width: 0, height: 0 }])
output
[
[1 /* become 1 */, 0, 0, 0, 0],
[1, 0, 1, 0, 0],
[0, 1, 1, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
]