From 7cd614a0cd2019d913f78bd83467ce8bd7d0d268 Mon Sep 17 00:00:00 2001 From: moostoet <70690976+moostoet@users.noreply.github.com> Date: Sat, 15 Feb 2025 22:48:26 +0100 Subject: [PATCH] Fix AI wrongly thinking it strikes first with priority even if player is using priority themselves (#6274) --- src/battle_ai_util.c | 9 ++++++++- test/battle/ai/ai.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index e440091183..b765616802 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -1094,8 +1094,15 @@ s32 AI_WhoStrikesFirst(u32 battlerAI, u32 battler, u32 moveConsidered) u32 abilityAI = AI_DATA->abilities[battlerAI]; u32 abilityPlayer = AI_DATA->abilities[battler]; - if (GetMovePriority(battlerAI, moveConsidered) > 0) + u32 predictedMove = AI_DATA->lastUsedMove[battler]; // TODO update for move prediction + + s8 aiPriority = GetMovePriority(battlerAI, moveConsidered); + s8 playerPriority = GetMovePriority(battler, predictedMove); + + if (aiPriority > playerPriority) return AI_IS_FASTER; + else if (aiPriority < playerPriority) + return AI_IS_SLOWER; speedBattlerAI = GetBattlerTotalSpeedStatArgs(battlerAI, abilityAI, holdEffectAI); speedBattler = GetBattlerTotalSpeedStatArgs(battler, abilityPlayer, holdEffectPlayer); diff --git a/test/battle/ai/ai.c b/test/battle/ai/ai.c index 0883e3cc59..5f01c761a6 100644 --- a/test/battle/ai/ai.c +++ b/test/battle/ai/ai.c @@ -831,3 +831,17 @@ AI_SINGLE_BATTLE_TEST("AI stays choice locked into moves in spite of the player' TURN { EXPECT_MOVE(opponent, aiMove); } } } + +AI_SINGLE_BATTLE_TEST("AI won't use Sucker Punch if it expects a move of the same priority bracket and the opponent is faster") +{ + GIVEN { + ASSUME(gMovesInfo[MOVE_QUICK_ATTACK].priority == 1); + ASSUME(gMovesInfo[MOVE_SUCKER_PUNCH].priority == 1); + AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT); + PLAYER(SPECIES_WOBBUFFET) { Speed(300); Moves(MOVE_QUICK_ATTACK); } + OPPONENT(SPECIES_WOBBUFFET) { Speed(100); Moves(MOVE_SUCKER_PUNCH, MOVE_TACKLE); } + } WHEN { + TURN { MOVE(player, MOVE_QUICK_ATTACK); EXPECT_MOVE(opponent, MOVE_SUCKER_PUNCH); } + TURN { MOVE(player, MOVE_QUICK_ATTACK); EXPECT_MOVE(opponent, MOVE_TACKLE); } + } +}