This site, and information within is adapted from the Generation 4 site. During the initial deployment some information in this briefing, and the subsequent move choice scoring may reflect that - please report any issues wherever you discovered this site.
This page will look up trainer battle AI procedures for the Generation III Pokémon games – Pokémon Emerald.
The Battle AI uses a scoring system to determine which move to use (and which target to use it on, if applicable). Each move starts with a score of 100 (but this starting point is arbitrary), which is then added or subtracted to by the different parts of the scoring procedure.
Every move is scored on every target on the field (even if that doesn't make sense for the move, such as Swords Dance or Earthquake), with scores being independent for each target. After all scoring is completed, the move and target with the highest score is selected. If multiple moves tie for the highest score, one will be selected from them at random. In double battles, a move is selected for each target first, then if the scores between targets are tied, a target is selected at random.
Scoring is skipped if the target is fainted, or if the move being scored cannot be selected due to being out of PP or locked out by Taunt, Torment, Choice items, Encore, etc. However, procedures that compare one move to another, such as to check which deals more damage, do not consider if other moves are locked out of use.
The scoring process is nondeterministic: a given move and target may result in a different score each time it is checked due to randomness within the scoring functions.
The scoring procedure is split into four main modules: Basic, Strong, Expert, and Doubles (others exist as well, but they are not used for Frontier battles).
As a general rule:
Basic AI discourages using moves without effect: stat-boosting moves when already at +6, healing moves when already at full HP, etc.
Strong AI encourages doing the most damage possible and going for a KO if one is available.
Expert AI encourages using smarter strategies on a per-move basis.
Doubles AI discourages using attacks on the ally without a good reason, and checks if moves such as weather or Trick Room will help or harm the ally.
Doubles AI is split into two parts: a part for checking attacks against enemies, and a part for checking if there is a reason to attack the ally.
None, one, or several of these modules run their scoring procedure depending upon the context of the battle. Each module runs independently, and their scores stack together. Only Doubles AI will attempt to use moves on the ally. The "terminate" keyword within a module means that the scoring of the module is complete, but other modules may still continue on top of the work that it did.
In the Battle Frontier, the AI is enabled as follows:
Battle Tower, Battle Dome, Battle Palace, Battle Arena, Battle Pike, and Battle Pyramid:
Always Basic + Strong + Expert AI.
Battle Factory:
"No AI" means that moves and targets are selected purely at random. Doubles AI is always enabled during double / multi battles, regardless of what other AI is enabled.
The AI always knows what item you're holding. It cheats to see it.
The AI always knows your exact current HP and max HP.
The AI does not know your moves until it sees you use them. Other methods that expose moves, such as Sleep Talk or the Forewarn ability, do not count.
The AI does not know your ability until it sees a text box with the ability name, such as: "... makes ground moves miss using LEVITATE", or "... FLASH FIRE made Flamethrower useless". If the AI does not know your ability, then most times it tries to check what your ability is, it will randomly guess one of the possible abilities your Pokémon's species can normally have. Abilities that modify damage but do not generate text, like Heatproof or Solid Rock, are not known to the AI even after damage is dealt. However, the AI is aware of the reduced damage that will be inflicted (e.g., for a Heatproof Bronzong, it will assume Levitate 50% of the time, but also will know that the Bronzong may survive a high-damage Fire attack that would KO if it had Levitate).
Rarely, the AI must specifically see your ability, or your species must not have any other possible ability, in order for a check to succeed; these cases are worded as "If the target's ability is certainly...".
There is one exception to this: the AI knows if your ability is Shadow Tag, Magnet Pull, or Arena Trap preventing it from switching.
The AI always knows the attack order of all Pokémon on the field, barring speed ties or Quick Claws. It knows if there will be a speed tie, but does not know who will win it. If the AI is checking if it will attack before or after another target, and there is a speed tie, it will randomly guess the outcome of the tie. For any Pokémon on the field with a Quick Claw, it will randomly guess the Quick Claw will activate 20% of the time, independent of if the Quick Claw will actually activate.
The AI always knows the exact abilities, items, and moves of itself and its ally.
If you switch out, the AI will forget its knowledge of your moves and abilities.
When the AI checks for move effectiveness, it does so regardless of if the move in question is actually damaging.
When the AI checks something like "50% chance of score +1 and terminate", this means that the score change happens with probability 50%, but the termination happens regardless, unless noted otherwise.
When the AI checks for HP as a percentage, it first multiplies the current HP by 100, then divides by the max HP, then rounds down. Therefore, for example, a Blissey with 361/362 HP is considered to be at 99%, and 54/362 HP is considered to be at 14%. When checks specify "If the user's HP is over 20%...", this means the calculated HP percent must be 21-100.
Rarely, the AI will compare a Pokémon's HP to 0%; this is not the same thing as being fainted: a Pokémon with 1/101 HP is considered 0% after rounding.
There are multiple instances where a nonrandom check by the AI is executed multiple times, or is broken and never triggers properly; for clarity, these have been removed.
Many of these checks are implemented using a jumbled spaghetti system of branching and jumping; I have tried to transcribe them in a way that is as clear and concise as possible with little ambiguity in interpretation, but if something is worded unclearly, do contact me with requests for clarification.
Generally, read the checks from top to bottom, indenting in a block when the condition above is met, and stop whenever a branch reaches a "terminate".
Read the checks carefully! There are often times errors left in by the developers; for example, Expert AI scoring Facade checks if the target is afflicted by a status condition instead of the user.