core

package
v0.0.0-...-32cbd93 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: Unlicense Imports: 3 Imported by: 0

Documentation

Index

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

func (bg *BaseGrid[T]) ComputeMaxDims() []int

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

func (bg *BaseGrid[T]) GetCellByHash(hash uint64) *Cell[T]

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

func (*Cell[T]) String

func (c *Cell[T]) String() string

useful for debugging

type CellSet

type CellSet[T comparable] map[uint64]*Cell[T]

Not quite a set

will only add an element if already does not exist

func (CellSet[T]) Add

func (s CellSet[T]) Add(k uint64, v *Cell[T])

type CellularAutomata

type CellularAutomata[T comparable] struct {
	Grid    *Grid[T]
	RuleSet RuleSet[T]
	Steps   int
}

func (*CellularAutomata[T]) Step

func (ca *CellularAutomata[T]) Step()

step not in parallel

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)

func (*CellularAutomata[T]) Stepp

func (ca *CellularAutomata[T]) Stepp()

step in parallel

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

func (*Grid[T]) New

func (g *Grid[T]) New() *Grid[T]

Return an empty grid with the same configuration as the one it comes from

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

Jump to

Keyboard shortcuts

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