models

package
v0.0.0-...-8ad53de Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CellularAutomataType identifies the cellular automata simulation
	CellularAutomataType = "cellular_automata"

	// SlimeMoldType identifies the slime mold simulation
	SlimeMoldType = "slime_mold"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CellularAutomataConfig

type CellularAutomataConfig struct {
	// NSpecies is the number of different types of species that exist
	NSpecies int

	// PredatorThreshold is the amount of neighboring predators cells it takes
	// to eat a prey cell
	PredatorThreshold int

	// PredatorDirs contains the cardinal directions that predators may attack
	// prey cells from
	PredatorDirs []string
}

CellularAutomataConfig are options specific to the cellular automata simulation

type Features

type Features struct {

	// SpeciesID identifies the species type of a cell
	SpeciesID int
	// Neighbors stores pointers to an organism's neighbors
	Neighbors []*Organism

	// XPos is a float that represents an organisms location within the Grid.
	// Positions are floats so that organisms can be at locations that are between
	// Spaces. This allows them to travel in any direction (otherwise they would
	// be limited to 45˚ increments). Their visible location will still be one
	// discrete Space (whichever Space they are closest to).
	XPos float64

	// YPos is a float that represents an organisms location within the Grid.
	// Positions are floats so that organisms can be at locations that are between
	// Spaces. This allows them to travel in any direction (otherwise they would
	// be limited to 45˚ increments). Their visible location will still be one
	// discrete Space (whichever Space they are closest to).
	YPos float64

	// direction represents the angular direction (in degrees) that an organism
	// is facing.
	Direction gridphysics.DegreeAngle
}

Features are various parameters that define an organism. Not all features are used in every simulation.

type Grid

type Grid struct {
	// Rows is a 2-dimensional array that contains Spaces in the inner-array.
	Rows [][]*Space
}

Grid represents the simulation area. It contains Spaces that organisms occupy and move through.

func NewGrid

func NewGrid(width int, height int) *Grid

NewGrid initializes and returns a Grid with the given width and height

func (*Grid) DrawImage

func (g *Grid) DrawImage(s Simulation) (*image.Paletted, error)

DrawImage draws the current state of the grid into a paletted image

func (*Grid) GetNeighbors

func (g *Grid) GetNeighbors(x, y int, dirs []string) []*Space

GetNeighbors finds and returns all of the spaces that are adjacent to the given coordinates

func (*Grid) GetSpace

func (g *Grid) GetSpace(x, y int) (*Space, bool)

GetSpace returns the Space that resides at a given coordinate if the coordinate exists in the grid

func (*Grid) HasCoord

func (g *Grid) HasCoord(x, y int) bool

HasCoord returns a bool to indicate whether a coordinate falls within the Grid's height and width parameters.

func (*Grid) Height

func (g *Grid) Height() int

Height returns the height of the Grid in Spaces.

func (*Grid) Width

func (g *Grid) Width() int

Width returns the width of the Grid in Spaces.

type NextFeatures

type NextFeatures struct {
	SpeciesID int
	XPos      float64
	YPos      float64
}

NextFeatures holds the next state of certain features, so we can calculate every state transition and apply them all at once.

type Organism

type Organism struct {
	ID int

	Features     *Features
	NextFeatures *NextFeatures
}

Organism represents one creature that can be displayed at one Space

func NewOrganism

func NewOrganism(id int) *Organism

NewOrganism instantiates and returns a new Organism

type Simulation

type Simulation interface {
	OutputName() (string, error)
	InitializeGrid(g *Grid) error
	AdvanceFrame(g *Grid) error
	DrawSpace(sp *Space, img *image.Paletted, x int, y int) error
	GetPalette() color.Palette
}

Simulation is the interface that all simulations must follow

type SimulationConfig

type SimulationConfig struct {
	CellularAutomata CellularAutomataConfig
	SlimeMold        SlimeMoldConfig
}

SimulationConfig holds the configurations for the simulation

type SlimeMoldConfig

type SlimeMoldConfig struct {
	ScentDecay        float64
	ScentSpreadFactor float64
	SenseReach        int
	SenseDegree       int
}

SlimeMoldConfig are options specific to the cellular automata simulation

type Space

type Space struct {
	Organism  *Organism
	Neighbors []*Space

	Features *SpaceFeatures
}

Space represents one discrete location that may be occupied by an organism.

func NewSpace

func NewSpace() *Space

NewSpace returns a new Space

type SpaceFeatures

type SpaceFeatures struct {
	// Scent represents the strength of a scent that may be left behind by organisms.
	Scent float64
}

SpaceFeatures contains optional features of a Space that apply to certain simulations.

Jump to

Keyboard shortcuts

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