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

[Proposal] Add MoveActionWrapper #456

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions minigrid/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,3 +881,40 @@ def step(self, action):
reward += self.death_cost

return obs, reward, terminated, truncated, info


class MoveActionWrapper(Wrapper):
"""
Wrapper to change the action space to move actions, instead of turn.

Thus, the action space, become a Discrete(8) space, where the actions are:
0: Move right
1: Move down
2: Move left
3: Move up
4: pickup
5: drop
5: toggle
7: done

Note:
This wrapper is mostly useful with full observation, as the partial observation is rotated depending on the agent direction.
"""

def __init__(self, env):
super().__init__(env)
self.action_space = spaces.Discrete(8)

def step(self, action):
if action <= 3:
agent_dir = self.unwrapped.agent_dir
left_turns = (agent_dir - action) % 4
if left_turns == 3:
self.env.step(1)
else:
for _ in range(left_turns):
self.env.step(0)

return self.env.step(2)
else:
return self.env.step(action - 1)
2 changes: 2 additions & 0 deletions tests/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
FlatObsWrapper,
FullyObsWrapper,
ImgObsWrapper,
MoveActionWrapper,
NoDeath,
OneHotPartialObsWrapper,
PositionBonus,
Expand Down Expand Up @@ -160,6 +161,7 @@ def test_dict_observation_space_wrapper(env_spec):
OneHotPartialObsWrapper,
RGBImgPartialObsWrapper,
FullyObsWrapper,
MoveActionWrapper,
],
)
@pytest.mark.parametrize(
Expand Down
Loading