-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expansion's Improved Switch AI
WIP, pasting from an answer to a question in the Discord for now:
Okay so quick overview. There are two AI flags that dramatically affect how the AI behaves when switching. AI_FLAG_SMART_SWITCHING
improves the AI's ability to decide when to switch, and AI_FLAG_SMART_MON_CHOICES
improves the AI's ability to decide what to switch into, both mid-battle and after KOs, which are handled differently.
If you'd like to check these out in the code, the controls for when to switch are largely handled in the ShouldSwitch function, which if you scroll through a bit you'll find a list of other function calls that mostly look like ShouldSwitchIfXYZ
. You can go through all of these to get a sense of what it's doing, which I'll summarize for you.
The controls for what to switch into are in GetMostSuitableMonToSwitchInto
, which if you're using the smart flag will pass along its responsibilities to GetBestMonIntegrated
, which you can go through to see the details. Again, I'll give you a summary.
To summarize, assuming both of the smart switching flags are enabled. Many of these also have intentional failure rates, so the AI won't switch out 100% of the time in a lot of these cases to keep the player from being able to predict with certainty. Some of these also only apply to singles, such as HasBadOdds
. This is also simplifying many of the checks. The AI will be triggered to switch out when:
- It can't hit Wonder Guard and has another mon in the party that can (
ShouldSwitchIfWonderGuard
) - It's going to die to Perish Song, can't KO the player and is affected by Yawn, is being severely affected by a status condition that switching helps (curse, toxic, leech seed) (
ShouldSwitchIfGameStatePrompt
) - It has a mon that can trap the player's mon and win the 1v1 (
FindMonThatTrapsOpponent
) - It has a mon in the party that can absorb the player's next expected attack (
FindMonThatAbsorbsOpponentsMove
) - It will NOT switch if the current mon will die to hazards on re-entry (
CanMonSurviveHazardSwitchin
) - All its moves are bad (
ShouldSwitchIfAllBadMoves
) - It can take advantage of Natural Cure or Regenerator (
ShouldSwitchIfAbilityBenefit
) - Its Encore'd into something bad (
ShouldSwitchIfEncored
) - Its primary attacking stats are sufficiently lowered (
AreAttackingStatsLowered
) - Its "odds are bad" (
HasBadOdds
), which is the generic "try to make start, player-like decisions generally speaking" one.
HasBadOdds
can trigger switches if the AI has another mon that the smart mon choices AI has determined is a good switchin candidate, and:
- The current mon has a bad type matchup and doesn't have a super effective move and has at least 1/2 HP, or 1/4 and Regenerator, or
- The current mon loses the 1v1 quickly and has at least 1/2 HP, or 1/4 and Regenerator
Without getting too into the weeds about the AI does its calculations, the AI will decide what mon to send out in a switching situation using the following priorities.
For switches after their previous mon was KO'd, the priority is:
- Has a trapper (Arena Trap etc., and can 1v1 player's mon)
- Revenge killer (OHKO and outspeed)
- Slow revenge killer (OHKO, don't get OHKO'd, don't outspeed)
- Fast threaten (2HKO, don't get OHKO'd, outspeed)
- Slow threaten (2HKO, don't get 2HKO'd, don't outspeed)
- Good type matchup with a super effective move
- Good type matchup without a super effective move
- Has access to Baton Pass (the theory being that the AI should prioritize putting baton passers in early, this is sort of a vanilla holdover)
- Generic damage output in a vacuum with no other considerations
For mid-battle switches, the majority of which will be triggered by the HasBadOdds
function:
- Has a trapper (Arena Trap etc., and can 1v1 player's mon)
- Good type matchup with a super effective move
- Good type matchup without a super effective move
- Generic tankiest mon for the player's current mon
- Has access to Baton Pass (the theory being that the AI should prioritize putting baton passers in early, this is sort of a vanilla holdover)