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 uses trapping abilities aggressively #4669

Merged
merged 4 commits into from
Jun 1, 2024

Conversation

Pawkkie
Copy link
Collaborator

@Pawkkie Pawkkie commented May 30, 2024

Description

Encourages the AI to use the trapping abilities Shadow Tag, Arena Trap, and Magnet Pull in its switching decisions. Post-KO trapping switches are tied to the AI_FLAG_SMART_MON_CHOICES, and mid-battle trapping switches are tied to AI_FLAG_SMART_SWITCHING (which requires AI_FLAG_SMART_MON_CHOICES anyways).

The AI will switch in a trapper under the following conditions:

  • The player has other mons remaining in their party
  • The AI has a mon with an ability that can trap the player's current battler
  • The AI's trapping mon can win a 1v1 against the player's current mon

"Winning the 1v1" in this case is defined as KO'ing the player before they get KO'd themselves, based on the same hitsToKO calculations used elsewhere in the switch and scoring AI. These thresholds are different depending on whether the AI is switching mid-battle and needs to tank a hit vs after a KO and doesn't need to, and both cases are accounted for.

I've also included tests for both mid-battle and post-KO cases, as well as one to ensure the trapping mon isn't switched in preferentially when the player doesn't have any mons in their party.

I'm open to the idea of tying some random roll to these behaviours to make them more difficult to predict, though it will also make them more difficult to test as far as I understand it. The HasBadOdds() function uses a 50% chance of failure as a benchmark, but that function is significantly more likely to lead to switch spam than the trapper conditions, which won't lead to switch spam and will instead just deterministically switch in the trapper when the conditions are met. I'm not sure what threshold would be considered appropriate if any at all, but I'm happy to add one in to increase the variance if that's preferred!

This also includes some very minor refactoring in GetBestMonIntegrated to clean up some conditionals for readability.

Discord contact info

@Pawkkie

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.

Few things but looks good otherwise

src/battle_ai_switch_items.c Show resolved Hide resolved
src/battle_ai_switch_items.c Outdated Show resolved Hide resolved
src/battle_ai_switch_items.c Outdated Show resolved Hide resolved
src/battle_ai_switch_items.c Outdated Show resolved Hide resolved
@Pawkkie
Copy link
Collaborator Author

Pawkkie commented May 31, 2024

Ready for re-review :)

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.

Sorry didn't catch those first.

Non blocking but do you think it makes sense to make a new test file for the switch ai tests?

test/battle/ai.c Outdated Show resolved Hide resolved
test/battle/ai.c Outdated Show resolved Hide resolved
@Pawkkie
Copy link
Collaborator Author

Pawkkie commented May 31, 2024

Non blocking but do you think it makes sense to make a new test file for the switch ai tests?

YES

I thought you'd never ask <3

I'll move everything that has a switch AI flag into its own file called ai_switching.c :)

@Pawkkie
Copy link
Collaborator Author

Pawkkie commented May 31, 2024

Non blocking but do you think it makes sense to make a new test file for the switch ai tests?

This was an extra good idea because I found

AI_SINGLE_BATTLE_TEST("AI gets baited by Protect Switch tactics") // This behavior is to be fixed.

while doing it, which links all the way back to #3346 . D'you think we should wait for Egg to be around or is this something we can brainstorm for and then ping Egg when we have an implementation idea? It's something I'm interesting in poking around with in the near future now that I've remembered it exists :)

@AlexOn1ine
Copy link
Collaborator

while doing it, which links all the way back to #3346 . D'you think we should wait for Egg to be around or is this something we can brainstorm for and then ping Egg when we have an implementation idea? It's something I'm interesting in poking around with in the near future now that I've remembered it exists :)

You could ping him if you want but I don't think we should intentionally wait for him.

@AlexOn1ine AlexOn1ine merged commit cb1b4bc into rh-hideout:upcoming Jun 1, 2024
1 check passed
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.

2 participants