Skip to content

Commit

Permalink
Normalizes mouse action space for gym checker
Browse files Browse the repository at this point in the history
  • Loading branch information
rk1a committed Sep 10, 2023
1 parent fd6c429 commit 25dc410
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 6 additions & 3 deletions minetester/minetest_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ def _configure_spaces(self):
**{key: gym.spaces.Discrete(2) for key in KEY_MAP.keys()},
**{
"MOUSE": gym.spaces.Box(
np.array([-self.max_mouse_move_x, -self.max_mouse_move_y]),
np.array([self.max_mouse_move_x, self.max_mouse_move_y]),
np.array([-1, -1]),
np.array([1, 1]),
shape=(2,),
dtype=int,
dtype=float,
),
},
},
Expand Down Expand Up @@ -417,6 +417,9 @@ def step(self, action: Dict[str, Any]):
# Send action
if isinstance(action["MOUSE"], np.ndarray):
action["MOUSE"] = action["MOUSE"].tolist()
# Scale mouse action according to screen ratio
action["MOUSE"][0] = int(action["MOUSE"][0] * self.max_mouse_move_x)
action["MOUSE"][1] = int(action["MOUSE"][1] * self.max_mouse_move_y)
logging.debug("Sending action: {}".format(action))
pb_action = pack_pb_action(action)
self.socket.send(pb_action.SerializeToString())
Expand Down
7 changes: 6 additions & 1 deletion minetester/scripts/gymnasium_api_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import minetester
import gymnasium as gym
from gymnasium.utils.env_checker import check_env

env = gym.make("Minetest-v0")

check_env(env.unwrapped)
# Note: render check is skipped because it creates
# a new environment for each render_mode without incrementing
# the environment and server ports
# TODO implement automatic port incrementation and check render
check_env(env.unwrapped, skip_render_check=True)

0 comments on commit 25dc410

Please sign in to comment.