(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:
(agent-trials 'vacuum-world '(random-vacuum-agent reactive-vacuum-agent) :n 20) type (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. type (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]function (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.
Return the percept for this agent.method ((env environment))
Modify the environment, based on agents actions, etc.method ((env environment))
A list of the action operators that an agent can do.method ((env environment) agent)
Return a number saying how well this agent is doing.Here are the ones that can usually be inherited: method ((env environment))
Called once to do whatever is necessary to set up the environment for running the simulation.method ((env environment))
Return true if the simulation should end now.method ((env environment))
Display the current state of the environment.method ((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.function (environment-fn agent-type env-gen-random-state n)
Run n environments with an identical agent in each, and average the scores.function (env)
Each agent (if the agent is alive and has specified a legal action) takes the action.method ((env environment) stream)
File agents/environments/grid-env.lisp
type (name alive? loc bump size color shape sound contents max-contents container heading)
An object is anything that occupies space. Some objects are 'alive'.type nil
An agent body is an object; some bodies have a hand that can hold 1 thing.
Execute the actions and do bookkeeping on the bump sensor.method ((env grid-environment))
method ((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.method ((env grid-environment))
By default, we stop when there are no live agents.method ((env grid-environment))
Show what is in each location in the environment.method ((object object) stream)
Show an object's name, and if it is alive, the direction it faces.
The agent emits a sound.method ((env grid-environment) agent-body direction)
The agent changes its heading by turning right or left.method ((env grid-environment) agent-body)
Move the object to the location that is one step directly ahead of it.method ((env grid-environment) agent-body &optional args)
Grab an object at the specified location. Assumes a one-handed agent.function (object)
method ((env grid-environment) agent-body &optional args)
Release an object that is in the hand, putting it at the specified loc.
Place objects, defined by specs, in the environment.function (env spec)
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.function (n)
Make an instance of the specified type by calling make-TYPE.function (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.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.
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.method ((env vacuum-world) agent)
Percept is a three-element sequence: bump, dirt and home.method ((env vacuum-world))
method ((env environment) agent-body)
File agents/environments/wumpus.lisp
A dangerous world with pits and wumpuses, and some gold.type nil
The default wumpus agent body is given an arrow.type nil
End when some agent climbs out, or for the default reason (everyone dead).method ((env wumpus-world) agent)
Score 1000 for getting the gold, with penalty of 10000 if dead and penalty of 1 for each step taken.method ((env wumpus-world) agent)
Perceive stench, breeze, glitter, bump, and sound.method ((env wumpus-world))
In the wumpus world, agents can move around, grab gold and shoot arrows.function (object)
Pits and live wumpuses are deadly.
Climb out of the cave.method ((env wumpus-world) agent-body)
An arrow keeps going until it kills something or hits a wall.function (object)
Make the object no longer alive.
An agent that asks the user to type in an action.function (percept)
Ask the user what action to take.method ((agent agent) stream)
Agents are printed by showing their name (or body) and score.function (env)
Name the agents 1, 2, ... if they don't yet have a name.
A very stupid agent: ignore percept and choose a random action.type nil
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.type nil
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.
Return a list of objects in this location, optionally including objects that are contained within containers here.function (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.function (object loc env &optional initial?)
Put the object in its initial position or a new position in environment.function (object container env)
Put the object inside the container, if there is room.function (object env)
Remove the object from its current location.function (predicate loc env)
Return an object in this location that satisfies this predicate.function (predicate loc env)
Return an object in a neighboring square that satisfies the predicate.function (predicate loc env)
Return an object either in loc or a neighboring square that satisfies the predicate.function (loc1 loc2 &optional tolerance)
Are the two locations nearby each other?
Coordinate-wise addition of locations: (add-locs '(1 2) '(10 20)) = (11 22)function (&rest locations)
Coordinate-wise subtraction of locations.function (heading)
Convert a heading like (0 1) to a depictive string like ^.function (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.function (agent-body loc)
Return an offset from an agent that corresponds to the absolute loc.
AIMA Home | Authors | Lisp Code | AI Programming | Instructors Pages |