hsahovic / poke-env

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

Fix allyswitch on same turn as faint issue #442

Closed hsahovic closed 1 year ago

hsahovic commented 1 year ago

Fix https://github.com/hsahovic/poke-env/issues/437

We usually receive request messages before parsing the events of a turn. This leads to the status of pokemon being updated before actually receiving the corresponding individual messages. Because the _swap method that allyswitch messages call in battle objects checks whether a pokemon is fainted before switching their place, if a pokemon uses alyswitch before it or its partner faint later in the turn, we can erroneously not switch their place.

This PR adds a check in double message request parsing: if the faint status and species of mons do not match, we force-switch them.

Additionally, to make the check more robust to form changes, this PR adds a base_species property to Pokemon objects.

codecov[bot] commented 1 year ago

Codecov Report

Merging #442 (de7fc36) into master (f627cc2) will increase coverage by 0.09%. Report is 4 commits behind head on master. The diff coverage is 86.66%.

@@            Coverage Diff             @@
##           master     #442      +/-   ##
==========================================
+ Coverage   83.32%   83.41%   +0.09%     
==========================================
  Files          39       39              
  Lines        3946     3956      +10     
==========================================
+ Hits         3288     3300      +12     
+ Misses        658      656       -2