Friday, June 22, 2007

Design: AI – Part 2

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.


Anonymous said...

I like the CanPlayAI() function, but I wonder if you would be beter off if it returned an integer rather than a boolean. A boolean works great for now, but don't some cards want to be played at a certain time more than at others?

Take "Nevinyrral's Disk" for example. While it may be OK to put the card into play at any time, it isn't always a good time to set off it's effect. If the default value for a card was 10, for example, the value of CanPlayAI() for "Nevinyrral's Disk" when the human had 5 creatures in play vs. the AI's 1 creature the value might be 100. The value of CanPlayAI() for "Nevinyrral's Disk" when the human had 1 creatures in play vs. the AI's 5 creature the value might be 1. That would allow the AI to adjust the desirability of a playing a card if it needed to, or leave it the default.

Couldn't the computer then choose a random card from the top scoring cards according to CanPlayAI()?

It may be helpful to effectivly ask the card how useful it is at the moment.

Forge said...

I think I understand your suggestion, so if the computer has a choice of a 5 card or a 10 card, it would play a 10 card. The hard question is when should the computer play a card like Swords to Plowsharers, which destroys (removes) a creature? Naturally the computer should target a large human creature and that is what the computer does. Thanks for your comment.