• 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:
I would personally like that to be a possibility, still. While HOI4 is first and foremost a war game, I think a scenario in which all of the West fights against the Soviets shpld be on the table, still. Even if it is basically ‘easy mode.’

I don’t play these games solely for the challenge and balance - if I did, I’d play chess. I play to explore these various scenarios, and challenge is merely subordinate to that exploration.
It would also be fun and challenging to fight against the entire west as the Soviets!
 
(...) 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.
"Ready for a war with Germany", just like France was historically? ;) /irony off
 
Does the USA have a different behavior for the monarchist Germany?
 
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.

The second part here sounds particularly promising! :)
Will this include disabling or dynamically adjusting certain influence focuses? Now, even a democratic Italy will turn Bulgaria and Romania Fascist when it befriends them, and a democratic Germany will go through the Balkan tree, attacking Yugoslavia and Greece.
 
@SteelVolt is actually on Stellaris now since a few months back. Now we are spreading out AI among several people more although we got a new guy who's main responsibility it is (he is still a little forum shy, but I plan to lure him out when he is ready to show some really cool modders tools he has been working on in his spare time. Thats going to be for a patch later though not for release)

Does this mean you are creating an AI A-Team? A team responsible for all the AIs in your games? It is really a good idea in my humble opinion. I also applaud the scripting idea for different responses in the various nations. Less weird things to happen due to cross code responses.
 
Best dlc yet, good work guys.
 
@podcat I have noticed what seems to be a smoother border I the Danzig and Poznan/Posen region and then Qingdau previously which makes me very happy, but I am a little surprised that Eupen and northern Schweig haven't been added into the game with all the you have done to Germany including a Kaiser restoration.
 
Wasn't it a strategy back in the day in MP for the Soviet Union to send tanks into Ethiopia and fuck over Italy? Ooh... The good days in the summer of 2016 :rolleyes:, before Together for Victory got released and the tactics were plain and simple.. UK sends 90% of their equipment to India, Japan sends half of their army on Naval invasions, Axis keeps the world tension low, the Soviet Union conjures whatever they can to up the world tension so they can have the US join against the Axis, the Soviets boosting the low countries and Scandinavia on purpose so the UK can invade them... Oh the good times...

It seems nowadays people are playing MP on an Esports competitive scale, with rulebooks/Google docs the size of encyclopedia's.. I may misunderstand this, but this is how I experience it at leasto_O. I didn't dabble in the MP scene as I used to, but my last MP games were just Germany and other powers ordering me around to delete my army and focus on 1 kind of research, production and focus..
If the Italy is decent then Soviet tanks in Ethiopia wont mean much since the terrain there is horrible for tanks, also, the Soviets don't want to bog down their tanks in Ethiopia when they are needed more in the Spanish Civil War. Also, Italy kind of wants to grind the Army XP in Ethiopia so Italy isn't generally trying to end the war in Ethiopia too fast. A few tanks fighting poorly in the mountains wont mean much to them.

Yeah, that is how MP works. Some lobbies have so many rules that it is basically a script, some lobbies have a minimum amount of rules and just things like no coups and no unwanted boosting and only focus wars until 1939. Other lobbies have some basic rules to keep the major countries generally in the same factions against each other. If you don't have rules like that then 99% of MP games are just fill with very unskilled players or USSR declare war on Poland at the start of the game and then on Germany and there is nothing Germany or anyone else can do about it. Thats why only focus wars until 1939 is a pretty standard rule. USSR can just conquer the world at the start of the game if its not there.

A basic modicum of quality of life rules are necessary in order to make the game worthwhile playing. I host big MP games of 12-20 people almost every night and they last around 6-9 hours since I vet everyone and make sure they all have read the rules and are on discord speaking with their team. When you spend the time to set up the game right then you can get epic long games because people know things will be fair within reason so they are willing to stay and commit. Whereas 99% of no rules or low rules games devolve into like 2 people playing for maybe 2 or 3 hours because everyone else will leave once the tables turn ridiculously against them because people are just memeing the game on things you should really do in singleplayer.

You need a modicum of rules to make the whole world relevant such as no Sea Lion until Axis controls Suez and Gibraltar. This makes defending North Africa actually relevant and fun because otherwise once France dies my Axis team will just prepare to invade Britain and any British forces not defending the Island are just a waste.

In my lobbies I try to have the bare minimum amount of rules necessary. My lobbies are far more relaxed than ones which are 100% strictly historical or do things such as regulate your templates and armor division templates. I want to attract consistent players who are of at least decent quality in order to have fun, challenging and consistent games so I have to create an environment which makes the players know that I am a fair host and that my rules set create a fair game that will be worth them spending at least 4 hours on. For the minor countries I allow far more ideological and faction flexibility especially the DoD countries but, I make the commonwealth stay in the Allies and stay Democratic. UK is a pushover to Axis if it doesn't have its commonwealth backing it up. Many players call me the most chill and relaxed host who actually hosts good games rather than meme/no rules games.

I know very few people who will want to play a game let alone multiple games of HoI4 spending many hours when the whole world turns one ideology and faction and then you're just on your own waiting to die. I don't find that fun for MP and almost no one else does either. Thats why low/no rules games fall apart so quickly and generally last a short time.

When the new DLC launches I'll host some no rules games for maybe a week or two since everything will be different and people will want to explore all the new options. After that though any half way decent MP player will want to get back to having a game where the teams are somewhat guided so that they know they wont waste 3 hours building up only to have all the major powers just flip ideology and screw you.

The meta always changes but, right now most countries have a focus or a few focuses and then each country performs their role in order that the faction as a whole rather than one country, is as strong as possible. Some examples are Germany and USSR focusing primarily on tank research and production. Italy, Hungary and Romania focusing on special forces, air power. The same goes for the Allies. South Africa often focuses heavy tanks and Canada is often the air controller for the Allies. It also allows people to focus their micro. When I play Germany it helps so much not having to micro aircraft. Newer players can play in "high level" / semi serious games by being a minor country and performing a few specified tasks.
 
Last edited:
Does this mean you are creating an AI A-Team? A team responsible for all the AIs in your games? It is really a good idea in my humble opinion. I also applaud the scripting idea for different responses in the various nations. Less weird things to happen due to cross code responses.
Answer to those questions is both yes and no. Each team organizes their own AI development, but we do organize everyone actively doing AI work into regular synch-ups for knowledge sharing and such. I am responsible for this, and while it is not a dedicated team as such, the effect is along those lines.
 
Nice map change i see there in Wielkopolskie, but theres just 2 more things i'd like to mention
the province highlighted below should belong to Austria, not Slovenia (I believe it was part of the Carithian plebiscite, but ultimately it remained with Austria)
D9E914324A11BB8E6490638F19F8421345E06B32

Actually this is very true. Have a look here where the region is marked as disputed:

austria_after_wwi.jpg

http://www.emersonkent.com/map_archive/europe_1919.htm

After the Carinthian plebiscite in 1920 the region was placed under Austrian administration:

https://en.wikipedia.org/wiki/Carinthian_plebiscite,_1920

So should really be changed.
 
While I don't question validness of the province move to Austria, the map you've linked is ridiculously bad.

This is because technically speaking it is not a "map". However it makes the disputed state of the province after the Paris Peace Conference in 1919 visual. If you want to see if the province was under Austrian or Yugoslavian control in 1936 you may just double check any map you find appropriate from before WWII and you will see.
 
Whould you fix AI behavior for Germany (When Poland go fasist so Germany AI select Danzg for Slavakia), and Romania Behavior so they betray Germany around 1944 if historical path is on. And Finaly Yougoslavia so they ally with Germany and be a victiom op anti german uprising if history path is on.
 
Paradox, you are making a good job and all, but you can at least edit the Imperial borders in Poland like the mod people of the Iron Curtain cold war mod did it. Not only will I feel godo while blitzkrieging over France but I will feel like good old Kaiser willy. Please do! Sorry that I look like I am demanding it's just that I am a border maniac
 
What about reducing division spam from minor nations during late game? That would remove a lot of the lag from units as proven by the Expert AI mod. Countries like El Salvador spamming hundreds of divisions late game causes a lot of unnecessary lag.
 
What about reducing division spam from minor nations during late game? That would remove a lot of the lag from units as proven by the Expert AI mod. Countries like El Salvador spamming hundreds of divisions late game causes a lot of unnecessary lag.


Podcat's reply to Leutnant Walker seemed to say that the developers were working on the division spam problem.

upload_2018-2-24_4-53-57.png