Skip to content

Commit

Permalink
Fix Focus Punch scoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawkkie committed Jan 15, 2025
1 parent 8cce92e commit 7ed9666
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1321,11 +1321,11 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
// AI_CBM_HighRiskForDamage
if (aiData->abilities[battlerDef] == ABILITY_WONDER_GUARD && effectiveness < AI_EFFECTIVENESS_x2)
ADJUST_SCORE(-10);
if (HasDamagingMove(battlerDef) && !((gBattleMons[battlerAtk].status2 & STATUS2_SUBSTITUTE)
else if (HasDamagingMove(battlerDef) && !((gBattleMons[battlerAtk].status2 & STATUS2_SUBSTITUTE)
|| IsBattlerIncapacitated(battlerDef, aiData->abilities[battlerDef])
|| gBattleMons[battlerDef].status2 & (STATUS2_INFATUATION | STATUS2_CONFUSION)))
ADJUST_SCORE(-10);
if (HasMoveEffect(battlerAtk, EFFECT_SUBSTITUTE) && !(gBattleMons[battlerAtk].status2 & STATUS2_SUBSTITUTE))
else if (HasMoveEffect(battlerAtk, EFFECT_SUBSTITUTE) && !(gBattleMons[battlerAtk].status2 & STATUS2_SUBSTITUTE))
ADJUST_SCORE(-10);
break;
case EFFECT_COUNTER:
Expand Down Expand Up @@ -5280,6 +5280,8 @@ static s32 AI_PredictSwitch(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)

case EFFECT_FOCUS_PUNCH:
ADJUST_SCORE(DECENT_EFFECT);
if (AI_THINKING_STRUCT->aiFlags[battlerAtk] & AI_FLAG_CHECK_BAD_MOVE)
ADJUST_SCORE(10);
break;

// Free setup (U-Turn etc. handled in Check Viability by ShouldPivot)
Expand Down
19 changes: 8 additions & 11 deletions test/battle/ai/ai_flag_predict_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,23 @@ AI_SINGLE_BATTLE_TEST("AI_FLAG_PREDICT_SWITCH: AI can use Focus Punch on predict
PASSES_RANDOMLY(5, 10, RNG_AI_PREDICT_SWITCH);
GIVEN {
AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_CHECK_VIABILITY | AI_FLAG_OMNISCIENT | AI_FLAG_SMART_SWITCHING | AI_FLAG_SMART_MON_CHOICES | AI_FLAG_PREDICT_SWITCH);
PLAYER(SPECIES_CACNEA) { Moves(MOVE_ABSORB); }
PLAYER(SPECIES_DUGTRIO) { Ability(ABILITY_ARENA_TRAP); Moves(MOVE_ACROBATICS); }
OPPONENT(SPECIES_BRELOOM) { Moves(MOVE_FOCUS_PUNCH, MOVE_TACKLE); }
OPPONENT(SPECIES_BRELOOM);
PLAYER(SPECIES_BRONZONG) { Moves(MOVE_PSYCHIC); }
PLAYER(SPECIES_CONKELDURR) { Moves(MOVE_HAMMER_ARM); }
OPPONENT(SPECIES_TYRANITAR) { Moves(MOVE_FOCUS_PUNCH, MOVE_BRICK_BREAK); }
} WHEN {
TURN { SWITCH(player, 1); EXPECT_MOVE(opponent, MOVE_FOCUS_PUNCH); SEND_OUT(player, 0); }
TURN { MOVE(player, MOVE_ABSORB); EXPECT_MOVE(opponent, MOVE_TACKLE); }
TURN { SWITCH(player, 1); EXPECT_MOVE(opponent, MOVE_FOCUS_PUNCH); }
}
}

AI_SINGLE_BATTLE_TEST("AI_FLAG_PREDICT_SWITCH: AI would switch out in Focus Punch scenario")
{
GIVEN {
AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_CHECK_VIABILITY | AI_FLAG_OMNISCIENT | AI_FLAG_SMART_SWITCHING | AI_FLAG_SMART_MON_CHOICES);
PLAYER(SPECIES_BRELOOM) { Moves(MOVE_FOCUS_PUNCH, MOVE_TACKLE); }
PLAYER(SPECIES_BRELOOM);
OPPONENT(SPECIES_CACNEA) { Moves(MOVE_ABSORB); }
OPPONENT(SPECIES_DUGTRIO) { Ability(ABILITY_ARENA_TRAP); Moves(MOVE_ACROBATICS); }
PLAYER(SPECIES_TYRANITAR) { Moves(MOVE_FOCUS_PUNCH, MOVE_BRICK_BREAK); }
OPPONENT(SPECIES_BRONZONG) { Moves(MOVE_PSYCHIC); }
OPPONENT(SPECIES_CONKELDURR) { Moves(MOVE_HAMMER_ARM); }
} WHEN {
TURN { MOVE(player, MOVE_TACKLE); EXPECT_SWITCH(opponent, 1); }
TURN { EXPECT_SWITCH(opponent, 1); MOVE(player, MOVE_FOCUS_PUNCH); }
}
}

Expand Down

0 comments on commit 7ed9666

Please sign in to comment.