grid

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2025 License: MIT Imports: 0 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 {
	Alive bool
	Value int
}

Cell represents a single cell in the grid

type Grid

type Grid struct {
	Width  int
	Height int
	Cells  [][]Cell
}

Grid represents the cellular automaton grid

func NewGrid

func NewGrid(width, height int) *Grid

NewGrid creates a new grid with the specified dimensions

func (*Grid) Clear

func (g *Grid) Clear()

Clear resets all cells to empty

func (*Grid) Copy

func (g *Grid) Copy() *Grid

Copy creates a deep copy of the grid

func (*Grid) CountLiveNeighbors

func (g *Grid) CountLiveNeighbors(x, y int) int

CountLiveNeighbors counts the number of live neighbors for a cell

func (*Grid) Get

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

Get returns the cell at the specified coords

func (*Grid) IsAlive

func (g *Grid) IsAlive(x, y int) bool

IsAlive checks if the cell at the specified coords is alive

func (*Grid) Set

func (g *Grid) Set(x, y int, cell Cell)

Set sets the cell at the specified coords

func (*Grid) SetAlive

func (g *Grid) SetAlive(x, y int, alive bool)

SetAlive sets the alive status of the cell at the specified coords

func (*Grid) String

func (g *Grid) String() string

String returns a string representation of the grid

Jump to

Keyboard shortcuts

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