• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

Europa Universalis IV - Development Diary 19th of July 2022

Welcome to this week's Dev Diary! Today I'm back to talk about some of the changes we've made to the AI for 1.34.

National Ambitions

For a long time, there has been code and script for the AI to be aware of the conditions of its missions and decisions and try to achieve some of them. But because of various issues this has not had a significant impact.

For 1.34, we’ve made sure the AI takes many of these conditions into account, especially those related to conquests. We also made the AI pursue cultural unification, depending on government rank. These changes will work together with the AI’s more organic desires to shape its ambition and strategy. The result is an effect which is just noticeable in terms of AI behavior, but compounds over time to create AI empires - sometimes historically reminiscent - that provide a real challenge to players who continue into the late game.

We were a little worried that this might cause games to all look the same, but our hands-off overnight games look arguably even more varied than before.

Here are a bunch of recent hands-off 1821 maps, only slightly cherry-picked:
num1.png num2.png num3.png num4.png num5.png num6.png
It makes us happy and proud to see the AI form historical countries such as Germany, Italy and Qing.

Typically, these AIs balance off each other nicely. If your plan as a player is to “Kill Ottomans early, then chill”, you may find that you’ve just aided some other AI in taking their place as your end-game boss. Admittedly though, a downside of this more opportunistic AI is less clean borders.



Peace Negotiation

What started out as an investigation into why AIs often left OPMs alive in peace deals, turned into a slightly bigger project.

When the AI is winning a war, and making demands, it has a bunch of preferences that it tries to balance against each other for an optimal peace deal. This is unlike when it is losing, where it will only care about objective measures such as war score cost. However, when the AI is winning, but receives an offer, it has previously relied on very coarse-grained expressions for whether the offer matches its preferences:
  • “Does not want parts of the offer”
  • “Requires X to be part of the offer”
  • “Wants other concessions than gold”
This has given clever players a little too much room to outsmart the AI.

In 1.34, the second expression in particular has been reworked, to allow the AI to express its preferences in more detail. Let’s take a look at an example:

no_candar.png


Here, I was trying to get out of a bad situation by giving away my ally’s land, but Nassau wouldn’t have it. It’s not that they don’t want Candar to be released - note the green thumb - it’s that they’d much rather have me release some of my own land. Unlike the old “Requires X to be part of the offer”, this new condition can not be circumvented by completely filling the peace deal with less important treaties.

As a consequence of this, we’ve also been able to loosen up the “Does not want” condition by making the thumbs green in more cases.

One more subtle but important change is that when an AI warleader considers a separate peace with individual enemies, it will be more lenient. This helps expanding AIs take more stuff, while also reducing the risk and cost of war, compared to just waiting for the enemy warleader to sign a deal. It will also make it more risky for players to start a war where they rely too heavily on their allies.

As a related side note, we’ve fixed a crash related to the PRESS_THEM_FURTHER moddable define. If enabled, it makes your war allies who have been promised land get mad at not getting enough land, even if the war leader doesn’t take anything for itself.



Independence Wars

independence.png


Given that we’re doing a Scandinavia-themed update, it seemed appropriate to do something about subjects’ willingness to declare independence. We haven’t changed a lot, but subjects will overall be a bit bolder when it comes to declaring independence. In particular they may now do it while at war, if at 100% Liberty Desire, so no more constant wars to pacify your subjects. There’s not much more to say about it, but we can for example see independent Sweden a bit more often, as well as a collapsing Timurids and occasionally breakaway nations in the Americas.



War Evaluation

tunis_reasons_before.png

(But Tunis will accept once I start the war)

When the AI considers starting a new war, it will look at basically the same information as the player can see in this window to figure out who will join on either side. Unfortunately, this has had a couple of bugs, related to the “Attitude towards enemies” and “Distant war” reasons potentially changing as the war starts and additional countries join. This has made both players and AIs declare suicidal wars.

These inconsistencies have now been fixed, where we could find them. But the problem remains when predicting acceptance for recursively called allies (such as allies of the Holy Roman Emperor when attacking a member state). Because of this, already in 1.33, the player interface doesn’t try to tell you whether those countries will join or not. But the AI still tried to “look at the checkmark”. In 1.34, the AI will simply assume that recursively called countries would all join. This will fix the “Burgundy suicides into Liege” bug.



Passive Subjects

Players with Rights of Man are able to set their subjects’ military focus to “Passive” and “Defensive”, but these focuses have been a bit wonky for some time. We fixed a number of bugs with these for 1.34, and there is one I would especially like to share.

In very simplified terms, this is how Passive was originally coded:

Code:
Objective #1: Avoid foreign territory.
Objective #2: Avoid enemy armies on home territory.
Objective #3: Avoid attrition (with a big margin if possible).

But then single-province subjects with big armies would stay and take attrition (especially if another country is also standing there), as well as when enemy armies are approaching. So the objectives were reordered:

Code:
Objective #1: Avoid enemy armies on home territory.
Objective #2: Avoid attrition (with a big margin if possible).
Objective #3: Avoid foreign territory.

And it turns out the AI knows you can’t take attrition while fighting a battle… So “passive” subjects would sometimes actively seek out enemy armies on foreign territory in order to avoid attrition!



Other

There have been a number of improvements to for example army and navy handling. This Dev Diary is already long enough, but the biggest bug worth mentioning is when the AI would just lock its armies in place near the coast, while its navy was too afraid (often irrationally) to come and pick them up. This easily caused e.g. Denmark/England/Spain not making themselves useful in wars.

Historically, many AI bugs have been caused late in the development cycle of a patch, perhaps because they often need time to be found. Right now, we’re quite happy with the state of the AI in our internal builds so we will try not to repeat that mistake by stirring things up before 1.34 releases.



Patch Notes

Here are roughly the AI-related patch notes so far. This is still WIP and a more final and curated list will be released in connection with the update as usual.

Buildings
- AI will now properly calculate when to construct Docks based on a multitude of factors such as sailor percentage, idea group choices, capital position and more.
- Fixed that AI sometimes deleted all forts right after a bad war.
- Fixed another case of AI deleting forts unnecessarily.
- Fixed bug that 'Conqueror' ruler personality made AI delete all/most forts.
- AI less keen to build fort in capital (though still preferred). This will somewhat reduce the fort slog in Central Europe.

Budgeting
- Changed AI budgeting algorithm to be more flexible. Fixes e.g. small CNs sometimes not colonizing when they should.

Geopolitics - Declare wars
- Fixed some cases of AI declaring war over provinces it can't/won't take.
- Made AI less likely to declare war on island nations it lacks the transports to invade.
- Fixed bug that revolutionary AI could declare war on coalition target with any cb, thinking coalition members would join.
- AI is no longer blocked from declaring independence when at war.
- Fixed bug that sometimes made aggressor AI erroneously think HRE allies would refuse to join when attacking HRE minors.

Geopolitics - Missions and Decisions
- Added AI weights to mission trees which make them now more considerate which mission they want to strive for and how much (for context related reasons).
- AI now understands and tries to achieve army_size and army_size_percent triggers in missions.

Geopolitics - Other
- Fixed bug that AI couldn't get hostile towards, and hence rarely attacked, others’ vassals and some other subjects.
- AI is now better at evaluating when to annex/integrate a subject.
- Fixed bug that catholic AI colonial nations avoided expanding into overlord's Tordesilla regions.
- Reduced AI avoidance of having interest in provinces that are vital to allies.
- AI Duchies are now permanently interested in provinces of their culture, Kingdoms their entire culture group, and Empires also all provinces on their border.

Peacemaking
- Fixed some issues with AI peace acceptance 'wants other concessions than gold' and 'does not want anything else', causing AI to often leave OPMs in peaces.
- Fixed bug sometimes preventing AI from taking the last enemy province.
- AI warleaders are now more happy to make separate peaces with non-cobelligerents.
- AI will unconditionally surrender in more cases.

Army
- Fixed one bug that made AI send armies far away instead of defending home.
- Made AI more likely to reinforce adjacent battles.
- Improved AI attrition handling. Should get both less attrition and less confused behavior.
- Fixed bug that AI helped allies with rebels even when at peace.
- AI overlord now treat subjects' rebels like their own in more cases.
- Fixed bug that made AI ignore flanking when evaluating battle.
- Fixed multiple cases of AI subjects being stupid when set to Passive or Defensive.
- Increased preferred size of AI armies, especially late game.
- Increased AI desire to disrupt sieges, especially with high progress.
- Improved AI logic for when to abandon sieges.
- Made AI armies prioritize coordinated offensives more.
- Made army AI try to stay close to enemy armies when it has nothing else to do.
- AI somewhat more likely to defend homeland.
- Improved AI for consolidation before battle.
- Fixed instance of AI armies going back and forth when sieging.
- AI vassals no longer delete exiled armies if they can get home.
- Fixed issues with autonomous sieging and rebel suppression missions.
- Fixed case of AI armies canceling movement every other day

Navy
- Fixed some issues with AI naval invasions.
- Made AI better at understanding when a naval invasion risks being intercepted.
- Fixed bug that made AI often unassign general when naval invading.
- Fixed yet another case of AI naval invasion stalling forever.
- Made AI fleets consider troops further away when protecting straits.

Trade Company
- Fixed bug that AI sometimes wouldn't ever core Trade Company provinces.
- AI will no longer accidentally remove trade companies by creating states.

Cheats
- Fixed bug that AI could add provinces to HRE when emperor, even if not a member.
- Fixed bug that AI could use Break Alliance for Favors diplomatic action with Leviathan disabled.

That's it for today. I hope you found this Dev Diary interesting!

Next week my colleague @Pavía will be showing all the new Monuments that will be added in the 1.34 Update, along with some game balance and changes we want to share and discuss with the community, coming also for free in the update.
 
  • 132Like
  • 68Love
  • 11
  • 3
  • 2
Reactions:
subjects will overall be a bit bolder when it comes to declaring independence. In particular they may now do it while at war, if at 100% Liberty Desire, so no more constant wars to pacify your subjects.
This is a really big change to be honest, but I'm happy for it. I'm interested in how easy it will be to make use of it offensively, too.
 
  • 6
  • 1Like
Reactions:
- AI Duchies are now permanently interested in provinces of their culture, Kingdoms their entire culture group, and Empires also all provinces on their border.

This is amazing. Thank you Gnivom!
 
  • 4Like
Reactions:
Most consistently well performing nation in the testruns: Spain
Location of the studio now responsible for EU4: Spain
Not suspicious at all ;)

Anyways looks really good. Especially the "Vassals can declare independence while Overlord is at war" part, the Burgundy suicide thing and that now AI nations can declare war on other nations subjects which was always a bit weird to me that they couldn't.
So please give us a date. I want to test this really badly.
 
  • 10Haha
Reactions:
- Fixed that AI sometimes deleted all forts right after a bad war.
- Fixed another case of AI deleting forts unnecessarily.
- Fixed bug that 'Conqueror' ruler personality made AI delete all/most forts.
- AI less keen to build fort in capital (though still preferred). This will somewhat reduce the fort slog in Central Europe.
- Fixed some cases of AI declaring war over provinces it can't/won't take.
- Made AI less likely to declare war on island nations it lacks the transports to invade.
- Fixed bug that revolutionary AI could declare war on coalition target with any cb, thinking coalition members would join.
- AI is no longer blocked from declaring independence when at war.
- Fixed bug that sometimes made aggressor AI erroneously think HRE allies would refuse to join when attacking HRE minors.
- Fixed bug that AI couldn't get hostile towards, and hence rarely attacked, others’ vassals and some other subjects.
- Fixed some issues with AI peace acceptance 'wants other concessions than gold' and 'does not want anything else', causing AI to often leave OPMs in peaces.
- Fixed bug sometimes preventing AI from taking the last enemy province.
- Fixed one bug that made AI send armies far away instead of defending home.
- Made AI more likely to reinforce adjacent battles.
- Improved AI attrition handling. Should get both less attrition and less confused behavior.
- Fixed bug that AI helped allies with rebels even when at peace.
- Fixed multiple cases of AI subjects being stupid when set to Passive or Defensive.
- Made AI armies prioritize coordinated offensives more.
- Made army AI try to stay close to enemy armies when it has nothing else to do.
- AI somewhat more likely to defend homeland.
- Fixed instance of AI armies going back and forth when sieging.
- Fixed case of AI armies canceling movement every other day
- Fixed some issues with AI naval invasions.
- Made AI better at understanding when a naval invasion risks being intercepted.
Hooray!
- AI will unconditionally surrender in more cases.
Boo!
 
  • 2Like
  • 2
Reactions:
So the railroading “optional” feature we shouldn’t worry about will now be used by the AI…

Otherwise, a bunch of good changes in that DD! Thanks to the devs for fixing a lot of common issues.
 
  • 11
  • 1
Reactions:
For a long time, there has been code and script for the AI to be aware of the conditions of its missions and decisions and try to achieve some of them. But because of various issues this has not had a significant impact.

For 1.34, we’ve made sure the AI takes many of these conditions into account, especially those related to conquests. We also made the AI pursue cultural unification, depending on government rank. These changes will work together with the AI’s more organic desires to shape its ambition and strategy. The result is an effect which is just noticeable in terms of AI behavior, but compounds over time to create AI empires - sometimes historically reminiscent - that provide a real challenge to players who continue into the late game.

We were a little worried that this might cause games to all look the same, but our hands-off overnight games look arguably even more varied than before.

- AI Duchies are now permanently interested in provinces of their culture, Kingdoms their entire culture group, and Empires also all provinces on their border.

Are these changes enough to justify removing the -100 opinion to fellow Confucians given to Chinese kingdoms? That modifier always felt like an awkward and ill-fitting improvisation to get Chinese kingdoms to fight each other. It also had silly consequences such as Chinese kingdoms being too okay with some colonial European power grabbing a piece of Chinese coastal land.

But it makes no sense to keep it anymore if we can now just give all Chinese kingdoms missions to take the right land and culturally unify, and get them motivated enough to carry it out.
 
  • 4
  • 3
  • 1
Reactions:
Just wondering: what is a 'revived AI programmer'?
Edit - Oh its Gnivom, i had no idea you were referring to them, i thought you meant something inside the text-post itself for AI controllers or something like that. Apologies on my now deleted post content

This is a really big change to be honest, but I'm happy for it. I'm interested in how easy it will be to make use of it offensively, too.

I hope its summarily leading to a influence ideas buff, or tall builds are going to suffer when you need to go over your relations-limit just to squeeze 50 more force limit on your free-city/ limited state merchant nation and dont want to use quantity ideas, which it'll slide towards the already controverisal group (more troops is always more intimidating than good quality troops, only condoterri seem to rate quality fairly in decisionmaking)

If you can deal with vassals, annulling their independence war for the big liberty drop then sure, but normally they're never alone diplomatically (not that you can force them to break inter vassal alliances or target supporting nations in the peacedeals of wars against them). Also kind of dissapointing no mention about the Independence mechanic not being CoP exclusive anymore with their self styled importance that it was nessecary to make changes to the system, when Sweden and Denmark experience the most central focus of the 'Support Independence' mechanic in the first place.

Edit - I did double check, Its in El-Dorado too, but it wouldnt hurt to have a third fixture with some QoL given the setting would it?
 
Last edited:
  • 1
Reactions:
So excited to see those maps, I wish there were even more, like 10, for good statistics. Huge Commonwealth in every game, sometimes military hegemon, is my main pet peeve and I am glad to see them tamed...
 
Very nice. The one thing that I would expect to find under AI is the blatant aggression of natives, did you address that? Or is fixing the bug that gives colonized tribal land and unowned cores to a newly formed federation tag enough? It looks like colonizers are succesful again in the overnights, which is good :)
It's not in the patchnotes, which is a mistake. It has been fixed. It can still happen, but waay less common
 
  • 23Like
  • 7
  • 2
Reactions:
I am so concerned about the forts. Listed change about reducing AI preference on building forts on capital should partially solve the problem. But i think it may not be enough.

When a small nation or OMP build a fort early game, they will want to upgrade it every time regardless if they gained income or not. So they will end up with fort level 8 if they ever happen to have level 2. They may not be able to afford it and also have a functioning army, as it is sometimes an issue late game. This also contribute to fort spam in OMP areas, like HRE or India. So maybe nations below certain dev should not build forts, at all (like belo 20-25), and only if they are rich (40-50).

Also AI could consider deleting newly conquered forts of they are next to another owned fort. This way AI would clean up most of the for spam on their own, while still having a big fort system.

But i can be totally wrong, since i gave no idea how AI handles forts on the test builds.

Other than that, they changes seems resonable, particularly declaring independence at war at 100 LD. This removes a very stupid exploit.
 
  • 5
  • 4Like
Reactions:
REALLY crucial question. Is the Timruids start going to be taken into account with the change that allows AI to declare independence while at war? Currently one of the most crucial things to do when playing them is to stay at war until youre able to grow strong enough on your own. I worry the change can make unifying as Timurids completely unviable
 
  • 1
  • 1
Reactions:
How do the AI ambitions work in relation to Random New World? I know it's an old DLC and probably not much used, but have you tried running some games with it and looked at the outcomes and AI behaviour?
 
  • 3
Reactions: