From 47562ffe9b2b51553207befe41ffee316e6685b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Thu, 15 Feb 2018 22:13:24 +0100 Subject: [PATCH] Add test for Table-Driven-Vacuum-Agent. Note that this changes the percept sequence table in the code, it now slightly differs from table 2.3 in the book. The underlying problem here is that a full table can principally not be specified, so '...' is used to represent the missing table entries. While this works for the book, the code requires some additional table entries for the agent to succeed. --- README.md | 2 +- agents.py | 3 +++ tests/test_agents.py | 14 +++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 91ce5b37e..c1c957471 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and | 2 | Model-Based-Vacuum-Agent | `ModelBasedVacuumAgent` | [`agents.py`][agents] | Done | Included | | 2.1 | Environment | `Environment` | [`agents.py`][agents] | Done | Included | | 2.1 | Agent | `Agent` | [`agents.py`][agents] | Done | Included | -| 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | | Included | +| 2.3 | Table-Driven-Vacuum-Agent | `TableDrivenVacuumAgent` | [`agents.py`][agents] | Done | Included | | 2.7 | Table-Driven-Agent | `TableDrivenAgent` | [`agents.py`][agents] | | Included | | 2.8 | Reflex-Vacuum-Agent | `ReflexVacuumAgent` | [`agents.py`][agents] | Done | Included | | 2.10 | Simple-Reflex-Agent | `SimpleReflexAgent` | [`agents.py`][agents] | | Included | diff --git a/agents.py b/agents.py index 9308225f2..957b4d9d7 100644 --- a/agents.py +++ b/agents.py @@ -183,10 +183,13 @@ def TableDrivenVacuumAgent(): ((loc_B, 'Dirty'),): 'Suck', ((loc_A, 'Clean'), (loc_A, 'Clean')): 'Right', ((loc_A, 'Clean'), (loc_A, 'Dirty')): 'Suck', + ((loc_A, 'Dirty'), (loc_A, 'Clean')): 'Right', # ... ((loc_A, 'Clean'), (loc_A, 'Clean'), (loc_A, 'Clean')): 'Right', ((loc_A, 'Clean'), (loc_A, 'Clean'), (loc_A, 'Dirty')): 'Suck', # ... + ((loc_A, 'Dirty'), (loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck', + # ... } return Agent(TableDrivenAgentProgram(table)) diff --git a/tests/test_agents.py b/tests/test_agents.py index 59ab6bce9..9c517f5f8 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -2,7 +2,7 @@ from agents import Direction from agents import Agent from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment, compare_agents,\ - RandomVacuumAgent + RandomVacuumAgent, TableDrivenVacuumAgent random.seed("aima-python") @@ -93,6 +93,18 @@ def test_ModelBasedVacuumAgent() : # check final status of the environment assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'} +def test_TableDrivenVacuumAgent() : + # create an object of the ModelBasedVacuumAgent + agent = TableDrivenVacuumAgent() + # 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_compare_agents() : environment = TrivialVacuumEnvironment pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy