bees

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 -- Bee Hives

A stylized model of bee foraging and scouting.

Bees scout, forage, return to the hive and potentially do the waggle dance. Other bees in the hive may fly to a patch indicated by a waggle dance, or go scouting on their own.

Uses different components to indicate the different activities. Hive internal decision making uses Arche's entity relations feature.

See the live demo for this example.

Documentation

Overview

Package bees provides a stylized model of bee foraging and scouting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run()

Types

type ActFollow

type ActFollow struct {
	// Position of the target patch.
	Target Position
}

ActFollow component indicating "following a waggle dance" activity.

type ActForage

type ActForage struct {
	// Starting tick of the activity.
	Start int64
	// Resource load collected so far.
	Load float64
}

ActForage activity component indicating foraging activity.

type ActInHive

type ActInHive struct{}

ActInHive activity component indicating idle/in-hive activity.

type ActReturn

type ActReturn struct {
	// Target position for return movement.
	Target Position
	// Source position of the return.
	Source Position
	// Resource load carried.
	Load float64
}

ActReturn activity component indicating return to hive activity.

type ActScout

type ActScout struct {
	// Starting tick of the activity.
	Start int64
}

ActScout component indicating scouting activity.

type ActWaggleDance

type ActWaggleDance struct {
	// End tick of the activity.
	End int64
	// Target position the dance is pointing at.
	Target Position
	// Load the bee brought home.
	Load float64
	// Expected benefit, being load brought, divided by distance.
	Benefit float64
}

ActWaggleDance activity component indicating waggle dance activity.

type Colors

type Colors struct {
	Scout  color.RGBA
	Forage color.RGBA
	Return color.RGBA
	Waggle color.RGBA
	InHive color.RGBA
	Follow color.RGBA
}

Colors resource, holding colors for drawing bee activities.

func NewColors

func NewColors() Colors

NewColors returns default bee activity colors.

type Direction

type Direction struct {
	X float64
	Y float64
}

Direction component.

type FlowerPatch

type FlowerPatch struct {
	X         int
	Y         int
	Resources float64
}

FlowerPatch component.

type Hive

type Hive struct{}

Hive component, as a label for bee hives.

type HomeHive

type HomeHive struct {
	ecs.Relation
}

HomeHive component. This is an ecs.Relation component, associating each bee with it's home hive.

type Params

type Params struct {
	MaxBeeSpeed float64
}

Params resource for parameters that are used by multiple systems.

type Patches

type Patches struct {
	Rows     int
	Cols     int
	CellSize int
	Patches  [][]ecs.Entity
}

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) 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 Random256

type Random256 struct {
	Value uint8
}

Random256 component, contains an uint8 value for scheduling things in intervals, but randomized over entities.

type SysFleeing

type SysFleeing struct {
	FleeDistance float64
	// contains filtered or unexported fields
}

SysFleeing is a system that makes bees switch to the ActReturn activity when the mouse is near. Affects activities ActScout, ActFollow and ActForage. Actual fleeing is implemented in system SysReturning.

func (*SysFleeing) Finalize

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

Finalize the system

func (*SysFleeing) Initialize

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

Initialize the system

func (*SysFleeing) Update

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

Update the system

type SysFollowing

type SysFollowing struct {
	MaxRotation      float64
	ScoutProbability float64
	// contains filtered or unexported fields
}

SysFollowing is a system that handles the movement of bees that currently fly to a patch that was indicated by them by a waggle dance (ActFollow).

Switches activity to ActForage or ActReturn on arrival.

func (*SysFollowing) Finalize

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

Finalize the system

func (*SysFollowing) Initialize

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

Initialize the system

func (*SysFollowing) Update

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

Update the system

type SysForaging

type SysForaging struct {
	MaxForagingTime int64
	MaxCollect      float64
	// contains filtered or unexported fields
}

SysForaging is a system that handles resource extraction of foraging bees (ActForage) from patches.

Switches activity to ActReturn after a certain foraging time.

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 SysHiveDecisions

type SysHiveDecisions struct {
	ReleaseInterval  int64
	ReleaseCount     int
	ScoutProbability float64

	DanceSamples int
	// contains filtered or unexported fields
}

SysHiveDecisions is a system that performs bee decisions in the hive.

Particularly, it decides whether bees go for scouting, or whether they follow a waggle dance, and which one.

func (*SysHiveDecisions) Finalize

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

Finalize the system

func (*SysHiveDecisions) Initialize

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

Initialize the system

func (*SysHiveDecisions) Update

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

Update the system

type SysInitBees

type SysInitBees struct {
	// Target number of bees per hive.
	CountPerHive int
}

SysInitBees is a system that creates a number of bee entities per hive.

func (*SysInitBees) Finalize

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

Finalize the system

func (*SysInitBees) Initialize

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

Initialize the system

func (*SysInitBees) Update

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

Update the system

type SysInitHives

type SysInitHives struct {
	// Target number of hives.
	Count int
}

SysInitHives is a system that creates a number of randomly places hives.

func (*SysInitHives) Finalize

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

Finalize the system

func (*SysInitHives) Initialize

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

Initialize the system

func (*SysInitHives) Update

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

Update the system

type SysManagePatches

type SysManagePatches struct {
	// Target number of patches.
	Count int
	// contains filtered or unexported fields
}

SysManagePatches is a system that creates a number of randomly placed flower patches. Further, it removes patches that are depleted, and creates new patches if the number of patches falls below Count.

func (*SysManagePatches) Finalize

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

Finalize the system

func (*SysManagePatches) Initialize

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

Initialize the system

func (*SysManagePatches) Update

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

Update the system

type SysReturning

type SysReturning struct {
	MaxRotation         float64
	FleeDistance        float64
	MaxDanceProbability float64
	// contains filtered or unexported fields
}

SysReturning is a system that handles movement of bees returning to their hive (ActReturn).

Switches activity to ActInHive or ActWaggleDance on arrival. The probability of dancing depends on the resource load the bee brought back.

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 {
	MaxRotation  float64
	MaxScoutTime int64
	// contains filtered or unexported fields
}

SysScouting is a system that handles movement of scouting bees (ActScout).

Switches activity to ActReturn after a certain time of scouting.

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 SysWaggleDance

type SysWaggleDance struct {
	MinDanceDuration int64
	MaxDanceDuration int64
	// contains filtered or unexported fields
}

SysWaggleDance is a system that handles bees doing a waggle dance at the hive (ActWaggleDance).

Switches activity to ActInHive after a certain time of dancing. Duration of dancing depends on the resource load the bee brought back.

func (*SysWaggleDance) Finalize

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

Finalize the system

func (*SysWaggleDance) Initialize

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

Initialize the system

func (*SysWaggleDance) Update

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

Update the system

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 UISysDrawBees

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

UISysDrawBees is a system for drawing bees as colored pixels.

func (*UISysDrawBees) FinalizeUI

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

FinalizeUI the system

func (*UISysDrawBees) InitializeUI

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

InitializeUI the system

func (*UISysDrawBees) PostUpdateUI

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

PostUpdateUI the system

func (*UISysDrawBees) UpdateUI

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

UpdateUI the system

type UISysDrawHives

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

UISysDrawHives is a system for drawing hives as pie charts over the activities of related bees.

func (*UISysDrawHives) FinalizeUI

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

FinalizeUI the system

func (*UISysDrawHives) InitializeUI

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

InitializeUI the system

func (*UISysDrawHives) PostUpdateUI

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

PostUpdateUI the system

func (*UISysDrawHives) UpdateUI

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

UpdateUI the system

type UISysDrawPatches

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

UISysDrawPatches is a system for drawing flower patches as squares with fading green color as they become depleted.

func (*UISysDrawPatches) FinalizeUI

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

FinalizeUI the system

func (*UISysDrawPatches) InitializeUI

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

InitializeUI the system

func (*UISysDrawPatches) PostUpdateUI

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

PostUpdateUI the system

func (*UISysDrawPatches) UpdateUI

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