• 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.

HOI4 Dev Diary - Performance and AI

Hello! I’ve been drafted from EU4 to fight in the trenches together with the HOI4 team for a month and give some support on AI and performance. So I’m here to talk about those.

AI

I’ve been mostly devoting my time into improving garrison orders to solve some really wonky cases that could happen. Like it placing two units on Magdeburg instead of Berlin letting the capital be completely exposed. But also focused on making the garrison work a lot better when you don’t have enough troops to cover every point in the order that needs it.

First I implemented a new tool for HOI4 to let us programmers visually inspect what the unit controller is up to.

capture(95).png

Province Weights

capture(96).png

State Weights


After that came the big task, rewriting garrison order and how it assigns units. There’s been a lot of issues here and you’ve probably experienced them from time to time. Shuffling, units prioritizing the wrong states or provinces, the list goes on.

So what did I do that is new. Instead of having the old logic setting up rules for where units should go I went with a thing I hate. Mathematics. The main difference is that each state will sort of calculate how “painful” it is to remove a unit from it now. This means as each state goes through this, they will be trying to find the least painful way to perform the garrison order and will eventually settle on a sort of equilibrium.

It’s given us a lot easier way to control where units should go in a garrison and where they end up will match a lot more in style of the weights you can see on the pictures above.


A thing that we have been planning to do for a long time and finally got around to is to allow a more flexible way to control how the AI plays. We use a system we call “Ai Strategic Plans” for this. Its essentially telling Ai to act a certain way when it comes to national focuses and priorities based on scripted conditions. To put that in english I am going to hand over to @Bratyn for some examples:

Some situations in which the new Strategy Plans have been useful is to ensure ‘compatible’ AI behaviour in the case of an ahistorical Germany. A lot of the AI behaviours for the major European powers has been based on the assumption that Germany remains fascist and causes mayhem in Europe. This means that AI Italy would usually see Germany as an ally, and that AI France would either always go with the United Kingdom (if historic mode was turned on), or be so unpredictable that it was problematic for planning out and predicting alternate history scenarios.

Using strategy plans, we have made these AI nations partly behave more logical to the changing world scene, and partly ensure that the player will always have a challenging playthrough. Going democratic Germany, only to get your only enemy (Soviet Union) end up at war with both the Allies and yourself, is not a very fulfilling playthrough. Instead, a new strategy plan will now load for France upon German completion of the “Oppose Hitler” focus. This delays their pick of which political direction to head into until we have more information from the German player, essentially a ‘holding pattern’.

  • If Germany revives the Kaiserreich and chooses “Focus on the True Enemy”, France is released from the holding pattern and will go with Britain, forming a counter-reaction to rising German colonialism. Essentially, in this playthrough not much will change other than Germany being unaligned rather than fascist. The war will likely develop in a similar matter (though not on a similar timeline), with one war with the Allies, and one war with the Soviet Union.

  • If Germany revives the Kaiserreich and chooses “Expatriate the Communists”, these communists will head to France and give them a communist drift national spirit. France is released from the holding pattern and will go communist, choosing to side closer with the USSR so that both powers can stand against the new Anglo-German alliance.
  • If Germany goes democratic, France is released from this holding pattern and will choose to Revise Versailles. Which direction they pick next is up to the AI, ensuring some unpredictability. France may go Communist and start their own faction, or join the Soviet Union, ensuring a two-front war if Germany goes to war with the USSR. Alternatively, the French may go fascist. They then will go for “Woo Italy”, creating a new semi-powerful Fascist faction in south-west Europe. Similar strategy plans for Italy (and liberal application of AI strategy values…) ensure this alliance is stable. A new focus for france “Dismantle the Democracies” becomes available if Germany is democratic, and the AI has a high likelihood of taking this when the Germans are already at war with the USSR. This makes gameplay more dynamic, and ensures Germany will have ample enemies to fight against even if they elected to go democratic.
We also used AI strategy plans to teach the Chinese AI how to handle the Inflation mechanic and do things like making the PRC AI keep the peace in China when they are going for the peaceful takeover through the political struggle. All in all, to myself and @Archangel85, this has been (and will continue to be) an invaluable tool for ensuring believable and, most importantly, fun playthroughs for each ahistorical path that one can take. We hope to continue building upon this basis and make nations ‘smarter’ in dealing with alternate history situations, or just general oddities that arise in the state of the world over the course of a playthrough.

Modders I am sure are going to like this a lot, so for you guys check out the example below for how it can be set up (regular humans without modding superpowers can safely ignore ;) ).

upload_2018-2-21_16-49-6.png


upload_2018-2-21_16-49-24.png

PERFORMANCE

Late game performance have always been a tough nut to crack for us on our games. For Cornflakes we rolled up our sleeves and got elbow deep into the code to improve it the best we could.

In order to measure performance and see where it goes bad to better pinpoint what causes the slowdown I write a little script that generates this super sexy graph for us.

capture(93).png


We did tons of neat little tricks to improve our performance. AI when it micromanages does a lot less pathfinding now. The game will automatically balance workload between cores depending on how long the hourly update took for a country, The fronts system has been a lot more streamlined to make it not hog performance

And we’ve done quite A good job at it as well. Here’s the result of our hard work just this week

capture(94).png


Between finding ways to make things more efficient and utilizing the cores on the CPU better we’ve gotten an overall improvement late game. We won’t rest there though, there’s tons more that we can do to make late game an even more enjoyable experience!



To conclude this Dev Diary, we have a reminder for you. Tune in for the first day of the Three Day War later tonight, 20:00 until 22:00 CET. Since the release of Waking the Tiger is approaching we have invited some of the grandest streamers to battle it out in multiplayer and show off the expansion as well as put the build to the test.


Quill18, Alex the Rambler, Marbozir, Enter Elysium, Solar Gamer, Spiffing Brit, Drew Durnil, The Prussian Prince, Bratyn, Da9L, Shen Plays and Jay’s Gaming will all be streaming their point of view in their own channels, and we’ll be hosting a main observer stream at the Paradox Twitch channel: https://www.twitch.tv/paradoxinteractive

Next week we are going to try and do a big recap of all the features and changes and also talked about a bunch of small stuff that hasn't fit into diaries so far. See you then!


Rejected Titles:
Droogies Quest For The Missing Core
Hoi4 Dev diary: Reverse the polarity of the deflector dish
Graphs are hot!
 
Last edited by a moderator:
The one thing that frustrates me about garrisons is when I play Japan I use a garrison army to guard the islands from invasion but when I have too many divisions in that army (more then is needed) my units just take turns sailing around till they get sunk.
 
They could solve it by giving the USSR some insane buffs in that scenario, so it would fight pretty much everybody like Germany did historically.

Sure, they could. Or it could just be an unbalanced war. Then again, the Nazis had the resources of most of continental Europe at their disposal, and they still failed, historically. What if its just Germany and Eastern Europe vs the USSR, with France and Britain sitting the whole mess out? I just think there should be more options than 'France turns Red for gameplay balance.'
 
It could also be a non exhaustive list of cases.

Who is to say they told us every case in that dev diary (I’m willing to get they haven’t)?

Beyond that, you or any modder could make your own cases to get the desired alt history you want.

Paradox is simply providing us with their multiverse alt history universe.

They’ve given you the tools to make your own alt history fantasy
 
Sure, they could. Or it could just be an unbalanced war. Then again, the Nazis had the resources of most of continental Europe at their disposal, and they still failed, historically. What if its just Germany and Eastern Europe vs the USSR, with France and Britain sitting the whole mess out? I just think there should be more options than 'France turns Red for gameplay balance.'

I've read just recently that the occupied territories for the Nazis were a net loss economically (more expensive to occupy than the benefit they got from them), so other than Austria and parts of Czechoslovakia, I'm not sure having to manage a large occupied and not-particularly-happy empire necessarily did them that much good. Note - I've only read this in one place, so it take with a grain of salt.

As for game balance vs 'historical plausibility', while more options are always good, given the already fairly adventurous alternative-history angle on these things (I'm pretty sure we've just brought back the Kaiser prior to all this happening, although would have to confirm looking at the DD on the German focus tree) I expect that most players going down that path aren't necessarily strictly focussing on historical plausibility, so shooting for game balance first makes sense (and the devs have said on numerous occasions that "gameplay > realism", even if I'll sometimes argue myself that realism = immersion which is an element of gameplay - but as per the first part of this para, we're not exactly standing on strictly 'realistic' ground to begin with).

By the sound of the DD, there's plenty of room to expand the system via modding, and I'm sure modders will come up with other alternatives before too long :).

@Sourlol - sorry for my initially poor response to your question about books - took me a while to warm up and remember more - on which note, Battle Line (by the two Hones) is an interesting look at the interwar USN, and fairly accessible as well :).
 
Maybe the French should have a percentage chance of threatening to go red to get their way with the British, spite the Germans, or frighten the Spanish.
 
I don't like the idea that if Germany goes Democratic France is determined to go revise Versailles, I mean France shouldnt be always an enemy towards Germany
 
Sure, they could. Or it could just be an unbalanced war. Then again, the Nazis had the resources of most of continental Europe at their disposal, and they still failed, historically. What if its just Germany and Eastern Europe vs the USSR, with France and Britain sitting the whole mess out? I just think there should be more options than 'France turns Red for gameplay balance.'
Then you'd have a war that lasts about 6 months and nothing to do after that.
 
Use this in stellaris, EU4 and ck , plz :eek:
It is from EU4? If you check we had a dev diary before, the charts should look familiar ;)
I'm borrowed by HOI4 until end of February, then I'm going back to my project.
 
Looks really nice!

Does this mean that you don't necessarily have to have several garisson orders for the same area now (i.e. 1 army for coast defence, 1 army for supression..) ?

Also, really nice graphs. Makes it a lot easier to understand what's going on.
 
Your project? Is that just eu4 or you been given free reign to do something crazy?!
It's obviously taking over the world using an army hedgehogs. They only look cute but are, in fact, vicious. But @Groogy will never admit that.

But, to be more serious and back on topic, both graphs have shown quite significant, if sparse, spikes in performance. Have you managed to identify what causes them? In my experience, there are certain repeatable hour ticks in a year (12->13th April 1936 for instance IIRC) where there is a noticeable lag for a couple seconds and everything comes back to normal performance wise. Admittedly, they are not game-breaking, but are quite annoying.

Also, would it be possible to get percentage times each portion of the engine uses (countries_parallel, countries_serial, ai_actors, etc.) over time? What does "units" category contain? Only unit movements or also unit movement AI? In general, more explanation of what the categories include would be much appreciated, especially in the context of what is feasible to extend modding wise. For instance, if I am reading this graph right and my assumptions are correct one could easily double or even triple the amount of in-game states without it having much of an impact on performance.

Bonus question: What is the in-game time those graphs are representing? Is, it say, one year?
 
Excellent idea for France reacting to Germany. Does this French behavior only apply to player Germany, or to AI Germany as well? Will France delay choosing a political direction (Revise/Status Quo) if Germany doesn't go Rhineland/Oppose straight away? If so, for how long will they linger? Regardless, this is a great way to make Single-player more interesting.

It applies to AI Germany as well. And yes, the choice to 'go with Britain' has been delayed until the last possible for a historical playthrough, meaning that even if you don't pick immediately, France will still refrain from leaping on the 'go with Britain' focus. At the same time, they will still go with Britain in time to be ready for a war with Germany, assuming Germany sticks to a historical timeline.
 
@Groogy is the special forces of PDS. Each time a project needs help with some delicate, very high technicity work, they call Googy, and he delivers.
It's no coincidence that the patch notes are also measured in the "Groogy" unit.

Thanks for the diary and the hard work to the entire team.
 
Frontline shifting units (loosing entrenchment and time) and theater shifting (loosing time and often troops in sunk convoys) are the biggest bummers AI does, I hope we'll see a lot of improvements there. Also basic construction/research builds and templates could be upgraded to make AI just play better. If you dont like AI min/maxing mayby put that behing "real" difficulty level instead of innate bonus to AI current dificulty levels are.
 
It's obviously taking over the world using an army hedgehogs. They only look cute but are, in fact, vicious.

upload_2018-2-22_8-36-37.jpeg


What other warrior hedgehogs are there to be concerned about?

I am worried that there are other army hedgehogs out there.
 
I’m disappointed to not get more information about AI improvements. We’ve been seeing major problems with the AI since HOI4 shipped. Examples of issues I’d hoped to see addressed:
  • AI underproducing equipment and overproducing units, resulting in shortages.
  • AI wasting its equipment and manpower with suicidal attacks.
  • AI wasting its equipment and manpower by sending transports through sea zones controlled by the enemy.
@podcat, my question for you is whether any other major issues have been addressed in the AI. If so, I hope they can be covered here or in a later Dev Diary. If not, I’d like to know if and when we can expect to see movement in this area.
@podcat, in case this was missed in the thread, I’m reiterating my request for the dev diary about AI improvements to tell us about the AI improvements.