From b084dcd8d3e8ae1653de2a4d52420e2c181d8697 Mon Sep 17 00:00:00 2001 From: Pawkkie <61265402+Pawkkie@users.noreply.github.com> Date: Sun, 14 Jul 2024 16:00:51 -0400 Subject: [PATCH] Fix Upper Hand being used blindly (#4973) --- src/battle_ai_main.c | 2 +- test/battle/move_effect/upper_hand.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index b890493c3aaa..d9055162341b 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -2644,7 +2644,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score) ADJUST_SCORE(-10); break; case EFFECT_UPPER_HAND: - if (predictedMove == MOVE_NONE || IS_MOVE_STATUS(predictedMove) || AI_WhoStrikesFirst(battlerAtk, battlerDef, move) == AI_IS_SLOWER || GetMovePriority(battlerDef, move) < 1 || GetMovePriority(battlerDef, move) > 3) // Opponent going first or not using priority move + if (predictedMove == MOVE_NONE || IS_MOVE_STATUS(predictedMove) || AI_WhoStrikesFirst(battlerAtk, battlerDef, move) == AI_IS_SLOWER || GetMovePriority(battlerDef, predictedMove) < 1 || GetMovePriority(battlerDef, predictedMove) > 3) // Opponent going first or not using priority move ADJUST_SCORE(-10); break; case EFFECT_PLACEHOLDER: diff --git a/test/battle/move_effect/upper_hand.c b/test/battle/move_effect/upper_hand.c index 04f2b8522565..6a041182fe5f 100644 --- a/test/battle/move_effect/upper_hand.c +++ b/test/battle/move_effect/upper_hand.c @@ -116,3 +116,19 @@ SINGLE_BATTLE_TEST("Upper Hand is boosted by Sheer Force") HP_BAR(player); } } + +AI_SINGLE_BATTLE_TEST("AI won't use Upper Hand unless it has seen a priority move") +{ + u16 move; + PARAMETRIZE { move = MOVE_TACKLE; } + PARAMETRIZE { move = MOVE_QUICK_ATTACK; } + GIVEN { + AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT); + ASSUME(gMovesInfo[MOVE_QUICK_ATTACK].priority == 1); + PLAYER(SPECIES_WOBBUFFET) {Moves(move); } + OPPONENT(SPECIES_WOBBUFFET) { Moves(MOVE_UPPER_HAND, MOVE_KARATE_CHOP); } + } WHEN { + TURN { MOVE(player, move); EXPECT_MOVE(opponent, MOVE_KARATE_CHOP); } + TURN { MOVE(player, move); EXPECT_MOVE(opponent, move == MOVE_QUICK_ATTACK ? MOVE_UPPER_HAND : MOVE_KARATE_CHOP); } + } +}