game

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Interval is the time between grid updates in milliseconds.
	Interval = 100
)
View Source
var (
	// ReproduceMethod is the method of reproduction used when a cell becomes alive.
	ReproduceMethod = ReproduceTypeMajorityWins
)

Functions

This section is empty.

Types

type CellType

type CellType int

CellType is the design and color of the cell.

const (
	// CellTypeCross has a cross pattern in the middle.
	CellTypeCross CellType = iota

	// CellTypePlus has a plus pattern in the middle.
	CellTypePlus

	// CellTypeCircle has a circle pattern in the middle.
	CellTypeCircle

	// CellTypeDot has a dot pattern in the middle.
	CellTypeDot
)
const (
	// ReproduceTypeMajorityWins will determine cell type based on a majority of neighbors.
	ReproduceTypeMajorityWins CellType = iota

	// ReproduceTypeRandomPercentage will determine cell type by randomly picking one of the neighbors.
	ReproduceTypeRandomPercentage
)

type Grid added in v1.1.0

type Grid map[Position]CellType

Grid of cells.

func NewGrid added in v1.1.0

func NewGrid() Grid

NewGrid will create a new empty grid.

func (Grid) Add added in v1.1.0

func (g Grid) Add(x, y int, value CellType)

Add cell at position (x, y).

func (Grid) Clear added in v1.1.0

func (g Grid) Clear()

Clear the entire grid.

func (Grid) Copy added in v1.1.0

func (g Grid) Copy() Grid

Copy the grid structure using a shallow copy.

func (Grid) Delete added in v1.1.0

func (g Grid) Delete(x, y int)

Delete cell at position (x, y).

func (Grid) Retrieve added in v1.1.0

func (g Grid) Retrieve(x, y int) (interface{}, bool)

Retrieve cell at position (x, y).

type Manager

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

Manager controls the grid updates.

func NewManager

func NewManager() *Manager

NewManager creates a new Manager.

func (*Manager) Cells

func (m *Manager) Cells() Grid

Cells returns the grid.

func (*Manager) Clear

func (m *Manager) Clear()

Clear the grid.

func (*Manager) Load

func (m *Manager) Load(path string) error

Load a pattern from a file into the grid.

func (*Manager) Reset

func (m *Manager) Reset()

Reset the grid to the copy stored in memory.

func (*Manager) Running

func (m *Manager) Running() bool

Running returns true if the simulation is active.

func (*Manager) Save

func (m *Manager) Save(path string) error

Save the grid to a file.

func (*Manager) Start

func (m *Manager) Start()

Start the grid updates.

func (*Manager) Stop

func (m *Manager) Stop()

Stop the grid updates.

func (*Manager) Store

func (m *Manager) Store()

Store the grid in memory.

func (*Manager) Update

func (m *Manager) Update()

Update the grid buffer and swap it with the currently displayed grid if the interval has elapsed.

type Position added in v1.1.0

type Position struct {
	X int
	Y int
}

Position is a 2D point in space.

func NewPosition added in v1.1.0

func NewPosition(x, y int) Position

NewPosition will create a new position.

type ReproduceType

type ReproduceType int

ReproduceType is the type of logic used to determine cell type when it becomes alive.

Jump to

Keyboard shortcuts

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