A Go module implementation of Conway's Game of Life.
A Go module implementation of Conway's Game of Life.
A demo can be found at https://vergol.vercel.app.
1. First you need to create a new instance of the GameOfLife
structure and put a Size
into it to describe the dimensions of the game:
gol "github.com/stefma/go-l"
func main() {
gameOfLife := gol.NewGameOfLife(gol.Size(10))
}
1.1 Additionally, you can use a custom generator
function to create the game Cell
s yourself:
gameOfLife := gol.NewGameOfLifeWithGenerator(
gol.Size(10),
func(x, y int) gol.Cell { /* Custom logic here */ },
)
2.0 Get the current game board by calling gameOfLife.GameBoard
and render it somewhere:
var gameBoard [][]Cell = gameOfLife.GameBoard
3.0 To update the Cell
s to the next evolution call Next()
:
gameOfLife.Next()
4.0 Repeat steps 2 and 3 🙃
One consumer of this module is Vergol, also part of this repository.