rh-hideout/pokeemerald-expansion

Better Shed Tail Switch AI Handling

Opened this issue · 0 comments

Description

#5494 KNOWN_FAILING'd a broken test that was broken by #5488. The test is very straightforward:

AI_SINGLE_BATTLE_TEST("AI will use Shed Tail to pivot to another mon while in damage stalemate with player")
{
    KNOWN_FAILING; // missing AI code
    GIVEN {
        AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT);
        PLAYER(SPECIES_WOBBUFFET) { Speed(100); Ability(ABILITY_RUN_AWAY); Moves(MOVE_TACKLE, MOVE_CELEBRATE); }
        OPPONENT(SPECIES_WOBBUFFET) { Speed(50); Ability(ABILITY_RUN_AWAY); Moves(MOVE_CONFUSION, MOVE_SHED_TAIL); }
        OPPONENT(SPECIES_SCIZOR) { Speed(101); Moves(MOVE_CELEBRATE, MOVE_X_SCISSOR); }
    } WHEN {
        TURN { MOVE(player, MOVE_TACKLE); EXPECT_MOVE(opponent, MOVE_CONFUSION); }
        TURN { MOVE(player, MOVE_TACKLE); EXPECT_MOVE(opponent, MOVE_SHED_TAIL); }
    }
}

The reason it fails is because the AI mon switches out instead of using Shed Tail. This test should have been failing since its inception, because FindMonWithFlagsAndSuperEffective finds Scizor in the party and triggers a switch to it. FindMonWithFlagsAndSuperEffective depends on gLastLandedMoves to function properly, which wasn't working properly for any switching behaviour until #5488 fixed it.

The ideal solution to this would be to implement "Don't switch if you're going to use Shed Tail", but that requires running the move scoring functions before ShouldSwitch, which is awkward because we need to run ShouldSwitch to use its result in the move scoring. It's also a pile of duplicate code and also feels kinda gross to just score everything tagged with IsSwitchOutEffect in ShouldSwitch because the scoring code is expensive, we really don't want to duplicate it.

I'm not entirely sure what the best implementation to solve this problem is, but I wanted to clarify that it existed in some detail as I'm not sure when it'll get addressed.

Discord contact info

@Pawkkie