Skip to content

Commit 391b17c

Browse files
fixed tests
1 parent 2d5c78c commit 391b17c

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/ale/python/vector_env.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ def __init__(
126126
self.full_action_space = full_action_space
127127
self.continuous = continuous
128128
self.continuous_action_threshold = continuous_action_threshold
129+
self.map_action_idx = np.zeros((3, 3, 2), dtype=np.int32)
130+
for h in (-1, 0, 1):
131+
for v in (-1, 0, 1):
132+
for f in (0, 1):
133+
action = AtariEnv.map_action_idx(h, v, bool(f)).value
134+
self.map_action_idx[h + 1, v + 1, f] = action
129135
self.single_action_space, self.action_space = (
130136
self._setup_continuous_action()
131137
if self.continuous
@@ -141,12 +147,6 @@ def _setup_obs(self, stack_num: int, img_height: int, img_width: int) -> tuple:
141147
return single, gymnasium.vector.utils.batch_space(single, self.batch_size)
142148

143149
def _setup_continuous_action(self) -> tuple:
144-
self.map_action_idx = np.zeros((3, 3, 2), dtype=np.int32)
145-
for h in (-1, 0, 1):
146-
for v in (-1, 0, 1):
147-
for f in (0, 1):
148-
action = AtariEnv.map_action_idx(h, v, bool(f)).value
149-
self.map_action_idx[h + 1, v + 1, f] = action
150150
# Actions are radius, theta, and fire, where first two are the parameters of polar coordinates.
151151
single = Box(
152152
low=np.array([0.0, -np.pi, 0.0]).astype(np.float32),

tests/python/test_atari_vector_env.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,12 @@ def test_same_step_autoreset_mode(
666666
gym_envs.close()
667667
ale_envs.close()
668668

669+
670+
class TestMultiRomVectorEnv:
671+
"""Tests for multi-ROM support in AtariVectorEnv."""
672+
669673
@pytest.mark.parametrize("game,n_minimal", [("breakout", 4), ("pong", 6)])
670-
def test_single_action_space(game, n_minimal):
674+
def test_single_action_space(self, game, n_minimal):
671675
"""single_action_space reflects the real action-set size, not a constant."""
672676
env = AtariVectorEnv(game=game, num_envs=3)
673677
assert env.single_action_space == gym.spaces.Discrete(n_minimal)
@@ -684,10 +688,6 @@ def test_single_action_space(game, n_minimal):
684688
assert np.all(env.action_space.nvec == 18)
685689
env.close()
686690

687-
688-
class TestMultiRomVectorEnv:
689-
"""Tests for multi-ROM support in AtariVectorEnv."""
690-
691691
def test_single_action_space_none_for_different_roms(self):
692692
"""Different ROMs (different action-set sizes) have no single space."""
693693
# num_envs repeats each ROM, so this is [pong, pong, breakout, breakout].

0 commit comments

Comments
 (0)