2
2
from agents import Direction
3
3
from agents import Agent
4
4
from agents import ReflexVacuumAgent , ModelBasedVacuumAgent , TrivialVacuumEnvironment , compare_agents ,\
5
- RandomVacuumAgent , TableDrivenVacuumAgent
5
+ RandomVacuumAgent , TableDrivenVacuumAgent , TableDrivenAgentProgram , RandomAgentProgram
6
6
7
7
8
8
random .seed ("aima-python" )
@@ -54,6 +54,21 @@ def test_add():
54
54
assert l1 .direction == Direction .U
55
55
assert l2 .direction == Direction .D
56
56
57
+ def test_RandomAgentProgram () :
58
+ #create a list of all the actions a vacuum cleaner can perform
59
+ list = ['Right' , 'Left' , 'Suck' , 'NoOp' ]
60
+ # create a program and then an object of the RandomAgentProgram
61
+ program = RandomAgentProgram (list )
62
+
63
+ agent = Agent (program )
64
+ # create an object of TrivialVacuumEnvironment
65
+ environment = TrivialVacuumEnvironment ()
66
+ # add agent to the environment
67
+ environment .add_thing (agent )
68
+ # run the environment
69
+ environment .run ()
70
+ # check final status of the environment
71
+ assert environment .status == {(1 , 0 ): 'Clean' , (0 , 0 ): 'Clean' }
57
72
58
73
def test_RandomVacuumAgent () :
59
74
# create an object of the RandomVacuumAgent
@@ -68,6 +83,34 @@ def test_RandomVacuumAgent() :
68
83
assert environment .status == {(1 ,0 ):'Clean' , (0 ,0 ) : 'Clean' }
69
84
70
85
86
+ def test_TableDrivenAgent () :
87
+ #create a table that would consist of all the possible states of the agent
88
+ loc_A , loc_B = (0 , 0 ), (1 , 0 )
89
+
90
+ table = {((loc_A , 'Clean' ),): 'Right' ,
91
+ ((loc_A , 'Dirty' ),): 'Suck' ,
92
+ ((loc_B , 'Clean' ),): 'Left' ,
93
+ ((loc_B , 'Dirty' ),): 'Suck' ,
94
+ ((loc_A , 'Dirty' ), (loc_A , 'Clean' )): 'Right' ,
95
+ ((loc_A , 'Clean' ), (loc_B , 'Dirty' )): 'Suck' ,
96
+ ((loc_B , 'Clean' ), (loc_A , 'Dirty' )): 'Suck' ,
97
+ ((loc_B , 'Dirty' ), (loc_B , 'Clean' )): 'Left' ,
98
+ ((loc_A , 'Dirty' ), (loc_A , 'Clean' ), (loc_B , 'Dirty' )): 'Suck' ,
99
+ ((loc_B , 'Dirty' ), (loc_B , 'Clean' ), (loc_A , 'Dirty' )): 'Suck'
100
+ }
101
+ # create an program and then an object of the TableDrivenAgent
102
+ program = TableDrivenAgentProgram (table )
103
+ agent = Agent (program )
104
+ # create an object of the TrivialVacuumEnvironment
105
+ environment = TrivialVacuumEnvironment ()
106
+ # add agent to the environment
107
+ environment .add_thing (agent )
108
+ # run the environment
109
+ environment .run ()
110
+ # check final status of the environment
111
+ assert environment .status == {(1 , 0 ): 'Clean' , (0 , 0 ): 'Clean' }
112
+
113
+
71
114
def test_ReflexVacuumAgent () :
72
115
# create an object of the ReflexVacuumAgent
73
116
agent = ReflexVacuumAgent ()
0 commit comments