creatur-5.9.30: Framework for artificial life experiments.
Copyright(c) 2012-2021 Amy de Buitléir
LicenseBSD-style
Maintaineramy@nualeargais.ie
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

ALife.Creatur.Universe

Description

Provides a habitat for artificial life.

Synopsis

Constructors

class (Clock (Clock u), Logger (Logger u), Database (AgentDB u), Namer (Namer u), Checklist (Checklist u), Agent (Agent u), Record (Agent u), Agent u ~ DBRecord (AgentDB u)) => Universe u where Source #

A habitat containing artificial life.

Associated Types

type Agent u Source #

type Clock u Source #

type Logger u Source #

type AgentDB u Source #

type Namer u Source #

type Checklist u Source #

Methods

clock :: u -> Clock u Source #

setClock :: u -> Clock u -> u Source #

logger :: u -> Logger u Source #

setLogger :: u -> Logger u -> u Source #

agentDB :: u -> AgentDB u Source #

setAgentDB :: u -> AgentDB u -> u Source #

agentNamer :: u -> Namer u Source #

setNamer :: u -> Namer u -> u Source #

checklist :: u -> Checklist u Source #

setChecklist :: u -> Checklist u -> u Source #

Instances

Instances details
(Agent a, SizedRecord a) => Universe (CachedUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

(Agent a, Record a) => Universe (SimpleUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

data SimpleUniverse a Source #

Instances

Instances details
Eq (SimpleUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

Show (SimpleUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

(Agent a, Record a) => Universe (SimpleUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type Agent (SimpleUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type Agent (SimpleUniverse a) = a
type Clock (SimpleUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type Logger (SimpleUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type AgentDB (SimpleUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type Namer (SimpleUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type Checklist (SimpleUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

data CachedUniverse a Source #

Instances

Instances details
Eq a => Eq (CachedUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

Show a => Show (CachedUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

(Agent a, SizedRecord a) => Universe (CachedUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type Agent (CachedUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type Agent (CachedUniverse a) = a
type Clock (CachedUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type Logger (CachedUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type AgentDB (CachedUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type Namer (CachedUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

type Checklist (CachedUniverse a) Source # 
Instance details

Defined in ALife.Creatur.Universe

Clock

currentTime :: Universe u => StateT u IO Time Source #

The current "time" (counter) in this universe

incTime :: Universe u => StateT u IO () Source #

Increment the current "time" (counter) in this universe.

Logging

writeToLog :: Universe u => String -> StateT u IO () Source #

Write a message to the log file for this universe.

Database

agentIds :: Universe u => StateT u IO [AgentId] Source #

Returns the list of agents in the population.

archivedAgentIds :: Universe u => StateT u IO [AgentId] Source #

Returns the list of (dead) agents in the archive.

popSize :: Universe u => StateT u IO Int Source #

Returns the current size of the population.

getAgent :: (Universe u, Serialize (Agent u)) => AgentId -> StateT u IO (Either String (Agent u)) Source #

Fetches the agent with the specified ID from the population. Note: Changes made to this agent will not "take" until store is called.

getAgentFromArchive :: (Universe u, Serialize (Agent u)) => AgentId -> StateT u IO (Either String (Agent u)) Source #

Fetches the agent with the specified ID from the archive.

getAgents :: (Universe u, Serialize (Agent u)) => [AgentId] -> StateT u IO [Agent u] Source #

Fetches the agents with the specified IDs from the population.

store :: (Universe u, Serialize (Agent u)) => Agent u -> StateT u IO () Source #

If the agent is alive, adds it to the population (replacing the the previous copy of that agent, if any). If the agent is dead, places it in the archive.

Names

genName :: Universe u => StateT u IO AgentId Source #

Generate a unique name for a new agent.

Agent programs

type AgentProgram u = Agent u -> StateT u IO (Agent u) Source #

A program involving one agent. The input parameter is the agent. The program must return the agent (which may have been modified).

withAgent :: (Universe u, Serialize (Agent u)) => AgentProgram u -> AgentId -> StateT u IO () Source #

Run a program involving one agent

type AgentsProgram u = [Agent u] -> StateT u IO [Agent u] Source #

A program involving multiple agents. The input parameter is a list of agents. The program must return a list of agents that have been *modified*. The order of the output list is not important.

Agent rotation

lineup :: Universe u => StateT u IO [AgentId] Source #

Returns the current lineup of (living) agents in the universe. Note: Check for endOfRound and call refreshLineup if needed before invoking this function.

startOfRound :: Universe u => StateT u IO Bool Source #

Returns true if no agents have yet their turn at the CPU for this round.

endOfRound :: Universe u => StateT u IO Bool Source #

Returns true if the lineup is empty or if all of the agents in the lineup have had their turn at the CPU for this round.

refreshLineup :: Universe u => StateT u IO () Source #

Creates a fresh lineup containing all of the agents in the population, in random order.

markDone :: Universe u => AgentId -> StateT u IO () Source #

Mark the current agent done. If it is still alive, it will move to the end of the lineup.