Skip to content

Commit

Permalink
testing round trip of action -> order and order -> action
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronangliss committed Jan 5, 2025
1 parent c64cdad commit 359ccfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion integration_tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ def embed_battle(self, battle):
return np.array([0])


def play_function(env, n_battles):
def play_function(env: CIEnv, n_battles: int):
for _ in range(n_battles):
done = False
env.reset()
while not done:
assert env.battle1 is not None
assert env.battle2 is not None
actions = {name: env.action_space(name).sample() for name in env.agents}
[a1, a2] = list(actions.values())
o1 = CIEnv.action_to_order(a1, env.battle1)
o2 = CIEnv.action_to_order(a2, env.battle2)
assert a1 == CIEnv.order_to_action(o1, env.battle1)
assert a2 == CIEnv.order_to_action(o2, env.battle2)
_, _, terminated, truncated, _ = env.step(actions)
done = any(terminated.values()) or any(truncated.values())

Expand Down
4 changes: 2 additions & 2 deletions src/poke_env/player/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ def close(self, purge: bool = True):
)
closing_task.result()

Check warning on line 361 in src/poke_env/player/env.py

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L361

Added line #L361 was not covered by tests

def observation_space(self, agent: str) -> Space:
def observation_space(self, agent: str) -> Space[ObsType]:
return self.observation_spaces[agent]

Check warning on line 364 in src/poke_env/player/env.py

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L364

Added line #L364 was not covered by tests

def action_space(self, agent: str) -> Space:
def action_space(self, agent: str) -> Space[ActionType]:
return self.action_spaces[agent]

###################################################################################
Expand Down

0 comments on commit 359ccfa

Please sign in to comment.