pmariglia / showdown

A Pokemon Showdown Battle Bot written in Python
GNU General Public License v3.0
254 stars 176 forks source link

KeyError: 'mewtwomegax' #3

Open fwqefwqef opened 5 years ago

fwqefwqef commented 5 years ago

The bot crashes during the game if the bot uses a team with 2 or more of the same pokemon, specifically when it brings out said pokemon. Obviously, this is not a problem in metagames like OU where there is a species clause, but it is a problem for other metas like Balanced Hackmons where there is no species restriction. Sadly, I do not have much experience with python so I am having trouble fixing the issue.. Replays: me vs the bot with 6 Mega-Mewtwo-X: https://replay.pokemonshowdown.com/gen7balancedhackmons-897012029 error: (sorry for the Won currency signs, it is supposed to be \ but Korean Language)

keyerror mmx

me vs the bot with 2 Mega-Mewtwo-X: https://replay.pokemonshowdown.com/gen7balancedhackmons-897009410 (error is identical: everything seemed to be running fine until the Keyerror made the bot crash)

me vs the bot with no duplicate pokemon (Replaced Mega-Mewtwo-X with Mega-Mewtwo-Y): https://replay.pokemonshowdown.com/gen7balancedhackmons-896857312 As you can see, the bot does not crash and battles until the end as expected.

pmariglia commented 5 years ago

Hey, thanks for bringing this up.

I actually had this come up during development - I was just mostly testing the other metagames and ignored it (bad choice).

This happens because of a poor design choice I made early on. Each side has an attribute called reserve which is a Python dictionary. The keys for this dictionary are the Pokemon names and, as you can imagine, this does not allow for Pokemon with duplicate names to exist. The KeyError itself is a by-product that occurs when trying to find the transposition for switching twice in a row.

I will fix this - I'll just need to investigate the best way to go about refactoring the representation of the reserve pokemon.

fwqefwqef commented 4 years ago

Hello, is this bug fixed yet? I made my own version way back to address this issue but it's not updated for gen8 so I was wondering if I needed to make changes again if I install the latest version.

fwqefwqef commented 4 years ago

image I guess not? ahaha

pmariglia commented 4 years ago

Ahh sorry about that, I started to look into this and realized it was far more work than I had originally thought. There's a lot of code in the engine built around the assumption that there can only be one of each Pokmon on each team.

I still have this on a to-do list of mine, it has just dropped in priority and I'm not sure when it will (if ever) be addressed.

ghost commented 3 years ago

can't you give the pokemon ids? like example (megamewtwo0, megamewtwo1, rotom0, regigas0, suntfisk0, mantine0). When needed it can remove the id and use it so it will avoid it.