life: Index | Files

package life

import ""


Package Files

life.go patterns.go pond.go processors.go rules.go tracker.go


const (
    NeighborsAll neighborsSelector = iota

Enumeration of the method to select neighbors

func ConwayTester Uses

func ConwayTester() func(int, bool) bool

ConwayTester returns a rules tester with Conway Normal rules

func RulesTester Uses

func RulesTester(rules *Rules) func(int, bool) bool

RulesTester returns a RulesTest function that uses the given ruleset

func SimultaneousProcessor Uses

func SimultaneousProcessor(pond *pond, rules func(int, bool) bool)

SimultaneousProcessor simultaneously applies the given rules to the given pond. This is the default Conway processor.

type Dimensions Uses

type Dimensions struct {
    Width  int
    Height int

Dimensions is a simple structure capturing the given dimensions

func (*Dimensions) Capacity Uses

func (t *Dimensions) Capacity() int

Capacity returns the number of cells possible with the given dimensions

func (*Dimensions) Equals Uses

func (t *Dimensions) Equals(rhs *Dimensions) bool

Equals is a basic equality test for the given object

func (*Dimensions) String Uses

func (t *Dimensions) String() string

type Generation Uses

type Generation struct {
    Num    int
    Living []Location

Generation encapsulates a snapshot of each generation

type Life Uses

type Life struct {
    Seed        []Location
    Generations int
    // contains filtered or unexported fields

Life structure is the primary structure for the simulation

func New Uses

func New(dims Dimensions,
    neighbors neighborsSelector,
    initializer func(Dimensions, Location) []Location,
    rules func(int, bool) bool,
    processor func(pond *pond, rules func(int, bool) bool)) (*Life, error)

New creates a new Life structure

func (*Life) Dimensions Uses

func (t *Life) Dimensions() Dimensions

Dimensions returns the dimensions of the Life board

func (*Life) Generation Uses

func (t *Life) Generation(num int) *Generation

Generation provides the snapshot of the given generation It will actually simulate the full progression from seed to the given generation

func (*Life) Start Uses

func (t *Life) Start(listener chan *Generation) func()

Start enables the seeded simulation with each tick providing a Generation object

func (*Life) String Uses

func (t *Life) String() string

type Location Uses

type Location struct {
    X   int
    Y   int

Location is a simple coordinate structure

func Beacons Uses

func Beacons(dimensions Dimensions, offset Location) []Location

Beacons generates a Beacon oscillator

Period 1   Period 2
00--       00--
0---       00--
---0       --00
--00       --00

func Beehive Uses

func Beehive(dimensions Dimensions, offset Location) []Location

Beehive generates the Beehive still pattern


func Blinkers Uses

func Blinkers(dimensions Dimensions, offset Location) []Location

Blinkers generates a basic Blinker oscillator

Period 1  Period 2
-0-       ---
-0-       000
-0-       ---

func Blocks Uses

func Blocks(dimensions Dimensions, offset Location) []Location

Blocks generates the Block still pattern


func Boat Uses

func Boat(dimensions Dimensions, offset Location) []Location

Boat generates the Boat still pattern


func Gliders Uses

func Gliders(dimensions Dimensions, offset Location) []Location

Gliders generates a basic Glider spaceship

Period 1   Period 2   Period 3   Period 4
-0--       ----       ----       ----
--0-       0-0-       --0-       -0--
000-       -00-       0-0-       --00
----       -0--       -00-       -00-

func Loaf Uses

func Loaf(dimensions Dimensions, offset Location) []Location

Loaf generates the Loaf still pattern


func Pulsar Uses

func Pulsar(dimensions Dimensions, offset Location) []Location

Pulsar generates a Pulsar oscillator

Period 1          Period 2          Period 3
---------------   ----0-----0----   ---------------
---000---000---   ----0-----0----   ---00-----00---
---------------   ----00---00----   ----00---00----
-0----0-0----0-   ---------------   -0--0-0-0-0--0-
-0----0-0----0-   000--00-00--000   -000-00-00-000-
-0----0-0----0-   --0-0-0-0-0-0--   --0-0-0-0-0-0--
---000---000---   ----00---00----   ---000---000---
---------------   ---------------   ---------------
---000---000---   ----00---00----   ---000---000---
-0----0-0----0-   --0-0-0-0-0-0--   --0-0-0-0-0-0--
-0----0-0----0-   000--00-00--000   -000-00-00-000-
-0----0-0----0-   ---------------   -0--0-0-0-0--0-
---------------   ----00---00----   ----00---00----
---000---000---   ----0-----0----   ---00-----00---
---------------   ----0-----0----   ---------------

func Random Uses

func Random(dimensions Dimensions, offset Location, percent int) []Location

Random generates a random pattern

func Toads Uses

func Toads(dimensions Dimensions, offset Location) []Location

Toads generates a Toad oscillator

Period 1	  Period 2
----       --0-
-000       0--0
000-       0--0
----       -0--

func (*Location) Equals Uses

func (t *Location) Equals(rhs *Location) bool

Equals is a basic equality test for the given object

func (*Location) String Uses

func (t *Location) String() string

type Rules Uses

type Rules struct {
    Survive []int // The number of neighbors an alive cell needs to have to survive
    Born    []int // The number of neighbors a dead cell needs to have to be born

Rules encapsulates the standard Life rules

func GetConwayRules Uses

func GetConwayRules() *Rules

GetConwayRules returns a Rules struct filled with the normal Conway rules of 23/3

-- Rules --
1. If live cell has < 2 neighbors, it dies
2. If live cell has 2 or 3 neighbors, it lives
3. If live cell has > 3 neighbors, it dies
4. If dead cell has exactly 3 neighbors, it lives

func (*Rules) String Uses

func (t *Rules) String() string

Package life imports 6 packages (graph) and is imported by 1 packages. Updated 2019-09-16. Refresh now. Tools for package owners.