Skip to content

Commit 195708d

Browse files
apb7norvig
authored andcommitted
Fix #731: Add table and tests for TableDrivenVacuumAgent (#732)
* Add test for TableDrivenVacuumAgent * Debug Travis * Minor fix * Fixed table for TableDrivenAgent * Update README
1 parent a6edaa1 commit 195708d

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
3434
| 2 | Model-Based-Vacuum-Agent | `ModelBasedVacuumAgent` | [`agents.py`][agents] | Done | Included |
3535
| 2.1 | Environment | `Environment` | [`agents.py`][agents] | Done | Included |
3636
| 2.1 | Agent | `Agent` | [`agents.py`][agents] | Done | Included |
37-
| 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | | Included |
37+
| 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | Done | Included |
3838
| 2.7 | Table-Driven-Agent | `TableDrivenAgent` | [`agents.py`][agents] | | Included |
3939
| 2.8 | Reflex-Vacuum-Agent | `ReflexVacuumAgent` | [`agents.py`][agents] | Done | Included |
4040
| 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | | Included |

agents.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ def TableDrivenVacuumAgent():
181181
((loc_A, 'Dirty'),): 'Suck',
182182
((loc_B, 'Clean'),): 'Left',
183183
((loc_B, 'Dirty'),): 'Suck',
184-
((loc_A, 'Clean'), (loc_A, 'Clean')): 'Right',
185-
((loc_A, 'Clean'), (loc_A, 'Dirty')): 'Suck',
186-
# ...
187-
((loc_A, 'Clean'), (loc_A, 'Clean'), (loc_A, 'Clean')): 'Right',
188-
((loc_A, 'Clean'), (loc_A, 'Clean'), (loc_A, 'Dirty')): 'Suck',
189-
# ...
184+
((loc_A, 'Dirty'), (loc_A, 'Clean')): 'Right',
185+
((loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck',
186+
((loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck',
187+
((loc_B, 'Dirty'), (loc_B, 'Clean')): 'Left',
188+
((loc_A, 'Dirty'), (loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck',
189+
((loc_B, 'Dirty'), (loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck'
190190
}
191191
return Agent(TableDrivenAgentProgram(table))
192192

tests/test_agents.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from agents import Direction
33
from agents import Agent
44
from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\
5-
RandomVacuumAgent
5+
RandomVacuumAgent, TableDrivenVacuumAgent
66

77

88
random.seed("aima-python")
@@ -94,6 +94,19 @@ def test_ModelBasedVacuumAgent() :
9494
assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'}
9595

9696

97+
def test_TableDrivenVacuumAgent() :
98+
# create an object of the TableDrivenVacuumAgent
99+
agent = TableDrivenVacuumAgent()
100+
# create an object of the TrivialVacuumEnvironment
101+
environment = TrivialVacuumEnvironment()
102+
# add agent to the environment
103+
environment.add_thing(agent)
104+
# run the environment
105+
environment.run()
106+
# check final status of the environment
107+
assert environment.status == {(1, 0):'Clean', (0, 0):'Clean'}
108+
109+
97110
def test_compare_agents() :
98111
environment = TrivialVacuumEnvironment
99112
agents = [ModelBasedVacuumAgent, ReflexVacuumAgent]

0 commit comments

Comments
 (0)