Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how AI chooses damaging moves #3199

Merged
merged 8 commits into from
Oct 1, 2023

Conversation

DizzyEggg
Copy link
Collaborator

Fixes #3130
Fixes #3153

The general flow should be like this(assuming there are no special effects which would otherwise be more preferable):
if can faint -> choose the move without side effects(e.g. recoil, recharge, loading turn), and with better accuracy(e.g. Tackle over Mega Punch if both are 1hko)
if can't faint -> choose the move which takes the least no of hits to KO, but only if the other move doesn't have any advantages(otherwise it's a toss-up and depends on the battle conditions).

Also fixed Taunt's score to be minus 10 and improved handling of Solar Beam.

Before:
pokeemerald_01

254561947-0587a7ef-6651-4172-ba75-3bda57df9eeb

After:
pokeemerald_06

pokeemerald_08

@AlexOn1ine
Copy link
Collaborator

AlexOn1ine commented Aug 3, 2023

What do you think about removing this switch block?

        switch (AI_DATA->effectiveness[battlerAtk][battlerDef][AI_THINKING_STRUCT->movesetIndex])
        {
        case AI_EFFECTIVENESS_x8:
            score += 8;
            break;
        case AI_EFFECTIVENESS_x4:
            score += 4;
            break;
        case AI_EFFECTIVENESS_x2:
            if (AI_RandLessThan(176))
                score += 2;
            else
                score++;
            break;
        }

Your PR takes care of a lot of edge cases and this block looks unnecessary with it. You would just get score increases for the sake of increasing it.

Also how valuable are these checks?

        if (gBattleMoves[move].highCritRatio)
            score += 2; // crit makes it more likely to make them faint
    if (!WillAIStrikeFirst() && CanTargetFaintAi(battlerDef, battlerAtk))
    { // AI_TryToFaint_Danger
        if (GetMoveDamageResult(move) != MOVE_POWER_BEST)
            score--;
        else
            score++;
    }

Since you made the AI pick the best damaging move in AI_CheckViability,it seems redundant to check again in AI_TryToFaint

    if (gBattleMoves[move].power)
        score += AI_CompareDamagingMoves(battlerAtk, battlerDef, AI_THINKING_STRUCT->movesetIndex);

/Edit: resolved in discord

@AlexOn1ine
Copy link
Collaborator

AlexOn1ine commented Aug 28, 2023

I did some testing and my suggestion generally would be to only decrease the score when compared to a better move.
The problem with increases is that it inflates the score since each move is compared against each other which might render status moves unusable.
Let's say we have the base

Good move, score 100
Bad Move, score 100
Bad Move, score 100
Bad Move, score 100

If the comparison from this PR are applied it ends up like this

Good move, score 103
Bad Move, score 99
Bad Move, score 99
Bad Move, score 99

My suggestion would be to decrease the bad moves only

Good move, score 100
Bad Move, score 99 
Bad Move, score 99
Bad Move, score 99

Same result but you don't inflate the score

The problem gets worse if there are 2 different bad moves present, like a less accurate move and a recoil move.

/Edit: I just noticed the decreases are somewhat inconsistent in the PR. Sometimes it increases and decreases, sometimes it only increases. Like I said my suggestion would be to only decrease but regardless I would make it consistent across the board.

@DizzyEggg DizzyEggg mentioned this pull request Sep 18, 2023
@DizzyEggg
Copy link
Collaborator Author

Despite the issue you Alex mentioned I still think this PR does more good than evil. Would it be fine to merge it to upcoming and then improve it? The thing is even if it's not perfect with this PR, it is still worse without it. Also, I hope to have AI tests soon, so it'll be easier to catch these issues.

@DizzyEggg
Copy link
Collaborator Author

@AsparagusEduardo Should be ready to merge.

include/config/debug.h Outdated Show resolved Hide resolved
src/battle_ai_main.c Show resolved Hide resolved
src/battle_ai_main.c Outdated Show resolved Hide resolved
src/battle_ai_main.c Outdated Show resolved Hide resolved
DizzyEggg and others added 3 commits October 1, 2023 19:11
Co-authored-by: Eduardo Quezada D'Ottone <[email protected]>
Co-authored-by: Eduardo Quezada D'Ottone <[email protected]>
@AsparagusEduardo AsparagusEduardo merged commit c69d8e0 into rh-hideout:upcoming Oct 1, 2023
1 check passed
wiz1989 pushed a commit to wiz1989/pokeemerald-expansion-master that referenced this pull request Jan 29, 2024
wiz1989 added a commit to wiz1989/pokeemerald-expansion-master that referenced this pull request Jan 29, 2024
@DizzyEggg DizzyEggg deleted the ai_fixes branch June 23, 2024 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants