creatur-5.2.1: Framework for artificial life experiments.

Portabilityportable
Stabilityexperimental
Maintaineramy@nualeargais.ie
Safe HaskellNone

ALife.Creatur.Universe

Contents

Description

Provides a habitat for artificial life.

Synopsis

Constructors

class (Clock (Clock u), Logger (Logger u), Database (AgentDB u), AgentNamer (AgentNamer u), Checklist (Checklist u), Agent (Agent u), Record (Agent u), Agent u ~ DBRecord (AgentDB u)) => Universe u whereSource

A habitat containing artificial life.

Associated Types

type Agent u Source

type Clock u Source

type Logger u Source

type AgentDB u Source

type AgentNamer u Source

type Checklist u Source

Instances

Clock

currentTime :: Universe u => StateT u IO TimeSource

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 IntSource

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 (Either String [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 AgentIdSource

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.

isNew :: Universe u => AgentId -> StateT u IO BoolSource

EXPORTED FOR TESTING ONLY

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 refresh if needed before invoking this function.

endOfRound :: Universe u => StateT u IO BoolSource

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

refresh :: 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.