Skip to content

Commit

Permalink
Fixed the issue found here Farama-Foundation#419
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwassathish committed Feb 25, 2024
1 parent df4e675 commit 6b81300
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
26 changes: 17 additions & 9 deletions minigrid/minigrid_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,19 +649,27 @@ def gen_obs(self):

return obs

def get_pov_render(self, tile_size):
def get_pov_render(self, tile_size, agent_view_size=None):
"""
Render an agent's POV observation for visualization
"""
grid, vis_mask = self.gen_obs_grid()

grid, vis_mask = self.gen_obs_grid(agent_view_size)
# Render the whole grid
img = grid.render(
tile_size,
agent_pos=(self.agent_view_size // 2, self.agent_view_size - 1),
agent_dir=3,
highlight_mask=vis_mask,
)
if agent_view_size is None:
img = grid.render(
tile_size,
agent_pos=(self.agent_view_size // 2, self.agent_view_size - 1),
agent_dir=3,
highlight_mask=vis_mask,
)
else:
img = grid.render(
tile_size,
agent_pos=(agent_view_size // 2, agent_view_size - 1),
agent_dir=3,
highlight_mask=vis_mask,
)

return img

Expand Down
6 changes: 5 additions & 1 deletion minigrid/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def __init__(self, env, tile_size=8):
self.tile_size = tile_size

obs_shape = env.observation_space.spaces["image"].shape

new_image_space = spaces.Box(
low=0,
high=255,
Expand All @@ -376,7 +377,10 @@ def __init__(self, env, tile_size=8):
)

def observation(self, obs):
rgb_img_partial = self.get_frame(tile_size=self.tile_size, agent_pov=True)
rgb_img_partial = self.get_pov_render(
tile_size=self.tile_size,
agent_view_size=self.agent_view_size
)

return {**obs, "image": rgb_img_partial}

Expand Down

0 comments on commit 6b81300

Please sign in to comment.