@@ -201,6 +201,50 @@ def GA_GraphColoringInts(edges, fitness):
201201 return genetic_algorithm (population , fitness )
202202
203203
204+ def test_simpleProblemSolvingAgent ():
205+ class vacuumAgent (SimpleProblemSolvingAgentProgram ):
206+ def update_state (self , state , percept ):
207+ return percept
208+
209+ def formulate_goal (self , state ):
210+ goal = [state7 , state8 ]
211+ return goal
212+
213+ def formulate_problem (self , state , goal ):
214+ problem = state
215+ return problem
216+
217+ def search (self , problem ):
218+ if problem == state1 :
219+ seq = ["Suck" , "Right" , "Suck" ]
220+ elif problem == state2 :
221+ seq = ["Suck" , "Left" , "Suck" ]
222+ elif problem == state3 :
223+ seq = ["Right" , "Suck" ]
224+ elif problem == state4 :
225+ seq = ["Suck" ]
226+ elif problem == state5 :
227+ seq = ["Suck" ]
228+ elif problem == state6 :
229+ seq = ["Left" , "Suck" ]
230+ return seq
231+
232+ state1 = [(0 , 0 ), [(0 , 0 ), "Dirty" ], [(1 , 0 ), ["Dirty" ]]]
233+ state2 = [(1 , 0 ), [(0 , 0 ), "Dirty" ], [(1 , 0 ), ["Dirty" ]]]
234+ state3 = [(0 , 0 ), [(0 , 0 ), "Clean" ], [(1 , 0 ), ["Dirty" ]]]
235+ state4 = [(1 , 0 ), [(0 , 0 ), "Clean" ], [(1 , 0 ), ["Dirty" ]]]
236+ state5 = [(0 , 0 ), [(0 , 0 ), "Dirty" ], [(1 , 0 ), ["Clean" ]]]
237+ state6 = [(1 , 0 ), [(0 , 0 ), "Dirty" ], [(1 , 0 ), ["Clean" ]]]
238+ state7 = [(0 , 0 ), [(0 , 0 ), "Clean" ], [(1 , 0 ), ["Clean" ]]]
239+ state8 = [(1 , 0 ), [(0 , 0 ), "Clean" ], [(1 , 0 ), ["Clean" ]]]
240+
241+ a = vacuumAgent (state1 )
242+
243+ assert a (state6 ) == "Left"
244+ assert a (state1 ) == "Suck"
245+ assert a (state3 ) == "Right"
246+
247+
204248
205249# TODO: for .ipynb:
206250"""
0 commit comments