@@ -65,7 +65,7 @@ class Agent(Thing):
6565 """An Agent is a subclass of Thing with one required slot,
6666 .program, which should hold a function that takes one argument, the
6767 percept, and returns an action. (What counts as a percept or action
68- will depend on the specific environment in which the agent exists.)
68+ will depend on the specific environment in which the agent exists.)
6969 Note that 'program' is a slot, not a method. If it were a method,
7070 then the program could 'cheat' and look at aspects of the agent.
7171 It's not supposed to do that: the program can only look at the
@@ -87,7 +87,7 @@ def can_grab(self, thing):
8787 """Returns True if this agent can grab this thing.
8888 Override for appropriate subclasses of Agent and Thing."""
8989 return False
90-
90+
9191def TraceAgent (agent ):
9292 """Wrap the agent's program to print its input and output. This will let
9393 you see what the agent is doing in the environment."""
@@ -253,7 +253,7 @@ def list_things_at(self, location, tclass=Thing):
253253 "Return all things exactly at a given location."
254254 return [thing for thing in self .things
255255 if thing .location == location and isinstance (thing , tclass )]
256-
256+
257257 def some_things_at (self , location , tclass = Thing ):
258258 """Return true if at least one of the things at location
259259 is an instance of class tclass (or a subclass)."""
@@ -297,7 +297,7 @@ class XYEnvironment(Environment):
297297 def __init__ (self , width = 10 , height = 10 ):
298298 super (XYEnvironment , self ).__init__ ()
299299 update (self , width = width , height = height , observers = [])
300-
300+
301301 def things_near (self , location , radius = None ):
302302 "Return all things within radius of location."
303303 if radius is None : radius = self .perceptible_distance
@@ -343,7 +343,7 @@ def move_to(self, thing, destination):
343343 thing .location = destination
344344 for o in self .observers :
345345 o .thing_moved (thing )
346-
346+
347347 def add_thing (self , thing , location = (1 , 1 )):
348348 super (XYEnvironment , self ).add_thing (thing , location )
349349 thing .holding = []
@@ -356,7 +356,7 @@ def delete_thing(self, thing):
356356 # Any more to do? Thing holding anything or being held?
357357 for obs in self .observers :
358358 obs .thing_deleted (thing )
359-
359+
360360 def add_walls (self ):
361361 "Put walls around the entire perimeter of the grid."
362362 for x in range (self .width ):
@@ -367,14 +367,14 @@ def add_walls(self):
367367 self .add_thing (Wall (), (self .width - 1 , y ))
368368
369369 def add_observer (self , observer ):
370- """Adds an observer to the list of observers.
370+ """Adds an observer to the list of observers.
371371 An observer is typically an EnvGUI.
372-
372+
373373 Each observer is notified of changes in move_to and add_thing,
374374 by calling the observer's methods thing_moved(thing)
375375 and thing_added(thing, loc)."""
376376 self .observers .append (observer )
377-
377+
378378 def turn_heading (self , heading , inc ):
379379 "Return the heading to the left (inc=+1) or right (inc=-1) of heading."
380380 return turn_heading (heading , inc )
@@ -388,11 +388,11 @@ class Wall(Obstacle):
388388 pass
389389
390390#______________________________________________________________________________
391- ## Vacuum environment
391+ ## Vacuum environment
392392
393393class Dirt (Thing ):
394394 pass
395-
395+
396396class VacuumEnvironment (XYEnvironment ):
397397 """The environment of [Ex. 2.12]. Agent perceives dirty or clean,
398398 and bump (into obstacle) or not; 2D discrete world of unknown size;
@@ -440,9 +440,9 @@ def __init__(self):
440440 loc_B : random .choice (['Clean' , 'Dirty' ])}
441441
442442 def thing_classes (self ):
443- return [Wall , Dirt , ReflexVacuumAgent , RandomVacuumAgent ,
443+ return [Wall , Dirt , ReflexVacuumAgent , RandomVacuumAgent ,
444444 TableDrivenVacuumAgent , ModelBasedVacuumAgent ]
445-
445+
446446 def percept (self , agent ):
447447 "Returns the agent's location, and the location status (Dirty/Clean)."
448448 return (agent .location , self .status [agent .location ])
@@ -485,16 +485,16 @@ def thing_classes(self):
485485
486486 ## Needs a lot of work ...
487487
488-
488+
489489#______________________________________________________________________________
490490
491491def compare_agents (EnvFactory , AgentFactories , n = 10 , steps = 1000 ):
492492 """See how well each of several agents do in n instances of an environment.
493493 Pass in a factory (constructor) for environments, and several for agents.
494- Create n instances of the environment, and run each agent in copies of
494+ Create n instances of the environment, and run each agent in copies of
495495 each one for steps. Return a list of (agent, average-score) tuples."""
496496 envs = [EnvFactory () for i in range (n )]
497- return [(A , test_agent (A , steps , copy .deepcopy (envs )))
497+ return [(A , test_agent (A , steps , copy .deepcopy (envs )))
498498 for A in AgentFactories ]
499499
500500def test_agent (AgentFactory , steps , envs ):
@@ -527,7 +527,7 @@ def score(env):
527527## give is a range of expected scores. If this test fails, it does
528528## not necessarily mean something is wrong.
529529>>> envs = [TrivialVacuumEnvironment() for i in range(100)]
530- >>> def testv(A): return test_agent(A, 4, copy.deepcopy(envs))
530+ >>> def testv(A): return test_agent(A, 4, copy.deepcopy(envs))
531531>>> 7 < testv(ModelBasedVacuumAgent) < 11
532532True
533533>>> 5 < testv(ReflexVacuumAgent) < 9
@@ -551,12 +551,12 @@ class EnvGUI(tk.Tk, object):
551551 def __init__ (self , env , title = 'AIMA GUI' , cellwidth = 50 , n = 10 ):
552552
553553 # Initialize window
554-
554+
555555 super (EnvGUI , self ).__init__ ()
556556 self .title (title )
557557
558558 # Create components
559-
559+
560560 canvas = EnvCanvas (self , env , cellwidth , n )
561561 toolbar = EnvToolbar (self , env , canvas )
562562 for w in [canvas , toolbar ]:
@@ -569,14 +569,14 @@ def __init__(self, parent, env, canvas):
569569 super (EnvToolbar , self ).__init__ (parent , relief = 'raised' , bd = 2 )
570570
571571 # Initialize instance variables
572-
572+
573573 self .env = env
574574 self .canvas = canvas
575575 self .running = False
576576 self .speed = 1.0
577577
578578 # Create buttons and other controls
579-
579+
580580 for txt , cmd in [('Step >' , self .env .step ),
581581 ('Run >>' , self .run ),
582582 ('Stop [ ]' , self .stop ),
@@ -608,7 +608,7 @@ def background_run(self):
608608 delay_sec = 1.0 / max (self .speed , 1.0 ) # avoid division by zero
609609 ms = int (1000.0 * delay_sec ) # seconds to milliseconds
610610 self .after (ms , self .background_run )
611-
611+
612612 def list_things (self ):
613613 print "Things in the environment:"
614614 for thing in self .env .things :
@@ -621,4 +621,4 @@ def list_agents(self):
621621
622622 def set_speed (self , speed ):
623623 self .speed = float (speed )
624-
624+
0 commit comments