game

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Dead = iota
	Alive
)
View Source
const (
	IDLength = 32
)

Variables

View Source
var NullID = strings.Repeat("0", IDLength)

Functions

func GenerateKey added in v1.2.0

func GenerateKey() string

GenerateKey returns a string of length 32, since that is what you get from 16 bytes encoded as a hex string.

func RuleB2S added in v1.3.0

func RuleB2S(cell uint8, liveNeighbors uint8) uint8

RuleB2S implements the B2S rules: https://conwaylife.com/wiki/OCA:Seeds

func RuleB3678S34678 added in v1.3.0

func RuleB3678S34678(cell uint8, liveNeighbors uint8) uint8

RuleB3678S34678 implements the B3678/S34678 rules: https://conwaylife.com/wiki/OCA:Day_%26_Night

func RuleB3S23 added in v1.2.0

func RuleB3S23(cell uint8, liveNeighbors uint8) uint8

RuleB3S23 implements the B3/S23 rules: https://www.conwaylife.com/wiki/Conway%27s_Game_of_Life#Rules

Types

type DistributedUniverse added in v1.2.0

type DistributedUniverse struct {
	*Universe

	ID             string
	TopID          string
	TopNeighbor    *DistributedUniverse `json:"-"`
	BottomID       string
	BottomNeighbor *DistributedUniverse `json:"-"`
	LeftID         string
	LeftNeighbor   *DistributedUniverse `json:"-"`
	RightID        string
	RightNeighbor  *DistributedUniverse `json:"-"`

	// set the GetNeighbor function with implementation for
	// the distributed environment.
	GetNeighbor func(id string) *DistributedUniverse `json:"-"`
}

func NewDistributedUniverse added in v1.2.0

func NewDistributedUniverse(id string, height, width uint32) *DistributedUniverse

func (*DistributedUniverse) Bytes added in v1.2.0

func (d *DistributedUniverse) Bytes() []byte

func (*DistributedUniverse) Neighbors added in v1.2.0

func (d *DistributedUniverse) Neighbors(row, column uint32) uint8

Neighbors returns the number of alive neighbors for a given cell. It uses the Moore neighborhood, which includes the eight cells surrounding the given cell, but also extended to adjoining neighbor Universes.

func (*DistributedUniverse) Read added in v1.2.0

func (d *DistributedUniverse) Read(p []byte) (n int, err error)

func (*DistributedUniverse) SetBottomNeighbor added in v1.2.0

func (d *DistributedUniverse) SetBottomNeighbor(id string) error

func (*DistributedUniverse) SetLeftNeighbor added in v1.2.0

func (d *DistributedUniverse) SetLeftNeighbor(id string) error

func (*DistributedUniverse) SetRightNeighbor added in v1.2.0

func (d *DistributedUniverse) SetRightNeighbor(id string) error

func (*DistributedUniverse) SetTopNeighbor added in v1.2.0

func (d *DistributedUniverse) SetTopNeighbor(id string) error

func (*DistributedUniverse) Write added in v1.2.0

func (d *DistributedUniverse) Write(p []byte) (n int, err error)

type Figure added in v1.2.0

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

func Beehive added in v1.2.0

func Beehive() *Figure

func Glider added in v1.2.0

func Glider() *Figure

func Pulsar added in v1.2.0

func Pulsar() *Figure

func (*Figure) DeltaX added in v1.2.0

func (f *Figure) DeltaX() uint32

func (*Figure) DeltaY added in v1.2.0

func (f *Figure) DeltaY() uint32

func (*Figure) Values added in v1.2.0

func (f *Figure) Values() [][]uint8

type NeighborConnection added in v1.2.0

type NeighborConnection struct {
	SendCh    chan NeighborData
	ReceiveCh chan NeighborData
	Data      NeighborData
}

func NewNeighborConnection added in v1.2.0

func NewNeighborConnection() *NeighborConnection

type NeighborData added in v1.2.0

type NeighborData struct {
	Generation uint32
	Cells      []uint8
}

type ParallelUniverse added in v1.2.0

type ParallelUniverse struct {
	*Universe

	TopNeighbor    *NeighborConnection
	BottomNeighbor *NeighborConnection
	LeftNeighbor   *NeighborConnection
	RightNeighbor  *NeighborConnection
	// contains filtered or unexported fields
}

func NewParallelUniverse added in v1.2.0

func NewParallelUniverse(height, width uint32) *ParallelUniverse

func (*ParallelUniverse) MultiTick added in v1.2.0

func (p *ParallelUniverse) MultiTick()

func (*ParallelUniverse) Neighbors added in v1.2.0

func (p *ParallelUniverse) Neighbors(row, column uint32) uint8

The ParallelUniverse Neighbors function returns the number of alive neighbors for a given cell. It uses the Moore neighborhood, which includes the eight cells surrounding the given cell, but also extended to adjoining neighbor Universes.

func (*ParallelUniverse) SendDataToNeighbors added in v1.2.0

func (p *ParallelUniverse) SendDataToNeighbors()

func (*ParallelUniverse) SetBottomNeighbor added in v1.2.0

func (p *ParallelUniverse) SetBottomNeighbor(n *ParallelUniverse) error

func (*ParallelUniverse) SetLeftNeighbor added in v1.2.0

func (p *ParallelUniverse) SetLeftNeighbor(n *ParallelUniverse) error

func (*ParallelUniverse) SetRightNeighbor added in v1.2.0

func (p *ParallelUniverse) SetRightNeighbor(n *ParallelUniverse) error

func (*ParallelUniverse) SetTopNeighbor added in v1.2.0

func (p *ParallelUniverse) SetTopNeighbor(n *ParallelUniverse) error

func (*ParallelUniverse) WaitForNeighborsData added in v1.2.0

func (p *ParallelUniverse) WaitForNeighborsData()

WaitForNeighborsData waits for all neighbors to send their data.

type Universe

type Universe struct {
	Generation uint32

	Rules func(cell uint8, row, column uint32) uint8 `json:"-"`
	// contains filtered or unexported fields
}

func NewUniverse

func NewUniverse(height, width uint32) *Universe

func (*Universe) Cell

func (u *Universe) Cell(idx uint32) uint8

func (*Universe) ConwayRules added in v1.2.0

func (u *Universe) ConwayRules(cell uint8, row, column uint32) uint8

ConwayRules implements the classic Game of Life rules.

func (*Universe) ConwayRulesWrap added in v1.3.0

func (u *Universe) ConwayRulesWrap(cell uint8, row, column uint32) uint8

ConwayRulesWrap implements the classic Game of Life rules but wraps the grid.

func (*Universe) DayAndNightRules added in v1.3.0

func (u *Universe) DayAndNightRules(cell uint8, row, column uint32) uint8

DayAndNightRules implements the Day And Night rules. See https://conwaylife.com/wiki/OCA:Day_%26_Night

func (*Universe) Dead added in v1.2.0

func (u *Universe) Dead() bool

func (*Universe) GetIndex

func (u *Universe) GetIndex(row, column uint32) uint32

func (*Universe) Height

func (u *Universe) Height() uint32

func (*Universe) MooreNeighbors added in v1.2.0

func (u *Universe) MooreNeighbors(row, column uint32) uint8

MooreNeighbors returns the number of alive neighbors for a given cell. It uses the Moore neighborhood, which includes the eight cells surrounding the given cell.

func (*Universe) MooreNeighborsWrap added in v1.3.0

func (u *Universe) MooreNeighborsWrap(row, column uint32) uint8

MooreNeighborsWrap returns the number of alive neighbors for a given cell. It uses the Moore neighborhood, which includes the eight cells surrounding the given cell, but wraps to the other side if it would be off the grid.

func (*Universe) OneDimensionalNeighbors added in v1.4.0

func (u *Universe) OneDimensionalNeighbors(row, column uint32) (uint8, uint8)

func (*Universe) Parse added in v1.4.0

func (u *Universe) Parse(data string) error

func (*Universe) Randomize added in v1.1.0

func (u *Universe) Randomize(livePopulation int)

func (*Universe) Read added in v1.2.0

func (u *Universe) Read(p []byte) (n int, err error)

func (*Universe) Reset

func (u *Universe) Reset()

func (*Universe) SeedsRules added in v1.3.0

func (u *Universe) SeedsRules(cell uint8, row, column uint32) uint8

SeedsRules implements the Seeds rules. See https://conwaylife.com/wiki/OCA:Seeds

func (*Universe) SetRectangle

func (u *Universe) SetRectangle(startingRow, startingColumn uint32, values [][]uint8)

func (*Universe) Size added in v1.2.0

func (u *Universe) Size() int

func (*Universe) Stable added in v1.2.0

func (u *Universe) Stable() bool

Stable returns true if the universe has reached a stable state. A stable state is one in which no cells have changed between ticks. See https://conwaylife.com/wiki/Still_life for more information.

func (*Universe) String added in v1.2.0

func (u *Universe) String() string

func (*Universe) Tick

func (u *Universe) Tick()

func (*Universe) ToggleCellAt

func (u *Universe) ToggleCellAt(row, column uint32)

func (*Universe) Width

func (u *Universe) Width() uint32

func (*Universe) WolframRule110 added in v1.4.0

func (u *Universe) WolframRule110(cell uint8, row, column uint32) uint8

WolframRule110 implements Rule 110 from Stephen Wolfram's "A New Kind of Science". See https://en.wikipedia.org/wiki/Rule_110

func (*Universe) WolframRule184 added in v1.4.0

func (u *Universe) WolframRule184(cell uint8, row, column uint32) uint8

WolframRule184 implements Rule 184 from Stephen Wolfram's "A New Kind of Science". See https://en.wikipedia.org/wiki/Rule_184

func (*Universe) WolframRule30 added in v1.4.0

func (u *Universe) WolframRule30(cell uint8, row, column uint32) uint8

WolframRule30 implements Rule 30 from Stephen Wolfram's "A New Kind of Science". See https://en.wikipedia.org/wiki/Rule_30

func (*Universe) WolframRule90 added in v1.4.0

func (u *Universe) WolframRule90(cell uint8, row, column uint32) uint8

WolframRule90 implements Rule 90 from Stephen Wolfram's "A New Kind of Science". See https://en.wikipedia.org/wiki/Rule_90

func (*Universe) Write added in v1.2.0

func (u *Universe) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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