evolution

package
v0.0.0-...-28575ab Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: MIT Imports: 21 Imported by: 0

README

Arche Demo – Evolution

An evolutionary model of grazer behavior.

Grazers have genes for 4 traits:

  • MaxAngle is the maximum turning angle,
  • MinGrass is the grass threshold to stop grazing and start searching,
  • Investment is the energy invested in offspring,
  • Offspring is the number of offspring.

Colors of grazers are also inherited and mutated, but have no influence on fitness. Grazers can only mate with other grazers with a similar color.

See the live demo for this example.

Documentation

Overview

Package evolution provides an evolutionary model of grazer behavior.

Index

Constants

This section is empty.

Variables

View Source
var GeneNames = [7]string{
	"MaxAngle",
	"MinGrass",
	"Invest",
	"Offspring",
	"Red",
	"Green",
	"Blue",
}

GeneNames for plotting.

Functions

func Run

func Run()

Types

type Activity

type Activity struct {
	IsGrazing bool
}

Activity component

type Age

type Age struct {
	TickOfBirth int64
}

Age component

type Color

type Color struct {
	Color color.RGBA
}

Color components

func (*Color) From

func (c *Color) From(g *Genotype)

From sets the Colors to a Genotype.

type Energy

type Energy struct {
	Energy float32
}

Energy component

type Genotype

type Genotype struct {
	Genes [7]float32
}

Genotype components

func (*Genotype) Defaults

func (g *Genotype) Defaults()

Defaults sets all genes to default values

func (*Genotype) Randomize

func (g *Genotype) Randomize()

Randomize all genes

type Grass

type Grass struct {
	Grass  common.Grid[float32]
	Growth common.Grid[float32]
	Scale  int
}

Grass resource.

func NewGrass

func NewGrass(width, height, cellsize int, scale int) Grass

NewGrass creates a new Grass resource.

type GrasserCount

type GrasserCount = common.Grid[int32]

GrasserCount resource.

type Heading

type Heading struct {
	Angle float32
}

Heading component

func (*Heading) Direction

func (h *Heading) Direction() (float32, float32)

Direction returns the unit vector corresponding to the heading.

type MouseSelection

type MouseSelection struct {
	Selections []*SelectionEntry
}

MouseSelection resource.

type Phenotype

type Phenotype struct {
	MaxAngle  float32
	MinGrass  float32
	Invest    float32
	Offspring uint8
}

Phenotype components

func (*Phenotype) From

func (p *Phenotype) From(g *Genotype)

From sets the Phenotype to a Genotype.

type Position

type Position struct {
	X float32
	Y float32
}

Position component

type SelectionEntry

type SelectionEntry struct {
	XIndex   int
	YIndex   int
	Position Position
	Radius   float32
	Active   bool
}

SelectionEntry for MouseSelection.

type SysDecisions

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

SysDecisions is a system to perform grazer decisions.

func (*SysDecisions) Finalize

func (s *SysDecisions) Finalize(world *ecs.World)

Finalize the system

func (*SysDecisions) Initialize

func (s *SysDecisions) Initialize(world *ecs.World)

Initialize the system

func (*SysDecisions) Update

func (s *SysDecisions) Update(world *ecs.World)

Update the system

type SysDisturbance

type SysDisturbance struct {
	Interval    int
	Count       int
	MinRadius   int
	MaxRadius   int
	TargetValue float32
	// contains filtered or unexported fields
}

SysDisturbance is a system that applies disturbances.

func (*SysDisturbance) Finalize

func (s *SysDisturbance) Finalize(world *ecs.World)

Finalize the system

func (*SysDisturbance) Initialize

func (s *SysDisturbance) Initialize(world *ecs.World)

Initialize the system

func (*SysDisturbance) Update

func (s *SysDisturbance) Update(world *ecs.World)

Update the system

type SysGrazing

type SysGrazing struct {
	MaxUptake    float32
	UptakeFactor float32
	// contains filtered or unexported fields
}

SysGrazing is a system that handle grazing of entities on Grass.

func (*SysGrazing) Finalize

func (s *SysGrazing) Finalize(world *ecs.World)

Finalize the system

func (*SysGrazing) Initialize

func (s *SysGrazing) Initialize(world *ecs.World)

Initialize the system

func (*SysGrazing) Update

func (s *SysGrazing) Update(world *ecs.World)

Update the system

type SysGrowGrassLinear

type SysGrowGrassLinear struct {
	Interval int
	BaseRate float32
	// contains filtered or unexported fields
}

SysGrowGrassLinear is a system to grow the Grass resource.

func (*SysGrowGrassLinear) Finalize

func (s *SysGrowGrassLinear) Finalize(world *ecs.World)

Finalize the system

func (*SysGrowGrassLinear) Initialize

func (s *SysGrowGrassLinear) Initialize(world *ecs.World)

Initialize the system

func (*SysGrowGrassLinear) Update

func (s *SysGrowGrassLinear) Update(world *ecs.World)

Update the system

type SysGrowGrassLogistic

type SysGrowGrassLogistic struct {
	Interval int
	BaseRate float32
	// contains filtered or unexported fields
}

SysGrowGrassLogistic is a system to grow the Grass resource.

func (*SysGrowGrassLogistic) Finalize

func (s *SysGrowGrassLogistic) Finalize(world *ecs.World)

Finalize the system

func (*SysGrowGrassLogistic) Initialize

func (s *SysGrowGrassLogistic) Initialize(world *ecs.World)

Initialize the system

func (*SysGrowGrassLogistic) Update

func (s *SysGrowGrassLogistic) Update(world *ecs.World)

Update the system

type SysInitEntities

type SysInitEntities struct {
	InitialBatches  int
	ReleaseInterval int
	ReleaseBatches  int
	BatchSize       int
	RandomGenes     bool
	// contains filtered or unexported fields
}

SysInitEntities is a system to initialize entities.

func (*SysInitEntities) Finalize

func (s *SysInitEntities) Finalize(world *ecs.World)

Finalize the system

func (*SysInitEntities) Initialize

func (s *SysInitEntities) Initialize(world *ecs.World)

Initialize the system

func (*SysInitEntities) Update

func (s *SysInitEntities) Update(world *ecs.World)

Update the system

type SysInitGrass

type SysInitGrass struct {
	Frequency float32
	Octaves   int
	Falloff   float32
	Cutoff    float32
}

SysInitGrass is a system to initialize the Grass resource.

func (*SysInitGrass) Finalize

func (s *SysInitGrass) Finalize(world *ecs.World)

Finalize the system

func (*SysInitGrass) Initialize

func (s *SysInitGrass) Initialize(world *ecs.World)

Initialize the system

func (*SysInitGrass) Update

func (s *SysInitGrass) Update(world *ecs.World)

Update the system

type SysMetabolism

type SysMetabolism struct {
	RateGrazing   float32
	RateSearching float32
	// contains filtered or unexported fields
}

SysMetabolism is a system that reduces the energy of grazers due to metabolism.

func (*SysMetabolism) Finalize

func (s *SysMetabolism) Finalize(world *ecs.World)

Finalize the system

func (*SysMetabolism) Initialize

func (s *SysMetabolism) Initialize(world *ecs.World)

Initialize the system

func (*SysMetabolism) Update

func (s *SysMetabolism) Update(world *ecs.World)

Update the system

type SysMortality

type SysMortality struct {
	MaxAge int64
	// contains filtered or unexported fields
}

SysMortality is a system that removes entities with energy below zero.

func (*SysMortality) Finalize

func (s *SysMortality) Finalize(world *ecs.World)

Finalize the system

func (*SysMortality) Initialize

func (s *SysMortality) Initialize(world *ecs.World)

Initialize the system

func (*SysMortality) Update

func (s *SysMortality) Update(world *ecs.World)

Update the system

type SysReproduction

type SysReproduction struct {
	MatingTrials        int
	MaxMatingDist       int
	MaxMatingDiff       uint8
	CrossProb           float32
	MutationProbability float32
	MutationMagnitude   float32
	AllowAsexual        bool
	HatchRadius         float32
	// contains filtered or unexported fields
}

SysReproduction is a system that handles reproduction of grazers.

func (*SysReproduction) Finalize

func (s *SysReproduction) Finalize(world *ecs.World)

Finalize the system

func (*SysReproduction) Initialize

func (s *SysReproduction) Initialize(world *ecs.World)

Initialize the system

func (*SysReproduction) Update

func (s *SysReproduction) Update(world *ecs.World)

Update the system

type SysSearching

type SysSearching struct {
	MaxSpeed float32
	// contains filtered or unexported fields
}

SysSearching is a system to move around searching entities.

func (*SysSearching) Finalize

func (s *SysSearching) Finalize(world *ecs.World)

Finalize the system

func (*SysSearching) Initialize

func (s *SysSearching) Initialize(world *ecs.World)

Initialize the system

func (*SysSearching) Update

func (s *SysSearching) Update(world *ecs.World)

Update the system

type UISysDrawEntities

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

UISysDrawEntities is a system that draws entities as white pixels on an [Image] resource.

func (*UISysDrawEntities) FinalizeUI

func (s *UISysDrawEntities) FinalizeUI(world *ecs.World)

FinalizeUI the system

func (*UISysDrawEntities) InitializeUI

func (s *UISysDrawEntities) InitializeUI(world *ecs.World)

InitializeUI the system

func (*UISysDrawEntities) PostUpdateUI

func (s *UISysDrawEntities) PostUpdateUI(world *ecs.World)

PostUpdateUI the system

func (*UISysDrawEntities) UpdateUI

func (s *UISysDrawEntities) UpdateUI(world *ecs.World)

UpdateUI the system

type UISysDrawGrass

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

UISysDrawGrass is a system that draws the Grass resource.

func (*UISysDrawGrass) FinalizeUI

func (s *UISysDrawGrass) FinalizeUI(world *ecs.World)

FinalizeUI the system

func (*UISysDrawGrass) InitializeUI

func (s *UISysDrawGrass) InitializeUI(world *ecs.World)

InitializeUI the system

func (*UISysDrawGrass) PostUpdateUI

func (s *UISysDrawGrass) PostUpdateUI(world *ecs.World)

PostUpdateUI the system

func (*UISysDrawGrass) UpdateUI

func (s *UISysDrawGrass) UpdateUI(world *ecs.World)

UpdateUI the system

type UISysDrawScatter

type UISysDrawScatter struct {
	Interval       int
	IntervalOffset int
	XIndex         int
	YIndex         int
	ImageOffset    image.Point
	Width          int
	Height         int
	// contains filtered or unexported fields
}

UISysDrawScatter is a system that draws a scatter plot of entity [Genes].

func (*UISysDrawScatter) FinalizeUI

func (s *UISysDrawScatter) FinalizeUI(world *ecs.World)

FinalizeUI the system

func (*UISysDrawScatter) InitializeUI

func (s *UISysDrawScatter) InitializeUI(world *ecs.World)

InitializeUI the system

func (*UISysDrawScatter) PostUpdateUI

func (s *UISysDrawScatter) PostUpdateUI(world *ecs.World)

PostUpdateUI the system

func (*UISysDrawScatter) UpdateUI

func (s *UISysDrawScatter) UpdateUI(world *ecs.World)

UpdateUI the system

type UISysManagePause

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

UISysManagePause is a simple system that transfers the pause state from the common.PauseMouseListener resource to the model's model.Systems.

func (*UISysManagePause) FinalizeUI

func (s *UISysManagePause) FinalizeUI(world *ecs.World)

FinalizeUI the system

func (*UISysManagePause) InitializeUI

func (s *UISysManagePause) InitializeUI(world *ecs.World)

InitializeUI the system

func (*UISysManagePause) PostUpdateUI

func (s *UISysManagePause) PostUpdateUI(world *ecs.World)

PostUpdateUI the system

func (*UISysManagePause) UpdateUI

func (s *UISysManagePause) UpdateUI(world *ecs.World)

UpdateUI the system

Jump to

Keyboard shortcuts

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