There are two methods in the class SpellAbility that the computer AI uses. Those methods are canPlayAI() and chooseTargetAI() The canPlayAI() returns a boolean value and dictates whether the computer can play this card are not. Some cards like Remove Soul the computer cannot play; I could never get the logic to work correctly.
And currently the computer only plays cards during his turn. Serpent Warrior’s canPlayAI() method checks to see if the computer’s life is over 3, so the computer doesn’t kill himself. (Serpent Warrior causes its controller 3 damage when it comes into play.) Hex’s canPlayAI() checks to see if there are 6 enemy creatures in play. Remember that SpellAbility is used for Spells as wells as for Abilities, so Royal Assassin’s ability checks to see if there are any tapped enemy creatures.
The method chooseTargetAI() does what it says, it sets the target for the computer if the spell or ability has a target. Cards like Giant Growth and Shock need a target, while Counsel of the Soratami (2U, draw 2 cards) and Wrath of God do not have any targets.