poke-env
poke-env copied to clipboard
Bug with battle.force_switch
So there's actually two bugs. The first is what I mentioned here. Specifically, in the scenario where battle.force_switch
is True and there are no Pokemon left on the bench, both battle.available_moves
and battle.available_switches
are empty.
I fixed this while defining a custom _action_to_move()
function but encountered a second bug. Specifically:
battle.won: None
battle.lost: False
battle.finished: False
battle.turn: 25
battle.force_switch: True
battle.team:
{
'p1: Latias': latias (pokemon object) [Active: False, Status: FNT],
'p1: Zoroark': zoroark (pokemon object) [Active: False, Status: FNT],
'p1: Nidoqueen': nidoqueen (pokemon object) [Active: False, Status: FNT],
'p1: Shiftry': shiftry (pokemon object) [Active: False, Status: FNT],
'p1: Kartana': kartana (pokemon object) [Active: True, Status: FNT],
'p1: Corsola': corsolagalar (pokemon object) [Active: False, Status: FNT]
}
battle.available_switches:
[]
battle.available_moves:
[]
So this is really weird because the battle should be over here. All 6 Pokemon on the user's side have fainted so the fact that we have no actions is correct, but we shouldn't be receiving this state at all right?
This might be related to #246
Another weird scenario:
> print(battle.won, battle.lost, battle.finished, battle.turn)
None False False 8
> print(battle.force_switch, force_switch, battle.trapped)
False False True
> print(battle.team)
{'p1: Scyther': scyther (pokemon object) [Active: False, Status: None],
'p1: Zoroark': zoroark (pokemon object) [Active: False, Status: None],
'p1: Hitmonchan': hitmonchan (pokemon object) [Active: False, Status: None],
'p1: Dialga': dialga (pokemon object) [Active: False, Status: FNT],
'p1: Wobbuffet': wobbuffet (pokemon object) [Active: False, Status: FNT],
'p1: Doublade': doublade (pokemon object) [Active: True, Status: None]}
> print(battle.available_switches)
[hitmonchan (pokemon object) [Active: False, Status: None], scyther (pokemon object) [Active: False, Status: None],
doublade (pokemon object) [Active: True, Status: None]]
> print(battle.available_moves)
[flamethrower (Move object), darkpulse (Move object), nastyplot (Move object), sludgebomb (Move object)]
> print(battle.active_pokemon.moves)
{'ironhead': ironhead (Move object), 'shadowsneak': shadowsneak (Move object),
'swordsdance': swordsdance (Move object), 'closecombat': closecombat (Move object)}
battle.available_moves
and battle.moves
have completely different values.
That's a good find. Do you have an idea of where the parsing goes wrong?
Unfortunately not. This was the only error that popped up while training and I haven't been able to reproduce it since then. I've had the other two scenarios I mentioned happen multiple times though. At the moment I'm just printing these different values whenever I encounter a scenario with no legal actions so I haven't been able to investigate further.
I have one potential idea for this problem's cause - I'll test it today. It's related to requests
message resulting in an action before some messages arriving at the same time have been parsed, and should be addressable by deferring the choice.
I experimented with my hypothesis - It was wrong. However, in doing so, I did identify the root cause of every example I looked at: Zoroark and illusion. poke-env
sometimes wrongly sets the pokemon that Zoroark was impersonating as fainted when it faints, and doesn't:
- Remove the fainted state when a request with contradictory information arrives
- Correctly interacts illusion related messages to status updates
There is a clear direction forward on both of these fronts. I'll take a crack at it over the weekend.