Skip to content

Commit 442f312

Browse files
committed
Finished porting to Python 3
Used tool 2to3 to finish the porting to Python 3 plus some fixes by hand.
1 parent e40b72c commit 442f312

14 files changed

Lines changed: 239 additions & 164 deletions

agents.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from utils import *
3939
import random
4040
import copy
41+
import collections
4142

4243
#______________________________________________________________________________
4344

@@ -80,8 +81,8 @@ def __init__(self, program=None):
8081
self.bump = False
8182
if program is None:
8283
def program(percept):
83-
return input('Percept={}; action? ' .format(percept))
84-
assert callable(program)
84+
return eval(input('Percept={}; action? ' .format(percept)))
85+
assert isinstance(program, collections.Callable)
8586
self.program = program
8687

8788
def can_grab(self, thing):
@@ -95,7 +96,7 @@ def TraceAgent(agent):
9596
old_program = agent.program
9697
def new_program(percept):
9798
action = old_program(percept)
98-
print('{} perceives {} and does {}'.format(agent, percept, action))
99+
print(('{} perceives {} and does {}'.format(agent, percept, action)))
99100
return action
100101
agent.program = new_program
101102
return agent
@@ -280,9 +281,9 @@ def delete_thing(self, thing):
280281
except(ValueError, e):
281282
print(e)
282283
print(" in Environment delete_thing")
283-
print(" Thing to be removed: {} at {}" .format(thing, thing.location))
284-
print(" from list: {}" .format([(thing, thing.location)
285-
for thing in self.things]))
284+
print((" Thing to be removed: {} at {}" .format(thing, thing.location)))
285+
print((" from list: {}" .format([(thing, thing.location)
286+
for thing in self.things])))
286287
if thing in self.agents:
287288
self.agents.remove(thing)
288289

@@ -504,7 +505,7 @@ def score(env):
504505
env.add_thing(agent)
505506
env.run(steps)
506507
return agent.performance
507-
return mean(map(score, envs))
508+
return mean(list(map(score, envs)))
508509

509510
#_________________________________________________________________________
510511

0 commit comments

Comments
 (0)