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

Switch AI refactor + considers free switches #5379

Merged
merged 12 commits into from
Oct 1, 2024

Conversation

Pawkkie
Copy link
Collaborator

@Pawkkie Pawkkie commented Sep 12, 2024

Description

This started as a solution to #5220, and expanded in scope once I realized that the best place to handle this was in GetBestMonIntegrated, which has been in need of a refactor as different pieces of it have evolved to be handled in different ways (ie. Trapping was handled smarter / cleaner than the rest of the function because I'd spent like an extra year working on the project).

The refactor largely moves a lot of conditionals into a few new helper functions, and bases many decisions on the new CanSwitchinWin1v1 rather than having large stacking conditions with various pieces being considered or missing. DoesSwitchinMoveFirst is a similar helper function that just increases readability. The second one in particular was already kicked around as a follow-up to the Trapper PR and I thought this was a good time to do it.

Lastly the totally new content that address #5220, the Smart Mon Choices flag will now consider switches as "free switches" or not using IsFreeSwitch. This means it's no longer tied to just mid-battle vs post-KO switching, and can detect whether the AI has a free switch from an effect like a slow U-Turn or an Eject Button and switch offensively in these scenarios rather than defensively.

Overall the PR should allow the AI to be more aggressive with switching when it makes sense to do so, and this function should be much easier to work with going forward.

EDIT: There are also tests for the new free switches, and several related tests were cleaned up a bit to ensure consistency for the AI's scenario.

Issue(s) that this PR fixes

#5220

Discord contact info

@Pawkkie

@Pawkkie Pawkkie added category: battle-ai Pertains to Battle Engine Upgrade's AI type: refactor new-feature Adds a feature labels Sep 12, 2024
@Pawkkie Pawkkie changed the title Switch AI refactor + considers free switches from pivot move Switch AI refactor + considers free switches Sep 12, 2024
include/battle.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@AlexOn1ine AlexOn1ine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a neat solution

src/battle_ai_switch_items.c Outdated Show resolved Hide resolved
src/battle_ai_switch_items.c Outdated Show resolved Hide resolved
@AlexOn1ine AlexOn1ine self-assigned this Sep 14, 2024
@Pawkkie
Copy link
Collaborator Author

Pawkkie commented Sep 14, 2024

I can't find this on GH for some reason, and if you deleted it cuz you answered your own question, no worries! But my email has

I wonder if using GetBattlerTurnOrderNum in AI calcs is safe. I know it can have values from a previous turn so that might mess up calcs

And I don't know the answer to this question. This was just the best approach I could find for determining which mon moved first, if you're aware of an alternative I'm all ears :)

@AlexOn1ine
Copy link
Collaborator

I can't find this on GH for some reason, and if you deleted it cuz you answered your own question, no worries! But my email has

I wonder if using GetBattlerTurnOrderNum in AI calcs is safe. I know it can have values from a previous turn so that might mess up calcs

And I don't know the answer to this question. This was just the best approach I could find for determining which mon moved first, if you're aware of an alternative I'm all ears :)

I deleted it because I realized that in this case it is a good solution 😅

@Pawkkie
Copy link
Collaborator Author

Pawkkie commented Sep 14, 2024

I deleted it because I realized that in this case it is a good solution 😅

Okay awesome, I did not mean to call you out on that I just wasn't confident about it myself lmao

@Pawkkie
Copy link
Collaborator Author

Pawkkie commented Sep 28, 2024

Now back from honeymoon, moved the new parameters to AiLogicData as requested and ready for re-review :)

@Pawkkie Pawkkie requested a review from AlexOn1ine September 28, 2024 16:31
Copy link
Collaborator

@AlexOn1ine AlexOn1ine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicts but generally a lot of good clean up.

@Pawkkie
Copy link
Collaborator Author

Pawkkie commented Oct 1, 2024

Done making changes this should be good to go :)

@AlexOn1ine AlexOn1ine merged commit ded97e5 into rh-hideout:upcoming Oct 1, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: battle-ai Pertains to Battle Engine Upgrade's AI new-feature Adds a feature type: refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants