Skip to content

Commit

Permalink
better behavior when standing next to the goal
Browse files Browse the repository at this point in the history
  • Loading branch information
rizar committed Jan 23, 2019
1 parent 57d97ab commit 509db24
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions babyai/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,15 @@ def get_action(self):
# CASE 1: The position we are on is the one we should go next to
# -> Move away from it
if manhattan_distance(target_pos, self.pos) == (1 if self.adjacent else 0):
if self.fwd_cell is None:
def steppable(cell):
return cell is None or (cell.type == 'door' and cell.is_open)
if steppable(self.fwd_cell):
return self.actions.forward
if self.bot.mission.grid.get(*(self.pos + self.right_vec)) is None:
if steppable(self.bot.mission.grid.get(*(self.pos + self.right_vec))):
return self.actions.right
if self.bot.mission.grid.get(*(self.pos - self.right_vec)) is None:
if steppable(self.bot.mission.grid.get(*(self.pos - self.right_vec))):
return self.actions.left
# TODO: There is a corner case : you are on the position but surrounded in 4 positions
# otherwise: forward, left and right are full, we assume that you can go behind
# Spin and hope for the best
return self.actions.left

# CASE 2: we are facing the target cell, subgoal completed
Expand Down

0 comments on commit 509db24

Please sign in to comment.