cellauto

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: MIT Imports: 4 Imported by: 0

README

Cell Auto

Cellular automaton library.

Go Reference

Documentation

Overview

Package cellauto provide a cellular automaton implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

type Game struct {
	Rule Rule
	Grid *Grid
	// contains filtered or unexported fields
}

Game is a cellular automaton game.

func (*Game) Step

func (g *Game) Step()

Step runs the Game for 1 step.

type Grid

type Grid struct {
	Size    Point
	Squares []uint8
}

Grid is a grid of squares with multiple states.

By convention, the X-axis goes from left to right, and the Y-axis goes from top to bottom.

func NewGrid

func NewGrid(size Point) *Grid

NewGrid creates a new Grid.

func (*Grid) Contains

func (g *Grid) Contains(p Point) bool

Contains returns true if the Grid contains the Point, and false otherwise.

func (*Grid) Get

func (g *Grid) Get(p Point) uint8

Get returns the value of a Point.

func (*Grid) Neighbors

func (g *Grid) Neighbors(p Point) [8]uint8

Neighbors returns the neighbors value of a Point. Start from top-left, and go clockwise. Out of bounds neighbors are equal to 0.

func (*Grid) Set

func (g *Grid) Set(p Point, v uint8)

Set sets the value of a Point.

type Point

type Point struct {
	X, Y int
}

Point is a point on a Grid.

func (Point) Add

func (p Point) Add(q Point) Point

Add adds a Point to another.

func (Point) String

func (p Point) String() string

type Rule

type Rule func(p Point, g *Grid) uint8

Rule represents a rule applied to a Point on a Grid.

Directories

Path Synopsis
cmd
gameoflife
Package gameoflife is a "Game of Life" application.
Package gameoflife is a "Game of Life" application.
wireworld
Package wireworld is a WireWorld application.
Package wireworld is a WireWorld application.
Package gameoflife implements the "Game Of Life" variant of the cellular automaton.
Package gameoflife implements the "Game Of Life" variant of the cellular automaton.
Package wireworld implements the "Wireworld" variant of the cellular automaton.
Package wireworld implements the "Wireworld" variant of the cellular automaton.

Jump to

Keyboard shortcuts

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