From 03c8152d8f8081f63a1e29a65cc906e03ef728ce Mon Sep 17 00:00:00 2001 From: Shivam Kohli Date: Thu, 8 Mar 2018 11:45:13 +0530 Subject: [PATCH 1/4] Added tests for Simple-Reflex-Agent --- tests/test_agents.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/test_agents.py b/tests/test_agents.py index caefe61d4..9d8914695 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -130,7 +130,41 @@ def test_ReflexVacuumAgent() : environment.run() # check final status of the environment assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'} - + +def test_SimpleReflexAgentProgram(): + class Rule: + + def __init__(self, state, action): + self.__state = state + self.action = action + + def matches(self, state): + return self.__state == state + + loc_A = (0, 0) + loc_B = (1, 0) + + # create rules for a two state Vacuum Environment + rules = [Rule((loc_A, "Dirty"), "Suck"), Rule((loc_A, "Clean"), "Right"), + Rule((loc_B, "Dirty"), "Suck"), Rule((loc_B, "Clean"), "Left")] + + def interpret_input(state): + return state + + # create a program and then an object of the SimpleReflexAgentProgram + program = SimpleReflexAgentProgram(rules, interpret_input) + agent = Agent(program) + # create an object of TrivialVacuumEnvironment + environment = TrivialVacuumEnvironment() + # add agent to the environment + environment.add_thing(agent) + # run the environment + environment.run() + # check final status of the environment + assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'} + + + def test_ModelBasedVacuumAgent() : # create an object of the ModelBasedVacuumAgent From b0f4be715c8d2cd823992ff226c1b3cc1a788a3c Mon Sep 17 00:00:00 2001 From: Shivam Kohli Date: Thu, 8 Mar 2018 11:48:01 +0530 Subject: [PATCH 2/4] Added tests for Simple-Reflex-Agent --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c97db60f1..04b87734e 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and | 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | Done | Included | | 2.7 | Table-Driven-Agent | `TableDrivenAgent` | [`agents.py`][agents] | Done | Included | | 2.8 | Reflex-Vacuum-Agent | `ReflexVacuumAgent` | [`agents.py`][agents] | Done | Included | -| 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | | Included | +| 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | Done | Included | | 2.12 | Model-Based-Reflex-Agent | `ReflexAgentWithState` | [`agents.py`][agents] | | Included | | 3 | Problem | `Problem` | [`search.py`][search] | Done | Included | | 3 | Node | `Node` | [`search.py`][search] | Done | Included | @@ -186,4 +186,4 @@ Many thanks for contributions over the years. I got bug reports, corrected code, [rl]:../master/rl.py [search]:../master/search.py [utils]:../master/utils.py -[text]:../master/text.py \ No newline at end of file +[text]:../master/text.py From 16ed692bc97b73c34e3a0e0efdac523afdccc94f Mon Sep 17 00:00:00 2001 From: Shivam Kohli Date: Thu, 8 Mar 2018 12:02:33 +0530 Subject: [PATCH 3/4] Removed bug --- tests/test_agents.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_agents.py b/tests/test_agents.py index 9d8914695..fb9093d7f 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -2,7 +2,8 @@ from agents import Direction from agents import Agent from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\ - RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram + RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram, \ + SimpleReflexAgentProgram, rule_match random.seed("aima-python") From 2ed2f00912261231134898f8cf4b0f6f8bdc2e28 Mon Sep 17 00:00:00 2001 From: Shivam Kohli Date: Thu, 8 Mar 2018 12:04:03 +0530 Subject: [PATCH 4/4] Removed bug --- tests/test_agents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_agents.py b/tests/test_agents.py index fb9093d7f..b8209f0f3 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -3,7 +3,7 @@ from agents import Agent from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\ RandomVacuumAgent, TableDrivenVacuumAgent, TableDrivenAgentProgram, RandomAgentProgram, \ - SimpleReflexAgentProgram, rule_match + SimpleReflexAgentProgram, rule_match random.seed("aima-python")