-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fixed grabbing behaviour in agent #1148
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -510,14 +510,17 @@ 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(thing)] | ||
if things: | ||
agent.holding.append(things[0]) | ||
print("Grabbing ", things[0].__class__.__name__) | ||
self.delete_thing(things[0]) | ||
elif action == 'Release': | ||
if agent.holding: | ||
agent.holding.pop() | ||
dropped = agent.holding.pop() | ||
print("Dropping ", dropped.__class__.__name__) | ||
self.add_thing(dropped, location=agent.location) | ||
|
||
def default_location(self, thing): | ||
location = self.random_location_inbounds() | ||
|
@@ -569,10 +572,7 @@ 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) | ||
del thing.holding | ||
|
||
super().delete_thing(thing) | ||
for obs in self.observers: | ||
|
@@ -967,21 +967,16 @@ def execute_action(self, agent, action): | |
|
||
agent.bump = False | ||
if action == 'TurnRight': | ||
agent.direction += Direction.R | ||
super().execute_action(agent,action) | ||
agent.performance -= 1 | ||
elif action == 'TurnLeft': | ||
agent.direction += Direction.L | ||
super().execute_action(agent,action) | ||
agent.performance -= 1 | ||
elif action == 'Forward': | ||
agent.bump = self.move_to(agent, agent.direction.move_forward(agent.location)) | ||
super().execute_action(agent,action) | ||
agent.performance -= 1 | ||
elif action == 'Grab': | ||
things = [thing for thing in self.list_things_at(agent.location) | ||
if agent.can_grab(thing)] | ||
if len(things): | ||
print("Grabbing", things[0].__class__.__name__) | ||
if len(things): | ||
agent.holding.append(things[0]) | ||
super().execute_action(agent,action) | ||
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. You need a space after the comma, to comply with the overall project style. 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. done |
||
agent.performance -= 1 | ||
elif action == 'Climb': | ||
if agent.location == (1, 1): # Agent can only climb out of (1,1) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think the if statement could be streamlined if we rewrote it as:
I think the above looks a bit better.
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.
I had that in mind, but I thought to myself that being more articulate and reasonably redundant in code would help the student retaining the information that is my case.
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.
But actually seeing it, it really didn't help much.