Bibor
Doomsday Machine
AI LAND OFFENSE
My last article dealed with determining the proper decision-making and positioning in the defensive aspect of the game. This time I will to deal with the most difficult part - land-based offensive and counterattacks (thus leaving the easiest, naval combat for last).
So is it possible to design an effective combat AI? My example choice, Age of Mythology, proves that is a 100% correct answer. That game had an AI you could learn from, and it could beat you without cheating until you got better than it was (which was after several months), and the same is true for the Panzer General Forever AI.
Where the AI usually fails, and it is no different in this game, is that the AI has the proper questions but has the wrong answers. More specifically, the key to victory is not the capture of cities but the total annihilation of opposing forces and control over tacticaly important hexes. Captured cities, like resources, are the sideffect of the annihilation, not the other way around. Annihilation of opposing forces, furthermore, comes from removing them from the board, or to be most specific:
To make the AI able to achieve a military victory over another player, we must reduce cities, resources, roads and other militarily important features into a single, qunatifiable value easily understood by the AI. The aim of an agressive war is to reduce these values to an acceptable minimum.
STEP ONE: Learning the military strength
Before an AI should be willing to go to war, it has to access the situation first. How strong is it? How strong is the opponent? This is not just about existing military forces, its also about production capabilities. For the AI to be able to do that, we are going to run a series of calculations. I'll base it on the fact that AI has the whole continent explored, since it starts with gazillion units. If not, it will use the visible tiles.
Lets do an example on Medieval era.
a. First the AI takes note every time a certain player enters a new era (this time Medieval)
b. the AI should also count the number of turns that passed since that player entered its current Era
c. The AI reads its script that says the following:
- First tier Medieval era has 5 techs, second tier Medieval era has 6 techs
- Techs that give units in 1st tier are 1
- Techs that give units in 2nd tier are 4
- Average number of turns to reach next tech is 10 (maybe not the best number; discuss)
- If less than 50(5 techs*10 turns) + 10 turns passed since entering Era, treat only 1 medieval unit available
- For each 15 ((5 techs/4 units)*10) turns past 60 into medieval era add another unit
- Medieval unit costs: Pikeman 100
, Longswordsman 150
, Knight 150
, Trebuchet170
, Crossbowman 120
for an average of 138
per unit.
- Pre-medieval unit costs: Spearman 50
, Swordsman 80
, Horseman 80
, Catapult 100
, Archer 70
for an average of 76
- Consider Bismarck etc. for specific values.
d. It should take into consideration if the calculation's target is Hiawatha or Catherine or any other civ that has production bonuses based on some tech (or building).
e. it counts any maritime city states you are allied with (that are known to him)
f. Now what the AI does is that it assigns a number value to each of the opponents non-puppet cities based on the following factors:
- treat every other forest as lumbermill past 60 turns into medieval era
- treat all hills as mines
- add up the total possible hammer output of all visible opponent's hammer producing tiles (plus two for the city hex)
- add up total possible food output of all tiles that can produce
(plus possible era benefits of maritimes)
- add up total population of all non-puppet cities
- Divide the total hammers produced by total population.
- Divide the total food production output of the 2-hex radius of a city by its population number*2, add known maritime era bonus. If it's not negative, confirm total hammer output of the city calculation
- check if number of hammer producing tiles is less than total population. If so, use the number of tiles instead
g. Now the AI takes into consideration the opponents budget (whether it can rush-buy units or not and if yes how many), using similar gold values to what I described here for hammers.
h. And finally, it comes to a conclusion of how many units can the enemy produce per turn if need be.
Lets see how this works out for me.
- Montezuma entered Renaissance era on turn 205 (now it's turn 219). Don't need a screenshot I hope
- Total number of hammers per turn within known borders: 71
- Total non-puppet population 34, total hammer-featuring tiles 39 so use population # instead
- total maximum production of hammers per turn: 71, or 2.08 per citizen (lets make it 2 for simplicity).
- total number of medieval units available: 4.
- average cost of his units: around 120.
- Montezuma can produce 0.59 units every turn.
- It also has +53 GPT and 374 Gold so it can rush-buy 0 units + one unit every 9 turns.
Thus his cities have the following unit production value:
You'll immediately notice how numbers for Teotihuacan are off, but that's okay, gold is production as well.
Now I do the same thing to myself:
I check my production and divide it by number of my citizens:
98 hammers per turn, 43 non-puppet citizens, bringing it to 2.27 hammers per turn per citizen.
I also have all but trebuchet available so that's 120 cost per unit.
My cities can produce 0.81 units every turn.
I also have 4931 gold and 213 GPT which means I can rush buy 10 units and do it again every 2 turns.
STEP TWO: Calculating if an offensive war is winnable
After the AI calculated the production strenghts of enemy cities and nation, it's time to make a decision.
AI makes a projection for 10, 20, 50 and 100 turns. For sake of simplifying things now lets just take the 20 turns example now.
a. The AI (Monty in this case) checks the demographics/soldiers. Checks if the opponent is top or bottom. If neither, he takes the average value. Lets say he doesn't see us in top or bottom.
b. Now it checks his own soldiers value.
c. the AI now compares the hammer cost of its units to the power rating he just read and converts the average power rating to hammers.
d. In the given screenshots example, the average power rating is 65,317. I'm neither top or bottom. And I have 60,000 soldiers. Since I can't see Monty's units, I'll take my own for calculation.
- 1 trireme (60
), 5 samurai (750
), 1 knight (150
), 1 crossbowman (120
), 3 catapults (300
)(maybe 3 GGs also count into power rating, dunno) for a total of 1380 hammers. 60,000/1380=43 hammers per power rating. Lets say 1 hammer equals 43 power rating (though my numbers may be off).
e. That means that by calculation, the average army strenght, and thus my army in hammers should be 1500
or roughly 10 units. A pretty precise estimate.
f. now the AI makes the projection based on 20 turns (lets say his strenght is also average, 1500 hammers).
- Enemy has 1500 hammers of units. AI has 1500 hammers of units.
Projection conclusion:
Enemy (me) can produce 16 units in 20 turns and immediately rush-buy additional 10 units, and rush buy another 10 units in 20 turns for a total or 44 units.
AI (Monty) can produce 11.8 units in 20 turns and immediately rush-buy additional 0 units, and rush buy another 2 units in 20 turns for a total of 13.8 units.
AI wisely decides it's time to boost economy not go to war.
My last article dealed with determining the proper decision-making and positioning in the defensive aspect of the game. This time I will to deal with the most difficult part - land-based offensive and counterattacks (thus leaving the easiest, naval combat for last).
So is it possible to design an effective combat AI? My example choice, Age of Mythology, proves that is a 100% correct answer. That game had an AI you could learn from, and it could beat you without cheating until you got better than it was (which was after several months), and the same is true for the Panzer General Forever AI.
Where the AI usually fails, and it is no different in this game, is that the AI has the proper questions but has the wrong answers. More specifically, the key to victory is not the capture of cities but the total annihilation of opposing forces and control over tacticaly important hexes. Captured cities, like resources, are the sideffect of the annihilation, not the other way around. Annihilation of opposing forces, furthermore, comes from removing them from the board, or to be most specific:
To make the AI able to achieve a military victory over another player, we must reduce cities, resources, roads and other militarily important features into a single, qunatifiable value easily understood by the AI. The aim of an agressive war is to reduce these values to an acceptable minimum.
STEP ONE: Learning the military strength
Before an AI should be willing to go to war, it has to access the situation first. How strong is it? How strong is the opponent? This is not just about existing military forces, its also about production capabilities. For the AI to be able to do that, we are going to run a series of calculations. I'll base it on the fact that AI has the whole continent explored, since it starts with gazillion units. If not, it will use the visible tiles.
Lets do an example on Medieval era.
a. First the AI takes note every time a certain player enters a new era (this time Medieval)
b. the AI should also count the number of turns that passed since that player entered its current Era
c. The AI reads its script that says the following:
- First tier Medieval era has 5 techs, second tier Medieval era has 6 techs
- Techs that give units in 1st tier are 1
- Techs that give units in 2nd tier are 4
- Average number of turns to reach next tech is 10 (maybe not the best number; discuss)
- If less than 50(5 techs*10 turns) + 10 turns passed since entering Era, treat only 1 medieval unit available
- For each 15 ((5 techs/4 units)*10) turns past 60 into medieval era add another unit
- Medieval unit costs: Pikeman 100






- Pre-medieval unit costs: Spearman 50






- Consider Bismarck etc. for specific values.
d. It should take into consideration if the calculation's target is Hiawatha or Catherine or any other civ that has production bonuses based on some tech (or building).
e. it counts any maritime city states you are allied with (that are known to him)
f. Now what the AI does is that it assigns a number value to each of the opponents non-puppet cities based on the following factors:
- treat every other forest as lumbermill past 60 turns into medieval era
- treat all hills as mines
- add up the total possible hammer output of all visible opponent's hammer producing tiles (plus two for the city hex)
- add up total possible food output of all tiles that can produce

- add up total population of all non-puppet cities
- Divide the total hammers produced by total population.
- Divide the total food production output of the 2-hex radius of a city by its population number*2, add known maritime era bonus. If it's not negative, confirm total hammer output of the city calculation
- check if number of hammer producing tiles is less than total population. If so, use the number of tiles instead
g. Now the AI takes into consideration the opponents budget (whether it can rush-buy units or not and if yes how many), using similar gold values to what I described here for hammers.
h. And finally, it comes to a conclusion of how many units can the enemy produce per turn if need be.
Lets see how this works out for me.
- Montezuma entered Renaissance era on turn 205 (now it's turn 219). Don't need a screenshot I hope

- Total number of hammers per turn within known borders: 71
- Total non-puppet population 34, total hammer-featuring tiles 39 so use population # instead
- total maximum production of hammers per turn: 71, or 2.08 per citizen (lets make it 2 for simplicity).
- total number of medieval units available: 4.
- average cost of his units: around 120.
- Montezuma can produce 0.59 units every turn.
- It also has +53 GPT and 374 Gold so it can rush-buy 0 units + one unit every 9 turns.
Thus his cities have the following unit production value:
Spoiler :

You'll immediately notice how numbers for Teotihuacan are off, but that's okay, gold is production as well.
Now I do the same thing to myself:
I check my production and divide it by number of my citizens:
98 hammers per turn, 43 non-puppet citizens, bringing it to 2.27 hammers per turn per citizen.
I also have all but trebuchet available so that's 120 cost per unit.
My cities can produce 0.81 units every turn.
I also have 4931 gold and 213 GPT which means I can rush buy 10 units and do it again every 2 turns.
STEP TWO: Calculating if an offensive war is winnable
After the AI calculated the production strenghts of enemy cities and nation, it's time to make a decision.
AI makes a projection for 10, 20, 50 and 100 turns. For sake of simplifying things now lets just take the 20 turns example now.
a. The AI (Monty in this case) checks the demographics/soldiers. Checks if the opponent is top or bottom. If neither, he takes the average value. Lets say he doesn't see us in top or bottom.
b. Now it checks his own soldiers value.
c. the AI now compares the hammer cost of its units to the power rating he just read and converts the average power rating to hammers.
d. In the given screenshots example, the average power rating is 65,317. I'm neither top or bottom. And I have 60,000 soldiers. Since I can't see Monty's units, I'll take my own for calculation.
- 1 trireme (60





e. That means that by calculation, the average army strenght, and thus my army in hammers should be 1500

f. now the AI makes the projection based on 20 turns (lets say his strenght is also average, 1500 hammers).
- Enemy has 1500 hammers of units. AI has 1500 hammers of units.
Projection conclusion:
Enemy (me) can produce 16 units in 20 turns and immediately rush-buy additional 10 units, and rush buy another 10 units in 20 turns for a total or 44 units.
AI (Monty) can produce 11.8 units in 20 turns and immediately rush-buy additional 0 units, and rush buy another 2 units in 20 turns for a total of 13.8 units.
AI wisely decides it's time to boost economy not go to war.