[BTS] AI Strategy - war

glider1

Deity
Joined
May 29, 2006
Messages
2,905
Location
Where animals hop not run
This sub forum of the "Better than BTS" project is for discussing AI behaviour regarding the strategy of warfare. This pertains to things like border war declarations, current problems and future possibilities for new war plan behaviours as well.

The discussion of "war tactics" is a huge area as well and has it's own sub-forum.
 
I looked into the chances for Friendly/Pleased war declarations a little more. In AI_doWar there's a odds check against AI_noWarAttitudeProb before the startWarVal is even computed ... each AI has their own % of the time they will not even consider a DOW for certain attitudes specified in XML under <NoWarAttitudeProbs>. None of the AIs will initiate a war when they are Friendly to you which is good. About half will also never start a war against you on Pleased, for the rest the odds are mostly 10% with a smattering of 20%.

The chances for a Pleased declaration of war on a neighbor if the 10-20% chance check passes are now much higher with the Closeness fixes, but the initial check makes this still a fairly rare event. On aggressive AI those 10-20% chances are more like 20-30% and the differentiation in startWarVal for close vs non-close civs means you really can't really trust your neighbors unless they're Friendly or engaged in other wars.

When the AI is Cautious towards you the odds of checking startWarVal range from 80% to only 10% for Sitting Bull. This is the scenario where most of the changes in behavior will occur I think, the AI will pick a war against a neighbor they're Cautious towards over a distant Annoyed much more often now. On Aggressive AI they will even be fairly likely to declare on a neighbor they're Cautious towards over a distant Furious.

This is an example of the type of content relevant to this sub forum. As far as I can perceive, this is all good news for Better BTS build 0.11 at least in the middle ages. A distant furious war declaration will still occur in terms of diplomacy objectives, but that doesn't override local border considerations it would seem. Of course it's not that simple once long range and cooperative warfare becomes possible late game.....

Sigh, there is still a lot of testing to do...
Cheers.
 
One serious crippling part of the AI is the inability to actually gauge the relative power of two empires.

Currently, "power" that the AI uses is the sum of the "power" stat of units, technologies and buildings. This is ... absolutely horrid at guaging the military power of an empire.

We can:
A> Change the meaning of Power. This would impact in-game graphs, etc.
B> Produce a Munged Power value, and replace strategic evaluation of Power with this.
C> Other

Option <A> opens up more, new knowledge to players.
Option <B> requires more finness. Do we pay attention to the Espionage knowledge of a side? (I think currently the AI cheats, and knows power even if it doesn't have the Esp, right?)
Option <C> is wide open.
 
The AI definitely knows power regardless of espionage ... this isn't too much of a cheat to me, the human player is able to judge roughly how strong another empire is based on observed history, techs, size, etc even without the power graph. Personally I have never really used the power graph to decide ahead of time whether to declare war, if things aren't going my way quickly I might check to if my enemy's graph has dropped to help judge if things are headed for a stalemate or whether another offensive will break through.

I noticed that the perceived power and "asset" value of units was changed across the board in XML for 3.17 ... don't know quite why, didn't seem to be mentioned in the change list. What does the "asset" value do anyway?
 
For those who are not familiar, there is a good description of how power and other demographics are currently calculated in this article
 
I have played several games recently using the excelllent tectonics map script from the new patch.
This script is particularly good at generating interesting landmasses with many choke points, unfortunately the AI seems to have no appreciation of either the value or danger of choke points.
This would be an area in the AI's strategic 'thinking' that would certainly benefit from some scrutiny.

For example, the mongolian hordes were decimated in attempts to take this fortress

attachment.php


and Tokugawa's samurai threw themselves in vain at this mountain pass (of course he created some great CG3/Guer2 longbowmen for me in the process!!)

attachment.php


Note that the fortress on his side of the pass was built on a stone resource outside any BFC, not because he recognised the strategic value of the location.
 

Attachments

  • Choke1.JPG
    Choke1.JPG
    93.8 KB · Views: 310
  • Choke2.JPG
    Choke2.JPG
    53.2 KB · Views: 1,217
There are AI algorithms for recognizing chokepoints. That would be useful defensively...

Offensively, chokepoints might be dealable with tactically. Ie:

Don't attack an enemy stack if the battle will almost certainly fail both tactically and economically using available resources.
 
There are AI algorithms for recognizing chokepoints. That would be useful defensively...
Very Interesting. I wonder if that goes as far as settling cities to deliberately control those chokepoints and whether those checks are performed during peace as well as war and most importantly then influence worker/unit behaviour.
How sophisticated can the AI be in this area without a significantly improved capacity for long-term planning, coordination and goal setting.

Not directly related to my original point, but as a human player I often settle cities sub-optimally as psuedo-choke points (to neighbours with whom I refuse to open borders) to preserve a swathe of land for later settlement when I can afford the extra city costs. I have not observed the AI doing anything similar deliberately.
 
I'm looking for the function which calculate the power of a country or a stack. I didn't find it can someone give me it name please?

Armand
 
I'm off to breakfast, but country power is tracked via an updated delta-function called something like CvPlayer::GetPower(). It doesn't do the calculation -- when things that add or subtract from a player's power happen, they just update the Power counter on the Player.

Stack... might be a plot power function, can't recall.
 
(I am not looking at the code, but going from memory.)

We added something for BetterAI that would look at whole stack vs whole stack odds, when deciding whether to attack, rather than just look at the odds of one unit vs a stack. I am not sure how much of this survived into BtS, as I have not looked.

The way this works is a bit convoluted as I recall, going through several functions, so I would suggest studying it closely, or even stepping through it a few times to understand how it works.

I believe the function(s) are named something like getCombatOdds, or perhaps that is the name of the low level function that the one you care about is calling. Do a search for 'odds'

-Iustus
 
I have played several games recently using the excelllent tectonics map script from the new patch.

It's a great map isn't it? It almost feels like it was included by Fireaxis as a challenge for us here to improve the AI. The choke points and terrain structures are a wonderful testbed for building a truly clever intelligence (SIDE NOTE: from looking at the placement of bonuses it looks like the map script has been adjusted for better late game corporate balance *I think*)

In your example, it seems sad that the AI only built that fortress for the stone and not because of it's choke point promise...

You'd think there would be a fairly achievable way of getting the AI to understand choke points but it probably is not simple in reality. As a quick pass you could do this to implement something short term:
1) Once x number of border cities have been established to y-culture execute 2)
2) If not at war with no threat of war execute 3)
3) Discover the extent of "terrain holes" on my now well established borders
4) If terrain holes are few enough execute 5)
5) Decide how to plug the terrain holes (forts verses units verses treat hole with the same defense priority as a city)
6) Plug them quickly....

Without a strategic planning AI, once 6) has been executed the AI simply returns to generic behaviour but keeps a track of the "holes" and refills them as necessary throughout it's remaining existence whenever it is not at war. It will of course do potentially stupid and unneccessary things like "overdefend it's interior cities" but at least it covers for the possibility of invasion despite terrain security. The algorithm beyond step (2) above is only calculated once for every "unique" body of culture the AI possesses or if the body of culture has expanded by a certain amount where upon the algorithm is re-executed beyond step (2). The complexity of this algorithm is probably on the same par as "amphibious invasion" if not more.

As for terrain funnels, that is too much of a challenge for this existing AI I think. However all is not lost because perhaps terrain funnels produce interesting "generic" behaviour in the AI anyway.

This is unsatisfactory of course, but without strategic planning what does an AI do? In theory if it could plug all the holes and choke points, it could concentrate military at these points and areas then underdefend it's cities and concentrate on it's economy...

Cheers.
 
(I am not looking at the code, but going from memory.)

We added something for BetterAI that would look at whole stack vs whole stack odds, when deciding whether to attack, rather than just look at the odds of one unit vs a stack. I am not sure how much of this survived into BtS, as I have not looked.

The way this works is a bit convoluted as I recall, going through several functions, so I would suggest studying it closely, or even stepping through it a few times to understand how it works.

I believe the function(s) are named something like getCombatOdds, or perhaps that is the name of the low level function that the one you care about is calling. Do a search for 'odds'

-Iustus

Great, thanks for the clues ... I'll definitely dig that up.
 
The current power calculation is not all that good but I'd worry that the AI doesn't use it enough. For declaring war, there's a simple inequality that's weighted in their favour. Even the most cautious AI's will attack civs with considerably more power. Bts made them consider attacking with 2/3 the power they would have in Warlords. Would putting the ratio in AI_startWarVal be a good idea. A decent minimum might stop the weakest player being dogpiled but still make the AI more wary of stronger civs.
 
AI_startWarVal is basically the sum of:
1> How much closeness we have with them.
2> The value of the tiles near the border between us and them
3> How close our capitols are.

For some reason, along with 2), the AI counts the number of bonuses in our empire. That's with no qualification about distance or landmass. This means AIs like attacking big civs. With the generousness of the AI power comparison, this is a good recipe for suicidal wars.
Of course, the bug in 1) might make this effect smaller than I'd thought it was previously.
 
CvTeamAI::AI_calculatePlotWarValue is actually a bit deceiving ... while it seems to loop through and sum extra pieces for every bonus, GC.getBonusInfo(eBonus).getAIObjective() returns 0 for all bonuses. The iAIObjective XML tag for bonuses was introduced in Warlords but is always 0, even for oil. This was not changed in BTS. You can easily verify that this bonus code does nothing by looking at the values produced by CvTeamAI::AI_calculatePlotWarValue ... mouse over a civ's capital in debug mode and hold down CTRL and you'll see:

Code:
Opponents Name(6): city closeness (player closeness, team closeness)
    String about war state:   start war val ([B]plot war value[/B], capital Proximity, attitude and war check %)

The plot war values will make it clear that the AI is never adding 40 * anything for the other players resources ... it's only 4 * number of other teams' tiles adjacent to this player's territory.

So, as it stands right now the AI does not choose wars for resource reasons at all ... this is something that we should definitely change. I think we should try re-instituting the iAIObjective tag for a few strategic resources and then change the code in CvTeamAI::AI_calculatePlotWarValue so the AI will pick wars where it might pickup important resources it doesn't currently have. This function is only called when picking war victims so we can afford to spend a little more compute time to weigh enemy resources by need and proximity.

Frankly we might as well move the resource calculations to a new function so it's easy to see the new resource value. My sense is that for a really desirable target (say multiple nearby oil resources when this civ has none) the return value should be between 50 and 80 so as not to upset the balance between the existing components of startWarVal.

So, we'd need to assign iAIObjective values for each resource type plus determine good formulas for how badly the AI needs the resource and how close it is. Doing a quick search for getBonusType returned a bunch of places where the AI makes choices based on bonuses, there should certainly be some opportunities for adapting ideas from other places plus using what we come up with in more places as well. In particular, CvPlayerAI::AI_targetCityValue (as the name suggests, it is used to pick cities to attack) right now simply counts bonuses in the fat cross with no regard for whether it's the oil we don't have or yet another sources of cows ...
 
The iAIObjective XML tag for bonuses was introduced in Warlords but is always 0, even for oil.

That'll teach me to actually look at the XML some days. I presume it's for mods where resources might be more victory critical.
Opponents Name(6): city closeness (player closeness, team closeness)
String about war state: start war val (plot war value, capital Proximity, attitude and war check %)

Nice. I've not had a chance to play with your mod as I only revisited this forum today. As I posted in the other thread, I've been using a modified version of the better AI war information mouseover which didn't break down start war val. But then, I was trying to mod the overall chance for war.

so as not to upset the balance between the existing components of startWarVal.
Balance? If all of the changes to this function since the original CIV have either done nothing or nothing like what was intended, then you can reasonably do you want with it and not be too different.
 
There is something I often saw, when civ are at war they don't produce military unit sometime in their city, I mean that sometime 3/4 of their city are in research production.
Where does it come from?

Armand.
 
Depends greatly on the situation ... I've seen this mostly for intercontinental war and am currently working on improving/fixing exactly this issue (see the Amphibious thread).

If you've seen this for local wars, please post a save so we can check it out.

I don't know if the AI ever builds research if there's something else useful it could be doing, I'll check into that.
 
It stops building units for attack when it thinks its unit costs are too high. It stops building units for defence when it thinks it has enough. It will then build research when it runs out of buildings.

The same formula for unit costs is a major part of the AI's decision about whether to go to war.

This is not a bad idea in principle the implementation isn't perfect. It takes the unit cost and supply as a percentage of the total cost. So a small empire, which will have low maintenance, will build less units even as a proportion of the size of its empire than a large empire. As it thinks it has a lot of units, it will then go to war which might be suicidal. A large and underdeveloped empire with high costs will spam units like there's no tomorrow even if its economy is in trouble. On the other side, since Better AI, the upgrade discounts the AI gets are much lower than its unit cost and supply discounts especially on the higher difficulty levels. Then the AI may build so many units that it will fall behind in science trying to upgrade them all.

I've been experimenting with a formula which includes an a guess at the average upgrade cost over the game and takes the costs as a percentage of its economy (i.e. mostly science and gold per turn minus the costs) rather than costs. It seems to work better. Some exceptions to the maximum cost rule might also be a good idea.
 
Back
Top Bottom