Skip to content

Commit

Permalink
Fix incorrect column row order (mila-iqia#107)
Browse files Browse the repository at this point in the history
* Fix incorrect column row order

For RoomGrid.get_room(i, j), RoomGrid.add_door(i, j, ...), RoomGrid.add_object(i, j, ...), `i` should be column, `j` should be row.

Switching the order can cause crash if num_rows is not same as num_cols.

* i for column, j for row

* Update iclr19_levels.py

Co-authored-by: Maxime Chevalier-Boisvert <[email protected]>
  • Loading branch information
emailweixu and maximecb authored Mar 17, 2021
1 parent e85ccb1 commit 0c1fa62
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
28 changes: 14 additions & 14 deletions babyai/levels/iclr19_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,15 @@ class Level_GoToImpUnlock(RoomGridLevel):

def gen_mission(self):
# Add a locked door to a random room
id = self._rand_int(0, self.num_rows)
jd = self._rand_int(0, self.num_cols)
id = self._rand_int(0, self.num_cols)
jd = self._rand_int(0, self.num_rows)
door, pos = self.add_door(id, jd, locked=True)
locked_room = self.get_room(id, jd)

# Add the key to a different room
while True:
ik = self._rand_int(0, self.num_rows)
jk = self._rand_int(0, self.num_cols)
ik = self._rand_int(0, self.num_cols)
jk = self._rand_int(0, self.num_rows)
if ik is id and jk is jd:
continue
self.add_object(ik, jk, 'key', door.color)
Expand All @@ -330,8 +330,8 @@ def gen_mission(self):
# We do this to speed up the reachability test,
# which otherwise will reject all levels with
# objects in the locked room.
for i in range(self.num_rows):
for j in range(self.num_cols):
for i in range(self.num_cols):
for j in range(self.num_rows):
if i is not id or j is not jd:
self.add_distractors(
i,
Expand Down Expand Up @@ -404,8 +404,8 @@ def gen_mission(self):

# Collect a list of all the doors in the environment
doors = []
for i in range(self.num_rows):
for j in range(self.num_cols):
for i in range(self.num_cols):
for j in range(self.num_rows):
room = self.get_room(i, j)
for door in room.doors:
if door:
Expand All @@ -424,15 +424,15 @@ class Level_Unlock(RoomGridLevel):

def gen_mission(self):
# Add a locked door to a random room
id = self._rand_int(0, self.num_rows)
jd = self._rand_int(0, self.num_cols)
id = self._rand_int(0, self.num_cols)
jd = self._rand_int(0, self.num_rows)
door, pos = self.add_door(id, jd, locked=True)
locked_room = self.get_room(id, jd)

# Add the key to a different room
while True:
ik = self._rand_int(0, self.num_rows)
jk = self._rand_int(0, self.num_cols)
ik = self._rand_int(0, self.num_cols)
jk = self._rand_int(0, self.num_rows)
if ik is id and jk is jd:
continue
self.add_object(ik, jk, 'key', door.color)
Expand All @@ -450,8 +450,8 @@ def gen_mission(self):
# We do this to speed up the reachability test,
# which otherwise will reject all levels with
# objects in the locked room.
for i in range(self.num_rows):
for j in range(self.num_cols):
for i in range(self.num_cols):
for j in range(self.num_rows):
if i is not id or j is not jd:
self.add_distractors(
i,
Expand Down
8 changes: 4 additions & 4 deletions babyai/levels/levelgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def validate_instrs(self, instr):
# Gather the colors of locked doors
if hasattr(self, 'unblocking') and self.unblocking:
colors_of_locked_doors = []
for i in range(self.num_rows):
for j in range(self.num_cols):
for i in range(self.num_cols):
for j in range(self.num_rows):
room = self.get_room(i, j)
for door in room.doors:
if door and door.is_locked:
Expand Down Expand Up @@ -191,8 +191,8 @@ def open_all_doors(self):
Open all the doors in the maze
"""

for i in range(self.num_rows):
for j in range(self.num_cols):
for i in range(self.num_cols):
for j in range(self.num_rows):
room = self.get_room(i, j)
for door in room.doors:
if door:
Expand Down

0 comments on commit 0c1fa62

Please sign in to comment.