Go implementation of Conway's Game of Life. Possible to use as library or cli.
Get latest version
go get github.com/easy-death/game-of-life-go
Import
import (
gameoflife "github.com/easy-death/game-of-life-go"
)
Library works in two modes: "time machine" and observer.
Returns state after given time delay or ticks count:
engine := gameoflife.NewEngine()
state := gameoflife.State{
gameoflife.StateRow{false, true, false},
gameoflife.StateRow{false, true, false},
gameoflife.StateRow{false, true, false},
}
engine.SetInitialState(state)
newState, err := engine.GetStateAfterTicks(10)
engine.Config.TicksPerSecond = 15
engine.GetStateAfterSeconds(10)
State can be listened by multiple listeners with desired frequency:
channel, err := engine.ListenState(context.Background())
if err == nil {
for state := range channel {
// ...
}
}
Navigate into cmd/gameoflife
, exec go build
, and you can call it with ./gameoflife
. Be aware that table is filled randomly,
restart to check how other state will look.
Console app which will print 2 dimensional array of bools which will follow Conway's Game of life
Usage:
gameoflife [flags]
Flags:
--columns uint How many columns in matrix (default 10)
-h, --help help for gameoflife
--rows uint How many rows in matrix (default 10)