-
-
Notifications
You must be signed in to change notification settings - Fork 135
Fix move tracking #816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix move tracking #816
Changes from 27 commits
68fcb9d
19a67fd
69ecb45
531bb23
1fb0d39
bf481a6
0949aa4
24e1981
b231155
994fdab
58eacf1
0cef241
a7acc7d
4add818
bd124c9
491b108
a3804c4
46e89e7
fd6e247
631769f
ae97244
cd0d901
4c64ecd
a62b65d
b6dcef6
85458a7
0f578fa
1d2fec5
05433db
70916af
6c56267
7fd69fa
45f3dd2
4318f77
ada8c73
053807c
e8d907e
702800c
7ce1dde
5009bc1
b9f02be
799f33a
e371053
e3afdd5
5e1393b
4cc2a11
da08488
e5a3dd0
87a3824
1b9d418
aee76f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,14 @@ def parse_request( | |
| self._trapped = True | ||
|
|
||
| if self.active_pokemon is not None: | ||
| if ( | ||
| strict_battle_tracking | ||
| and self.gen not in [7, 8] | ||
|
||
| and "illusion" not in [p.ability for p in self.team.values()] | ||
| and "illusion" | ||
| not in [p.ability for p in self.opponent_team.values()] | ||
| ): | ||
| self.active_pokemon.check_move_consistency(active_request) | ||
| # TODO: the illusion handling here works around Zoroark's | ||
| # difficulties. This should be properly handled at some point. | ||
| try: | ||
|
|
@@ -125,6 +133,37 @@ def parse_request( | |
| if not pokemon.active and self.reviving == pokemon.fainted: | ||
| self._available_switches.append(pokemon) | ||
|
|
||
| def _pressure_on(self, pokemon: str, move: str, target_str: Optional[str]) -> bool: | ||
| if self.gen == 7: | ||
|
||
| return False | ||
| move_data = self._data.moves[Move.retrieve_id(move)] | ||
| if move_data["target"] == "all" or target_str is None: | ||
| target = ( | ||
| self.opponent_active_pokemon | ||
| if self.player_role == pokemon[:2] | ||
| else self.active_pokemon | ||
| ) | ||
| assert target is not None | ||
| else: | ||
| target = self.get_pokemon(target_str) | ||
| return ( | ||
| target.ability == "pressure" | ||
| and not target.fainted | ||
| and ( | ||
| move_data["target"] | ||
| in [ | ||
| "all", | ||
| "allAdjacent", | ||
| "allAdjacentFoes", | ||
| "any", | ||
| "normal", | ||
| "randomNormal", | ||
| "scripted", | ||
| ] | ||
| or "mustpressure" in move_data["flags"] | ||
| ) | ||
| ) | ||
|
|
||
| def switch(self, pokemon_str: str, details: str, hp_status: str): | ||
| identifier = pokemon_str.split(":")[0][:2] | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| import copy | ||
| from functools import lru_cache | ||
| from typing import Any, Dict, List, Optional, Set, Tuple, Union | ||
|
|
||
|
|
@@ -13,7 +12,6 @@ | |
| from poke_env.data import GenData, to_id_str | ||
|
|
||
| SPECIAL_MOVES: Set[str] = {"struggle", "recharge"} | ||
|
|
||
| _PROTECT_MOVES = { | ||
| "protect", | ||
| "detect", | ||
|
|
@@ -80,7 +78,6 @@ class Move: | |
| "_current_pp", | ||
| "_dynamaxed_move", | ||
| "_gen", | ||
| "_is_empty", | ||
| "_moves_dict", | ||
| "_request_target", | ||
| ) | ||
|
|
@@ -102,16 +99,18 @@ def __init__(self, move_id: str, gen: int, raw_id: Optional[str] = None): | |
| pass | ||
|
|
||
| self._current_pp = self.max_pp | ||
| self._is_empty: bool = False | ||
|
|
||
| self._dynamaxed_move = None | ||
| self._request_target = None | ||
|
|
||
| def __repr__(self) -> str: | ||
| return f"{self._id} (Move object)" | ||
|
|
||
| def use(self): | ||
| self._current_pp -= 1 | ||
| def use(self, pressure: bool = False): | ||
| if pressure: | ||
| self.current_pp -= 2 | ||
| else: | ||
| self.current_pp -= 1 | ||
|
||
|
|
||
| @staticmethod | ||
| def is_id_z(id_: str, gen: int) -> bool: | ||
|
|
@@ -219,6 +218,14 @@ def current_pp(self) -> int: | |
| """ | ||
| return self._current_pp | ||
|
|
||
| @current_pp.setter | ||
| def current_pp(self, pp: int): | ||
| """ | ||
| :param pp: New PP value. | ||
| :type pp: int | ||
| """ | ||
| self._current_pp = min(max(0, pp), self.max_pp) | ||
hsahovic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @property | ||
| def damage(self) -> Union[int, str]: | ||
| """ | ||
|
|
@@ -402,14 +409,6 @@ def ignore_immunity(self) -> Union[bool, Set[PokemonType]]: | |
| } | ||
| return False | ||
|
|
||
| @property | ||
| def is_empty(self) -> bool: | ||
| """ | ||
| :return: Whether the move is an empty move. | ||
| :rtype: bool | ||
| """ | ||
| return self._is_empty | ||
|
|
||
| @property | ||
| def is_protect_counter(self) -> bool: | ||
| """ | ||
|
|
@@ -768,21 +767,6 @@ def z_move_power(self) -> int: | |
| return 200 | ||
|
|
||
|
|
||
| class EmptyMove(Move): | ||
| def __init__(self, move_id: str): | ||
| self._id = move_id | ||
| self._is_empty: bool = True | ||
|
|
||
| def __getattribute__(self, name: str): | ||
| try: | ||
| return super(Move, self).__getattribute__(name) | ||
| except (AttributeError, TypeError, ValueError): | ||
| return 0 | ||
|
|
||
| def __deepcopy__(self, memodict: Optional[Dict[int, Any]] = {}): | ||
| return EmptyMove(copy.deepcopy(self._id, memodict)) | ||
|
|
||
|
|
||
| class DynamaxMove(Move): | ||
| BOOSTS_MAP = { | ||
| PokemonType.BUG: {"spa": -1}, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is sky attack still handled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See here for what I yielded from my investigation: ada8c73. Basically, that message only seems to appear in random battles in early gens, so I added those to the strict integration tests and passed through them a few times to weed out existing early-gen bugs.