Skip to content

Commit

Permalink
np the types
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronangliss committed Jan 4, 2025
1 parent 751645b commit c64cdad
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/poke_env/player/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from weakref import WeakKeyDictionary

import numpy as np
import numpy.typing as npt
from gymnasium.spaces import Discrete, MultiDiscrete, Space
from pettingzoo.utils.env import ( # type: ignore[import-untyped]
ActionType,
Expand Down Expand Up @@ -556,10 +557,10 @@ def order_to_action(order: BattleOrder, battle: AbstractBattle) -> ActionType:
raise TypeError()

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

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L557

Added line #L557 was not covered by tests

@staticmethod
def _singles_order_to_action(order: BattleOrder, battle: Battle) -> int:
def _singles_order_to_action(order: BattleOrder, battle: Battle) -> np.int64:
assert order.order is not None
if isinstance(order, ForfeitBattleOrder):
return -1
action = -1
elif isinstance(order.order, Pokemon):
action = [p.base_species for p in battle.team.values()].index(

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

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L561-L565

Added lines #L561 - L565 were not covered by tests
order.order.base_species
Expand Down Expand Up @@ -593,29 +594,29 @@ def _singles_order_to_action(order: BattleOrder, battle: Battle) -> int:
), "invalid pick"
assert not order.dynamax or battle.can_dynamax, "invalid pick"
assert not order.terastallize or battle.can_tera is not None, "invalid pick"
return action
return np.int64(action)

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

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L595-L597

Added lines #L595 - L597 were not covered by tests

@staticmethod
def _doubles_order_to_action(
order: DoubleBattleOrder, battle: DoubleBattle
) -> List[int]:
) -> npt.NDArray[np.int64]:
action1 = PokeEnv._doubles_order_to_action_individual(

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

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L603

Added line #L603 was not covered by tests
order.first_order, battle, 0
)
action2 = PokeEnv._doubles_order_to_action_individual(

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

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L606

Added line #L606 was not covered by tests
order.second_order, battle, 1
)
return [action1, action2]
return np.array([action1, action2])

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

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L609

Added line #L609 was not covered by tests

@staticmethod
def _doubles_order_to_action_individual(
order: Optional[BattleOrder], battle: DoubleBattle, pos: int
) -> int:
) -> np.int64:
if order is None:
return 0
return np.int64(0)
assert order.order is not None
if isinstance(order, ForfeitBattleOrder):
return -1
action = -1
elif isinstance(order.order, Pokemon):
action = [p.base_species for p in battle.team.values()].index(

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

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L615-L621

Added lines #L615 - L621 were not covered by tests
order.order.base_species
Expand Down Expand Up @@ -644,7 +645,7 @@ def _doubles_order_to_action_individual(
assert order.move_target in battle.get_possible_showdown_targets(

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

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L645

Added line #L645 was not covered by tests
order.order, active_mon
), "invalid pick"
return action
return np.int64(action)

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

View check run for this annotation

Codecov / codecov/patch

src/poke_env/player/env.py#L648

Added line #L648 was not covered by tests

###################################################################################
# Helper methods
Expand Down

0 comments on commit c64cdad

Please sign in to comment.