wave

package
v0.0.0-...-adc953a Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MAX_VAL = 3
)

Functions

func Abundance

func Abundance(neighborhood map[uint8]uint8) ([]uint8, uint8)

Abundance the color(s), which corresponds to a value [1-3], and the number of counted neighbors of that color [0-8]. Since there could be a tie for the highest count, multiple colors are returned in an array.

func NewNeighborhood

func NewNeighborhood() map[uint8]uint8

Neighborhood represents the total color counts in the surrounding cells.

func WhoEatsMe

func WhoEatsMe(myColor uint8) uint8

WhoEatsMe returns the color that consumes the specified color, if nearby. If will only return a 0 if it passes through all of the cases.

Types

type Field

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

Field represents a two-dimensional field of cells.

func NewField

func NewField(w, h int) *Field

NewField returns an empty field of the specified width and height.

func (*Field) Next

func (f *Field) Next(x, y int) uint8

Next returns the state of the specified cell at the next time step.

func (*Field) Set

func (f *Field) Set(x, y int, b uint8)

Set sets the state of the specified cell to the given value.

func (*Field) WhatIs

func (f *Field) WhatIs(x, y int) uint8

WhatsIs reports the number that is at the specified cell. NOTE: THIS WRAPS AROUND THE MAP.

type GridState

type GridState struct {
	GridState string
}

type Life

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

Life stores the state of a round of Conway's Game of Life.

func NewLife

func NewLife(w, h int) *Life

NewLife returns a new Life game state with a random initial state.

func (*Life) AlterAt

func (l *Life) AlterAt(x, y int, val uint8)

AlterAt changes the value at a specific position of the field.

func (*Life) LifeStateMessage

func (l *Life) LifeStateMessage() []byte

LifeStateMessage returns an encoded Json message, ready to be sent.

func (*Life) Step

func (l *Life) Step()

Step advances the game by one instant, recomputing and updating all cells.

func (*Life) String

func (l *Life) String() string

String returns the game board as a string.

Jump to

Keyboard shortcuts

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