creatur-5.8.2: Framework for artificial life experiments.

Copyright(c) Amy de Buitléir 2012-2014
LicenseBSD-style
Maintaineramy@nualeargais.ie
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell98

ALife.Creatur.Universe

Contents

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

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 (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 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.

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

isNew :: Universe u => AgentId -> StateT u IO Bool Source

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.