ants

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: 16 Imported by: 0

README

Arche Demo -- Ant Colony

A stylized model of ants foraging and scouting, using trail pheromones.

Ants lay trails of two types of pheromones: one when coming from the nest,and another one when coming from a resource.

Using these trails, workers find their way to resources and back to the nest. To find new resources, scouts swarm out and do a random walk until they find something.

In this example, the landscape is a network with nodes and edges represented by ECS entities.

See the live demo for this example.

Documentation

Overview

Package ants provides a stylized model of ants foraging and scouting, using trail pheromones.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run()

Types

type ActForage

type ActForage struct {
	Start int64
}

ActForage component

type ActInNest

type ActInNest struct{}

ActInNest component

type ActReturn

type ActReturn struct {
	Start int64
	Load  float64
}

ActReturn component

type ActScout

type ActScout struct {
	Start int64
}

ActScout component

type Ant

type Ant struct{}

Ant label component

type AntEdge

type AntEdge struct {
	Edge   ecs.Entity
	From   Position
	Dir    Position
	Length float64
	Pos    float64
}

AntEdge component

func (*AntEdge) Update

func (e *AntEdge) Update(edge ecs.Entity, geom *EdgeGeometry)

Update the AntEdge to the given edge

func (*AntEdge) UpdatePos

func (e *AntEdge) UpdatePos(pos *Position)

UpdatePos updates the argument to the ant's position along the edge

type Colors

type Colors struct {
	Scout  color.RGBA
	Forage color.RGBA
	Return color.RGBA
	InNest color.RGBA
}

Colors resource, holding colors for drawing bee activities.

func NewColors

func NewColors() Colors

NewColors returns default bee activity colors.

type Edge

type Edge struct {
	From ecs.Entity
	To   ecs.Entity
}

Edge component

type EdgeGeometry

type EdgeGeometry struct {
	From   Position
	Dir    Position
	Length float64
}

EdgeGeometry component

type Nest

type Nest struct {
	Node ecs.Entity
	Pos  Position
}

Nest resource, representing an ant nest.

type Node

type Node struct {
	NumEdges int
	InEdges  [8]ecs.Entity
	OutEdges [8]ecs.Entity
}

Node component

func (*Node) Add

func (n *Node) Add(in, out ecs.Entity)

Add adds a pair of edges to the node.

type NodeResource

type NodeResource struct {
	Resource float64
}

NodeResource component

type Patches

type Patches struct {
	Rows     int
	Cols     int
	CellSize int
	// contains filtered or unexported fields
}

Patches resource holding a grid of potential flower patches.

func NewPatches

func NewPatches(width, height int, cellSize int) Patches

NewPatches creates a new Patches resource from world dimensions and grid cell size.

func (*Patches) CellCenter

func (p *Patches) CellCenter(x, y int) (float64, float64)

CellCenter returns the world coordinates of the center of the given cell.

func (*Patches) Contains

func (p *Patches) Contains(x, y int) bool

Contains returns whether the grid contains the given cell.

func (*Patches) Get

func (p *Patches) Get(x, y int) ecs.Entity

Get the node at a coordinate.

func (*Patches) Set

func (p *Patches) Set(x, y int, node ecs.Entity)

Set the node at a coordinate.

func (*Patches) ToCell

func (p *Patches) ToCell(x, y float64) (int, int)

ToCell converts world coordinates to integer patch coordinates.

func (*Patches) ToCellCenter

func (p *Patches) ToCellCenter(x, y float64) (float64, float64)

ToCellCenter returns the world coordinates of the center of the cell the given point is in.

type Position

type Position struct {
	X float64
	Y float64
}

Position component

type SysForaging

type SysForaging struct {
	MaxCollect       float64
	ProbExponent     float64
	RandomProb       float64
	TraceDecay       float64
	MaxSearchTime    int
	ScoutProbability float64
	// contains filtered or unexported fields
}

SysForaging is a system that performs forager decisions.

func (*SysForaging) Finalize

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

Finalize the system

func (*SysForaging) Initialize

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

Initialize the system

func (*SysForaging) Update

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

Update the system

type SysInitGrid

type SysInitGrid struct{}

SysInitGrid is a system to create a network on a grid.

func (*SysInitGrid) Finalize

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

Finalize the system

func (*SysInitGrid) Initialize

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

Initialize the system

func (*SysInitGrid) Update

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

Update the system

type SysInitNest

type SysInitNest struct {
	AntsPerNest int
	// contains filtered or unexported fields
}

SysInitNest is a system to initialize an ant nest, and to populate it with ants.

func (*SysInitNest) Finalize

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

Finalize the system

func (*SysInitNest) Initialize

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

Initialize the system

func (*SysInitNest) Update

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

Update the system

type SysMoveAnts

type SysMoveAnts struct {
	MaxSpeed float64
	// contains filtered or unexported fields
}

SysMoveAnts is a system that moves ants along their edges.

func (*SysMoveAnts) Finalize

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

Finalize the system

func (*SysMoveAnts) Initialize

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

Initialize the system

func (*SysMoveAnts) Update

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

Update the system

type SysNestDecisions

type SysNestDecisions struct {
	ReleaseInterval  int64
	ReleaseCount     int
	ScoutProbability float64
	ProbExponent     float64
	// contains filtered or unexported fields
}

SysNestDecisions is a system that performs ant decisions in the nest.

Particularly, it decides whether bees go for scouting or foraging.

func (*SysNestDecisions) Finalize

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

Finalize the system

func (*SysNestDecisions) Initialize

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

Initialize the system

func (*SysNestDecisions) Update

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

Update the system

type SysResources

type SysResources struct {
	Count int
	// contains filtered or unexported fields
}

SysResources is a system that initializes and manages collectible resources.

func (*SysResources) Finalize

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

Finalize the system

func (*SysResources) Initialize

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

Initialize the system

func (*SysResources) Update

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

Update the system

type SysReturning

type SysReturning struct {
	ProbExponent float64
	RandomProb   float64
	TraceDecay   float64
	// contains filtered or unexported fields
}

SysReturning is a system that performs decisions of ants going back to their nest.

func (*SysReturning) Finalize

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

Finalize the system

func (*SysReturning) Initialize

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

Initialize the system

func (*SysReturning) Update

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

Update the system

type SysScouting

type SysScouting struct {
	MaxCollect    float64
	TraceDecay    float64
	MaxSearchTime int
	// contains filtered or unexported fields
}

SysScouting is a system that performs scout decisions.

func (*SysScouting) Finalize

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

Finalize the system

func (*SysScouting) Initialize

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

Initialize the system

func (*SysScouting) Update

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

Update the system

type SysTraceDecay

type SysTraceDecay struct {
	Persistence float64
	// contains filtered or unexported fields
}

SysTraceDecay is a system that decays ant traces.

func (*SysTraceDecay) Finalize

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

Finalize the system

func (*SysTraceDecay) Initialize

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

Initialize the system

func (*SysTraceDecay) Update

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

Update the system

type Trace

type Trace struct {
	FromNest     float64
	FromResource float64
}

Trace component

type UISysClearFrame

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

UISysClearFrame is a simple system that clears the [Image] resource before other systems draw on it.

func (*UISysClearFrame) FinalizeUI

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

FinalizeUI the system

func (*UISysClearFrame) InitializeUI

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

InitializeUI the system

func (*UISysClearFrame) PostUpdateUI

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

PostUpdateUI the system

func (*UISysClearFrame) UpdateUI

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

UpdateUI the system

type UISysDrawAnts

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

UISysDrawAnts is a system that draws ants.

func (*UISysDrawAnts) FinalizeUI

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

FinalizeUI the system

func (*UISysDrawAnts) InitializeUI

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

InitializeUI the system

func (*UISysDrawAnts) PostUpdateUI

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

PostUpdateUI the system

func (*UISysDrawAnts) UpdateUI

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

UpdateUI the system

type UISysDrawGrid

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

UISysDrawGrid is a system that draws grid nodes.

func (*UISysDrawGrid) FinalizeUI

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

FinalizeUI the system

func (*UISysDrawGrid) InitializeUI

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

InitializeUI the system

func (*UISysDrawGrid) PostUpdateUI

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

PostUpdateUI the system

func (*UISysDrawGrid) UpdateUI

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

UpdateUI the system

type UISysDrawNest

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

UISysDrawNest is a system that draws the ant nest.

func (*UISysDrawNest) FinalizeUI

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

FinalizeUI the system

func (*UISysDrawNest) InitializeUI

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

InitializeUI the system

func (*UISysDrawNest) PostUpdateUI

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

PostUpdateUI the system

func (*UISysDrawNest) UpdateUI

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

UpdateUI the system

type UISysDrawResources

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

UISysDrawResources is a system that draws resource patches.

func (*UISysDrawResources) FinalizeUI

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

FinalizeUI the system

func (*UISysDrawResources) InitializeUI

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

InitializeUI the system

func (*UISysDrawResources) PostUpdateUI

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

PostUpdateUI the system

func (*UISysDrawResources) UpdateUI

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

UpdateUI the system

type UISysManagePause

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

UISysManagePause is a simple system that listens to clicks and pauses the simulation..

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

type UISysRepaint

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

UISysRepaint is a simple system that paints an [Image] resource to a common.Canvas.

func (*UISysRepaint) FinalizeUI

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

FinalizeUI the system

func (*UISysRepaint) InitializeUI

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

InitializeUI the system

func (*UISysRepaint) PostUpdateUI

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

PostUpdateUI the system

func (*UISysRepaint) UpdateUI

func (s *UISysRepaint) 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