Fix Switch AI Bug: AI never switching out when it could be OHKO'd #5089
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Egg found this bug and reported it on Discord here. Basically the HasBadOdds switch check, which is enabled with Smart Switching, should trigger a switch out 50% of the time if the AI's mon can be KO'd and it has a good switchin candidate in its party. This was never triggering.
On investigation, it seems there was just an oversight in #4760 , where the
damageTaken
variable was removed and replaced by admg
variable, butmaxDamageTaken
was still referring todamageTaken
to update itself, which was always zero and never changed.This PR fixes this issue, changes the HasBadOdds 50% chance of failure to use
RandomPercentage
with theRNG_AI_HASBADODDS
tag instead of the more opaque modulo, and writes a test to make sure we don't accidentally reintroduce the bug with a future refactor. It also removes the Smart Switching flag from one of the Smart Mon Choices tests that would otherwise be affected by failing 50% of the time due to RNG, when the test has nothing to do with evaluating switch out decisions and is instead meant to ensure an infinite loop doesn't exist in Smart Mon Choices' hits to KO calculation.Issue(s) that this PR fixes
Fixed before issue made heck yeah
People who collaborated with me in this PR
Egg found the bug! :D
Discord contact info
@Pawkkie