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 , TableDrivenAgentProgram , RandomAgentProgram
5
+ RandomVacuumAgent , TableDrivenVacuumAgent , TableDrivenAgentProgram , RandomAgentProgram , \
6
+ SimpleReflexAgentProgram , rule_match
6
7
7
8
8
9
random .seed ("aima-python" )
@@ -156,6 +157,38 @@ def test_TableDrivenVacuumAgent() :
156
157
environment .run ()
157
158
# check final status of the environment
158
159
assert environment .status == {(1 , 0 ):'Clean' , (0 , 0 ):'Clean' }
160
+
161
+ def test_SimpleReflexAgentProgram ():
162
+ class Rule :
163
+
164
+ def __init__ (self , state , action ):
165
+ self .__state = state
166
+ self .action = action
167
+
168
+ def matches (self , state ):
169
+ return self .__state == state
170
+
171
+ loc_A = (0 , 0 )
172
+ loc_B = (1 , 0 )
173
+
174
+ # create rules for a two state Vacuum Environment
175
+ rules = [Rule ((loc_A , "Dirty" ), "Suck" ), Rule ((loc_A , "Clean" ), "Right" ),
176
+ Rule ((loc_B , "Dirty" ), "Suck" ), Rule ((loc_B , "Clean" ), "Left" )]
177
+
178
+ def interpret_input (state ):
179
+ return state
180
+
181
+ # create an program and then an object of the SimpleReflexAgentProgram
182
+ program = SimpleReflexAgentProgram (rules , interpret_input )
183
+ agent = Agent (program )
184
+ # create an object of TrivialVacuumEnvironment
185
+ environment = TrivialVacuumEnvironment ()
186
+ # add agent to the environment
187
+ environment .add_thing (agent )
188
+ # run the environment
189
+ environment .run ()
190
+ # check final status of the environment
191
+ assert environment .status == {(1 ,0 ):'Clean' , (0 ,0 ) : 'Clean' }
159
192
160
193
161
194
def test_compare_agents () :
@@ -181,3 +214,18 @@ def constant_prog(percept):
181
214
agent = Agent (constant_prog )
182
215
result = agent .program (5 )
183
216
assert result == 5
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
0 commit comments