3838from utils import *
3939import random
4040import 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