• 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:
Speaking of AI, can they stop suggesting changes to Federation laws after failing a few times? The players can see how likely a law can pass and will rarely nominate a laws that's sure to fail to avoid hurting Cohesion, but the AI will happily spam the same Changing Enable/Disable migration law off cooldown, absolutely nuking cohesion and destroying relation.
Also unrelated, but any plan to buff The End of Cycle? The Reckoning itself has been powercrept heavily and is barely a threat nowadays.
 
  • 11Like
Reactions:
Well, this looks solid in my view. With an eye to rare resources: Will the AI be able to upgrade buildings? I know its not "meta" to upgrade, but building up planets to higher tiers is a problem since the release of 2.2 and was always involved in the fast crumbling of competitiveness when certain upgrades are available even for casual non pro players.
 
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
}
Would it be possible to have those targets be scripted variables? Alloys needed scales with the fleet you want to support, so perhaps the final alloy target should be a multiple of your naval capacity. Research and unity targets could be a multiple of population. It seems like any hard target you set will get outstripped by empire size in the late game, so a dynamic one should be the goal.
 
  • 6
  • 4Like
Reactions:
I really love the Custodians work, but do you guys have an idea of when will the devs start sharing plans for the next actual expansion?


EDIT: wait, what? I just asked a question, why is everybody downvoting?

If you do anything else than praise the dev you are downvoted to hell.

I'm frequently downvoted just for respectfully disagreing with some choice (like using Unity for the admin cap like it will most likely be reworked).

You will get used to it.
 
  • 11
  • 1Haha
  • 1
Reactions:
Would it be possible to have those targets be scripted variables? Alloys needed scales with the fleet you want to support, so perhaps the final alloy target should be a multiple of your naval capacity. Research and unity targets could be a multiple of population. It seems like any hard target you set will get outstripped by empire size in the late game, so a dynamic one should be the goal.

Plus modifier for the difficulties. Grand Admiral AI should have higher goal than Captain AI for example.
 
  • 1Like
  • 1
Reactions:
The final sub-plan that we're currently looking at is set up as follows:
Does the AI consider things differently if it is significantly above its target? For example, if the AI has a planet with many high-level bureaucracy buildings but then loses that planet in a war, it will have a very large income of rare crystals as it will no longer have to pay the upkeep of the lost buildings. Does the AI know to maybe replace some of its synthetic crystal plants with other buildings as it has such a surplus income? Or does the AI just sell to the market when it has a large excess of rare crystals, which in some ways goes back round into its economy to focus on other areas?

Also, is there any way to make the numbers a bit more dynamic? For example once a nation reaches repeatable techs, research becomes much less useful so usually it is best to focus on alloys at that point. Is it possible to make @research_target dynamic such as if the (techs researched)/(total tech tree) >= 90% then research_target = research_target/2 or /3 or etc? or something like if total_num_repeatables_researched >= 10 then reduce the research_target in the same way? Or would making the numbers dynamic add too much complexity and maybe the AI should just switch to a different plan?
 
  • 2
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
}
Will there only be one "final" sub-plan with equal priorities for all empires? It would be great if the priorities after the basic needs are met are decided by the government type of the AI - e.g. a "Star Empire", "War Council" or "Military Junta" would prioritize alloys over consumer goods, vice versa for a "Trade League". A Technocracy would immediately prioritize science, and an ai curator might want to go for a combo of societal research and robot stuff. Maybe there could be a ordered priority in the government type file, which sets this priority. It would make it easy to mod, and would give empires distinct flavors.
 
  • 2
  • 1Like
Reactions:
Looks like the dev blog mostly covers changes that were already implemented to some extent in 3.1, but I'm happy to see this given being more visible attention and am happy that iterations on the stuff in the blog are coming in 3.2 as mentioned.

For any players who are interested in this topic, we have an active thread here discussing various bug reports and observations:

After the economic AI is shored up a bit, the next obvious problem to tackle is the military AI -- which also has issues.

My ultimate desire is to be able to win as a peaceful federation builder with my allies carrying the military load and effort against the endgame crisis, on default settings. Seems like it should be doable someday.

Big fan of this being a Custodians team priority!
 
  • 1Like
  • 1
Reactions:
One more note, I'd love it if the best alien-empire AI improvements were somehow transitioned to the player-empire planetary/sector AI, which also needs a lot of fixes/improvements.
 
  • 2
Reactions:
Incredibly stupid question: when we will know the theme of the next DLC? I still waiting for those biomechanical/biological shipset and Aquatic Species Pack...
 
As long as the asteroids take more than a month to hit, and the game runs smoothly without having to commit xenocide, I'm a happy guy!
 
  • 1Like
  • 1
Reactions:
Will the AI still build a starbase in every system with a gate?


It's not necessary, gates are not wormholes, if at war, nothing hostile can come out of it.

Unless it thinks gate systems are of strategic value and should be protected? But in practice, the AI guard systems even when it's 100 years away from activating the gate, so it's a useless expense, maintaining that starbase in every gate system.
 
Speaking of AI, can they stop suggesting changes to Federation laws after failing a few times? The players can see how likely a law can pass and will rarely nominate a laws that's sure to fail to avoid hurting Cohesion, but the AI will happily spam the same Changing Enable/Disable migration law off cooldown, absolutely nuking cohesion and destroying relation.
Also unrelated, but any plan to buff The End of Cycle? The Reckoning itself has been powercrept heavily and is barely a threat nowadays.
I agree. this can ruin a federation, because they just won't stop suggesting stuff that you are forced to downvote. CONSTANTLY. It's a death sentence to relations and the federation.

They should restrict the number of how many times you're allowed to vote on something, based on the number of envoys you commit or something.

Like if you commit 1 envoy, you get to propose something once per year, or once per 5 years, or once per president cycle, or whatever...

If you have zero envoys - you don't get to propose anything, ever.

Fair is fair, no? If you don't care to send an envoy to the federation, then shut up and take whatever they do up there in the federal HQ.

I think locking more diplomatic options behind envoys also makes them more valuable and interesting. And not just a button to click and forget, after the first contact missions are done. I won't comment on the current iteration of the espionage system.
 
  • 4
Reactions:
Looking like great changes.

For AI I would suggest, please make it so that your Federation doesn't constantly spam resolutions you've vetoed 20 times in a row
 
  • 3Like
  • 2
Reactions:
Have you "thought" about helping the AI specialising its planets the way human do?

Last game I played, each time I took a planet and check their buildings it was exactly the same "template" : A bureaucratic center, a random Forge, 2 or 3 district of each

That kind of stupid thing nobody with a functional brain would do in Stellaris.

I had this Idea of a totally separate script which would "swap" building or district between each other in order to regroup them.
It wouldn't change much the production of the AI so it wouldn't overreact by building an other district but their planets would be "cleaner" and the AI would benefit a lot more from buildings boosting production of a particular ressource and from planetary designation.

It would have 2 benefits, the AI being better and the player enjoying more conquered planets, because those are just better and you don't need to rebuild it entirely.
 
AI improvements are great. Hopefully this will mean we no longer need Starnet/Startech AI mod to teach the AI how to play the game.
honestly the AI is still REALLY weak, the only way I play the game now is using "StarTech AI" mod as it actually fixes a lot of the issues with AI.

I think that you know the AI is good when you don't need to increase the difficulty (having the AI cheat resources) in order for it to be a fun game...right now with default AI i need to put it to grand admiral.
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.

And all this whining about the ai getting "cheat" ressources and the existence of a "magic" market is utter nonsense. During the game the player stacks buff modifiers from events like crazy which the ai cannot get. Also there are players which dont want to play competitive all the time and turning singleplayer into a massmurder even on ensign is defenitely not the way. If u want challenge go multiplayer.
And what about all the exploits the player tends to use and call them "skill"?
I believe the bonus ressources the ai gets in higher difficulties are good, as the ai just isnt human and not so good in optimizing. It just has to learn not to make so many mistakes and to take advantage of that extra ressources properly. Combine that with a proper use of the market and an improved military behavior and u will get way more unteresting games than startech ever could.
One way streets like starnet, while the game has potential for dozens of steets is not the way to go. It scares away new players and bores everyone not competitive to dead as it forces competitive play on them without giving them interesting and distinct ai behavior. Where u spawn for example would not matter anymore with even fanatic pacifists begaving like genocidals.
 
  • 8
  • 3Like
  • 1
Reactions:
Have you "thought" about helping the AI specialising its planets the way human do?

Last game I played, each time I took a planet and check their buildings it was exactly the same "template" : A bureaucratic center, a random Forge, 2 or 3 district of each

That kind of stupid thing nobody with a functional brain would do in Stellaris.

I had this Idea of a totally separate script which would "swap" building or district between each other in order to regroup them.
It wouldn't change much the production of the AI so it wouldn't overreact by building an other district but their planets would be "cleaner" and the AI would benefit a lot more from buildings boosting production of a particular ressource and from planetary designation.

It would have 2 benefits, the AI being better and the player enjoying more conquered planets, because those are just better and you don't need to rebuild it entirely.
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?