Copyright | (c) Amy de Buitléir 2012-2016 |
---|---|
License | BSD-style |
Maintainer | amy@nualeargais.ie |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
Provides a habitat for artificial life.
- 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
- 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, setClock, logger, setLogger, agentDB, setAgentDB, agentNamer, setNamer, checklist, setChecklist
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 #
(Agent a, SizedRecord a) => Universe (CachedUniverse a) Source # | |
(Agent a, Record a) => Universe (SimpleUniverse a) Source # | |
data SimpleUniverse a Source #
Eq (SimpleUniverse a) Source # | |
Show (SimpleUniverse a) Source # | |
(Agent a, Record a) => Universe (SimpleUniverse a) Source # | |
type Agent (SimpleUniverse a) Source # | |
type Clock (SimpleUniverse a) Source # | |
type Logger (SimpleUniverse a) Source # | |
type AgentDB (SimpleUniverse a) Source # | |
type Namer (SimpleUniverse a) Source # | |
type Checklist (SimpleUniverse a) Source # | |
data CachedUniverse a Source #
Eq a => Eq (CachedUniverse a) Source # | |
Show a => Show (CachedUniverse a) Source # | |
(Agent a, SizedRecord a) => Universe (CachedUniverse a) Source # | |
type Agent (CachedUniverse a) Source # | |
type Clock (CachedUniverse a) Source # | |
type Logger (CachedUniverse a) Source # | |
type AgentDB (CachedUniverse a) Source # | |
type Namer (CachedUniverse a) Source # | |
type Checklist (CachedUniverse a) Source # | |
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.