Add function to adjust AI scoring for generalized item effects (#6247)

This commit is contained in:
moostoet 2025-02-13 18:51:25 +01:00 committed by GitHub
parent 9c4fbbf274
commit a42de40eb2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 1 deletions

View File

@ -35,7 +35,7 @@ typedef s32 (*AiScoreFunc)(u32, u32, u32, s32);
#define POWERFUL_STATUS_MOVE 10 // Moves with this score will be chosen over a move that faints target
#define NO_DAMAGE_OR_FAILS -20 // Move fails or does no damage
// Scores given in AI_CalcMoveEffectScore
// Scores given in AI_CalcMoveEffectScore and AI_CalcHoldEffectMoveScore
#define NO_INCREASE 0
#define WEAK_EFFECT 1
#define DECENT_EFFECT 2

View File

@ -43,6 +43,9 @@
#define SHOULD_SWITCH_REGENERATOR_PERCENTAGE 50
#define SHOULD_SWITCH_REGENERATOR_STATS_RAISED_PERCENTAGE 20
// AI held item-based move scoring
#define BLUNDER_POLICY_ACCURACY_THRESHOLD 75 // Moves with accuracy equal below this value are prioritized when holding Blunder Policy
// AI prediction chances
#define PREDICT_SWITCH_CHANCE 50

View File

@ -3295,6 +3295,34 @@ static s32 AI_CompareDamagingMoves(u32 battlerAtk, u32 battlerDef, u32 currId)
return score;
}
static u32 AI_CalcHoldEffectMoveScore(u32 battlerAtk, u32 battlerDef, u32 move)
{
struct AiLogicData *aiData = AI_DATA;
u32 holdEffect = aiData->holdEffects[battlerAtk];
s32 score = 0;
switch (holdEffect)
{
case HOLD_EFFECT_BLUNDER_POLICY:
{
u32 moveAcc = aiData->moveAccuracy[battlerAtk][battlerDef][AI_THINKING_STRUCT->movesetIndex];
if (moveAcc <= BLUNDER_POLICY_ACCURACY_THRESHOLD)
{
ADJUST_SCORE(GOOD_EFFECT);
}
else
{
ADJUST_SCORE(-DECENT_EFFECT);
}
}
break;
}
return score;
}
static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
{
// move data
@ -4831,6 +4859,7 @@ static s32 AI_CheckViability(u32 battlerAtk, u32 battlerDef, u32 move, s32 score
}
ADJUST_SCORE(AI_CalcMoveEffectScore(battlerAtk, battlerDef, move));
ADJUST_SCORE(AI_CalcHoldEffectMoveScore(battlerAtk, battlerDef, move));
return score;
}