From ad54a3650bf1a1f26445558f400599d6417e9644 Mon Sep 17 00:00:00 2001 From: tirthasheshpatel Date: Sun, 17 Nov 2019 21:38:38 +0530 Subject: [PATCH 1/5] Add example for TableDrivenVacuumAgent --- agents.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/agents.py b/agents.py index 6c01aa5b4..261752453 100644 --- a/agents.py +++ b/agents.py @@ -204,7 +204,14 @@ def RandomVacuumAgent(): def TableDrivenVacuumAgent(): - """[Figure 2.3]""" + """Tabular approach towards vacuum world as mentioned in [Figure 2.3] + >>> agent = TableDrivenVacuumAgent() + >>> environment = TrivialVacuumEnvironment() + >>> environment.add_thing(agent) + >>> environment.run() + >>> environment.status == {(1,0):'Clean' , (0,0) : 'Clean'} + True + """ table = {((loc_A, 'Clean'),): 'Right', ((loc_A, 'Dirty'),): 'Suck', ((loc_B, 'Clean'),): 'Left', From 47505241c41af01bb812dab8d8fe201e873e62c2 Mon Sep 17 00:00:00 2001 From: tirthasheshpatel Date: Sun, 17 Nov 2019 21:47:34 +0530 Subject: [PATCH 2/5] Add example of TableDrivenVacuumAgent in agents4e.py --- agents4e.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/agents4e.py b/agents4e.py index fab36a46c..7c8ace05d 100644 --- a/agents4e.py +++ b/agents4e.py @@ -204,7 +204,14 @@ def RandomVacuumAgent(): def TableDrivenVacuumAgent(): - """[Figure 2.3]""" + """Tabular approach towards vacuum world as mentioned in [Figure 2.3] + >>> agent = TableDrivenVacuumAgent() + >>> environment = TrivialVacuumEnvironment() + >>> environment.add_thing(agent) + >>> environment.run() + >>> environment.status == {(1,0):'Clean' , (0,0) : 'Clean'} + True + """ table = {((loc_A, 'Clean'),): 'Right', ((loc_A, 'Dirty'),): 'Suck', ((loc_B, 'Clean'),): 'Left', From d5db44c5af71da64a797a35c556f1b0166e61926 Mon Sep 17 00:00:00 2001 From: tirthasheshpatel Date: Tue, 19 Nov 2019 21:44:48 +0530 Subject: [PATCH 3/5] FIX: grid not updating in GraphicEnvironment --- agents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents.py b/agents.py index 261752453..d7da12186 100644 --- a/agents.py +++ b/agents.py @@ -619,7 +619,7 @@ def get_world(self): for x in range(x_start, x_end): row = [] for y in range(y_start, y_end): - row.append(self.list_things_at([x, y])) + row.append(self.list_things_at((x, y))) result.append(row) return result From 04fdd93e26145348bb86c4123f1a1fabf4164386 Mon Sep 17 00:00:00 2001 From: tirthasheshpatel Date: Tue, 19 Nov 2019 21:49:55 +0530 Subject: [PATCH 4/5] FIX: grid not updating in GraphicEnvironment in agents4e.py --- agents4e.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents4e.py b/agents4e.py index 7c8ace05d..3a17e2dbf 100644 --- a/agents4e.py +++ b/agents4e.py @@ -620,7 +620,7 @@ def get_world(self): for x in range(x_start, x_end): row = [] for y in range(y_start, y_end): - row.append(self.list_things_at([x, y])) + row.append(self.list_things_at((x, y))) result.append(row) return result From 0738ebff1dd308651bafef186b7edd32f21d2ab8 Mon Sep 17 00:00:00 2001 From: tirthasheshpatel Date: Wed, 20 Nov 2019 08:34:12 +0530 Subject: [PATCH 5/5] FIX: list_things_at to support all iterables --- agents.py | 8 +++++++- agents4e.py | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/agents.py b/agents.py index d7da12186..a1916a239 100644 --- a/agents.py +++ b/agents.py @@ -44,6 +44,7 @@ import random import copy import collections +import numbers # ______________________________________________________________________________ @@ -340,7 +341,12 @@ def run(self, steps=1000): def list_things_at(self, location, tclass=Thing): """Return all things exactly at a given location.""" - return [thing for thing in self.things if thing.location == location and isinstance(thing, tclass)] + if isinstance(location, numbers.Number): + return [thing for thing in self.things + if thing.location == location and isinstance(thing, tclass)] + return [thing for thing in self.things + if all(x==y for x,y in zip(thing.location, location)) + and isinstance(thing, tclass)] def some_things_at(self, location, tclass=Thing): """Return true if at least one of the things at location diff --git a/agents4e.py b/agents4e.py index 3a17e2dbf..14b01cd4c 100644 --- a/agents4e.py +++ b/agents4e.py @@ -44,6 +44,7 @@ import random import copy import collections +import numbers # ______________________________________________________________________________ @@ -340,8 +341,12 @@ def run(self, steps=1000): def list_things_at(self, location, tclass=Thing): """Return all things exactly at a given location.""" + if isinstance(location, numbers.Number): + return [thing for thing in self.things + if thing.location == location and isinstance(thing, tclass)] return [thing for thing in self.things - if thing.location == location and isinstance(thing, tclass)] + if all(x==y for x,y in zip(thing.location, location)) + and isinstance(thing, tclass)] def some_things_at(self, location, tclass=Thing): """Return true if at least one of the things at location