CS 370 Artificial Intelligence hw1¶

You are to edit the file hw1.py, as described in the instructions. We have provided a solution file, hw1a.pyc, which is compiled bytecode that you may run.

Below we demonstrate the code, both with and without graphics.

In [1]:
from hw1a import *
In [2]:
gv = GraphicVacuumEnvironment(10,10,bias=0.5,color={'Agent': (200,0,0), 'Dirt': (230, 115, 40), 'Wall': (100,100,100)})
In [3]:
rv = TraceAgent(BetterReflexVacuumAgent())
gv.add_thing(rv)
gv.get_world()
Out[3]:
[[[<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>]],
 [[<Wall>],
  [<Dirt>],
  [<Dirt>],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Agent>],
  [],
  [],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [<Dirt>],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [<Dirt>],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [<Dirt>],
  [],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [<Dirt>],
  [],
  [<Dirt>],
  [],
  [],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [],
  [],
  [],
  [<Dirt>],
  [],
  [<Dirt>],
  [<Dirt>],
  [],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [],
  [<Dirt>],
  [],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [],
  [<Dirt>],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [<Dirt>],
  [],
  [],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [<Dirt>],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>]]]
In [4]:
rv.performance
Out[4]:
0
In [5]:
rv.location
Out[5]:
(1, 6)
In [6]:
gv.run(10)
<Agent> perceives ('Clean', 'None') and does Left at (1, 6)
<Agent> perceives ('Clean', 'None') and does Down at (1, 6)
<Agent> perceives ('Clean', 'None') and does Right at (1, 7)
<Agent> perceives ('Clean', 'None') and does Left at (2, 7)
<Agent> perceives ('Clean', 'None') and does Left at (1, 7)
<Agent> perceives ('Clean', 'None') and does Left at (1, 7)
<Agent> perceives ('Clean', 'None') and does Left at (1, 7)
<Agent> perceives ('Clean', 'None') and does Down at (1, 7)
<Agent> perceives ('Clean', 'None') and does Up at (1, 8)
<Agent> perceives ('Clean', 'None') and does Left at (1, 7)
In [7]:
rv.location
Out[7]:
(5, 1)
In [9]:
rv.performance
Out[9]:
-10

Now we create a vacuum world without graphics.

In [10]:
nve = NewVacuumEnvironment(10,10,bias=0.5)
In [11]:
nrv = TraceAgent(BetterReflexVacuumAgent())
nve.add_thing(nrv)
nve.get_world()
Out[11]:
[[[<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>]],
 [[<Wall>],
  [],
  [<Dirt>],
  [],
  [<Dirt>],
  [],
  [<Dirt>],
  [<Agent>],
  [],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [<Dirt>],
  [],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [<Dirt>],
  [<Dirt>],
  [],
  [<Dirt>],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [<Wall>, <Wall>]],
 [[<Wall>], [], [], [], [<Dirt>], [<Dirt>], [], [], [], [<Wall>, <Wall>]],
 [[<Wall>], [], [], [], [], [], [], [<Dirt>], [], [<Wall>, <Wall>]],
 [[<Wall>],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Wall>, <Wall>]],
 [[<Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>],
  [<Wall>, <Wall>]]]
In [11]:
nve.run(10)
<Agent> perceives ('Dirty', 'None') and does Suck at (1, 1)
<Agent> perceives ('Clean', 'None') and does Up at (1, 1)
<Agent> perceives ('Clean', 'None') and does Down at (1, 1)
<Agent> perceives ('Dirty', 'None') and does Suck at (1, 2)
<Agent> perceives ('Clean', 'None') and does Up at (1, 2)
<Agent> perceives ('Clean', 'None') and does Left at (1, 1)
<Agent> perceives ('Clean', 'None') and does Right at (1, 1)
<Agent> perceives ('Dirty', 'None') and does Suck at (2, 1)
<Agent> perceives ('Clean', 'None') and does Down at (2, 1)
<Agent> perceives ('Clean', 'None') and does Up at (2, 2)
In [12]:
nrv.location
Out[12]:
(1, 7)
In [13]:
nrv.performance
Out[13]:
0
In [14]:
main()
hours
# is it greater than 0?
 OK  got: 2 expected: <function main.<locals>.<lambda> at 0x7fa3ec19b6d0>
NewVacuumEnvironment - Walls
  X  got: '[[[<Wall>], [<Wall>], [<Wall>], [<Wall>], [<Wall>]], [[<Wall>], [], [], [], [<Wall>, <Wall>]], [[<Wall>], [], [], [], [<Wall>, <Wall>]], [[<Wall>], [], [], [], [<Wall>, <Wall>]], [[<Wall>], [<Wall>, <Wall>], [<Wall>, <Wall>], [<Wall>, <Wall>], [<Wall>, <Wall>]]]' expected: '[[[<Wall>], [<Wall>], [<Wall>], [<Wall>], [<Wall>]], [[<Wall>], [], [], [], [<Wall>]], [[<Wall>], [], [], [], [<Wall>]], [[<Wall>], [], [], [], [<Wall>]], [[<Wall>], [<Wall>], [<Wall>], [<Wall>], [<Wall>]]]'
NewVacuumEnvironment - Dirt
 OK  got: 167 expected: <function main.<locals>.<lambda> at 0x7fa410c47f40>
NewVacuumEnvironment - Very Clean
 OK  got: 0 expected: 0
NewVacuumEnvironment - Very Dirty
 OK  got: 324 expected: 324
TraceAgent and BetterReflexVacuumAgent
<Agent> perceives ('Dirty', 'None') and does Suck at (3, 10)
  X  got: (3, 10) expected: (1, 1)
 OK  got: 10 expected: 10
<Agent> perceives ('Clean', 'None') and does Left at (3, 10)
<Agent> perceives ('Dirty', 'None') and does Suck at (2, 10)
<Agent> perceives ('Clean', 'None') and does Right at (2, 10)
<Agent> perceives ('Clean', 'None') and does Left at (3, 10)
<Agent> perceives ('Clean', 'None') and does Right at (2, 10)
<Agent> perceives ('Clean', 'None') and does Down at (3, 10)
<Agent> perceives ('Dirty', 'None') and does Suck at (3, 11)
<Agent> perceives ('Clean', 'None') and does Left at (3, 11)
<Agent> perceives ('Dirty', 'None') and does Suck at (2, 11)
<Agent> perceives ('Clean', 'None') and does Left at (2, 11)
<Agent> perceives ('Dirty', 'None') and does Suck at (1, 11)
<Agent> perceives ('Clean', 'None') and does Down at (1, 11)
<Agent> perceives ('Dirty', 'None') and does Suck at (1, 12)
<Agent> perceives ('Clean', 'None') and does Left at (1, 12)
<Agent> perceives ('Clean', 'None') and does Down at (1, 12)
<Agent> perceives ('Dirty', 'None') and does Suck at (1, 13)
<Agent> perceives ('Clean', 'None') and does Left at (1, 13)
<Agent> perceives ('Clean', 'None') and does Left at (1, 13)
<Agent> perceives ('Clean', 'None') and does Down at (1, 13)
<Agent> perceives ('Dirty', 'None') and does Suck at (1, 14)
 OK  got: 67 expected: <function main.<locals>.<lambda> at 0x7fa3ec010e50>

Below we demonstrate the testing code from the end of agents.py

In [15]:
environment = TrivialVacuumEnvironment
In [16]:
agents = [ModelBasedVacuumAgent, ReflexVacuumAgent]
In [17]:
result = compare_agents(environment, agents)
In [18]:
result
Out[18]:
[(<function agents4e.ModelBasedVacuumAgent()>, 10),
 (<function agents4e.ReflexVacuumAgent()>, -987.9)]
In [ ]: