-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fixed grabbing behaviour in agent #1148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -510,14 +510,16 @@ def execute_action(self, agent, action): | |
agent.direction += Direction.L | ||
elif action == 'Forward': | ||
agent.bump = self.move_to(agent, agent.direction.move_forward(agent.location)) | ||
# elif action == 'Grab': | ||
# things = [thing for thing in self.list_things_at(agent.location) | ||
# if agent.can_grab(thing)] | ||
# if things: | ||
# agent.holding.append(things[0]) | ||
elif action == 'Grab': | ||
things = [thing for thing in self.list_things_at(agent.location)] | ||
if agent.can_grab(things[0]): | ||
if things: | ||
agent.holding.append(things[0]) | ||
self.delete_thing(things[0]) | ||
elif action == 'Release': | ||
if agent.holding: | ||
agent.holding.pop() | ||
dropped = agent.holding.pop() | ||
self.add_thing(dropped, location=agent.location) | ||
|
||
def default_location(self, thing): | ||
location = self.random_location_inbounds() | ||
|
@@ -569,10 +571,11 @@ def random_location_inbounds(self, exclude=None): | |
def delete_thing(self, thing): | ||
"""Deletes thing, and everything it is holding (if thing is an agent)""" | ||
if isinstance(thing, Agent): | ||
for obj in thing.holding: | ||
super().delete_thing(obj) | ||
for obs in self.observers: | ||
obs.thing_deleted(obj) | ||
# for obj in thing.holding: | ||
# super().delete_thing(obj) | ||
# for obs in self.observers: | ||
# obs.thing_deleted(obj) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a reason to comment these lines out. Even though the second line is redundant, the observers of the environment still need to be informed about each thing being deleted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we delete all of the agent holdings with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The observers of the environment need to be updated about all the things getting deleted along with the agent. I have not seen |
||
del thing.holding | ||
|
||
super().delete_thing(thing) | ||
for obs in self.observers: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line
if things
should be on the top otherwisethings[0]
(accessed in the line above) would raise an exception!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that is true