cella

package module
v0.0.0-...-1189363 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 2 Imported by: 0

README

Cella

Simple cellular automaton library

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualsGrid

func EqualsGrid(a, b *Grid) bool

Compare two grids

Types

type Cell

type Cell uint8

Cell is a cell in the grid defined as a uint8

type Cella2d

type Cella2d struct {
	InitGrid      *Grid     // Initial grid
	NextGrid      *Grid     // Next grid
	Width         int       // Width of the grid
	Height        int       // Height of the grid
	Rules         []*Rule2d // Rules of the automaton
	NumStates     int       // Number of states of the automaton
	States        []Cell    // States of the automaton
	CellsPerState []int     // Number of cells per state
	Generation    int       // Generation of the automaton
}

Cellular Automaton 2D. Currently only supports 3x3 neighbourhoods.

func NewCella2d

func NewCella2d(Width, Height, numStates int) *Cella2d

NewCella2d creates a new cellular automaton 2D

func (*Cella2d) CountCellsPerState

func (c *Cella2d) CountCellsPerState()

CountCellsPerState counts the number of cells per state of the automaton using the initial grid

func (*Cella2d) GetCellsPerState

func (c *Cella2d) GetCellsPerState() []int

GetCellsPerState gets the number of cells per state of the automaton

func (*Cella2d) GetGeneration

func (c *Cella2d) GetGeneration() int

GetGeneration gets the generation of the automaton

func (*Cella2d) GetInitGrid

func (c *Cella2d) GetInitGrid() *Grid

GetInitGrid gets the initial grid of the automaton

func (*Cella2d) GetNextGrid

func (c *Cella2d) GetNextGrid() *Grid

GetNextGrid gets the next grid of the automaton

func (*Cella2d) GetRules

func (c *Cella2d) GetRules() []*Rule2d

GetRules gets the rules of the automaton

func (*Cella2d) GetStates

func (c *Cella2d) GetStates() []Cell

GetStates gets the states of the automaton

func (*Cella2d) NextGeneration

func (c *Cella2d) NextGeneration() error

NextGeneration calculates the next generation of the automaton using the initial grid and the next grid

func (*Cella2d) SetAuxBordersAsToroidal

func (c *Cella2d) SetAuxBordersAsToroidal()

SetAuxBordersAsToroidal sets auxiliar borders with values as if the Grid of cells had a toroidal shape

func (*Cella2d) SetCellsPerState

func (c *Cella2d) SetCellsPerState(cps []int)

SetCellsPerState sets the number of cells per state of the automaton

func (*Cella2d) SetGeneration

func (c *Cella2d) SetGeneration(g int)

SetGeneration sets the generation of the automaton

func (*Cella2d) SetInitGrid

func (c *Cella2d) SetInitGrid(g *Grid)

SetInitGrid sets the initial grid of the automaton

func (*Cella2d) SetNextGrid

func (c *Cella2d) SetNextGrid(g *Grid)

SetNextGrid sets the next grid of the automaton

func (*Cella2d) SetRules

func (c *Cella2d) SetRules(r []*Rule2d)

SetRules sets the rules of the automaton

func (*Cella2d) SetStates

func (c *Cella2d) SetStates(numStates int)

SetStates sets the states of the automaton

type Grid

type Grid struct {
	Width     int      // Width of the grid
	Height    int      // Height of the grid
	Cells     [][]Cell // Cells of the grid
	WholeGrid [][]Cell // Cells of the grid with auxiliar borders
}

Grid is a grid of cells

func NewGrid

func NewGrid(Width, Height int) *Grid

NewGrid creates a new grid

func (*Grid) GetAuxBorderDown

func (g *Grid) GetAuxBorderDown() []Cell

GetAuxBorderDown gets a down auxiliar border of the grid used for the evaluation of the rules

func (*Grid) GetAuxBorderLeft

func (g *Grid) GetAuxBorderLeft() []Cell

GetAuxBorderLeft gets a left auxiliar border of the grid used for the evaluation of the rules

func (*Grid) GetAuxBorderRight

func (g *Grid) GetAuxBorderRight() []Cell

GetAuxBorderRigth gets a rigth auxiliar border of the grid used for the evaluation of the rules

func (*Grid) GetAuxBorderUp

func (g *Grid) GetAuxBorderUp() []Cell

GetAuxBorderUp gets a up auxiliar border of the grid used for the evaluation of the rules

func (*Grid) GetCell

func (g *Grid) GetCell(x, y int) Cell

Get gets a cell state in the grid

func (*Grid) GetNeighbourhood

func (g *Grid) GetNeighbourhood(x, y int, neighbours [][]Cell)

GetNeighbours gets the neighbours of a cell and copies them to the neighbours grid

func (*Grid) SetAuxBorderDown

func (g *Grid) SetAuxBorderDown(bd []Cell)

SetAuxBorderDown sets a down auxiliar border of the grid used for the evaluation of the rules

func (*Grid) SetAuxBorderLeft

func (g *Grid) SetAuxBorderLeft(bl []Cell)

SetAuxBorderLeft sets a left auxiliar border of the grid used for the evaluation of the rules

func (*Grid) SetAuxBorderRight

func (g *Grid) SetAuxBorderRight(br []Cell)

SetAuxBorderRigth sets a rigth auxiliar border of the grid used for the evaluation of the rules

func (*Grid) SetAuxBorderUp

func (g *Grid) SetAuxBorderUp(bu []Cell)

SetAuxBorderUp sets a up auxiliar border of the grid used for the evaluation of the rules

func (*Grid) SetCell

func (g *Grid) SetCell(x, y int, c Cell)

Set sets a cell state in the grid

type Rule2d

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

Rule2d conditions for a cell to change state. Only neighbourhoods of 3x3 are currently supported

func NewRule2d

func NewRule2d(condition string, state Cell, numStates int) *Rule2d

New creates a new rule by setting the condition and the state that the cell will change to if the condition is true

func (*Rule2d) CheckCondition

func (r *Rule2d) CheckCondition() (bool, error)

CheckCondition checks if the condition is true

func (*Rule2d) GetCondition

func (r *Rule2d) GetCondition() string

GetCondition returns the condition used to change the state

func (*Rule2d) GetState

func (r *Rule2d) GetState() Cell

GetState returns the state that the cell will change to if the condition is true

func (*Rule2d) SetNeighbourhood

func (r *Rule2d) SetNeighbourhood(neighbours [][]Cell)

SetNeighbourhood sets the neighbourhood used in the condition

Jump to

Keyboard shortcuts

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