Copyright | (c) 2012-2021 Amy de Buitléir |
---|---|
License | BSD-style |
Maintainer | amy@nualeargais.ie |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Provides a habitat for artificial life.
Synopsis
- 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
- type Agent u
- type Clock u
- type Logger u
- type AgentDB u
- type Namer u
- type Checklist 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
- 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 [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 ()
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.
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
data SimpleUniverse a Source #
Instances
data CachedUniverse a Source #
Instances
mkSimpleUniverse :: String -> FilePath -> SimpleUniverse a Source #
mkCachedUniverse :: String -> FilePath -> Int -> CachedUniverse a Source #
Clock
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.
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
is called.store
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
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 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.