life

package
v0.0.0-...-93f9cd5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package life manages the "game" state Shamelessly taken from https://golang.org/doc/play/life.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Grid

type Grid struct {
	Cells [][]bool
	// contains filtered or unexported fields
}

Shamelessly taken/inspired by https://golang.org/doc/play/life.go Grid is the structure in which the cellular automota live

func NewGrid

func NewGrid(h, size int) *Grid

NewGrid constructs a new Grid

func (*Grid) Alive

func (g *Grid) Alive(x, y int) bool

Alive returns whether the specified position is alive

func (*Grid) Draw

func (g *Grid) Draw(imd *imdraw.IMDraw)

Draw draws the grid

func (*Grid) Next

func (g *Grid) Next(x, y int) bool

Next returns the next state

func (*Grid) Set

func (g *Grid) Set(x, y int, state bool)

Set sets the state of a specific location

type Life

type Life struct {
	A *Grid
	// contains filtered or unexported fields
}

Life stores the state of a round of Conway's Game of Life.

func NewLife

func NewLife(h, size int) *Life

NewLife returns a new Life game state with a random initial state.

func (*Life) Step

func (l *Life) Step()

Step advances the game by one instant, recomputing and updating all cells.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL