conway

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2018 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package conway defines interfaces to generate animations of the Conway's game of life.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoordEqual

func CoordEqual(a, b Coord) bool

CoordEqual returns if two coordinates refer to the same cell.

func TestCoord

func TestCoord(t *testing.T, c Coord, x, y int)

TestCoord is a test helper that checks if the coordinate c has x and y as its components.

Types

type Animator

type Animator interface {
	// Add adds a grid to the collection to be used as a photogram in the animate method.
	Add(Grid) error
	// Encode creates an animation of all the added photograms and store it in
	// the given writer.
	Encode(w io.Writer) error
}

Animator represents a collection of grids that can be rendered in a graphical format and stored in a file.

type Coord

type Coord interface {
	// X returns the cell's abscissa.
	X() int
	// Y returns the cell's ordinate.
	Y() int
}

Coord represents the position of a cell in a grid.

type Grid

type Grid interface {
	// Width returns the width of the universe (number of cells).
	Width() int
	// Height returns the height of the universe (number of cells).
	Height() int
	// IsAlive returns if the cell at coordinates x, y is alive.
	// Returns an error if x or y are out of bounds.
	IsAlive(Coord) (bool, error)
}

Grid represents an inmutable snapshot of a universe.

type Universe

type Universe interface {
	// Status returns the current status of the universe as a grid.
	Status() Grid
	// Tick makes the universe evolve a single round (a tick).
	Tick() error
}

Universe is a collection of cells that evolves over time.

Jump to

Keyboard shortcuts

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