[BTS] AI Strategy - war

Is it possible to get the AI to read trends on the graphs so it can make better decisions about staying competitive in pop., gnp, production, power etc? This would leverage a 'memory' which is built in to the save game.

I coud say more, but unless it is possible there is little point.
 
Is it possible to get the AI to read trends on the graphs so it can make better decisions about staying competitive in pop., gnp, production, power etc? This would leverage a 'memory' which is built in to the save game.

I coud say more, but unless it is possible there is little point.

IIRC int CvReplayInfo::getPlayerScore(int iPlayer, int iTurn) can be used during the game to retrieve the score from a given turn. From the values returned it would be possible to determine trends, although it would take some work to get "trend recognition" working, and even more to make the AI react to a given trend in a given situation.
 
Yes, you can get all of the info graph data in the way ocitalis mentioned ... food, power, score, GNP, etc. Finding the right formula to detect trends though might be tricky, many of these things tend to have sharp changes when a civ goes into/out of a golden age, loses/gains a vassal, etc.
 
I would like to see temporary "war alliances" to defeat/decrease the power of a dominating civilization. atm it's only possible by religious votes.

Like: If Power(civ1)+Power(civ2) > Power(dominating civ) which is currently at war (so opponent+civ1+civ2 >>> domination civ) -> civ1 will 'ask' civ2 for a war vs dominating civ
 
That's a good idea. I haven't looked at all into how the AI chooses to ask for allies in war, I know that those joining a fight aren't as scared off by a powerful adversary as they would be if the potential enemy wasn't already engaged ... the power comparison rules for using a DOGPILE war plan (ie joining a war) are very different than for starting a LIMITED or TOTAL war. I'll report back what I find.
 
I think this idea is not one to be added with out a lot of thought if at all. It flattens out personalities in the game and makes the game more gamey... which isn't always fun. Grudges, past relationships, and trust are concerns here.

If civ 1 is winning, and civ 2 and 3 are weak and clearly going to lose militarily. What if Civ3 which has always been friendly with civ 1 took another route: "Hey let's ally with civ 1 and win together!" I see this sometimes in my game. Now if both civ 2&3 always sort of hated civ 1 and do still now... then sure, it makes sense for them to team up.

This already happens in the game relatively well, but maybe enforcing the direction they are ALREADY leading is would be ok. I don't want all my hard fought for diplomacy over hundreds of years to come for naught simply because I am more powerful.
 
LoveScale = 0 at -5 or lower, 1.0 at 10 or higher (Ie, (Attitude+5)/15, capped)
HateScale = 0 at +5 or higher, 1.0 at -10 or lower (Ie, (-Attitude-5)/15, capped)

GlobalDangerHate = HateScale * ((Percent Of World Power Empire Controls)*(Number Of Known Empires) - 1) * 5, capped from below at 0 and above at 5.

Ie, if you are twice as strong as the average world-wide empire, this works out to HateScale * 5.

GlobalDangerLove = LoveScale * [Worst mutual GlobalDangerHate]

This generates a tendency to gang-up on leaders, but if they already like you, they won't consider you to be a global danger. In fact, they'll ally with you against the "real" global dangers.

It just means that if there IS a global danger, then Empires which have any disliking for that empire will start to like each other more. And they won't have extra fond feelings for the allies of the global danger, leading to a possible additional tendency for the world to divide into two opposing power blocks...

This doesn't include the "you keep on betraying your friends, I shouldn't trust you" effect.
 
This doesn't include the "you keep on betraying your friends, I shouldn't trust you" effect.

This would be a good one to add. Currently the AI will trust and love any civ at friendly, wol't ever cross them. That's mostly good, I've only backstabbed a friendly AI a couple of times (only when going for conquest and they wol't ally, not much reason to otherwise). However not everyone plays like that, so it would be good for the AI to react if it sees a player attack, instigate a war, or otherwise backstab a "friend" and act accordingly. Hell it might not even be that bad an idea to make Mad Monty and maybe Peter play like an aggressive human player, have them consider attacking a friendly Civ if they are locked into a domination victory.
 
What would also be good is personallities which evolve or expand.

For instance if a non-war mongering Civ is attacked(possibly back stapped) but comes out of the war in a better position the Leader should be more likely to start a war in the future.

For instance if particular aspects of there personality brings results this aspect should be strengthed.

This would lead to a war monger with a lot of vassels slowly becoming more and more meglomanical. So they would be more likely to go for conquest / domination.

All you'd have to do for this is run a check to see how there score changes from start to finish of a war.

If it improves they should be more likely to declare war.

If it lowers they should be less likely to declare war in future.

I think this would really help civ repeating the same mistakes again and again, often if an early war mongers rush fails they just need to give up on that idea.

I do like the idea there should be a "Backstap" rating for every one too.
 
"Hey let's ally with civ 1 and win together!"

sorry, this is wrong. if there is a dominating civ, the other civ will be to WEAK to get into an alliance with the dominating civ (quote: "I don't need help." (or something like this)). there is absolutely no chance for a win for civ1 if civ1 won't start a dogpile war.
 
Should leader personalities be taken into account in making these sorts of global love/hate decisions?
 
sorry, this is wrong. if there is a dominating civ, the other civ will be to WEAK to get into an alliance with the dominating civ (quote: "I don't need help." (or something like this)). there is absolutely no chance for a win for civ1 if civ1 won't start a dogpile war.

Sorry, it's not wrong. It's happened again and again in my games. It depends on the relationship to that point- if it's been trusting, mutually religious, etc... they can join up.

Also depends on if you have permanent alliances running. Which can factor heavily into how the AI should play if it is to play smartly.
 
I'd like to know how the AI organize its defense? Because its seems that each time the attacker win the war (1vs1), even if the opponent have the possiblity to clearly defeat or stop the attack.

Armand.
 
I'd like to know that too ;)

The last line of defense comes from units set to UNITAI_CITY_DEFENSE. Other UNITAI types can also run defend city missions. The AI also has a bunch of units who operate as "floating defenders", exactly how these work or what they do I'm not sure. The CvPlayer AI keeps track of how many it has and cities will produce more if needed, so that's one thing to check out.

In terms of moving troops around and countering attacks, all of that is handled in CvUnitAI. There are different behavior routines for each UNITAI type so what units do what depends on their UNITAI and what behaviors are defined for them.

What would be very useful to figure out is to what extent the AI senses threats to certain cities and brings in extra troops from other places. It definitely tries to emergency build defenders, but I don't know about shifting them around ...

Check out the thread about debugging, you can get tons of info about the state of the AI and what it sees by mousing around in debug mode. Report anything you figure out or what questions come out of it!
 
I would like to see the AI declare war to pillage and get gold and once it has a full treasure chest / enough Gold the AI will make peace easily.
 
From my reading, the floating is the reserve units?

They look in their square if their city needs defenders (based off of a threat calculation, which takes into account nearby enemy units and nearby hostile territory, etc). If so, they stay put. If not, they look for a city nearby that needs defenders.

I think I remember city defense units switching to reserve if they are considered extra.

I couldn't see any provisions for an emergent "create a general shift of forces from one side of the empire to the other, when that side of the empire is under attack". Ie, I never saw the AI saying "well, that city needs defenders more than me, so shift some units over there" -- it looked like a bunch of "did it pass a threshold? If so, move".

If we implemented a threat-detection algorithm that created a gradient, and shifted 'excess' units along that gradient, then we would be able to have each individual unit AI follow the threat-gradient. This would cause an emergent plan of "build up forces along the borders with possibly hostile states" (and maybe on ocean-front cities).

Is there any 'city threat' data saved? From an initial look, it seems that it is calculated on the fly -- or did I miss it? Making this computationally reasonable might be tricky.
 
If we implemented a threat-detection algorithm that created a gradient, and shifted 'excess' units along that gradient, then we would be able to have each individual unit AI follow the threat-gradient.

That is a nice idea. I can see the algorithm in my head it is almost a visual representation on the map grid. It would seem that such an algorithm could work in conjunction with the current unit AI mechanisms, by "tending to" move defenders but not dictating them to do so.

Later on, if this algorithm were implemented well, it could be used as a sub algorithm of the general high level AI planner that is badly needed to improve the AI's high level organisation.

Cheers :goodjob:
 
Here's a report of the war decisions of several AIs in my recent game. This was a marathon game on a gigantic (200x132 plots) map with 34 civs, using BetterAI 0.41. I'm just going through the relevant civs and describe their decisions:

1. Mehmed
He really played a good aggressive game. As soon as he had Feudalism, he started to vassalize first Churchill, then Sitting Bull, then Suryvarman, then Joao. This would probably have gone on but I had to stop it.

I attacked him and Joao at four cities at the same time. Turned out that Mehmed had a massive army in one of these four cities. So while my other three armies captured one or even two cities each, the fourth army was slaughtered by Mehmed's forces, who then advanced into my territory, quickly capturing one of my cities, and advancing to the next (Thebes). I tried to mount some defenses there, but would've certainly lost the city (which would've hurt because it had the Pyramids). However, Mehmed spent two turns reducing the defenses instead of attacking the city. This was enough time for my other three armies to capture their cities. I then traded one city back to Mehmed for peace. In the end I had won 3 cities, lost one, and prevented a huge army from wrecking my only scarcely protected mainland. I think he made a bad deal by agreeing to my peace offer. I also think that he should've pressed his advantage at Thebes, quickly taking it instead of reducing the defenses first. He had an army of about 50 units there, against my mere handful of defenders, so reducing the defenses first may have saved the lives of some of his units, but also gave me time to move more defenders into the city, and capture cities with my other armies. Mehmed would've been better off sacrificing some weaker units and taking Thebes quickly - not only would that have strengthened his position in the peace talks, it would've also given him access to the Pyramids (and taken it away from me).

Mehmed also had another problem: At some point his research totally broke down. He had been among the tech leaders on the continent when he started his wars, but at some point he seemed to have stopped research altogether. In the battles above, I had riflemen and fought against his janissaries and cuirassiers. I then upgraded to Infantry and attacked again. It took him *ages* to get Rifling - by the time he finally had it, I had totally destroyed Joao and Suryavarman, and captured about 30 cities. Perhaps the maintenance costs for his empire (with four vassals) were eating up his research. He should have been able to direct his vassals' research to compensate for that, but I'm not sure whether the AI does that.

What went good, however, was the way Mehmed assembled his forces. After I defeated his army at my borders, for a while I only met his city defenders. Only after destroying Joao and Suryavarman I met another *huge* force of mounted units. It seems that instead of building those and throwing them at me piecemeal (as it would've happened in previous versions of Civ), he actually assembled a large force to counterattack with it in one single move.

One thing that left me wondering, however, was that he never attacked Tokugawa. After vassalizing Joao, Mehmed had surrounded Japan on three borders. I doubt that Tokugawa would've been able to withstand a three-front war, so in a way he was a low-hanging fruit for an already aggressive Mehmed. I don't know whether the AI takes such details into account when planning a war ("I should attack Tokugawa because with my vassals I can draw him into a three-front war"). I also don't know the relations between Mehmed and Tokugawa at this point, they may have played a role too, but I don't think they were excellent, the two had diferent religions after all.


2. Napoleon
Napoleon was boxed in badly, but at some point he managed to pass through Suryavarman's territory and declare war on India (which lay on the other side). He took two cities from Ashoka, who quickly capitulated. However, 30 turns later (which is not much on a Marathon game) he revolted and became independent again.

This means that at the time when Napoleon accepted Asoka's capitulation, Asoka must have been pretty close to the two 50% thresholds already which allow forced vassals to break free. The question is: Does the AI take this into account? Should Napoleon have pressed on and perhaps captured another city, assuring that Asoka wouldn't have such an easy time jumping over the 50% threshold?

Of course, it might have been a smart move by Napoleon if he didn't see a chance to win any more cities from Asoka. Napoleon couldn't reinforce his army quickly (his reinforcements would have to cross the whole Khmer territory again), so accepting a short-lived capitulation would have been preferable if the other option was to be crushed by the backlash. the question however remains whether the AI is perhaps too willing to stop attacking and accept a capitulation if the new vassal is very close to the threshold that allows him to break free again.


3. Suryavarman
Suryavarman played a very strong start. He was the first of all 34 civs to start a war, and in this war he captured four cities from Charlemagne, including the holy city of Christianity, the first religion founded in the game. It looked as if he saw a weakly defended holy city and capitalized on the opportunity, which would've been rather smart.

What I'm not sure about is whether it was a good idea of him to leave Charlemagne two cities. I've seen this on the other continent as well, where Willem and Stalin were reduced to two cities each. The AI seems reluctant to totally destroy another civ.

I'm not totally sure about this (I don't ever read strategy guides, part of the long-term fun that I have with Civ comes from figuring things out myself), but I think that in some situations it will be better to destroy another civ if you can. By destroying the other civ, you at once get rid of any "foreign population" unhappiness in the cities you captured. You can also draft (and whip?) sooner in them since the foreign part of the population will be removed from the calculation of ethnicities in a city - for example, if you had 10% of the population in this city already, and the home civ had 90%, then you won't be able to draft there for a long time - unless you eradicate the other civ, in which case the city is 100% yours and you can draft as soon as the city comes out of revolt, which is a handy way of making use of population that would have starved otherwise. This is a very powerful method for fueling further expansions, but it only works if you're eradicating your enemy. You also don't get higher maintenance costs (as you would for having a vassal) and you don't have "culture fights" (as you would if you made someone your vassal - although your city will keep its fat cross under its influence, it's still susceptible to revolts as long as your vassal has much more culture there).

On the other side, not eradicating the enemy means that you don't have to pay maintenance for more cities, and if you make him your vassal, you also get bonus happiness, can direct his research, and have an automatic ally for future wars.

Still, if the enemy only has two cities left, then he usually won't be able to provide many units or have much research. And the happiness you get in your cities is countered by the unhappiness you get in the conquered cities. So it seems to me that eradicating the enemy is preferable in many situations, but the AI doesn't seem to do it. In my game, it only happened with one civ (Charlemagne, who was already down to two cities, was destroyed by Gilgamesh, who declared war on his master).

4. Gilgamesh
Speaking of Gilgamesh, here's something strange. Towards the end of the game, Gilgamesh was building a *massive* military force, he was leading the power graph. At one point, he finally declared war on his neighbour Zara Yaqob. Gilgamesh had his vassal Wang Kon at his side, while Zara Yaqob was joined by his vassal Mansa Musa, and also by Saladin and Shaka.

I was surprised that I only got messages about Gilgamesh losing cities. He lost three cities in the first couple of turns after the war started, which was odd considering that he was leading the power graph and had started the war, so he shouldn't have been unprepared. I didn't see him achieving a single victory.

At that point I decided to invade the continent and subjugate Zara Yaqob, Mansa Musa, Saladin, and Shaka. So I took a lot of pressure from Gilgamesh. Afterwards, I decided to go after Gilgamesh myself, who was still showing strong on the power graph. However, my forces simply sliced through his cities, although he had the technologies for infantry and tanks. But I saw only a single tank, and his defense forces seemed way too small for his position on the power graph. I had reduced him to three cities when I found the reason: At one remote island at the edge of an archipelago, he had assembled a force of 22 destroyers, 22 transports, 20 infantry units, and some cavalry.

Now this force would've been nice in a counterattack against me, but he never used it. The units simply sat at their island until Gilgamesh capitulated.

I'm wondering about two things:
a) Why didn't he use this force against me?
b) Did this remote force perhaps lead him to overestimate his actual power on the mainland (based on the power graph), so that he declared war on Zara Yaqob who was actually *stronger* on the mainland?


5. General Observations

5a) Unit upgrades: The AI was still a bit reluctant to upgrade its units. When I finish researching a key military technology that lets me upgrade my units, I usually halt research for a couple of turns, throw everything into making money, and upgrade my forces. This usually pays off since it makes me a less likely target of attacks, makes me better prepared if I'm attacked nevertheless, and gives me a better position in diplomacy. The AI however doesn't seem to do this, or at least not aggressively.

5b) AI production: In the industrial era, my production absolutely skyrocketed until it was several times as large as that of the next best AI. Many factors contributed to this (playing Frederick, having Assembly Plants, managing to build the Three Gorges Dam, having a large empire), but I still got the impression that the AI didn't give production a high priority. Due to this, they were never able to build a meaningful amount of tanks - tanks are a very powerful unit which can't be gotten by upgrading others, so tanks are the point where having high production translates directly into military power. However, the only two enemies I fought that had Industrialism managed to field exactly one tank each (Gilgamesh may have had some more since he had this war against his neighbors before I reached him).

5c) Tech Trades: The AI doesn't see that making a lot of "bad" trades can add up to a substantial advantage. Example: An AI could trade a technology to five other AIs, but doesn't do so because none of those have anything to offer except 1000 gold each, and the technology is worth much more. So the AI won't trade its tech. Then the human player comes along, researches the same tech, and trades it to all five AIs for 1000 gold each. As a result, the human player now has 5,000 gold more, and probably better diplomatic modifiers with five other civs, whereas the AI who researched the tech first has neither.

I'm aware, however, that changing this would be a two-edged sword. It might all too easily come across as "The AIs are giving themselves easy trades in order to screw the human over". And I'm not even sure if it's *really* wise to trade technologies at a discount. But I get the impression that in my games I rely a lot on this technique to catch up in techs, or make money fast, and it seems to help me, so I wonder whether the AI is a disadvantage by not using it.

5d) Resource trades and Corporations: How does the AI value resources that it trades to me for use in my corporations? I get the impression that the AI gives such resources very little value. They usually give me several resources for one of mine, or they add gold per turn to the deal. This is not in proportion to the use I get from these resources when I have an empire with well-spread corporations - or am I missing something?

As usual, thanks for reading, and if you have questions, just ask. :) I hope that the AI questions I have raised can be answered. :)
 
Psyringe said:
I'm wondering about two things:
a) Why didn't he use this force against me?
b) Did this remote force perhaps lead him to overestimate his actual power on the mainland (based on the power graph), so that he declared war on Zara Yaqob who was actually *stronger* on the mainland?
These are what I'm most interested in hearing about.

But these sound like the sort of thing where having a savegame would be a huge help. I would hope you kept some autosaves etc.
 
But these sound like the sort of thing where having a savegame would be a huge help. I would hope you kept some autosaves etc.
Unfortunately I didn't. :( By the time I realized that this was something save-worthy, the war was already over. And while I do autosave each turn, I don't keep many autosaves around since my savegames are quite huge. Definitely something I'll change for my next game though.
 
Top Bottom