world

package
v0.0.0-...-e42dab0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	Color tcell.Color
}

func Random

func Random() *Cell

Random creates a new Cell with random color

type World

type World [][]*Cell

World is a two-dimensional array of cells

func New

func New(rows, cols int) World

New allocates a World with size specified by rows and columns

func (World) Draw

func (w World) Draw(s tcell.Screen)

Draw draws the state of the board to the screen.

func (World) Get

func (w World) Get(x, y int) *Cell

Get returns the cell at its Row and Column.

Out-of-bounds coordinates are wrapped.

If the cell is dead, nil is returned.

func (World) Neighbors

func (w World) Neighbors(x, y int) (count int, average tcell.Color)

Neighbors counts the live cells in the Moore neighborhood of the specified coordinate. The average color of surrounding live cells is also computed.

If there are no live cells, tcell.ColorDefault is used as the average color.

func (World) Next

func (w World) Next() World

Next computes the next generation according to the rules of the Game of Life according to John Conway

func (World) Randomize

func (w World) Randomize()

Randomize resets the world with random cells of random colors.

func (World) Size

func (w World) Size() (rows int, cols int)

Size returns the rows and columns of the world

Jump to

Keyboard shortcuts

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