Recently I’ve been tweaking the AI combat. The problem was that the AI would attack with most or all of his guys and then you would attack and win. The computer wasn’t holding back creatures so it could block and stay alive.
While explaining the problem seems simple, changing the code was a little bit more complicated (as always). The code for attacking and blocking are in two different classes so I had to update the attacking code to check if you, the player, were going to win during your next attack phase. The blocking code didn’t need to be changed because it would automatically block in order to stay alive.
While this does improve the AI a little, it still has a long way to go. The AI still doesn’t correctly block creatures with first or double strike. And the AI doesn’t take into account trample damage, so the AI may block but still lose. The AI may also use activated abilities that tap the creature instead of attacking or blocking with them.
Similar to my previous article about two types of AIs, the same thing applies to combat. One, either you tell the AI which creatures should attack or block. Two, you generate lots of combat situations and you try to find the best one.
It is very hard to code for every combat situation which is option one, so my gut feeling is that option two would be better in the long run. Option two would still work good enough even if it didn’t take into account creature activated abilities, which would greatly simplify the coding.
Programming the AI to not look completely stupid is very hard.