From 25dc410840d165d424434a6899e44740ef1cf936 Mon Sep 17 00:00:00 2001 From: rk1a Date: Sun, 10 Sep 2023 23:54:53 +0200 Subject: [PATCH] Normalizes mouse action space for gym checker --- minetester/minetest_env.py | 9 ++++++--- minetester/scripts/gymnasium_api_check.py | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/minetester/minetest_env.py b/minetester/minetest_env.py index b2e97ff01c8b..0d17a3cf2b2e 100644 --- a/minetester/minetest_env.py +++ b/minetester/minetest_env.py @@ -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, ), }, }, @@ -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()) diff --git a/minetester/scripts/gymnasium_api_check.py b/minetester/scripts/gymnasium_api_check.py index a33000431efa..20d085ee0c1a 100644 --- a/minetester/scripts/gymnasium_api_check.py +++ b/minetester/scripts/gymnasium_api_check.py @@ -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) \ No newline at end of file +# 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) \ No newline at end of file