|
43 | 43 | import random
|
44 | 44 | import copy
|
45 | 45 | import collections
|
| 46 | +import numbers |
46 | 47 |
|
47 | 48 |
|
48 | 49 | # ______________________________________________________________________________
|
@@ -211,7 +212,14 @@ def RandomVacuumAgent():
|
211 | 212 |
|
212 | 213 |
|
213 | 214 | def TableDrivenVacuumAgent():
|
214 |
| - """[Figure 2.3]""" |
| 215 | + """Tabular approach towards vacuum world as mentioned in [Figure 2.3] |
| 216 | + >>> agent = TableDrivenVacuumAgent() |
| 217 | + >>> environment = TrivialVacuumEnvironment() |
| 218 | + >>> environment.add_thing(agent) |
| 219 | + >>> environment.run() |
| 220 | + >>> environment.status == {(1,0):'Clean' , (0,0) : 'Clean'} |
| 221 | + True |
| 222 | + """ |
215 | 223 | table = {((loc_A, 'Clean'),): 'Right',
|
216 | 224 | ((loc_A, 'Dirty'),): 'Suck',
|
217 | 225 | ((loc_B, 'Clean'),): 'Left',
|
@@ -342,7 +350,12 @@ def run(self, steps=1000):
|
342 | 350 |
|
343 | 351 | def list_things_at(self, location, tclass=Thing):
|
344 | 352 | """Return all things exactly at a given location."""
|
345 |
| - return [thing for thing in self.things if thing.location == location and isinstance(thing, tclass)] |
| 353 | + if isinstance(location, numbers.Number): |
| 354 | + return [thing for thing in self.things |
| 355 | + if thing.location == location and isinstance(thing, tclass)] |
| 356 | + return [thing for thing in self.things |
| 357 | + if all(x==y for x,y in zip(thing.location, location)) |
| 358 | + and isinstance(thing, tclass)] |
346 | 359 |
|
347 | 360 | def some_things_at(self, location, tclass=Thing):
|
348 | 361 | """Return true if at least one of the things at location
|
@@ -621,7 +634,7 @@ def get_world(self):
|
621 | 634 | for x in range(x_start, x_end):
|
622 | 635 | row = []
|
623 | 636 | for y in range(y_start, y_end):
|
624 |
| - row.append(self.list_things_at([x, y])) |
| 637 | + row.append(self.list_things_at((x, y))) |
625 | 638 | result.append(row)
|
626 | 639 | return result
|
627 | 640 |
|
|
0 commit comments