Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateKey() string
- func RuleB2S(cell uint8, liveNeighbors uint8) uint8
- func RuleB3678S34678(cell uint8, liveNeighbors uint8) uint8
- func RuleB3S23(cell uint8, liveNeighbors uint8) uint8
- type DistributedUniverse
- func (d *DistributedUniverse) Bytes() []byte
- func (d *DistributedUniverse) Neighbors(row, column uint32) uint8
- func (d *DistributedUniverse) Read(p []byte) (n int, err error)
- func (d *DistributedUniverse) SetBottomNeighbor(id string) error
- func (d *DistributedUniverse) SetLeftNeighbor(id string) error
- func (d *DistributedUniverse) SetRightNeighbor(id string) error
- func (d *DistributedUniverse) SetTopNeighbor(id string) error
- func (d *DistributedUniverse) Write(p []byte) (n int, err error)
- type Figure
- type NeighborConnection
- type NeighborData
- type ParallelUniverse
- func (p *ParallelUniverse) MultiTick()
- func (p *ParallelUniverse) Neighbors(row, column uint32) uint8
- func (p *ParallelUniverse) SendDataToNeighbors()
- func (p *ParallelUniverse) SetBottomNeighbor(n *ParallelUniverse) error
- func (p *ParallelUniverse) SetLeftNeighbor(n *ParallelUniverse) error
- func (p *ParallelUniverse) SetRightNeighbor(n *ParallelUniverse) error
- func (p *ParallelUniverse) SetTopNeighbor(n *ParallelUniverse) error
- func (p *ParallelUniverse) WaitForNeighborsData()
- type Universe
- func (u *Universe) Cell(idx uint32) uint8
- func (u *Universe) ConwayRules(cell uint8, row, column uint32) uint8
- func (u *Universe) ConwayRulesWrap(cell uint8, row, column uint32) uint8
- func (u *Universe) DayAndNightRules(cell uint8, row, column uint32) uint8
- func (u *Universe) Dead() bool
- func (u *Universe) GetIndex(row, column uint32) uint32
- func (u *Universe) Height() uint32
- func (u *Universe) MooreNeighbors(row, column uint32) uint8
- func (u *Universe) MooreNeighborsWrap(row, column uint32) uint8
- func (u *Universe) OneDimensionalNeighbors(row, column uint32) (uint8, uint8)
- func (u *Universe) Parse(data string) error
- func (u *Universe) Randomize(livePopulation int)
- func (u *Universe) Read(p []byte) (n int, err error)
- func (u *Universe) Reset()
- func (u *Universe) SeedsRules(cell uint8, row, column uint32) uint8
- func (u *Universe) SetRectangle(startingRow, startingColumn uint32, values [][]uint8)
- func (u *Universe) Size() int
- func (u *Universe) Stable() bool
- func (u *Universe) String() string
- func (u *Universe) Tick()
- func (u *Universe) ToggleCellAt(row, column uint32)
- func (u *Universe) Width() uint32
- func (u *Universe) WolframRule110(cell uint8, row, column uint32) uint8
- func (u *Universe) WolframRule184(cell uint8, row, column uint32) uint8
- func (u *Universe) WolframRule30(cell uint8, row, column uint32) uint8
- func (u *Universe) WolframRule90(cell uint8, row, column uint32) uint8
- func (u *Universe) Write(p []byte) (n int, err error)
Constants ¶
const ( Dead = iota Alive )
const (
IDLength = 32
)
Variables ¶
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
RuleB2S implements the B2S rules: https://conwaylife.com/wiki/OCA:Seeds
func RuleB3678S34678 ¶ added in v1.3.0
RuleB3678S34678 implements the B3678/S34678 rules: https://conwaylife.com/wiki/OCA:Day_%26_Night
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
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 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 (*Universe) ConwayRules ¶ added in v1.2.0
ConwayRules implements the classic Game of Life rules.
func (*Universe) ConwayRulesWrap ¶ added in v1.3.0
ConwayRulesWrap implements the classic Game of Life rules but wraps the grid.
func (*Universe) DayAndNightRules ¶ added in v1.3.0
DayAndNightRules implements the Day And Night rules. See https://conwaylife.com/wiki/OCA:Day_%26_Night
func (*Universe) MooreNeighbors ¶ added in v1.2.0
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
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 (*Universe) SeedsRules ¶ added in v1.3.0
SeedsRules implements the Seeds rules. See https://conwaylife.com/wiki/OCA:Seeds
func (*Universe) SetRectangle ¶
func (*Universe) Stable ¶ added in v1.2.0
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) ToggleCellAt ¶
func (*Universe) WolframRule110 ¶ added in v1.4.0
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
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
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
WolframRule90 implements Rule 90 from Stephen Wolfram's "A New Kind of Science". See https://en.wikipedia.org/wiki/Rule_90