Skip to content

Commit e207551

Browse files
committed
modified print statements in agents.py to make it work in Py3, changed utils_test.py with regard to new utils.py
1 parent 52f46c7 commit e207551

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

agents.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def is_alive(self):
5454

5555
def show_state(self):
5656
"Display the agent's internal state. Subclasses should override."
57-
print "I don't know how to show_state."
57+
print("I don't know how to show_state.")
5858

5959
def display(self, canvas, x, y, width, height):
6060
# Do we need this?
@@ -94,7 +94,7 @@ def TraceAgent(agent):
9494
old_program = agent.program
9595
def new_program(percept):
9696
action = old_program(percept)
97-
print '%s perceives %s and does %s' % (agent, percept, action)
97+
print('%s perceives %s and does %s' % (agent, percept, action))
9898
return action
9999
agent.program = new_program
100100
return agent
@@ -172,7 +172,7 @@ def TableDrivenVacuumAgent():
172172

173173
def ReflexVacuumAgent():
174174
"A reflex agent for the two-state vacuum environment. [Fig. 2.8]"
175-
def program((location, status)):
175+
def program(location, status):
176176
if status == 'Dirty': return 'Suck'
177177
elif location == loc_A: return 'Right'
178178
elif location == loc_B: return 'Left'
@@ -181,7 +181,7 @@ def program((location, status)):
181181
def ModelBasedVacuumAgent():
182182
"An agent that keeps track of what locations are clean or dirty."
183183
model = {loc_A: None, loc_B: None}
184-
def program((location, status)):
184+
def program(location, status):
185185
"Same as ReflexVacuumAgent, except if everything is clean, do NoOp."
186186
model[location] = status ## Update the model here
187187
if model[loc_A] == model[loc_B] == 'Clean': return 'NoOp'
@@ -276,12 +276,12 @@ def delete_thing(self, thing):
276276
"""Remove a thing from the environment."""
277277
try:
278278
self.things.remove(thing)
279-
except ValueError, e:
280-
print e
281-
print " in Environment delete_thing"
282-
print " Thing to be removed: %s at %s" % (thing, thing.location)
283-
print " from list: %s" % [(thing, thing.location)
284-
for thing in self.things]
279+
except(ValueError, e):
280+
print(e)
281+
print(" in Environment delete_thing")
282+
print(" Thing to be removed: %s at %s" % (thing, thing.location))
283+
print(" from list: %s" % [(thing, thing.location)
284+
for thing in self.things])
285285
if thing in self.agents:
286286
self.agents.remove(thing)
287287

@@ -410,9 +410,8 @@ def thing_classes(self):
410410
def percept(self, agent):
411411
"""The percept is a tuple of ('Dirty' or 'Clean', 'Bump' or 'None').
412412
Unlike the TrivialVacuumEnvironment, location is NOT perceived."""
413-
status = if_(self.some_things_at(agent.location, Dirt),
414-
'Dirty', 'Clean')
415-
bump = if_(agent.bump, 'Bump', 'None')
413+
status = ('Dirty' if self.some_things_at(agent.location, Dirt) else 'Clean')
414+
bump = ('Bump' if agent.bump else'None')
416415
return (status, bump)
417416

418417
def execute_action(self, agent, action):
@@ -592,12 +591,12 @@ def __init__(self, parent, env, canvas):
592591
scale.pack(side='left')
593592

594593
def run(self):
595-
print 'run'
594+
print('run')
596595
self.running = True
597596
self.background_run()
598597

599598
def stop(self):
600-
print 'stop'
599+
print('stop')
601600
self.running = False
602601

603602
def background_run(self):
@@ -610,14 +609,14 @@ def background_run(self):
610609
self.after(ms, self.background_run)
611610

612611
def list_things(self):
613-
print "Things in the environment:"
612+
print("Things in the environment:")
614613
for thing in self.env.things:
615-
print "%s at %s" % (thing, thing.location)
614+
print("%s at %s" % (thing, thing.location))
616615

617616
def list_agents(self):
618-
print "Agents in the environment:"
617+
print("Agents in the environment:")
619618
for agt in self.env.agents:
620-
print "%s at %s" % (agt, agt.location)
619+
print("%s at %s" % (agt, agt.location))
621620

622621
def set_speed(self, speed):
623622
self.speed = float(speed)

utils_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import utils
32
from utils import *
43

54
def test_struct_initialization():
@@ -104,8 +103,6 @@ def f():
104103
return caller()
105104
assert f() == 'f'
106105

107-
def test_if_():
108-
assert if_(2 + 2 == 4, 'ok', lambda: expensive_computation()) == 'ok'
109106

110107
if __name__ == '__main__':
111108
pytest.main()

0 commit comments

Comments
 (0)