Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7450fb6

Browse files
committed
Auto-convert agent programs to agents.
1 parent 5aa68e8 commit 7450fb6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

agents.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __init__(self, program=None):
7979
if program is None:
8080
def program(percept):
8181
return raw_input('Percept=%s; action? ' % percept)
82+
assert callable(program)
8283
self.program = program
8384

8485
def can_grab(self, obj):
@@ -260,8 +261,12 @@ def some_objects_at(self, location, oclass=Object):
260261
return self.list_objects_at(location, oclass) != []
261262

262263
def add_object(self, obj, location=None):
263-
"""Add an object to the environment, setting its location. Also keep
264-
track of objects that are agents. Shouldn't need to override this."""
264+
"""Add an object to the environment, setting its location. For
265+
convenience, if obj is an agent program we make a new agent
266+
for it. (Shouldn't need to override this."""
267+
if not isinstance(obj, Object):
268+
obj = Agent(obj)
269+
assert obj not in self.objects, "Don't add the same object twice"
265270
obj.location = location or self.default_location(obj)
266271
self.objects.append(obj)
267272
if isinstance(obj, Agent):

0 commit comments

Comments
 (0)