Fix doubles switch AI to use new type matchup system (#7495)

This commit is contained in:
Pawkkie 2025-08-06 11:20:03 -04:00 committed by GitHub
parent e8b6d40f18
commit 3f9359765c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 18 deletions

View File

@ -1444,33 +1444,18 @@ static u32 GetBestMonBatonPass(struct Pokemon *party, int firstId, int lastId, u
static u32 GetBestMonTypeMatchup(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, u32 battler, u32 opposingBattler)
{
int i, bits = 0;
while (bits != 0x3F) // All mons were checked.
{
uq4_12_t bestResist = UQ_4_12(1.0);
u32 bestResist = UQ_4_12(2.0);
int bestMonId = PARTY_SIZE;
// Find the mon whose type is the most suitable defensively.
for (i = firstId; i < lastId; i++)
{
if (!((1u << i) & invalidMons) && !((1u << i) & bits))
{
u16 species = GetMonData(&party[i], MON_DATA_SPECIES);
uq4_12_t typeEffectiveness = UQ_4_12(1.0);
InitializeSwitchinCandidate(&party[i]);
u8 atkType1 = gBattleMons[opposingBattler].types[0];
u8 atkType2 = gBattleMons[opposingBattler].types[1];
u8 defType1 = GetSpeciesType(species, 0);
u8 defType2 = GetSpeciesType(species, 1);
typeEffectiveness = uq4_12_multiply(typeEffectiveness, (GetTypeModifier(atkType1, defType1)));
if (atkType2 != atkType1)
typeEffectiveness = uq4_12_multiply(typeEffectiveness, (GetTypeModifier(atkType2, defType1)));
if (defType2 != defType1)
{
typeEffectiveness = uq4_12_multiply(typeEffectiveness, (GetTypeModifier(atkType1, defType2)));
if (atkType2 != atkType1)
typeEffectiveness = uq4_12_multiply(typeEffectiveness, (GetTypeModifier(atkType2, defType2)));
}
u32 typeEffectiveness = GetBattleMonTypeMatchup(gBattleMons[opposingBattler], gAiLogicData->switchinCandidate.battleMon);
if (typeEffectiveness < bestResist)
{
bestResist = typeEffectiveness;

View File

@ -1316,6 +1316,21 @@ AI_SINGLE_BATTLE_TEST("AI_FLAG_SMART_MON_CHOICES: AI will properly consider immu
}
}
AI_DOUBLE_BATTLE_TEST("AI_FLAG_SMART_MON_CHOICES: AI will properly consider immunities when determining switchin type matchup (Doubles)")
{
GIVEN {
AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SMART_MON_CHOICES | AI_FLAG_OMNISCIENT);
PLAYER(SPECIES_POLIWRATH) { Moves(MOVE_WATER_GUN, MOVE_KARATE_CHOP); }
PLAYER(SPECIES_ZIGZAGOON) { Moves(MOVE_CELEBRATE); }
OPPONENT(SPECIES_ZIGZAGOON) { Level(1); Moves(MOVE_CELEBRATE); }
OPPONENT(SPECIES_ZIGZAGOON) { Level(1); Moves(MOVE_CELEBRATE); }
OPPONENT(SPECIES_CERULEDGE) { Moves(MOVE_SPARK); }
OPPONENT(SPECIES_WHIMSICOTT) { Moves(MOVE_MEGA_DRAIN); }
} WHEN {
TURN { MOVE(playerLeft, MOVE_KARATE_CHOP, target:opponentLeft); MOVE(playerRight, MOVE_CELEBRATE); EXPECT_MOVE(opponentLeft, MOVE_CELEBRATE); EXPECT_MOVE(opponentRight, MOVE_CELEBRATE); EXPECT_SEND_OUT(opponentLeft, 3); }
}
}
AI_SINGLE_BATTLE_TEST("AI_FLAG_SMART_SWITCHING: AI won't switch out due to bad odds if it can OHKO with a priority move")
{
PASSES_RANDOMLY(100, 100, RNG_AI_SWITCH_HASBADODDS);