hsahovic / poke-env

A python interface for training Reinforcement Learning bots to battle on pokemon showdown
https://poke-env.readthedocs.io/
MIT License
292 stars 98 forks source link

Consider the Reflect move #135

Closed Icemole closed 3 years ago

Icemole commented 3 years ago

Hey, I was implementing a gen 1 bot and I noticed that the program crashes when Reflect is used. I know gen 1 is not supported, but according to Bulbapedia, the move can also be seen on generations other than the first one. Maybe it was missed due to it not appearing on many games, but it's crashing at least once every ten battles in my training.

Here is the specific error:

Traceback (most recent call last):
  File "/proj/env/lib/python3.6/site-packages/poke_env/player/player.py", line 298, in _handle_battle_message
    battle._parse_message(split_message)
  File "/proj/env/lib/python3.6/site-packages/poke_env/environment/abstract_battle.py", line 269, in _parse_message
    pokemon._start_effect(effect)
  File "/proj/env/lib/python3.6/site-packages/poke_env/environment/pokemon.py", line 271, in _start_effect
    effect = Effect.from_showdown_message(effect)
  File "/proj/env/lib/python3.6/site-packages/poke_env/environment/effect.py", line 191, in from_showdown_message
    raise UnexpectedEffectException("Unexpected effect '%s' received" % message)
poke_env.exceptions.UnexpectedEffectException: Unexpected effect 'Reflect' received
 3229/10000 [========>.....................] - ETA: 4:21 - reward: 1.83822021-03-25 17:54:03,896 - SimpleRLPlayer 1 - ERROR - Unexpected effect 'Reflect' received
Traceback (most recent call last):
  File "/proj/env/lib/python3.6/site-packages/poke_env/environment/effect.py", line 189, in from_showdown_message
    return Effect[message.upper()]
  File "/home/icemole/.pyenv/versions/3.6.7/lib/python3.6/enum.py", line 329, in __getitem__
    return cls._member_map_[name]
KeyError: 'REFLECT'

It's not a priority for me since the program handles quite well these types of exceptions, but I think it's something to be considered.

hsahovic commented 3 years ago

Hi @Icemole,

Thanks for opening this issue. REFLECT is creating this problem because it's treated differently by showdown in gen1. I'll push a fix later today.

Apart from this, did you experience other problems with gen 1?

Icemole commented 3 years ago

Thanks for the quick reply! No, I haven't noticed any other issues. I will let you know if I find something else though :)

hsahovic commented 3 years ago

This should be fixed in this commit, and the corresponding poke-env release (version 0.4.9).

Upgrading via pip (or pulling master) should fix your current issue. Don't hesitate to open a new one if you find other problems! I've never spent time on testing gen 1 compatibility, so I'd love some feedback on how things go with your project :)