
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.
from hw1a import *
gv = GraphicVacuumEnvironment(10,10,bias=0.5,color={'Agent': (200,0,0), 'Dirt': (230, 115, 40), 'Wall': (100,100,100)})
rv = TraceAgent(BetterReflexVacuumAgent())
gv.add_thing(rv)
gv.get_world()
[[[<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>]]]
rv.performance
0
rv.location
(1, 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)
rv.location
(5, 1)
rv.performance
-10
Now we create a vacuum world without graphics.
nve = NewVacuumEnvironment(10,10,bias=0.5)
nrv = TraceAgent(BetterReflexVacuumAgent())
nve.add_thing(nrv)
nve.get_world()
[[[<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>]]]
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)
nrv.location
(1, 7)
nrv.performance
0
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
environment = TrivialVacuumEnvironment
agents = [ModelBasedVacuumAgent, ReflexVacuumAgent]
result = compare_agents(environment, agents)
result
[(<function agents4e.ModelBasedVacuumAgent()>, 10), (<function agents4e.ReflexVacuumAgent()>, -987.9)]