CS 470 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>], [<Agent>], [], [<Dirt>], [], [], [], [<Dirt>], [<Dirt>], [<Wall>]],
 [[<Wall>],
  [<Dirt>],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [<Wall>]],
 [[<Wall>],
  [],
  [],
  [<Dirt>],
  [<Dirt>],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [<Wall>]],
 [[<Wall>], [], [], [], [], [<Dirt>], [<Dirt>], [<Dirt>], [<Dirt>], [<Wall>]],
 [[<Wall>], [<Dirt>], [<Dirt>], [], [], [], [<Dirt>], [], [], [<Wall>]],
 [[<Wall>], [], [<Dirt>], [], [], [], [<Dirt>], [], [], [<Wall>]],
 [[<Wall>],
  [],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Wall>]],
 [[<Wall>],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [<Dirt>],
  [<Dirt>],
  [<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, 1)
In [6]:
gv.run(10)
<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 Right at (2, 1)
<Agent> perceives ('Clean', 'None') and does Right at (3, 1)
<Agent> perceives ('Clean', 'None') and does Right at (4, 1)
<Agent> perceives ('Dirty', 'None') and does Suck at (5, 1)
<Agent> perceives ('Clean', 'None') and does Up at (5, 1)
<Agent> perceives ('Clean', 'None') and does Down at (5, 1)
<Agent> perceives ('Dirty', 'None') and does Suck at (5, 2)
<Agent> perceives ('Clean', 'None') and does Up at (5, 2)
In [7]:
rv.location
Out[7]:
(5, 1)
In [8]:
rv.performance
Out[8]:
23

Now we create a vacuum world without graphics.

In [9]:
nve = NewVacuumEnvironment(10,10,bias=0.5)
In [10]:
nrv = TraceAgent(BetterReflexVacuumAgent())
nve.add_thing(nrv)
nve.get_world()
Out[10]:
[[[<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>],
  [<Wall>]],
 [[<Wall>],
  [<Dirt>, <Agent>],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Wall>]],
 [[<Wall>], [<Dirt>], [], [], [<Dirt>], [], [], [<Dirt>], [], [<Wall>]],
 [[<Wall>], [], [], [<Dirt>], [], [<Dirt>], [<Dirt>], [], [], [<Wall>]],
 [[<Wall>], [], [<Dirt>], [], [], [], [<Dirt>], [<Dirt>], [<Dirt>], [<Wall>]],
 [[<Wall>],
  [],
  [<Dirt>],
  [<Dirt>],
  [<Dirt>],
  [],
  [<Dirt>],
  [<Dirt>],
  [],
  [<Wall>]],
 [[<Wall>], [], [], [], [], [<Dirt>], [<Dirt>], [], [], [<Wall>]],
 [[<Wall>], [], [], [], [], [], [], [<Dirt>], [], [<Wall>]],
 [[<Wall>], [<Dirt>], [], [<Dirt>], [], [<Dirt>], [], [<Dirt>], [], [<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]:
(2, 1)
In [13]:
nrv.performance
Out[13]:
23
In [14]:
main()
hours
# is it greater than 0?
 OK  got: 2 expected: <function main.<locals>.<lambda> at 0x7fc32822fcb0>
NewVacuumEnvironment - Walls
 OK  got: '[[[<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: 159 expected: <function main.<locals>.<lambda> at 0x7fc328232170>
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 (1, 1)
 OK  got: (1, 1) expected: (1, 1)
 OK  got: 10 expected: 10
<Agent> perceives ('Clean', 'None') and does Left 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 Down at (1, 2)
<Agent> perceives ('Dirty', 'None') and does Suck at (1, 3)
<Agent> perceives ('Clean', 'None') and does Down at (1, 3)
<Agent> perceives ('Dirty', 'None') and does Suck at (1, 4)
<Agent> perceives ('Clean', 'None') and does Up at (1, 4)
<Agent> perceives ('Clean', 'None') and does Up at (1, 3)
<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 Left at (1, 1)
<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 Up at (2, 1)
<Agent> perceives ('Clean', 'None') and does Down at (2, 1)
<Agent> perceives ('Dirty', 'None') and does Suck at (2, 2)
<Agent> perceives ('Clean', 'None') and does Down at (2, 2)
 OK  got: 45 expected: <function main.<locals>.<lambda> at 0x7fc328242a70>

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 agents.ModelBasedVacuumAgent()>, 9),
 (<function agents.ReflexVacuumAgent()>, -989)]
In [ ]: