(run-environment (make-vacuum-world :aspec '(random-vacuum-agent)))
We also define AGENT-TRIALS to compare the performance of several different agents in a series of random environments, all drawn from an environment subtype. For example to run 2 agents in 20 environments each:
'(random-vacuum-agent reactive-vacuum-agent) :n 20)
environmenttype (agents step max-steps stream initialized state)
The world in which agents exist.An agent is something that perceives and acts. As such, each agent has a slot to hold its current percept, and its current action. The action will be handed back to the environment simulator to perform (if legal). Each agent also has a slot for the agent program, and one for its score as determined by the performance measure.
agenttype (program body score percept action name)
Agents take actions (based on percepts and the agent program) and receive a score (based on the performance measure). An agent has a body which can take action, and a program to choose the actions, based on percepts.
Basic environment simulator. It gives each agent its percept, gets an action from each agent, and updates the environment. It also keeps score for each agent, and optionally displays intermediate results. [p 48]
agent-trialsfunction (environment-fn agent-types &key n)
Report how well a single agent does in a set of N similar environments, and compare that to other agents in the same set of environments. Environment-fn takes a :agents keyword argument, and returns an environment. Agent-types is a list of names of functions that each create an agent.
get-perceptmethod ((env environment) agent)
Return the percept for this agent.
update-fnmethod ((env environment))
Modify the environment, based on agents actions, etc.
legal-actionsmethod ((env environment))
A list of the action operators that an agent can do.
performance-measuremethod ((env environment) agent)
Return a number saying how well this agent is doing.Here are the ones that can usually be inherited:
initializemethod ((env environment))
Called once to do whatever is necessary to set up the environment for running the simulation.
termination?method ((env environment))
Return true if the simulation should end now.
display-environmentmethod ((env environment))
Display the current state of the environment.
display-environment-snapshotmethod ((env environment))
Display a 'picture' of the current state of the environment.
Basic environment simulator; the same as run-environment. [p 48] We decided it was silly to run the environment and NOT eval the agents, so in this code, and in future editions of the book, we will only have RUN-ENVIRONMENT, and it will evaluate the agents.
agent-trialfunction (environment-fn agent-type env-gen-random-state n)
Run n environments with an identical agent in each, and average the scores.
Each agent (if the agent is alive and has specified a legal action) takes the action.
print-structuremethod ((env environment) stream)
grid-environmenttype (size grid objects start aspec bspec cspec)
objecttype (name alive? loc bump size color shape sound contents max-contents container heading)
An object is anything that occupies space. Some objects are 'alive'.
An agent body is an object; some bodies have a hand that can hold 1 thing.
update-fnmethod ((env grid-environment))
Execute the actions and do bookkeeping on the bump sensor.
legal-actionsmethod ((env grid-environment))
initializemethod ((env grid-environment))
Build a new environment with all the agents and objects in place. This gets passed an environment which may need to have the objects placed. See PARSE-SPECS below in this file for more on initialization.
termination?method ((env grid-environment))
By default, we stop when there are no live agents.
display-environment-snapshotmethod ((env grid-environment))
Show what is in each location in the environment.
print-structuremethod ((object object) stream)
Show an object's name, and if it is alive, the direction it faces.
speakmethod ((env grid-environment) agent-body sound)
The agent emits a sound.
turnmethod ((env grid-environment) agent-body direction)
The agent changes its heading by turning right or left.
forwardmethod ((env grid-environment) agent-body)
Move the object to the location that is one step directly ahead of it.
grabmethod ((env grid-environment) agent-body &optional args)
Grab an object at the specified location. Assumes a one-handed agent.
releasemethod ((env grid-environment) agent-body &optional args)
Release an object that is in the hand, putting it at the specified loc.
parse-specsfunction (env specs)
Place objects, defined by specs, in the environment.
parse-specfunction (env spec)
parse-wherefunction (env where whats)
parse-whatsfunction (env loc what-list)
parse-whatfunction (env loc what)
Place the objects specified by WHAT-LIST at the given location The default location is START for an agent, random otherwise. The notation (P 0.5 what...) means 50% chance of placing each what, and (* n what...) means place n copies of each what.
makefunction (type &rest args)
Make an instance of the specified type by calling make-TYPE.
random-locfunction (env &key if tries)
Return a random loc, somewhere in the environment. The loc must satisfy the :IF predicate. If it can't find such a location after a number of TRIES, it signals an error.
free-loc?function (loc env)
A location is free if there is no obstacle there and it is not the start.
A grid with some dirt in it, and by default a reactive vacuum agent.
performance-measuremethod ((env vacuum-world) agent)
100 points for each piece of dirt vacuumed up, -1 point for each step taken, and -1000 points if the agent does not return home.
get-perceptmethod ((env vacuum-world) agent)
Percept is a three-element sequence: bump, dirt and home.
legal-actionsmethod ((env vacuum-world))
suckmethod ((env vacuum-world) agent-body)
shut-offmethod ((env environment) agent-body)
A dangerous world with pits and wumpuses, and some gold.
The default wumpus agent body is given an arrow.
update-fnmethod ((env wumpus-world))
termination?method ((env wumpus-world))
End when some agent climbs out, or for the default reason (everyone dead).
performance-measuremethod ((env wumpus-world) agent)
Score 1000 for getting the gold, with penalty of 10000 if dead and penalty of 1 for each step taken.
get-perceptmethod ((env wumpus-world) agent)
Perceive stench, breeze, glitter, bump, and sound.
legal-actionsmethod ((env wumpus-world))
In the wumpus world, agents can move around, grab gold and shoot arrows.
Pits and live wumpuses are deadly.
climbmethod ((env wumpus-world) agent-body)
Climb out of the cave.
shootmethod ((env wumpus-world) agent-body)
propagate-arrowfunction (loc heading env)
An arrow keeps going until it kills something or hits a wall.
Make the object no longer alive.
An agent that asks the user to type in an action.
Ask the user what action to take.
print-structuremethod ((agent agent) stream)
Agents are printed by showing their name (or body) and score.
Name the agents 1, 2, ... if they don't yet have a name.
A very stupid agent: ignore percept and choose a random action.
When you bump, turn randomly; otherwise mostly go forward, but occasionally turn. Always suck when there is dirt.
The default wumpus agent gets an arrow.
This agent does the obvious reactive things: grab when there's a glitter, and turn and move when there's a bump. If the wumpus is alive and there's a stench, it turns and moves. Otherwise it wanders aimlessly.
grid-contentsfunction (env loc)
Return a list of objects in this location, optionally including objects that are contained within containers here.
move-object-tofunction (object loc env)
Move an object to an absolute location and return that location. However, attempting to move into a location with an obstacle fails (returns nil) and the object receives a bump.
place-objectfunction (object loc env &optional initial?)
Put the object in its initial position or a new position in environment.
place-in-containerfunction (object container env)
Put the object inside the container, if there is room.
remove-objectfunction (object env)
Remove the object from its current location.
find-object-iffunction (predicate loc env)
Return an object in this location that satisfies this predicate.
find-neighbor-iffunction (predicate loc env)
Return an object in a neighboring square that satisfies the predicate.
find-object-or-neighbor-iffunction (predicate loc env)
Return an object either in loc or a neighboring square that satisfies the predicate.
near?function (loc1 loc2 &optional tolerance)
Are the two locations nearby each other?
add-locsfunction (&rest locations)
Coordinate-wise addition of locations: (add-locs '(1 2) '(10 20)) = (11 22)
subtract-locsfunction (&rest locations)
Coordinate-wise subtraction of locations.
Convert a heading like (0 1) to a depictive string like ^.
absolute-locfunction (agent-body offset)
Return an absolute location given an offset from an agent, taking the agent's orientation into account. An offset of (1 2) means 1 square to the right and two ahead of the agent, given its present orientation.
offset-locfunction (agent-body loc)
Return an offset from an agent that corresponds to the absolute loc.
|AIMA Home||Authors||Lisp Code||AI Programming||Instructors Pages|