Skip to content

Commit

Permalink
Add reviving property in double battle and correctly handle revival b…
Browse files Browse the repository at this point in the history
…lessing in doubles
  • Loading branch information
hsahovic committed Apr 6, 2024
1 parent 7f57f4b commit 78b3245
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/poke_env/environment/double_battle.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def parse_request(self, request: Dict[str, Any]) -> None:
self._trapped = [False, False]
self._can_tera = [False, False]
self._force_switch = request.get("forceSwitch", [False, False])
self._reviving = any(
[mon.get("reviving") for mon in request["side"]["pokemon"]]
)

if any(self._force_switch):
self._move_on_next_request = True
Expand Down Expand Up @@ -200,7 +203,13 @@ def parse_request(self, request: Dict[str, Any]) -> None:
for pokemon in side["pokemon"]:
if pokemon:
pokemon = self._team[pokemon["ident"]]
if not pokemon.active and not pokemon.fainted:
if (
not self.reviving
and not pokemon.active
and not pokemon.fainted
):
self._available_switches[pokemon_index].append(pokemon)
if self.reviving and not pokemon.active and pokemon.fainted:
self._available_switches[pokemon_index].append(pokemon)

def switch(self, pokemon_str: str, details: str, hp_status: str):
Expand Down Expand Up @@ -486,3 +495,11 @@ def trapped(self) -> List[bool]:
@trapped.setter
def trapped(self, value: List[bool]):
self._trapped = value

@property
def reviving(self) -> bool:
"""
:return: Whether or not any of the player's Pokemon is reviving.
:rtype: bool
"""
return self._reviving

0 comments on commit 78b3245

Please sign in to comment.