If you are a frequent reader, you will already know the computer’s land is smoothed, to read more see my previous column. The computer’s AI is divided up into three main parts. The general “brain” that pays for card costs, plays a land, and calls all the other routines. Then there is the combat code that handles when to attack and block. Finally, some code is added to each card that tells the computer when it can be played. The AI code in each card also sets the targets.
The AI built into each card accounts for most of the computer’s intelligence. The computer is only as smart as the few lines of code that are added to each card. A card like Shock is difficult for the computer to play effectively because of the wide variety of game situations. The AI for Shock basically targets a 2/2 flyer or the human player if it would kill him. If the computer’s life is under 7 (an arbitrary number), the computer will target a random creature that it can kill. A card like Ancestral Recall (draw three cards) is much easier for the computer to use well.
Wrath of God is a very situational card that the computer has a hard time evaluating. The AI code will play Wrath of God if he would destroy 2 more human creatures than computer creatures, or if the computer is under 7 life. The AI won’t play Wrath if you, the human player, do not have any creatures in play. The computer can win more easily with straightforward cards like Epic Proportions (enchantment, target creature gets +5/+5 and trample.)
Previously, I have also talked about how playing cards during the Main1 or Main2 phase helps the AI. (link to AI and Phases)
I’m not sure if anyone is really interested, but the “brain” is the Java class ComputerAI_General. ComputerUtil_Attack2 and ComputerUtil_Block2 handle combat. The reason the “2” is there is because they are the second version. The AI card code is handled by the methods canPlayAI() and chooseTargetAI(). Every spell and ability is represented by the class SpellAbility. Each SpellAbility class has the methods canPlayAI() and chooseTargetAI(). Wrath of God doesn’t have any targets, so chooseTargetAI() is not needed.
//Wrath of God, taken from CardFactory
public boolean canPlayAI()
CardList human = new CardList
CardList computer = new CardList
human = human.getType("Creature");
computer = computer.getType("Creature");
/*the computer will at least destroy 2 more human creatures*/
return computer.size() < human.size()-1 ||
(AllZone.Computer_Life.getLife() < 7