Important: Background information
This page will look up trainer battle AI procedures for the Generation IV Pokémon games – Pokémon Diamond, Pearl, Platinum, HeartGold, and SoulSilver. Trainer AI between each of these games is nearly identical, with only Diamond and Pearl having a single small difference from Platinum, HeartGold, and SoulSilver (in Icy Wind / Mud Shot / Rock Tomb!).
I recommend you read over this whole article at least once to be made aware of all the strange quirks and edge cases that affect the AI procedures.
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.