Skip to content

Commit

Permalink
Added further Effects handling from Showdown parsing and fainting (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
caymansimpson authored Sep 3, 2024
1 parent 53fa383 commit 70bf850
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/poke_env/environment/abstract_battle.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class AbstractBattle(ABC):
"-ohko",
"-resisted",
"-singlemove",
"-singleturn",
"-supereffective",
"-waiting",
"-zbroken",
Expand Down Expand Up @@ -705,6 +704,9 @@ def parse_message(self, split_message: List[str]):
elif split_message[1] == "-sidestart":
side, condition = split_message[2:4]
self._side_start(side, condition)
elif split_message[1] in ["-singleturn", "-singlemove"]:
pokemon, effect = split_message[2:4]
self.get_pokemon(pokemon).start_effect(effect.replace("move: ", ""))
elif split_message[1] == "-swapboost":
source, target, stats = split_message[2:5]
source = self.get_pokemon(source)
Expand Down
1 change: 1 addition & 0 deletions src/poke_env/environment/pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def end_turn(self):
def faint(self):
self._current_hp = 0
self._status = Status.FNT
self._effects = {}

def forme_change(self, species: str):
species = species.split(",")[0]
Expand Down
5 changes: 5 additions & 0 deletions unit_tests/environment/test_battle.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ def test_battle_request_and_interactions(example_request):
for stat, boost in battle.opponent_active_pokemon.boosts.items():
assert boost == -boosts_before_invertion[stat]

battle.parse_message(["", "-singleturn", "p1: Tyranitar", "move: Rage Powder"])
assert Effect.RAGE_POWDER in battle.opponent_active_pokemon.effects
battle.end_turn(1)
assert Effect.RAGE_POWDER not in battle.opponent_active_pokemon.effects

battle.parse_message(
[
"",
Expand Down
5 changes: 5 additions & 0 deletions unit_tests/environment/test_enumerations.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ def test_effect_end():
if effect.is_volatile_status:
assert effect.ends_on_switch

furret.switch_in()
furret.start_effect("feint")
furret.faint()
assert furret.effects == {}


def test_field_str():
assert str(Field["ELECTRIC_TERRAIN"])
Expand Down

0 comments on commit 70bf850

Please sign in to comment.