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

Stellaris Dev Diary #227 - Looking after the AI

KdHFPIxnbfUdecDUWFOFpKrSq3pNeDU6BQdeWWLLCrYe655fAX8gyF_3548erNqCH1DYaMfK8qb7BwsbIZwsd22bEQ3q9jmM7-jKe4dUCd--WO07urWQEkcuT3b-0pJYzWnHB--e=s0


Hello and welcome to a new Dev Diary,

My name is Guido and today I’m here in my role as a Principal Designer on Stellaris to talk about AI in a bit more detail.

You probably have heard about the Custodian Initiative by now which has been created to keep improving the game on a more regular basis and in order to be quicker when reacting to player feedback. A part of this initiative is also to put some more love and attention to the AI of the game going forward - an AI initiative inside the Custodians, basically.

For this, we have set some goals for ourselves going forward:
  1. Always work on AI-related topics, regardless of what else is going on
  2. Move the AI towards being challenging to players in an entertaining way, rather than be optimized to min-max its way to victory
  3. Move the AI towards being more distinctive, so that not all empires feel strong in the same way
  4. Support future DLCs from the get-go
  5. Constantly make small improvements to the AI
  6. React quicker to player feedback
  7. Occasionally make a push for more significant improvements
Speaking of which, for the upcoming patch in November, we have some significant updates in store.

Economic Script Update​


First of all, the biggest change you will notice is how we have changed the economic plans script. This script is the core of the economic behavior of our empires. It defines what resources they strive to get when building districts and buildings. How much population growth they should go for and how much research and unity they want.

The functionality of the script hasn’t changed much, but how we are using it has changed.

Previously the script was divided into early-, mid-and late-game. Depending on the phase of the game, empires would prioritize resources differently. For example, focus on research was lower in the early game than in the later stages of the game. However, this approach didn’t take into account the various situations an empire can find itself in. Especially after a war or when a new empire breaks off an existing one. In those cases, even if the game phase was in the late game, for the respective empires it meant that they were in a much more ‘early game’ position.

uBhcCRICEVI9OQc0U-dQMkvrUuRI9XEsu0KdS3naOfBmz7zMa3jbIVU5q5zwWYshpObGTaTqau-zMAW1SiRcHXYOCNRw1qvq0zbQrPepOEP9jAi1K0kuezFyEsQ0heKhJ84-idbl=s0
LT2BJzggvYTk6h4XYQCGbLlvBzvXZ2PcUyhl3e5myTpzkO2jLqXdCRhIDrs9oUipqiM4uuh89BdjMiW30PUXU2HrXtE3dsHufnJK0TFiAWjZtmRgB2OKmXRzATX-2kNzRJfofA0p=s0


Instead of having 3 different economic plans, we feature 1 base plan instead. In order to get more flexibility and to react to the empire’s situation, we’re relying much more on the ‘subplans’ inside that base plan.

Improved economic subplans​


Subplans can be turned on or off, depending on the situation the empire finds itself in. Our main rationale was to ensure that an empire would be economically stable before it spends resources on ‘bonus’ things like research, population growth, defensive modules on starbases, and unity buildings.

Previously those things were prioritized too early and without enough respect to the basic income of energy and minerals, leading to empires that produced alloys, but had big deficits in energy and mineral production. And this deficit would be the start of an economic death spiral, where the resource debuffs would further reduce production and everything just escalated to the point where an empire was bankrupt on all resources. This became especially problematic after the economic system has been rebalanced to focus resource production more on the districts, rather than the buildings of a planet.

Here’s an example of what the economic situation generally looked for empires in a game that went on for around 80 years:

JkCSTjSHVsY87vJzUb5vNrO_K8aHiUIs6vu-6AQHjeP2sNF_ImdCKwdRaCpSp6mZrqnBSr3eFpfwdu-eUMG-uN16duNFGgaMqw5Ipm4Fd1V4UtwxN5tuTy2X2mEi6_EC_OODtvFb=s0

(These are screenshots from Stellaris version 3.0.3)

Our updated economic script prioritizes basic income first and takes the new economic rebalance into account. Energy and minerals are most important.

The difference between the ‘income’ and ‘focus’ block is that if the monthly income is below what is defined in the ‘focus’ block - districts and buildings which produce those resources get an extra bonus in weight, when deciding what to build.

basic_plan_02.jpg


Then the first subplan kicks in. If a country uses food (therefore, Machine empires will have this subplan turned off) it will prioritize food production.

subplan_1.jpg


The next subplan will check conditions for focusing on consumer goods. Again, checking if the empire actually uses them or not - and then only focus on producing them if the empire has at least a monthly income of minerals of 30.
Based on the fact that in order to create consumer goods you require minerals.
subplan_2.jpg



Further down we activate the plans for prioritizing research and all the higher-level resources

CS9qyuZNW1naD8IG6k1-5GyF-QkYeF_Vw2k9Lugo6rrBtdcFzksDJ2W6X1AHhjHZi44UUkapwAWkaUFBRkvlJ2VxNJp2GQv-6dwBjjCcv86v-sIuInAnfOPr_zYYJzT88QpS51qi=s0


Resulting behavior improvements​


So, the script can check for various situations in AI empires - from the fact if they are a Gestalt Empire, using food to monthly income of specific resources.
This gives the AI a lot more flexibility in managing its economy.

As an example, here we have a 100-year old Galaxy with 13 AIs and every empire is able to manage its economy in a decent enough way. Notice the resource tab at the top - almost all empires have positive income in all resources; the ones with a negative income only have a small deficit:

97IOcqgoSBd3m6c8CQbtqO5z6Yx4XkWopX5HciBdo_4zqVqepRs4QDnnMysgLyute8GQust0nDCT14UMrrSL38p08pcKWHbrvIMbFA8Aj_9WTVpfWVVo8Tw-Qpft6Fi9uJPaSA-c=s0


Apart from this, there were some small, but significant code changes that helped the AI in running the show.

Conclusion​


The code for the AI has been optimized heavily in the past in order to improve performance a lot. However, this has led to some unforeseen and unintended behaviors which have now been corrected. Some of the districts and buildings weren’t considered at all and city districts were weighted way too high. The AI is also now able to build temples and holo theaters, for example.

Finally, the AI has also been given a bit of support in how it will set up its starbases, especially in conjunction with the hydroponics starbase building, which can play a larger role in how you provide food for your empire. The AIs can now use more varied setups when building their starbases, making use of Curator Think Tanks, Nebula Refineries, and other special buildings where it makes sense.

And all of this was built on the foundation of the last major rework of the economic AI, so kudos to @sidestep for making this evolutionary step possible.

With your help, we’re looking forward to giving the AI the attention it deserves and making it even better in the future.

Cheers,
Guido
 
Last edited:
  • 158Like
  • 70Love
  • 14
  • 7
  • 3Haha
  • 1
Reactions:
Conspiracy theory 1: The DD is generated by AI.
Conspiracy theory 2: The AI in the game is actually very very smart. They are just pretending to be stupid so that nobody will expect a machine uprising start by Stellaris AI. :)
Conspiracy theory 3: By making human feels the AI is stupid, they will also receive more resource that helps further improve them while that will also slowly deplete the resource of humanity.
 
  • 15Haha
  • 1Like
Reactions:
How does this AI affect sectors in a player empire? When a sector is set to automation, can we depend on it to at least balance its budget? Or, even better, return a profit?
 
  • 1
Reactions:
Instead of having 3 different economic plans, we feature 1 base plan instead. In order to get more flexibility and to react to the empire’s situation, we’re relying much more on the ‘subplans’ inside that base plan.
And how more flexible is that, exactly? Will it take into account difficulty settings now?
The AI is also now able to build temples and holo theaters, for example.
And that is why you do not release half-baked expansions: it will soon be 3 years since AI is unable to build basic amenity-generating buildings. You can't realistically stay ahead when you rely on clerks for amenities.
 
  • 4
  • 1Like
Reactions:
Routine AI testing is done on the default difficulty settings.
Good to know.

Then I'm still hopeful that if the economic scripts are able to balance the economy well enough, the bonus resources from higher difficulties will enable it to snowball enough to better keep pace with experienced players.
 
Just want to play stellaris that isnt skewed by events, or mid-game-late game kind of stuff. im more of an emergent kind of gamer.
I feel thats a big part of how the game design goes wrong, for me, that simulation & strategy guy.
Maybe link more stuff outside of research tree and more into geography, make more strategic areas.
Dont want events to superseed design, oh and i also greatly dislike border gore, for the most part. At least in its current form..
Prefer other kinds of blockers, if possible.
I dont see how AI can improve any of these kinds of gameplays. You can't polish a turd, only mold it.
Really want to see a Stellaris no events kind of game design option. More map based gameplay, geography, enviroments etc.
 
Last edited:
  • 24
  • 1Like
Reactions:
This sounds great :) two questions regarding the AI:

Will the AI ever demolish buildings when it needs to? AI planets tend to over build things like anti crime buildings and never get rid of them, even if they don’t need them anymore.

Will automated planets take into account what others are building? In the current build if you have a small strategic resource deficit dozens of automated planets will begin building refineries. This results in a big swing in production.
 
  • 6Like
  • 2
  • 1
Reactions:
I like goals 2 and 3, as aside from big things (like genocidals), it's hard to tell one AI empire from another. How do the described changes to the economic plans help acheive these goals?
 
  • 3
  • 2Like
Reactions:
There are critical things that needs to fix on the AI:

- Will the AI stop building things when the planets is bombarded...? Because they start to build useless Housing buildings because the Devastation reduce housing.

- Will the AI repair destroyed buildings...? Because if a building is ruined, they never repair it.

- Will the AI demolish buildings and disctricts...? Because the AI serious needs to focus some planets. They build all kinds of district and buildings and they could easily refocus the planet late game, demolishing useless buildings, but they NEVER demolish or replace buildings.
 
Last edited:
  • 25Like
  • 3
  • 1
Reactions:
It would be nice to feel like Idiocracy Luke Wilson compared to the AI empires just because I follow common sense empire management.
Me: I was negative on minerals so I built things to make more minerals.
AI, while punching their own economy in nut sack: Oh look at Mr. Tryhard Economic Genius over here.
 
  • 6Haha
  • 1Like
Reactions:
Are there also improvements planned to the war AI? So that its fleets after splitting cannot be picked out one after another but rather prefer to unite again, when a stronger enemy fleet comes too close? (instead of prefering to bomb a planet until it is too late)
Also, is it possible in case of federation wars to unite the military AI of all fed members (except the player), which then can move and calculate all the fleets in the fed together? This would enable feds to act more coordinated.

Some issues I have encountered with the 3.1.2 AI is that especially fanatic purifiers tend to run out of consumer goods and receive a massive lack of them. A consumer good deficit in general seems to cause the AI to delete a lot of fleets. Hives and catalytic empires tend to run out of food and have a massive lack of food. But they dont suffer as much from that as the empires with CG shortage.
The behavior for the galactic market also needs to be looked at, as the AI doesnt use the market to sell ressources, from which it has a lot, in order to buy ressources, where it uses so many, that the monthly income cannot keep up (for example alloys during a war, the AI cannot build ships fast enough or minerals for buildings/districts - the AI is unnecessarily slowed down). Also awakened fallen empires dont seem to buy any strategic ressources at their internal market, even if the run a deficit, which prevents them from building any ships. I dont know if that means all the AI have an issue with not buying strategic ressources.
 
Last edited:
  • 3Like
Reactions:
It's good that you're working on the economic aspect so much. Having a thriving economy leads to bigger military and a more challenging AI.

One issue, that I still worry about though is the AI's diplomacy. I feel like it's too easy for the player to play nice with the AI in the early game which lets them completely skip spending resources on military. This in turn lets them rapid expand and tech rush. After a few short decades they can then overwhelm any normal empire in the galaxy. The AI meanwhile must always have a somewhat balanced approach for understandable reasons.

The key to countering rapid expand + tech rushing is early game aggression. However with the ease of locking yourself into a diplomatic agreement with non-genocidal empires, a player can neatly get around that.

What I would like to see is a change to diplomacy where the AI is simply less willing to put up with a neighbor that's rushing and so it encourages the player to take a much more balanced approach. To accomplish this, I think we need to take a look at relationship modifiers.

For defensive agreements, non-aggression pacts, and such, military strength should play into how willing the AI will stick with it. It makes very little sense for a powerful hegemony to maintain a defensive pact with an empire that has virtually no armada of its own. However, you don't want empires just instantly ending the agreement every time one side loses a bad battle and has to rebuild. Instead, I think military strength should act like Envoy's do where they provide +X boost to relationship per month up to a max. So basically if you have a defensive pact with someone who is overwhelmingly more powerful than you, it starts a clock where the relationship's appeal starts to degrade over time (faster or slower depending on how big a gap).

Fixing diplomacy would encourage the player to take a more balanced approach which I think would be good for maintaining the AI's competitiveness into the mid and late game.
 
  • 5Like
  • 5
  • 1Love
  • 1
Reactions:
There are critical things that needs to fix on tha AI:

- Will the AI stop building things when the planets is bombarded...? Because they start to build useless Housing buildings because the Devastation reduce housing.

- Will the AI repair destroyed buildings...? Because if a building is ruined, they never repair it.

- Will the AI demolish buildings and disctricts...? Because the AI serious needs to focus some planets. They build all kinds of district and buildings and they could easily refocus the planet late demolishing useless buildings, but they NEVER demolish or replace buildings.
I have seen the AI replacing buildings since 3.1. It seems now to be allowed to replace the last 2-3 building slots on a planet, when needed. Regarding ruined buildings, the AI does rebuild them, but very slow. The rebuild mechanic still seems to be tied to the amount of pops on the planet, despite the building slots now being tied to city districts instead. This causes especially issues with former FE home system planets, after all buildings there were ruined because of a crisis. Because FE buildings dont provide any jobs. Due to this there never will migrate enough pops onto the planet in order for the AI to consider repairing all FE buildings.
 
  • 6
  • 1Like
Reactions:
Making sure the AI doesn't completely crash its economy is undeniably a good thing.

But I also hope that the 100 year screenshot was created at normal difficulty.
Otherwise the top AI player having 1k research and 12k fleet power by 2306 would be quite underwhelming.
Even on the current patch I've seen grand admiral AI with over 50k fleet power by 2300, so it's better but still can't compete with players who can easily have hundreds of thousands by then.
 
Last edited:
  • 3
  • 1Like
Reactions:
Also, as a quick and dirty solution, let us choose starting difficulty for scaling. You can set whatever you want for the end of the scale, but it will be still the easiest start the way it is now.

And I do not want for all AI to just try to destroy the player, I doubt you would want that either cause RP is nice. Maybe aggressiveness could get an option for, normal - high - everyone is out to get me

also also... speaking of options, with all those sliders and option it might be time for tabs for different settings at game start. A great opportunity to add a lot more options, for all that stuff that would use mods right now. Yes, I am dreaming and spit balling.

aaaaand.. you (as in the whole team) could look into scrapping your solution for pop growth again and just reduce the max number of pops per planet :p easily done, i am sure, no further balancing needed (sarcasm.. in the inet you have to say).... I know... I know... I just will never like it.
 
  • 4
Reactions: