Portability | portable |
---|---|
Stability | experimental |
Maintainer | amy@nualeargais.ie |
Safe Haskell | None |
Provides a habitat for artificial life.
- class (Clock (Clock u), Logger (Logger u), Database (AgentDB u), Namer (Namer u), Checklist (Checklist u), EnergyPool (EnergyPool u), Agent (Agent u), Record (Agent u), Agent u ~ DBRecord (AgentDB u)) => Universe u where
- type Agent u
- type Clock u
- type Logger u
- type AgentDB u
- type Namer u
- type Checklist u
- type EnergyPool u
- clock :: u -> Clock u
- setClock :: u -> Clock u -> u
- logger :: u -> Logger u
- setLogger :: u -> Logger u -> u
- agentDB :: u -> AgentDB u
- setAgentDB :: u -> AgentDB u -> u
- agentNamer :: u -> Namer u
- setNamer :: u -> Namer u -> u
- checklist :: u -> Checklist u
- setChecklist :: u -> Checklist u -> u
- energyPool :: u -> EnergyPool u
- setEnergyPool :: u -> EnergyPool u -> u
- data SimpleUniverse a
- data CachedUniverse a
- mkSimpleUniverse :: String -> FilePath -> SimpleUniverse a
- mkCachedUniverse :: String -> FilePath -> Int -> CachedUniverse a
- currentTime :: Universe u => StateT u IO Time
- incTime :: Universe u => StateT u IO ()
- writeToLog :: Universe u => String -> StateT u IO ()
- agentIds :: Universe u => StateT u IO [AgentId]
- archivedAgentIds :: Universe u => StateT u IO [AgentId]
- popSize :: Universe u => StateT u IO Int
- getAgent :: (Universe u, Serialize (Agent u)) => AgentId -> StateT u IO (Either String (Agent u))
- getAgentFromArchive :: (Universe u, Serialize (Agent u)) => AgentId -> StateT u IO (Either String (Agent u))
- getAgents :: (Universe u, Serialize (Agent u)) => [AgentId] -> StateT u IO (Either String [Agent u])
- store :: (Universe u, Serialize (Agent u)) => Agent u -> StateT u IO ()
- genName :: Universe u => StateT u IO AgentId
- type AgentProgram u = Agent u -> StateT u IO (Agent u)
- withAgent :: (Universe u, Serialize (Agent u)) => AgentProgram u -> AgentId -> StateT u IO ()
- type AgentsProgram u = [Agent u] -> StateT u IO [Agent u]
- withAgents :: (Universe u, Serialize (Agent u)) => AgentsProgram u -> [AgentId] -> StateT u IO ()
- isNew :: Universe u => AgentId -> StateT u IO Bool
- lineup :: Universe u => StateT u IO [AgentId]
- startOfRound :: Universe u => StateT u IO Bool
- endOfRound :: Universe u => StateT u IO Bool
- refreshLineup :: Universe u => StateT u IO ()
- markDone :: Universe u => AgentId -> StateT u IO ()
- replenishEnergyPool :: Universe u => Double -> StateT u IO ()
- withdrawEnergy :: Universe u => Double -> StateT u IO Double
Constructors
class (Clock (Clock u), Logger (Logger u), Database (AgentDB u), Namer (Namer u), Checklist (Checklist u), EnergyPool (EnergyPool u), Agent (Agent u), Record (Agent u), Agent u ~ DBRecord (AgentDB u)) => Universe u whereSource
A habitat containing artificial life.
type EnergyPool u Source
setClock :: u -> Clock u -> uSource
setLogger :: u -> Logger u -> uSource
agentDB :: u -> AgentDB uSource
setAgentDB :: u -> AgentDB u -> uSource
agentNamer :: u -> Namer uSource
setNamer :: u -> Namer u -> uSource
checklist :: u -> Checklist uSource
setChecklist :: u -> Checklist u -> uSource
energyPool :: u -> EnergyPool uSource
setEnergyPool :: u -> EnergyPool u -> uSource
(Agent a, SizedRecord a) => Universe (CachedUniverse a) | |
(Agent a, Record a) => Universe (SimpleUniverse a) |
data SimpleUniverse a Source
Eq (SimpleUniverse a) | |
Show (SimpleUniverse a) | |
(Agent a, Record a) => Universe (SimpleUniverse a) |
data CachedUniverse a Source
Eq a => Eq (CachedUniverse a) | |
Show a => Show (CachedUniverse a) | |
(Agent a, SizedRecord a) => Universe (CachedUniverse a) |
mkSimpleUniverse :: String -> FilePath -> SimpleUniverse aSource
mkCachedUniverse :: String -> FilePath -> Int -> CachedUniverse aSource
Clock
Logging
writeToLog :: Universe u => String -> StateT u IO ()Source
Write a message to the log file for this universe.
Database
archivedAgentIds :: Universe u => StateT u IO [AgentId]Source
Returns the list of (dead) agents in the archive.
getAgent :: (Universe u, Serialize (Agent u)) => AgentId -> StateT u IO (Either String (Agent u))Source
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
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
Agent rotation
lineup :: Universe u => StateT u IO [AgentId]Source
Returns the current lineup of (living) agents in the universe.
Note: Check for
and call endOfRound
if needed
before invoking this function.
refreshLineup
startOfRound :: Universe u => StateT u IO BoolSource
Returns true if no agents have yet their turn at the CPU for this round.
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 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.