Batlle AI
2009-02-26 11:14:14
Previous post
Return to blog
Next post

The battlefieldpart of Imperial Domination II is slowly becoming a solid feature. However, it requires a good strategy to win a battle and this makes it very hard to program the AI. I've spend some hours looking to the screen thinking of the best way to solve this but those where some very wasted hours. In almost every blogpost I complain about not wanting to program AI and it should get a bit boring to read, but I'll try to explain why it's so hard.

First of all some more info about the battles. The gameplay can be compared with chess. You and your opponent can move one unit every turn. However, instead of "killing" an enemy unit when you move on it, they will fight each other every turn that follows. Every unit has 100 HP, infantryattack, cavalryattack and armorpercentage. Basically every turn a units HP is reduced by armor%*attack of every enemy unit in bordering cells.

So the basic strategy is to inflict as many damage on your opponent every turn while trying to receive little damage. This can be done for example by attacking cavalry with spearmen.

Now there are a few main aspects that the AI has to keep in mind while taking moves, most aspects that a human doesn't even has to think about. I think the most important are Space, Time & Teamwork and Reaction.

Space
As you can see on the image from the previous blogpost the battlefield is a hexagonal grid. Both players can deploy their units on their side of the grid before starting the battle. When the AI is the attacker it has to see how your units are deployed and where weak spots are. It has to take into account where it's own units are and how accessible the enemy's weak spots are.

Time & Teamwork
So when the AI decides where to attack it has to plan the attack on that area. Units can only move a few cells every turn so they have to move towards the goal in a couple of turns. But sending one unit ahead makes it very vulnerable, units have to move together. Every turn the AI should get a picture of where his units are, how far away from the target they are and how vulnerable they are. It has to look ahead to make the attack successful.

Reaction
The AI can't just plan an attack for multiple units and execute it in the following turns. The player could disrupt the plans so the AI has to keep updating it's strategy every turn and react on the player. This can not only cause heavy lag, there also is the possibility that AI constantly changes plan and thus never really accomplishes anything.

I really hope I can make the AI smart enough. When a battle is to easy to win it could not only make the battles boring, but also unbalance the campaign. I get back to you when I made good progress on the AI and hopefully I have a demo of the battles ready soon.

Comments


Leave a Comment
Name*
Message*