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

Possible bug when generating non-square DoorKey environments. #427

Open
rbankosegger opened this issue Apr 11, 2024 · 4 comments
Open

Possible bug when generating non-square DoorKey environments. #427

rbankosegger opened this issue Apr 11, 2024 · 4 comments

Comments

@rbankosegger
Copy link
Contributor

Consider the lines

doorIdx = self._rand_int(1, width - 2)
self.put_obj(Door("yellow", is_locked=True), splitIdx, doorIdx)

From:

https://github.com/Farama-Foundation/Minigrid/blame/617e4908e20fd08e4e135421cd47d52018a3148c/minigrid/envs/doorkey.py#L94

The variable doorIdx determines the y-coordinate of the door,
the sampling of which should depend on the grid height, not its width.
In situations where width > height, the door might be placed outside of the grid dimension.

Suggested fix:
Replace by

doorIdx = self._rand_int(1, height - 2)
@pseudo-rnd-thoughts
Copy link
Member

Could you provide an example image for a given seed with and without the fix

@rbankosegger
Copy link
Contributor Author

rbankosegger commented Apr 12, 2024

Here is an example.
I believe this bug cannot occur "in the wild" because width=height for all gym-registered environments.
But it might become an issue if someone decides to publish a non-square environment of this type.

from minigrid.envs.doorkey import DoorKeyEnv
env = DoorKeyEnv(render_mode='human', size=6)
env.reset(seed=1)
env._gen_grid(6,4)
env.render()

import time
time.sleep(100)

minigrid

@pseudo-rnd-thoughts
Copy link
Member

Ahh, that makes sense. Could you make a PR with this fix?

@rbankosegger
Copy link
Contributor Author

Here it is:
#429

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants