Skip to content
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

Make sure ObstructedMaze is solvable. #334

Merged
merged 8 commits into from
Mar 21, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions minigrid/envs/obstructedmaze.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,22 @@ def _gen_grid(self, width, height):
)

for k in [-1, 1]:
# Add a door to each side of the side room
self.add_door(
# Add a door to each side of the side room w/o placing a key
self.add_locked_door(
*side_room,
locked=True,
door_idx=(i + k) % 4,
color=self.door_colors[(i + k) % len(self.door_colors)],
key_in_box=self.key_in_box,
blocked=self.blocked,
)

# Add keys after all doors and their blocking balls are added
for k in [-1, 1]:
self.add_key(
*side_room,
color=self.door_colors[(i + k) % len(self.door_colors)],
key_in_box=self.key_in_box,
)

corners = [(2, 0), (2, 2), (0, 2), (0, 0)][: self.num_quarters]
ball_room = self._rand_elem(corners)

Expand All @@ -248,6 +254,30 @@ def _gen_grid(self, width, height):
)
self.place_agent(*self.agent_room)

def add_locked_door(self, i, j, door_idx=0, color=None, blocked=False):
door, door_pos = RoomGrid.add_door(self, i, j, door_idx, color, locked=True)

if blocked:
vec = DIR_TO_VEC[door_idx]
blocking_ball = Ball(self.blocking_ball_color) if blocked else None
self.grid.set(door_pos[0] - vec[0], door_pos[1] - vec[1], blocking_ball)

return door, door_pos

def add_key(
self,
i,
j,
color=None,
key_in_box=False,
):
obj = Key(color)
if key_in_box:
box = Box(self.box_color)
box.contains = obj
obj = box
self.place_in_room(i, j, obj)


class ObstructedMaze_2Dl(ObstructedMaze_Full):
def __init__(self, **kwargs):
Expand Down