Skip to content

Commit

Permalink
delete forgotten replan2
Browse files Browse the repository at this point in the history
  • Loading branch information
rizar committed Jan 26, 2019
1 parent 10ecafb commit 0a095e5
Showing 1 changed file with 0 additions and 69 deletions.
69 changes: 0 additions & 69 deletions babyai/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,75 +150,6 @@ def replan(self):

return self.actions.toggle

def replan2(self, action):
# CASE 1: The door is locked
# we need to fetch the key and return
# i.e. update the stack REGARDLESS of the action
# TODO: do we really need to be in front of the locked door to realize that we need the key for it ?
if self.fwd_cell.type == 'door' and self.fwd_cell.is_locked:
if not self.carrying or self.carrying.type != 'key' or self.carrying.color != self.fwd_cell.color:
# Find the key
key_desc = ObjDesc('key', self.fwd_cell.color)
key_desc.find_matching_objs(self.bot.mission)

# If we're already carrying something
if self.carrying:
self.bot.stack.pop()

# Find a location to drop what we're already carrying
drop_pos_cur = self.bot.find_drop_pos()

# Take back the object being carried
self.bot.stack.append(PickupSubgoal(self.bot))
self.bot.stack.append(GoNextToSubgoal(self.bot, drop_pos_cur))

# Go back to the door and open it
self.bot.stack.append(OpenSubgoal(self.bot, 'drop_the_key'))
self.bot.stack.append(GoNextToSubgoal(self.bot, tuple(self.fwd_pos)))

# Go to the key and pick it up
self.bot.stack.append(PickupSubgoal(self.bot))
self.bot.stack.append(GoNextToSubgoal(self.bot, key_desc))

# Drop the object being carried
self.bot.stack.append(DropSubgoal(self.bot))
self.bot.stack.append(GoNextToSubgoal(self.bot, drop_pos_cur))
else:
self.bot.stack.pop()

self.bot.stack.append(OpenSubgoal(self.bot, 'drop_the_key'))
self.bot.stack.append(GoNextToSubgoal(self.bot, tuple(self.fwd_pos)))
self.bot.stack.append(PickupSubgoal(self.bot))
self.bot.stack.append(GoNextToSubgoal(self.bot, key_desc))

return False

# CASE 2: The door is already open
# we need to close it so we can open it again
if self.fwd_cell.type == 'door' and self.fwd_cell.is_open:
if action in (self.actions.left, self.actions.right, self.actions.forward):
# Go back to the door to close it
self.bot.stack.append(GoNextToSubgoal(self.bot, tuple(self.fwd_pos)))
# done/pickup/drop actions won't have any effect -> next iteration would be CASE 2 of same subgoal
# toggle action will close the door, but we would need to go through the same subgoal again
# -> next iteration would be CASE 3 of same subgoal
return True

# CASE 3: The door is openable
if action == self.actions.toggle:
self.bot.stack.pop()
# Sometimes we need to drop the key that we just used to
# open the door in order to proceed with the mission
if self.fwd_cell.is_locked and self.datum == 'drop_the_key':
drop_key_pos = self.bot.find_drop_pos()
self.bot.stack.append(DropSubgoal(self.bot))
self.bot.stack.append(GoNextToSubgoal(self.bot, drop_key_pos))
if action in (self.actions.left, self.actions.right):
# Go back to the door to open it
self.bot.stack.append(GoNextToSubgoal(self.bot, tuple(self.fwd_pos)))
# done/pickup/drop/forward actions won't have any effect -> next iteration would be CASE 3 of same subgoal
return True


class DropSubgoal(Subgoal):

Expand Down

0 comments on commit 0a095e5

Please sign in to comment.