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

Teampreview doesn't trigger #587

Closed caymansimpson closed 2 months ago

caymansimpson commented 3 months ago

I have a simple case where I start a battle with two RandomPlayers for a VGC or Doubles format. I don't get a teampreview request from the showdown server, and so I never trigger teampreview. As you can see, I do get a teampreview split_message, which then calls _handle_battle_request with from_teampreview_request=True, but because I never get a teampreview request, I never trigger player.teampreview because I don't get the chance to set the battle._teampreview flag to be True.

However, poke-env doesn't fail because choose_move ends up returning default, which allows the battle to continue.

Upon further investigation, I do get a teampreview request, but I get it too late, so I never trigger player.teampreview; this is not deterministically reproducible

Code to reproduce:

    p1 = Player(
        AccountConfiguration("elitefurretai", None),
        battle_format="gen9vgc2024regg",
        team=team_str1,
    )
    p2 = Player(battle_format="gen9vgc2024regg", team=team_str2)
    await p1.battle_against(p2)

Printout:

in player._handle_battle_message (print split_messages)

[['>battle-gen9vgc2024regg-4567'], ['', 'init', 'battle'], ['', 'title', 'elitefurretai vs. CustomPlayer 1'], ['', 'j', '☆elitefurretai'], ['', 'j', '☆CustomPlayer 1'], ['', 't:', '1723324577'], ['', 'gametype', 'doubles'], ['', 'player', 'p1', 'elitefurretai', '170', ''], ['', 'player', 'p2', 'CustomPlayer 1', '265', ''], ['', 'teamsize', 'p1', '4'], ['', 'teamsize', 'p2', '4'], ['', 'gen', '9'], ['', 'tier', '[Gen 9] VGC 2024 Reg G'], ['', 'rule', 'Species Clause: Limit one of each Pokémon'], ['', 'rule', 'Item Clause: Limit one of each item'], ['', 'clearpoke'], ['', 'poke', 'p1', 'Wo-Chien, L50', ''], ['', 'poke', 'p1', 'Tyranitar, L50, F', ''], ['', 'poke', 'p1', 'Smeargle, L50, F', ''], ['', 'poke', 'p1', 'Raichu, L50, F', ''], ['', 'poke', 'p2', 'Rillaboom, L50, F', ''], ['', 'poke', 'p2', 'Pelipper, L50, M', ''], ['', 'poke', 'p2', 'Smeargle, L50, F', ''], ['', 'poke', 'p2', 'Cresselia, L50, F', ''], ['', 'teampreview', '4'], ['', 'uhtml', 'otsrequest', '<button name="send" value="/acceptopenteamsheets" class="button" style="margin-right: 10px;"><strong>Accept Open Team Sheets</strong></button><button name="send" value="/rejectopenteamsheets" class="button" style="margin-top: 10px"><strong>Deny Open Team Sheets</strong></button>'], ['', 'l', '☆CustomPlayer 1'], ['', 'player', 'p2', ''], ['', 'j', '☆CustomPlayer 1'], ['', 'player', 'p2', 'CustomPlayer 1', '265', ''], ['', 'j', '☆elitefurretai'], ['', 'player', 'p1', 'elitefurretai', '170', ''], ['', 'j', '☆CustomPlayer 1'], ['', 'player', 'p2', 'CustomPlayer 1', '265', ''], ['', 'l', '☆elitefurretai'], ['', 'player', 'p1', ''], ['', ''], ['', 't:', '1723326073'], ['', 'start'], ['', 'uhtmlchange', 'otsrequest', ''], ['', 'switch', 'p1a: Wo-Chien', 'Wo-Chien, L50', '160/160'], ['', 'switch', 'p1b: Tyranitar', 'Tyranitar, L50, F', '175/175'], ['', 'switch', 'p2a: Rillaboom', 'Rillaboom, L50, F', '100/100'], ['', 'switch', 'p2b: Pelipper', 'Pelipper, L50, M', '100/100'], ['', '-fieldstart', 'move: Grassy Terrain', '[from] ability: Grassy Surge', '[of] p2a: Rillaboom'], ['', '-enditem', 'p2a: Rillaboom', 'Grassy Seed'], ['', '-boost', 'p2a: Rillaboom', 'def', '1', '[from] item: Grassy Seed'], ['', '-weather', 'Sandstorm', '[from] ability: Sand Stream', '[of] p1b: Tyranitar'], ['', '-weather', 'RainDance', '[from] ability: Drizzle', '[of] p2b: Pelipper'], ['', '-ability', 'p1a: Wo-Chien', 'Tablets of Ruin'], ['', 'turn', '1'], ['', 'l', '☆CustomPlayer 1'], ['', 'player', 'p2', ''], ['', 'j', '☆elitefurretai'], ['', 'player', 'p1', 'elitefurretai', '170', ''], ['', 'l', '☆elitefurretai'], ['', 'player', 'p1', ''], ['', 'j', '☆CustomPlayer 1'], ['', 'player', 'p2', 'CustomPlayer 1', '265', ''], ['', 'j', '☆elitefurretai'], ['', 'player', 'p1', 'elitefurretai', '170', ''], ['']]

caymansimpson commented 2 months ago

Edit: I found this error solves itself when I restart Showdown. But if I break Showdown w/ an Exception and restart a battle with the same players, this error starts occurring again. Feel free to resolve?