From 4d1a6126912e0c832fde238d24d15d1c94da2d84 Mon Sep 17 00:00:00 2001 From: hsahovic Date: Wed, 26 Feb 2020 20:40:09 -0500 Subject: [PATCH 1/6] Update pre-commit version to 3.6.9 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e77c32a99..b98925be7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ default_language_version: - python: python3.7.4 + python: python3.6.9 repos: - repo: https://github.com/ambv/black rev: stable From 506eb231af3e274347962b2328b0e5d5ce8d3552 Mon Sep 17 00:00:00 2001 From: hsahovic Date: Wed, 26 Feb 2020 20:41:41 -0500 Subject: [PATCH 2/6] Add tests for pokemon typing --- unit_tests/environment/test_pokemon.py | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/unit_tests/environment/test_pokemon.py b/unit_tests/environment/test_pokemon.py index afa6b054e..85bab2d41 100644 --- a/unit_tests/environment/test_pokemon.py +++ b/unit_tests/environment/test_pokemon.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from poke_env.environment.pokemon import Pokemon +from poke_env.environment.pokemon_type import PokemonType def test_pokemon_moves(): @@ -13,3 +14,38 @@ def test_pokemon_moves(): assert not mon.preparing assert not mon.must_recharge + + +def test_pokemon_types(): + # single type + mon = Pokemon(species="pikachu") + assert mon.type_1 == PokemonType.ELECTRIC + assert mon.type_2 is None + + # dual type + mon = Pokemon(species="garchomp") + assert mon.type_1 == PokemonType.DRAGON + assert mon.type_2 == PokemonType.GROUND + + # alolan forms + mon = Pokemon(species="raichualola") + assert mon.type_1 == PokemonType.ELECTRIC + assert mon.type_2 == PokemonType.PSYCHIC + + # megas + mon = Pokemon(species="altaria") + assert mon.type_1 == PokemonType.DRAGON + assert mon.type_2 == PokemonType.FLYING + + mon._mega_evolve("altariaite") + assert mon.type_1 == PokemonType.DRAGON + assert mon.type_2 == PokemonType.FAIRY + + # primals + mon = Pokemon(species="groudon") + assert mon.type_1 == PokemonType.GROUND + assert mon.type_2 is None + + mon._primal() + assert mon.type_1 == PokemonType.GROUND + assert mon.type_2 == PokemonType.FIRE From 1814c61fc2b2bb739c1fa584f6afd678e58c7cdf Mon Sep 17 00:00:00 2001 From: hsahovic Date: Wed, 26 Feb 2020 20:45:00 -0500 Subject: [PATCH 3/6] Fix type assignation error in pokemon --- src/poke_env/environment/pokemon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poke_env/environment/pokemon.py b/src/poke_env/environment/pokemon.py index 4c45f60d2..c1c5663a6 100644 --- a/src/poke_env/environment/pokemon.py +++ b/src/poke_env/environment/pokemon.py @@ -208,7 +208,7 @@ def _update_from_pokedex(self, species: str) -> None: if len(dex_entry["types"]) == 1: self._type_2 = None else: - self._type_1 = PokemonType.from_name(dex_entry["types"][1]) + self._type_2 = PokemonType.from_name(dex_entry["types"][1]) self._possible_abilities = dex_entry["abilities"] self._heightm = dex_entry["heightm"] From 53b9fc96933bb2aa0ac05e3a2d7c2d74a2c8a203 Mon Sep 17 00:00:00 2001 From: hsahovic Date: Wed, 26 Feb 2020 22:57:22 -0500 Subject: [PATCH 4/6] Add details argument to battle.get_pokemon This allows more flexibility in defining species on pokemon creation, which solves problems related to alternate forms --- src/poke_env/environment/battle.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/poke_env/environment/battle.py b/src/poke_env/environment/battle.py index 41b263030..d68fd82c6 100644 --- a/src/poke_env/environment/battle.py +++ b/src/poke_env/environment/battle.py @@ -96,15 +96,20 @@ def __init__(self, battle_tag: str, username: str, logger: Logger): # pyre-igno self._team: Dict[str, Pokemon] = {} self._opponent_team: Dict[str, Pokemon] = {} - def get_pokemon(self, identifier: str, force_self_team: bool = False) -> Pokemon: + def get_pokemon( + self, identifier: str, force_self_team: bool = False, details: str = "" + ) -> Pokemon: """Returns the Pokemon object corresponding to given identifier. Can force to return object from the player's team if force_self_team is True. If the Pokemon - object does not exist, it will be created. + object does not exist, it will be created. Details can be given, which is + necessary to initialize alternate forms (eg. alolan pokemons) properly. :param identifier: The identifier to use to retrieve the pokemon. :type identifier: str :param force_self_team: Wheter to force returning a Pokemon from the player's team. Defaults to False. + :type details: str, optional + :param details: Detailled information about the pokemon. Defaults to ''. :type force_self_team: bool, optional, defaults to False :return: The corresponding pokemon object. :rtype: Pokemon @@ -114,7 +119,10 @@ def get_pokemon(self, identifier: str, force_self_team: bool = False) -> Pokemon if identifier[3] != " ": identifier = identifier[:2] + identifier[3:] species = identifier[5:] - species = identifier[4:] + if details: + species = details.split(", ")[0] + else: + species = identifier[4:] if is_mine or force_self_team: team: Dict[str, Pokemon] = self.team From f54c24f9331bda4bf1f69573fd248e0d957e6c2c Mon Sep 17 00:00:00 2001 From: hsahovic Date: Wed, 26 Feb 2020 22:57:58 -0500 Subject: [PATCH 5/6] Change pokemon-initializing calls to get_pokemon to include details --- src/poke_env/environment/battle.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/poke_env/environment/battle.py b/src/poke_env/environment/battle.py index d68fd82c6..f046440c2 100644 --- a/src/poke_env/environment/battle.py +++ b/src/poke_env/environment/battle.py @@ -141,13 +141,13 @@ def get_pokemon( return team[identifier] - def _end_illusion(self, pokemon_name: str): + def _end_illusion(self, pokemon_name: str, details: str): if pokemon_name[:2] == self._player_role: active = self.active_pokemon else: active = self.opponent_active_pokemon - pokemon = self.get_pokemon(pokemon_name) + pokemon = self.get_pokemon(pokemon_name, details=details) pokemon._set_hp(f"{active.current_hp}/{active.max_hp}") active._was_illusionned() pokemon._switch_in() @@ -279,7 +279,7 @@ async def _parse_message(self, split_message: List[str]) -> None: self._in_team_preview = True elif split_message[1] in ["drag", "switch"]: pokemon, details, hp_status = split_message[2:5] - self._switch(pokemon, hp_status) + self._switch(pokemon, details, hp_status) elif split_message[1] == "faint": pokemon = split_message[2] self.get_pokemon(pokemon)._faint() @@ -305,7 +305,8 @@ async def _parse_message(self, split_message: List[str]) -> None: self.register_pokemon(player, details, item) elif split_message[1] == "replace": pokemon = split_message[2] - self._end_illusion(pokemon) + details = split_message[3] + self._end_illusion(pokemon, details) elif split_message[1] == "rule": self._rules.append(split_message[2]) elif split_message[1] == "start": @@ -415,14 +416,14 @@ def _side_start(self, side, condition): def _swap(self, *args, **kwargs): self.logger.warning("swap method in Battle is not implemented") - def _switch(self, pokemon, hp_status): + def _switch(self, pokemon, details, hp_status): identifier = pokemon.split(":")[0][:2] if identifier == self._player_role: self.active_pokemon._switch_out() else: if self.opponent_team: self.opponent_active_pokemon._switch_out() - pokemon = self.get_pokemon(pokemon) + pokemon = self.get_pokemon(pokemon, details=details) pokemon._switch_in() pokemon._set_hp_status(hp_status) @@ -432,7 +433,7 @@ async def _tied(self): def _update_team_from_request(self, side: Dict) -> None: for pokemon in side["pokemon"]: self.get_pokemon( - pokemon["ident"], force_self_team=True + pokemon["ident"], force_self_team=True, details=pokemon["details"] )._update_from_request(pokemon) async def _won_by(self, player_name: str): From 6b6ef2e3dc3ad08beae75c56cba9efb2034ef99e Mon Sep 17 00:00:00 2001 From: hsahovic Date: Wed, 26 Feb 2020 23:10:36 -0500 Subject: [PATCH 6/6] Up version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ceab08a2d..8d1468aba 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ EMAIL = "contact@sahovic.fr" AUTHOR = "Haris Sahovic" REQUIRES_PYTHON = ">=3.6.0" -VERSION = "0.0.5" +VERSION = "0.0.6" # What packages are required for this module to be executed? with open("requirements.txt") as requirements: