40
40
#______________________________________________________________________________
41
41
42
42
43
- class Object (object ):
43
+ class Object (object ):
44
44
"""This represents any physical object that can appear in an Environment.
45
45
You subclass Object to get the objects you want. Each object can have a
46
46
.__name__ slot (used for output only)."""
@@ -60,7 +60,7 @@ def display(self, canvas, x, y, width, height):
60
60
"""Display an image of this Object on the canvas."""
61
61
pass
62
62
63
- class Agent ( Object ):
63
+ class Agent ( object ):
64
64
"""An Agent is a subclass of Object with one required slot,
65
65
.program, which should hold a function that takes one argument, the
66
66
percept, and returns an action. (What counts as a percept or action
@@ -102,7 +102,7 @@ def new_program(percept):
102
102
103
103
#______________________________________________________________________________
104
104
105
- class TableDrivenAgent (Agent ):
105
+ class TableDrivenAgent (Agent ):
106
106
"""This agent selects an action based on the percept sequence.
107
107
It is practical only for tiny domains.
108
108
To customize it you provide a table to the constructor. [Fig. 2.7]"""
@@ -124,7 +124,7 @@ def program(percept):
124
124
return program
125
125
126
126
127
- class RandomAgent (Agent ):
127
+ class RandomAgent (Agent ):
128
128
"An agent that chooses an action at random, ignoring all percepts."
129
129
130
130
def __init__ (self , actions ):
@@ -140,7 +140,7 @@ def make_agent_program(self):
140
140
141
141
loc_A , loc_B = (0 , 0 ), (1 , 0 ) # The two locations for the Vacuum world
142
142
143
- class ReflexVacuumAgent (Agent ):
143
+ class ReflexVacuumAgent (Agent ):
144
144
"A reflex agent for the two-state vacuum environment. [Fig. 2.8]"
145
145
146
146
def __init__ (self ):
@@ -174,7 +174,7 @@ def TableDrivenVacuumAgent():
174
174
return TableDrivenAgent (table )
175
175
176
176
177
- class ModelBasedVacuumAgent (Agent ):
177
+ class ModelBasedVacuumAgent (Agent ):
178
178
"An agent that keeps track of what locations are clean or dirty."
179
179
180
180
def __init__ (self ):
@@ -195,7 +195,7 @@ def program((location, status)):
195
195
#______________________________________________________________________________
196
196
197
197
198
- class Environment (object ):
198
+ class Environment (object ):
199
199
"""Abstract class representing an Environment. 'Real' Environment classes
200
200
inherit from this. Your Environment will typically need to implement:
201
201
percept: Define the percept that an agent sees.
@@ -295,7 +295,7 @@ def trace_list (name, objlist):
295
295
ol_list = [(obj , obj .location ) for obj in objlist ]
296
296
print "%s: %s" % (name , ol_list )
297
297
298
- class XYEnvironment (Environment ):
298
+ class XYEnvironment (Environment ):
299
299
"""This class is for environments on a 2D plane, with locations
300
300
labelled by (x, y) points, either discrete or continuous.
301
301
@@ -396,21 +396,21 @@ def turn_heading(self, heading, inc, headings=orientations):
396
396
"Return the heading to the left (inc=+1) or right (inc=-1) in headings."
397
397
return headings [(headings .index (heading ) + inc ) % len (headings )]
398
398
399
- class Obstacle ( Object ):
399
+ class Obstacle ( object ):
400
400
"""Something that can cause a bump, preventing an agent from
401
401
moving into the same square it's in."""
402
402
pass
403
403
404
- class Wall (Obstacle ):
404
+ class Wall (Obstacle ):
405
405
pass
406
406
407
407
#______________________________________________________________________________
408
408
## Vacuum environment
409
409
410
- class Dirt ( Object ):
410
+ class Dirt ( object ):
411
411
pass
412
412
413
- class VacuumEnvironment (XYEnvironment ):
413
+ class VacuumEnvironment (XYEnvironment ):
414
414
"""The environment of [Ex. 2.12]. Agent perceives dirty or clean,
415
415
and bump (into obstacle) or not; 2D discrete world of unknown size;
416
416
performance measure is 100 for each dirt cleaned, and -1 for
@@ -445,7 +445,7 @@ def execute_action(self, agent, action):
445
445
if action != 'NoOp' :
446
446
agent .performance -= 1
447
447
448
- class TrivialVacuumEnvironment (Environment ):
448
+ class TrivialVacuumEnvironment (Environment ):
449
449
450
450
"""This environment has two locations, A and B. Each can be Dirty
451
451
or Clean. The agent perceives its location and the location's
@@ -485,7 +485,7 @@ def default_location(self, object):
485
485
486
486
#______________________________________________________________________________
487
487
488
- class SimpleReflexAgent (Agent ):
488
+ class SimpleReflexAgent (Agent ):
489
489
"""This agent takes action based solely on the percept. [Fig. 2.13]"""
490
490
491
491
def __init__ (self , rules , interpret_input ):
@@ -503,7 +503,7 @@ def program(percept):
503
503
return action
504
504
return program
505
505
506
- class ReflexAgentWithState (Agent ):
506
+ class ReflexAgentWithState (Agent ):
507
507
"""This agent takes action based on the percept and state. [Fig. 2.16]"""
508
508
509
509
def __init__ (self , rules , update_state ):
@@ -532,11 +532,11 @@ def rule_match(state, rules):
532
532
#______________________________________________________________________________
533
533
## The Wumpus World
534
534
535
- class Gold ( Object ): pass
536
- class Pit ( Object ): pass
537
- class Arrow ( Object ): pass
538
- class Wumpus (Agent ): pass
539
- class Explorer (Agent ): pass
535
+ class Gold ( object ): pass
536
+ class Pit ( object ): pass
537
+ class Arrow ( object ): pass
538
+ class Wumpus (Agent ): pass
539
+ class Explorer (Agent ): pass
540
540
541
541
class WumpusEnvironment (XYEnvironment ):
542
542
@@ -608,7 +608,7 @@ def testv(A): return test_agent(A, 4, copy.deepcopy(envs))
608
608
609
609
import Tkinter as tk
610
610
611
- class EnvGUI (tk .Tk , object ):
611
+ class EnvGUI (tk .Tk , object ):
612
612
613
613
def __init__ (self , env , title = 'AIMA GUI' , cellwidth = 50 , n = 10 ):
614
614
@@ -625,7 +625,7 @@ def __init__(self, env, title = 'AIMA GUI', cellwidth=50, n=10):
625
625
w .pack (side = "bottom" , fill = "x" , padx = "3" , pady = "3" )
626
626
627
627
628
- class EnvToolbar (tk .Frame , object ):
628
+ class EnvToolbar (tk .Frame , object ):
629
629
630
630
def __init__ (self , parent , env , canvas ):
631
631
super (EnvToolbar , self ).__init__ (parent , relief = 'raised' , bd = 2 )
0 commit comments