grid

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: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinWidth is the minimum width for a grid.
	MinWidth = 3
	// MinHeight is the minimum height for a grid.
	MinHeight = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Grid

type Grid struct {
	// contains filtered or unexported fields
}

Grid represents a snapshot of a universe. The zero value of this type is not safe, use the function New below. The minimum width and height for a universe is 3 cells each.

func New

func New(width, height int, alives []conway.Coord) (*Grid, error)

New creates a new grid with the given width and height (number of cells) and the given list of alive cells. The grid has its origin of coordinates at the upper left corner. Returns an error if the width or the height are smaller than MinWidth and MinHeight or if any of the alive cells are out of bounds.

func NewRandom

func NewRandom(w, h, n int) *Grid

NewRandom returns a grid with n random alive cells inside a grid with the given dimensions.

func (*Grid) Height

func (g *Grid) Height() int

Height returns the height of the universe (number of cells). Implements conway.Grid.

func (*Grid) IsAlive

func (g *Grid) IsAlive(c conway.Coord) (bool, error)

IsAlive returns if the cell at coordinates c is alive. Returns an error if c is out of bounds. Implements conway.Grid.

func (*Grid) Width

func (g *Grid) Width() int

Width returns the width of the universe (number of cells). Implements conway.Grid.

Jump to

Keyboard shortcuts

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