poke-env icon indicating copy to clipboard operation
poke-env copied to clipboard

battle.opponent_active_pokemon is None

Open akashsara opened this issue 2 years ago • 2 comments

Hi, I encountered an odd situation during training where battle.opponent_active_pokemon was None. I was wondering why this would be the case. Even more odd is that battle.turn returns 0 and all Pokemon on both teams are alive. I should be able to reproduce this if I use the same seed in case you have any other questions.

Edit: If it helps, I'm not doing random battles. I'm generating random teams and playing in the anythinggoes game mode.

2022-08-16 13:37:31,155 - SimpleRLPlayerTe 2 - ERROR - Unhandled exception raised while handling message:
>battle-gen8anythinggoes-632316
|request|{"forceSwitch":[true],"side":{"name":"SimpleRLPlayerTe 2","id":"p1","pokemon":[{"ident":"p1: Duraludon","details":"Duraludon, F","condition":"281/281","active":true,"stats":{"atk":203,"def":266,"spa":339,"spd":137,"spe":295},"moves":["dracometeor","flashcannon","bodypress","stealthrock"],"baseAbility":"lightmetal","item":"","pokeball":"pokeball","ability":"lightmetal"},{"ident":"p1: Articuno","details":"Articuno","condition":"384/384","active":false,"stats":{"atk":185,"def":236,"spa":226,"spd":369,"spe":220},"moves":["freezedry","defog","healbell","roost"],"baseAbility":"pressure","item":"heavydutyboots","pokeball":"pokeball","ability":"pressure"},{"ident":"p1: Golett","details":"Golett","condition":"259/259","active":false,"stats":{"atk":269,"def":145,"spa":95,"spd":185,"spe":106},"moves":["poltergeist","dynamicpunch","earthquake","stealthrock"],"baseAbility":"noguard","item":"eviolite","pokeball":"pokeball","ability":"noguard"},{"ident":"p1: Keldeo","details":"Keldeo-Resolute","condition":"323/323","active":false,"stats":{"atk":162,"def":216,"spa":357,"spd":217,"spe":346},"moves":["calmmind","scald","secretsword","substitute"],"baseAbility":"justified","item":"leftovers","pokeball":"pokeball","ability":"justified"},{"ident":"p1: Corphish","details":"Corphish, F","condition":"227/227","active":false,"stats":{"atk":269,"def":185,"spa":122,"spd":106,"spe":165},"moves":["aquajet","crabhammer","knockoff","dragondance"],"baseAbility":"adaptability","item":"eviolite","pokeball":"pokeball","ability":"adaptability"},{"ident":"p1: Meowstic","details":"Meowstic-F, F","condition":"289/289","active":false,"stats":{"atk":118,"def":188,"spa":265,"spd":199,"spe":337},"moves":["nastyplot","psychic","thunderbolt","protect"],"baseAbility":"competitive","item":"colburberry","pokeball":"pokeball","ability":"competitive"}]},"noCancel":true,"rqid":4}
Traceback (most recent call last):
  File "e:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env-0.4.21-py3.9.egg\poke_env\player\player_network_interface.py", line 169, in _handle_message    
    await self._handle_battle_message(split_messages)
  File "e:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env-0.4.21-py3.9.egg\poke_env\player\player.py", line 242, in _handle_battle_message
    await self._handle_battle_request(battle)
  File "e:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env-0.4.21-py3.9.egg\poke_env\player\player.py", line 339, in _handle_battle_request
    message = await message
  File "e:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env-0.4.21-py3.9.egg\poke_env\player\openai_api.py", line 82, in env_move
    battle_to_send = self.user_funcs.embed_battle(battle)
  File "e:\Dev\meta-discovery\agents\simple_agent.py", line 30, in embed_battle
    battle.opponent_active_pokemon.type_1,
AttributeError: 'NoneType' object has no attribute 'type_1'
Task exception was never retrieved
future: <Task finished name='Task-2855189' coro=<PlayerNetwork._handle_message() done, defined at e:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env-0.4.21-py3.9.egg\poke_env\player\player_network_interface.py:155> exception=AttributeError("'NoneType' object has no attribute 'type_1'")>
Traceback (most recent call last):
  File "e:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env-0.4.21-py3.9.egg\poke_env\player\player_network_interface.py", line 220, in _handle_message    
    raise exception
  File "e:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env-0.4.21-py3.9.egg\poke_env\player\player_network_interface.py", line 169, in _handle_message    
    await self._handle_battle_message(split_messages)
  File "e:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env-0.4.21-py3.9.egg\poke_env\player\player.py", line 242, in _handle_battle_message
    await self._handle_battle_request(battle)
  File "e:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env-0.4.21-py3.9.egg\poke_env\player\player.py", line 339, in _handle_battle_request
    message = await message
  File "e:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env-0.4.21-py3.9.egg\poke_env\player\openai_api.py", line 82, in env_move
    battle_to_send = self.user_funcs.embed_battle(battle)
  File "e:\Dev\meta-discovery\agents\simple_agent.py", line 30, in embed_battle
    battle.opponent_active_pokemon.type_1,
AttributeError: 'NoneType' object has no attribute 'type_1'

akashsara avatar Aug 16 '22 18:08 akashsara

I did a little more digging:

x = player.last_battle
y = player.current_battle

# Same player
x.player_username
'SimpleRLPlayerTe 2'
y.player_username
'SimpleRLPlayerTe 2'

# Same battle
x.battle_tag
'battle-gen8anythinggoes-640830'
y.battle_tag
'battle-gen8anythinggoes-640830'

# Same turn
x.turn
0
y.turn
0

# Same team
x.team
{'p1: Marowak': marowakalola (pokemo...tus: None], 'p1: Latias': latias (pokemon obje...tus: None], 'p1: Heliolisk': heliolisk (pokemon o...tus: None], 'p1: Duraludon': duraludon (pokemon o...tus: None], 'p1: Arctozolt': arctozolt (pokemon o...tus: None], 'p1: Lycanroc': lycanroc (pokemon ob...tus: None]}
y.team
{'p1: Marowak': marowakalola (pokemo...tus: None], 'p1: Latias': latias (pokemon obje...tus: None], 'p1: Heliolisk': heliolisk (pokemon o...tus: None], 'p1: Duraludon': duraludon (pokemon o...tus: None], 'p1: Arctozolt': arctozolt (pokemon o...tus: None], 'p1: Lycanroc': lycanroc (pokemon ob...tus: None]}

# Player active Pokemon stays the same
x.active_pokemon
duraludon (pokemon object) [Active: True, Status: None]
y.active_pokemon
duraludon (pokemon object) [Active: True, Status: None]

# Opponent active Pokemon changes
x.opponent_active_pokemon

y.opponent_active_pokemon
litten (pokemon object) [Active: True, Status: None]

# Force switch is enabled somehow?
x.force_switch
[True]
y.force_switch
[True]

# Last battle sees more of the opponent's team?
x.opponent_team
{'mienfoo': mienfoo (pokemon obj...tus: None], 'kadabra': kadabra (pokemon obj...tus: None], 'regieleki': regieleki (pokemon o...tus: None], 'toxapex': toxapex (pokemon obj...tus: None], 'abomasnow': abomasnow (pokemon o...tus: None], 'litten': litten (pokemon obje...tus: None]}
y.opponent_team
{'p2: Litten': litten (pokemon obje...tus: None]}

There's a couple of weird things happening here, the last 3 parts of the above specifically.

akashsara avatar Aug 16 '22 21:08 akashsara

Encountered the same issue again. @hsahovic do you have any guesses on what might be causing this?

>battle-gen8anythinggoes-1200648
|request|{"forceSwitch":[true],"side":{"name":"Battle_Agent_1","id":"p1","pokemon":[{"ident":"p1: Duraludon","details":"Duraludon, M","condition":"281/281","active":true,"stats":{"atk":203,"def":266,"spa":339,"spd":137,"spe":295},"moves":["dracometeor","flashcannon","bodypress","stealthrock"],"baseAbility":"lightmetal","item":"","pokeball":"pokeball","ability":"lightmetal"},{"ident":"p1: Dugtrio","details":"Dugtrio-Alola, M","condition":"211/211","active":false,"stats":{"atk":299,"def":157,"spa":122,"spd":176,"spe":350},"moves":["stealthrock","earthquake","ironhead","suckerpunch"],"baseAbility":"tanglinghair","item":"lifeorb","pokeball":"pokeball","ability":"tanglinghair"},{"ident":"p1: Tirtouga","details":"Tirtouga, M","condition":"290/290","active":false,"stats":{"atk":205,"def":265,"spa":127,"spd":181,"spe":85},"moves":["stealthrock","stoneedge","liquidation","aquajet"],"baseAbility":"solidrock","item":"eviolite","pokeball":"pokeball","ability":"solidrock"},{"ident":"p1: Pheromosa","details":"Pheromosa","condition":"283/283","active":false,"stats":{"atk":373,"def":111,"spa":279,"spd":110,"spe":441},"moves":["uturn","closecombat","throatchop","tripleaxel"],"baseAbility":"beastboost","item":"choiceband","pokeball":"pokeball","ability":"beastboost"},{"ident":"p1: Nuzleaf","details":"Nuzleaf, M","condition":"281/281","active":false,"stats":{"atk":158,"def":178,"spa":156,"spd":196,"spe":158},"moves":["leechseed","defog","substitute","toxic"],"baseAbility":"pickpocket","item":"eviolite","pokeball":"pokeball","ability":"pickpocket"},{"ident":"p1: Porygon-Z","details":"Porygon-Z","condition":"311/311","active":false,"stats":{"atk":176,"def":176,"spa":369,"spd":187,"spe":306},"moves":["triattack","shadowball","trick","nastyplot"],"baseAbility":"adaptability","item":"choicespecs","pokeball":"pokeball","ability":"adaptability"}]},"noCancel":true,"rqid":4}
Traceback (most recent call last):
  File "E:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env\player\player_network_interface.py", line 179, in _handle_message
    await self._handle_battle_message(split_messages)
  File "E:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env\player\player.py", line 242, in _handle_battle_message
    await self._handle_battle_request(battle)
  File "E:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env\player\player.py", line 337, in _handle_battle_request
    message = self.choose_move(battle)
  File "E:\Dev\meta-discovery\agents\simple_agent.py", line 362, in choose_move
    state = self.embed_battle(battle)
  File "E:\Dev\meta-discovery\agents\simple_agent.py", line 168, in embed_battle
    battle.opponent_active_pokemon.type_1,
AttributeError: 'NoneType' object has no attribute 'type_1'
Task exception was never retrieved
future: <Task finished name='Task-1527931' coro=<PlayerNetwork._handle_message() done, defined at E:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env\player\player_network_interface.py:165> exception=AttributeError("'NoneType' object has no attribute 'type_1'")>
Traceback (most recent call last):
  File "E:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env\player\player_network_interface.py", line 230, in _handle_message
    raise exception
  File "E:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env\player\player_network_interface.py", line 179, in _handle_message
    await self._handle_battle_message(split_messages)
  File "E:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env\player\player.py", line 242, in _handle_battle_message
    await self._handle_battle_request(battle)
  File "E:\Dev\meta-discovery\torch_env\lib\site-packages\poke_env\player\player.py", line 337, in _handle_battle_request
    message = self.choose_move(battle)
  File "E:\Dev\meta-discovery\agents\simple_agent.py", line 362, in choose_move
    state = self.embed_battle(battle)
  File "E:\Dev\meta-discovery\agents\simple_agent.py", line 168, in embed_battle
    battle.opponent_active_pokemon.type_1,
AttributeError: 'NoneType' object has no attribute 'type_1'

akashsara avatar Sep 06 '22 00:09 akashsara