Skip to content

easy-death/game-of-life-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

game-of-life-go

Go Reference Go Report Card Release

Go implementation of Conway's Game of Life. Possible to use as library or cli.

Installation

Get latest version

go get github.com/easy-death/game-of-life-go

Import

import (
  gameoflife "github.com/easy-death/game-of-life-go"
)

Usage

Library works in two modes: "time machine" and observer.

Time machine

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)

Observer

State can be listened by multiple listeners with desired frequency:

channel, err := engine.ListenState(context.Background())
if err == nil {
  for state := range channel {
    // ...
  }
}

Cli usage

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)

About

Go implementation of Conway's Game of Life

Resources

License

Stars

Watchers

Forks

Languages