• 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:
My apologies if this has been changed or mentioned already, I haven't followed Stellaris for a while.

I believe what screws the economic plans is in part the giant bonuses the AU has on higher difficulties. Therefore you should change difficulty settings so that they make buying things cheaper instead of giving resources.
This would work well with the plans and also automatically scale into the late game.
The ai now makes a way better use if the bonus ressources. It still needs work in using the market better and in its military behavior. Having a bigger fleet is still useless for the ai which splits its fleets more and more the later ingame u get and naval capacity as well as research also arent properly build up in lategame.
 
I think we need to abandon the term "AI" for this game, it's clearly just scripts. If this, then that. A finite list of conditions.

To achieve what you're saying, maybe they should just make specific build lists, based on categorizing planets.

Elaborate build lists with hundreds of conditions.

Make the system do 1 check during colonization, to see which category and associated build list to apply.

Make it re-check and adjust the planet category every 10 or 20 years. If the category changes, make the "AI" demolish stuff that does not conform to its current planet-category-applied build list.

I mean this is a super primitive approach but what else can be done, considering the AI approach in this game?
Thats basically what the devs did before implementing economic plans. It went badly wrong, caused deathspiraling and performance hits. The ai now with eco plans performs better than it did in the primitive approach.
 
  • 5
Reactions:
Thats basically what the devs did before implementing economic plans. It went badly wrong, caused deathspiraling and performance hits. The ai now with eco plans performs better than it did in the primitive approach.
Sure.

But I'm thinking how to implement human behaviour with regards to demolishing and specializing planets, and I don't see any answer in the eco plans approach.

That said, I'm way out of my depth here, just thinking out loud.
 
  • 1
Reactions:
My query to throw into this would be: Will AI be able to upgrade/retrofit their military ships again? Something broke in an older update at some point, making it so AI can't actually upgrade outdated ships... Which can lead to quite lopsided fights, even if the AI is on par in tech, its fleets of outdated designs clog up its naval cap.
The ai retrofits its fleets in peacetimes. Or do you mean those broken fleetmanager ships?
 
Do these changes to AI include teaching them how to manage starbases properly i.e. downgrading excess starbases they get in wars, removing "border bastions" that are no longer needed, fortifying chokepoints, specializing starbases, and so on?
They do downgrade starbases sometimes. But i believe the ai receives no penalty on having too many. So the ai does not build starbases over the cap, but can get over it without damaging its eco through war. As soon it gets over the cap however it seems to stop upgrading its starbases. In general it seems that big military successful empires focus less on starbases than smaller, less successful empires.
 
Sure.

But I'm thinking how to implement human behaviour with regards to demolishing and specializing planets, and I don't see any answer in the eco plans approach.

That said, I'm way out of my depth here, just thinking out loud.
I believe proper planet spezialization as well as the ai learning how to create an properly use special worlds like ecumenopolis, resort worlds, penal colony and so on is the next big step the devs plan for the ai. They plan to make the ai more distinct as well as improving it without the need for minmax. So this is the way to go.
 
will this newfound economic competence of the ai lead to less breakdowns of their empires?
Yes - the ai is defenitive more stable. I have seen even empires reduced to one system return from the ashes. Vassals and tributaries however still prefer their breakdowns.
 
  • 2Like
Reactions:
Will the Ai still create 5000 different types of species all with randomly chosen traits?
Yes - i am afraid we have to further keep living with this for quite a while. Diabling xeno-compability helps a bit but i general this behavior and the whole species needs rework.
Its like with factions an unloved child. Currently the focus is on the ai, the empire sprawl rework and the 0 ressource exploits. This fills the time until middle 2022. Maybe if nothing breaks and the ai stays stable those things will be looked at by the custodian team. If u want to bring this into further attention, then make a post in the suggestion tab. The more votes it gets the higher the chance for it to happen (except for army overhaul posts, those get massive votes, but the devs already stated it not being worth the effort)
 
  • 1Like
Reactions:
I believe proper planet spezialization as well as the ai learning how to create an properly use special worlds like ecumenopolis, resort worlds, penal colony and so on is the next big step the devs plan for the ai. They plan to make the ai more distinct as well as improving it without the need for minmax. So this is the way to go.
I'd like to give you a friendly warning to hold your enthusiasm my friend. We've heard this before.
 
  • 1
Reactions:
Finally!!!!! AI can build holo theaters. though, do they still know how to build them efficiently? Also, after some point, the only 2 resources that really matter are tech and alloys, with rare resources coming a distant third. So, will the AI intelligently only target those resources once they reach that " end game" stage?
 
The final sub-plan that we're currently looking at is set up as follows:

Code:
@consumer_goods_target = 30
@research_target = 9999
@unity_target = 70
@alloy_target = 500
@rare_resource_target = 4

income = {
    physics_research = @research_target
    society_research = @research_target
    engineering_research = @research_target
    unity = @unity_target
    alloys = @alloy_target
    exotic_gases = @rare_resource_target
    volatile_motes = @rare_resource_target
    rare_crystals = @rare_resource_target
}
While this is a good step, what will happen after the AI reaches this goal? Also, the alloy target is a bit on the lower side while I cant really say about unity target due to the upcoming changes to unity, but that is wayyyyyy too low for the game as it is today. It would be great if the alloy target can be dynamically set to a value of each shipyard *50 for the final sub-plan. That means the end goal for alloys should be to be able to churn out ships constantly from all shipyards. In case you dont need to build more ships, then that alloy production can be diverted to megastructures/habitats/starbases

EDIT: for a crisis AI, we can also change the alloy/mineral targets as its much easier to spit out 100s of crisis ships using minerals
 
  • 1Like
Reactions:
The final sub-plan that we're currently looking at is set up as follows:

Code:
@consumer_goods_target = 30
@research_target = 9999
@unity_target = 70
@alloy_target = 500
@rare_resource_target = 4

income = {
    physics_research = @research_target
    society_research = @research_target
    engineering_research = @research_target
    unity = @unity_target
    alloys = @alloy_target
    exotic_gases = @rare_resource_target
    volatile_motes = @rare_resource_target
    rare_crystals = @rare_resource_target
}
If this is the final plan it is really small. With 20-30 planets and without any min-max i usually reach over 1k alloy production and up to 20k research until year 2450.

The ai currently really has an issue once it reaches all goals as most of the ressources it gets later above the goals just are wasted. Especially 500 as final alloy target is incredibly low, considering all the alloy u need for megastructures and ships. Even with 1k per month i often just cannot keep up, when rebuilding a fleet lost in war or/and building 2 megastructures at the same time.

Does the ai at least start to focus in increasing its naval capacity with fortresses (anchorages at that time probably are already all used up) once its subplans are all fullfilled? Especially on habitats the ai has lots of space for them.
 
  • 1Like
Reactions:
i still cant believe what im seeing; they actually went for the ai!? seriously. cant wait to get my hands on the new update/dlc. i also hope that theyll improve the way the ai handles specialised planets and link rulers charakter traits to favourised ai behaviour (maybe even as some sort of agenda)

great job guys, i so much looking forward to it!
 
Last edited by a moderator:
  • 1Like
Reactions:
The final sub-plan that we're currently looking at is set up as follows:

Code:
@consumer_goods_target = 30
@research_target = 9999
@unity_target = 70
@alloy_target = 500
@rare_resource_target = 4

income = {
    physics_research = @research_target
    society_research = @research_target
    engineering_research = @research_target
    unity = @unity_target
    alloys = @alloy_target
    exotic_gases = @rare_resource_target
    volatile_motes = @rare_resource_target
    rare_crystals = @rare_resource_target
}
Does an AI which became the crisis have a higher mineral target?
 
What starnet/startech does is basically letting the ai minmax. Every single ai has the exact same feel and they arent distinct from each other in the slightest. That is exactly what in this dev diary is mentioned of not being the goal. Its quite the opposite of what the devs whant ro achieve.

For non-economy stuff I agree Startech/Starnet is not the goal developers should have, but like I said in my earlier post if the AI empires want to act differently they are going to need a strong economy backing their behaviour, be it aggressive military conqueror or pacifist xenophobes who just want to be left alone. And even in a game complicated as Stellaris is there is only so many ways to build a strong economy and Startech/Starnet has certainly achieved that. Trying to make economies of AI empires different when not backed by economy changing civics just makes them inefficient and the AI economy is not visible behaviour to the player in most cases (conquering AI planet, AI economy grinding to a halt and making the AI empire unable to act etc).
 
  • 1
Reactions:
For non-economy stuff I agree Startech/Starnet is not the goal developers should have, but like I said in my earlier post if the AI empires want to act differently they are going to need a strong economy backing their behaviour, be it aggressive military conqueror or pacifist xenophobes who just want to be left alone. And even in a game complicated as Stellaris is there is only so many ways to build a strong economy and Startech/Starnet has certainly achieved that. Trying to make economies of AI empires different when not backed by economy changing civics just makes them inefficient and the AI economy is not visible behaviour to the player in most cases (conquering AI planet, AI economy grinding to a halt and making the AI empire unable to act etc).
Are there different routes to a strong economy? Are there different viable playstyles that require different economic priorities? If the answer to either is yes then adjusting the exact route of economic growth depending on different NPC "personalities" is a cool and neat goal. If the answer to both is no then, and I don't say this lightly, oof.
 
What starnet/startech does is basically letting the ai minmax. Every single ai has the exact same feel and they arent distinct from each other in the slightest. That is exactly what in this dev diary is mentioned of not being the goal. Its quite the opposite of what the devs whant ro achieve.


Ahh yes becuase nothing says unique feeling AI like:
A materialist who cannot focus tech
A spiritalist who cannot build unity buildings
A militalrist who cannot build vast fleets
A Pacifist who just dies because they won't build defensive fleets.
An AI who'se planets are total trash no matter the ethics.

The only ones that work are xenohiles who just let species run rampant but that's because the AI just doesn't really give a damn about species and will produce all sorts of nonsense traits for everyone, regardless of if they are xenophiles or not.

Purifiers also work, but that's only because they get big buffs.

Just face it, starnet exposes that the only things that really matter is fleet power, because everything else is just fluff. The galactic community is a joke, constantly proposing sanctions and repealing them. Espionage is extremely shallow and doesn't effect anything.
 
  • 3
  • 2
Reactions: