Documentation ¶
Index ¶
- func NewSparseCellGrid[T comparable]() *sparseCellGrid[T]
- type BaseGrid
- func (bg *BaseGrid[T]) AllCoordinates(dims []int) []Coordinate
- func (bg *BaseGrid[T]) CheckIntegrity()
- func (bg *BaseGrid[T]) ComputeMaxDims() []int
- func (bg *BaseGrid[T]) GetCell(coordinate Coordinate) *Cell[T]
- func (bg *BaseGrid[T]) GetCellByHash(hash uint64) *Cell[T]
- func (bg *BaseGrid[T]) SetCell(state T, coordinate Coordinate)
- func (bg *BaseGrid[T]) SetConfig(cfg []Coordinate, state T)
- type Cell
- type CellSet
- type CellularAutomata
- type Coordinate
- type GetNeighborsFunc
- type Grid
- type RuleSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSparseCellGrid ¶
func NewSparseCellGrid[T comparable]() *sparseCellGrid[T]
Types ¶
type BaseGrid ¶
type BaseGrid[T comparable] struct { // a list of dimension sizes // i.e for a 4x4 grid, dimensions = []int{4,4} // // note that you do not necessarily have to specify these // instead, max dims can be calculated via ComputeMaxDims() // these can be used to determine grid sizes // // however, if you want to use a finite grid size and handle boundary conditions // specifing the max dimensions will likely be better Dimensions []int Cells *sparseCellGrid[T] // must specify default state to work with sparse grids. // the default state is the one that is not stored in the map DefaultState T }
func (*BaseGrid[T]) AllCoordinates ¶
func (bg *BaseGrid[T]) AllCoordinates(dims []int) []Coordinate
pass in a list of dimensions
if the list is nil, use the dimensions specified in BaseGrid
this will probably not work with hexagonal grid systems because of negative coordinates
func (*BaseGrid[T]) CheckIntegrity ¶
func (bg *BaseGrid[T]) CheckIntegrity()
ensure that each cell coordinate's hash is assigned properly to the key
func (*BaseGrid[T]) ComputeMaxDims ¶
get the maximum value along each axis in the grid (in parallel)
can be used to dynamically size output drawings
func (*BaseGrid[T]) GetCell ¶
func (bg *BaseGrid[T]) GetCell(coordinate Coordinate) *Cell[T]
If the coordinate exists in the map, return it
otherwise return a cell with the base state
func (*BaseGrid[T]) GetCellByHash ¶
get the cell by hash
ONLY works for existing hashes Will panic if the hash is not in the map
func (*BaseGrid[T]) SetCell ¶
func (bg *BaseGrid[T]) SetCell(state T, coordinate Coordinate)
if the state is the default state, delete the coordinate from the map
otherwise add it to the map
func (*BaseGrid[T]) SetConfig ¶
func (bg *BaseGrid[T]) SetConfig(cfg []Coordinate, state T)
set a list of coordinates to the passed state
type Cell ¶
type Cell[T comparable] struct { State T Coordinate Coordinate }
a cell has a state of type T
type CellSet ¶
type CellSet[T comparable] map[uint64]*Cell[T]
Not quite a set
will only add an element if already does not exist
type CellularAutomata ¶
type CellularAutomata[T comparable] struct { Grid *Grid[T] RuleSet RuleSet[T] Steps int }
func (*CellularAutomata[T]) StepHead ¶
func (ca *CellularAutomata[T]) StepHead(coordinate Coordinate) Coordinate
apply the ruleset only at the passed coordinate
returns the coordinate of where the next cell goes
this is used to implement random walks (since we only keep track of the most recent coordinate)
type Coordinate ¶
type Coordinate []int
an n-dimensional coordinate on the grid
func (Coordinate) String ¶
func (c Coordinate) String() string
type GetNeighborsFunc ¶
type GetNeighborsFunc func(coord Coordinate) []Coordinate
return all the neighbors of a coordinate
type Grid ¶
type Grid[T comparable] struct { *BaseGrid[T] GetNeighborCoordinates GetNeighborsFunc }
a grid is a set of organized cells with a "geometry" (i.e. a way to get neighbors)
func (*Grid[T]) GetNeighbors ¶
func (g *Grid[T]) GetNeighbors(coord Coordinate) []*Cell[T]
Use the neighbor geometry function to get the cell neighbors
type RuleSet ¶
type RuleSet[T comparable] func(cell *Cell[T], neighbors []*Cell[T]) *Cell[T]
A Ruleset is a set of rules and a way of knowing which one to apply
Technically, this should be a list of functions, but often it is much simpler to encapsulate checking criteria and output into a single function