Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cameronangliss/poke-env into none…
Browse files Browse the repository at this point in the history
…-battleorder-is-pass
  • Loading branch information
cameronangliss committed Jan 4, 2025
2 parents d43f66d + ea4b5f3 commit 178a572
Show file tree
Hide file tree
Showing 12 changed files with 386 additions and 527 deletions.
94 changes: 26 additions & 68 deletions integration_tests/test_env_player.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest
from gymnasium.spaces import Box, Space
from gymnasium.utils.env_checker import check_env
from pettingzoo.test.parallel_test import parallel_api_test

from poke_env.player import (
Gen4EnvSinglePlayer,
Expand All @@ -10,7 +10,6 @@
Gen7EnvSinglePlayer,
Gen8EnvSinglePlayer,
Gen9EnvSinglePlayer,
RandomPlayer,
)


Expand Down Expand Up @@ -80,81 +79,61 @@ def embed_battle(self, battle):
return np.array([0])


def play_function(player, n_battles):
def play_function(env, n_battles):
for _ in range(n_battles):
done = False
player.reset()
env.reset()
while not done:
_, _, terminated, truncated, _ = player.step(player.action_space.sample())
done = terminated or truncated
actions = {name: env.action_space(name).sample() for name in env.agents}
_, _, terminated, truncated, _ = env.step(actions)
done = any(terminated.values()) or any(truncated.values())


@pytest.mark.timeout(30)
def test_random_gymnasium_players_gen4():
random_player = RandomPlayer(battle_format="gen4randombattle", log_level=25)
env_player = RandomGen4EnvPlayer(
log_level=25, opponent=random_player, start_challenging=False
)
env_player = RandomGen4EnvPlayer(log_level=25, start_challenging=False)
env_player.start_challenging(3)
play_function(env_player, 3)


@pytest.mark.timeout(30)
def test_random_gymnasium_players_gen5():
random_player = RandomPlayer(battle_format="gen5randombattle", log_level=25)
env_player = RandomGen5EnvPlayer(
log_level=25, opponent=random_player, start_challenging=False
)
env_player = RandomGen5EnvPlayer(log_level=25, start_challenging=False)
env_player.start_challenging(3)
play_function(env_player, 3)


@pytest.mark.timeout(30)
def test_random_gymnasium_players_gen6():
random_player = RandomPlayer(battle_format="gen6randombattle", log_level=25)
env_player = RandomGen6EnvPlayer(
log_level=25, opponent=random_player, start_challenging=False
)
env_player = RandomGen6EnvPlayer(log_level=25, start_challenging=False)
env_player.start_challenging(3)
play_function(env_player, 3)


@pytest.mark.timeout(30)
def test_random_gymnasium_players_gen7():
random_player = RandomPlayer(battle_format="gen7randombattle", log_level=25)
env_player = RandomGen7EnvPlayer(
log_level=25, opponent=random_player, start_challenging=False
)
env_player = RandomGen7EnvPlayer(log_level=25, start_challenging=False)
env_player.start_challenging(3)
play_function(env_player, 3)


@pytest.mark.timeout(30)
def test_random_gymnasium_players_gen8():
random_player = RandomPlayer(battle_format="gen8randombattle", log_level=25)
env_player = RandomGen8EnvPlayer(
log_level=25, opponent=random_player, start_challenging=False
)
env_player = RandomGen8EnvPlayer(log_level=25, start_challenging=False)
env_player.start_challenging(3)
play_function(env_player, 3)


@pytest.mark.timeout(30)
def test_random_gymnasium_players_gen9():
random_player = RandomPlayer(battle_format="gen9randombattle", log_level=25)
env_player = RandomGen9EnvPlayer(
log_level=25, opponent=random_player, start_challenging=False
)
env_player = RandomGen9EnvPlayer(log_level=25, start_challenging=False)
env_player.start_challenging(3)
play_function(env_player, 3)


@pytest.mark.timeout(60)
def test_two_successive_calls_gen8():
random_player = RandomPlayer(battle_format="gen8randombattle", log_level=25)
env_player = RandomGen8EnvPlayer(
log_level=25, opponent=random_player, start_challenging=False
)
env_player = RandomGen8EnvPlayer(log_level=25, start_challenging=False)
env_player.start_challenging(2)
play_function(env_player, 2)
env_player.start_challenging(2)
Expand All @@ -163,10 +142,7 @@ def test_two_successive_calls_gen8():

@pytest.mark.timeout(60)
def test_two_successive_calls_gen9():
random_player = RandomPlayer(battle_format="gen9randombattle", log_level=25)
env_player = RandomGen9EnvPlayer(
log_level=25, opponent=random_player, start_challenging=False
)
env_player = RandomGen9EnvPlayer(log_level=25, start_challenging=False)
env_player.start_challenging(2)
play_function(env_player, 2)
env_player.start_challenging(2)
Expand All @@ -175,39 +151,21 @@ def test_two_successive_calls_gen9():

@pytest.mark.timeout(60)
def test_check_envs():
random_player = RandomPlayer(battle_format="gen4randombattle", log_level=25)
env_player_gen4 = RandomGen4EnvPlayer(
log_level=25, opponent=random_player, start_challenging=True
)
check_env(env_player_gen4)
env_player_gen4 = RandomGen4EnvPlayer(log_level=25, start_challenging=True)
parallel_api_test(env_player_gen4)
env_player_gen4.close()
random_player = RandomPlayer(battle_format="gen5randombattle", log_level=25)
env_player_gen5 = RandomGen5EnvPlayer(
log_level=25, opponent=random_player, start_challenging=True
)
check_env(env_player_gen5)
env_player_gen5 = RandomGen5EnvPlayer(log_level=25, start_challenging=True)
parallel_api_test(env_player_gen5)
env_player_gen5.close()
random_player = RandomPlayer(battle_format="gen6randombattle", log_level=25)
env_player_gen6 = RandomGen6EnvPlayer(
log_level=25, opponent=random_player, start_challenging=True
)
check_env(env_player_gen6)
env_player_gen6 = RandomGen6EnvPlayer(log_level=25, start_challenging=True)
parallel_api_test(env_player_gen6)
env_player_gen6.close()
random_player = RandomPlayer(battle_format="gen7randombattle", log_level=25)
env_player_gen7 = RandomGen7EnvPlayer(
log_level=25, opponent=random_player, start_challenging=True
)
check_env(env_player_gen7)
env_player_gen7 = RandomGen7EnvPlayer(log_level=25, start_challenging=True)
parallel_api_test(env_player_gen7)
env_player_gen7.close()
random_player = RandomPlayer(battle_format="gen8randombattle", log_level=25)
env_player_gen8 = RandomGen8EnvPlayer(
log_level=25, opponent=random_player, start_challenging=True
)
check_env(env_player_gen8)
env_player_gen8 = RandomGen8EnvPlayer(log_level=25, start_challenging=True)
parallel_api_test(env_player_gen8)
env_player_gen8.close()
random_player = RandomPlayer(battle_format="gen9randombattle", log_level=25)
env_player_gen9 = RandomGen9EnvPlayer(
log_level=25, opponent=random_player, start_challenging=True
)
check_env(env_player_gen9)
env_player_gen9 = RandomGen9EnvPlayer(log_level=25, start_challenging=True)
parallel_api_test(env_player_gen9)
env_player_gen9.close()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
gymnasium
numpy
orjson
pettingzoo
requests
tabulate
websockets==12.0
1 change: 1 addition & 0 deletions src/poke_env/environment/effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ def is_from_move(self) -> bool:
"FLOWERVEIL": Effect.FLOWER_VEIL,
"FOCUSBAND": Effect.FOCUS_BAND,
"FOCUSENERGY": Effect.FOCUS_ENERGY,
"FOCUSPUNCH": Effect.FOCUS_PUNCH,
"FOLLOWME": Effect.FOLLOW_ME,
"FORESIGHT": Effect.FORESIGHT,
"FOREWARN": Effect.FOREWARN,
Expand Down
2 changes: 2 additions & 0 deletions src/poke_env/environment/pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ def forme_change(self, species: str):

def heal(self, hp_status: str):
self.set_hp_status(hp_status)
if self.fainted:
self._status = None

def invert_boosts(self):
self._boosts = {k: -v for k, v in self._boosts.items()}
Expand Down
6 changes: 4 additions & 2 deletions src/poke_env/player/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""poke_env.player module init.
"""

from pettingzoo.utils.env import ActionType, ObsType # type: ignore[import-untyped]

from poke_env.concurrency import POKE_LOOP
from poke_env.player import env_player, gymnasium_api, player, random_player, utils
from poke_env.player.baselines import MaxBasePowerPlayer, SimpleHeuristicsPlayer
Expand All @@ -19,7 +21,7 @@
Gen8EnvSinglePlayer,
Gen9EnvSinglePlayer,
)
from poke_env.player.gymnasium_api import ActType, GymnasiumEnv, ObsType
from poke_env.player.gymnasium_api import GymnasiumEnv
from poke_env.player.player import Player
from poke_env.player.random_player import RandomPlayer
from poke_env.player.utils import (
Expand All @@ -36,7 +38,7 @@
"player",
"random_player",
"utils",
"ActType",
"ActionType",
"ObsType",
"EnvPlayer",
"ForfeitBattleOrder",
Expand Down
Loading

0 comments on commit 178a572

Please sign in to comment.