• 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:
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).
In startech the ai always chooses the same ascension perks, traditions and even technologies (if possible) in the same order and this is one of the main reasons why the economic ai is considered to be better there. In reality even there is a min max approach in the background.

In my games i always go antimeta and try to optimize sub-optimal playstyles. Thats what makes the most fun too me.
And this is what i expect from a good ai. To be able to get the best out of their empire, without the need to do what is considered the perfect next step, while at the same time behaving more distinct in diplomacy depending on their personality and their current situation (no more friendly hegemonic imperialist or slaver in lategame just because a crisis or genocidal empire happened to cause enough threat for them to federate with a pacifist. No more overly friendly biggest former enemy after being subjugated and so on, currently the positive opinion modifiers just stack too much).
 
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.
I totally agree with this. For some reason all non military options were designed incredibly weak as for some reasons making them strong wasnt considered "fun" by the devs. But to be honest, even if u make them strong via mod, it is the military strongest empire, which ends up having the most power to use them and bully weaker empires.
 
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.
I’ve said this many times: If the problem is making the game too difficult, tie something to the difficulty slider (that barely changes anything right now) or add a toggle.

Don’t force everyone to play a less challenging game even on the highest difficulty just because the other half wants a less challenging game. The galaxy settings are there. Use them.
 
  • 2
  • 1
Reactions:
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.

Assuming a normal non-gestalt empire without any special civics then answer is pretty much no to both like I described in the original post. No matter if the empire is pacifist ("leave us alone in peace") or militarist or whatever they need a strong enough economy to achieve their goals. Gestalts and empires with special civics also need same thing but obviously some things are added or removed (eg. no food for machine empires, higher food demand for catalytic empire).

In startech the ai always chooses the same ascension perks, traditions and even technologies (if possible) in the same order and this is one of the main reasons why the economic ai is considered to be better there. In reality even there is a min max approach in the background.

True, but that is mostly a balancing issue if some techs are absolutely mandatory (eg. resource techs which I'd like to get removed entirely and moved to the planets itself somehow). Like I said, Startech/Starnet is not a good example when it comes to that level of AI behaviour and I don't think developers should follow it blindly but for actually building up the planets something similar would be nice.

Currently the AI basically picks techs and ascension perks at random regardless of the ethics or civics or AI personality which just makes bunch of similar and inefficient empires. This makes ascension perks especially bad as the AI tends to pick one soon as there is a free slot. Like I said in the original post the AI should be able to make some long term plans for picking ascension perks and related technology ("I want to repair the ruined megastructure so I need to research prequisities for mega-engineering", "I want to pick X ascension so I need to save two perk slots even if I currently lack the tech").

My point, as in the original post, is that the economic behaviour of the AI is mostly invisible to the player unless it fails completely, overwhelms the player or the player is playing as a MegaCorp since they interact with the other empires more. The economic AI (especially planet building) should be not entirely hamstrung just for sake making them different. There of course could be (and should be) slightly changed priorities depending on the situation. For example if the empire has friendly relationships and commercial pact with a megacorp they might be more likely to build a commercial zone if the planet has empty building slot and there isn't any other higher priority building (eg. alloy factory) available.

The focus for the different AI behaviour should be elsewhere than in the pure economy/planet building: In diplomacy, war, ascensions etc. which are far more visible the player. Currently the AIs behave very similarly though obviously a Xenophobic empire is less likely to ally without a common threat for example. This is especially visible in the Galactic Community where you can see many empires just proposing random stuff and never cancelling it. Hopefully future developer diaries expand on the possible changes to other parts of AI besides the economy.
 
  • 2
  • 1Like
Reactions:
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.

You are making it sound like the game offers some crazy strategic variety. This is not the case. If you want to do well, you need a good balance of alloy, science and managing your planets properly. As we all know, its not worth to invest into Unity too much, one of the many reasons why Spiritualists suck. So it ends up being a choice between Alloys or Science for everyone. As we can see from the screenshots, the AI can't manage their planets properly, since they don't even build Holo Theatres. And they can neither produce good Science or Alloy output.

What kind of variety do you want? Do you want the AI to build more Holo Theatres than needed? Or do you want Spiritualists AI do build more Temples? Do you want Fanatic Materialists to build more Science Labs? Do you want Megacorp to build a bunch of Clerk Buildings?

If the devs manage to do something like this while still keeping the AI somewhat competitive, then good job. But if they do not, then we will have to switch back to Startech/Starnet AI to make sure the AI can play the game properly. I rather have an AI that can play the game properly than have the AI spam useless buildings and jobs. Because they have been doing this for years already.
 
  • 3Like
  • 3
Reactions:
I welcome any improvement to the AI in terms of making single player more of a challenge because yeah, it's a total pushover at the moment. On the higher difficulties you only face a challenge in the first 20-30 years beyond which the player snowballs. That's the phenomenon that turned me off civ 6: crazy hard AI at game start then if you survive past that point it's a pushover. It's a symptom of generally poor AI where the AI is given lots of cheats that are relevant in the early game.

My main concern is the points of difference between what the player can do and what the AI can do. For example, temporarily restricting certain jobs; overriding default planetary designations, swapping leaders etc. These differences create problems; for the AI in terms of strength; for player expectations; for balance; for testing etc.
 
Last edited:
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.
There actually is!

It called tributary swarms, by outsourcing your energy and to a lesser degree mineral to all your tributary it make your economic plan somewhat different than regular strategy cuz in this playstyle you don't need to build any generator building at all if you get at least 3-4 small tributaries and the need to build mineral jobs is also lower though not to an extent that you don't need to build it.

So instead you would focus all your pops on complex resources such as alloys, CG, research, etc.

I don't know if this actually viable in multiplayer aka competitive play though but it would be cool if there exist ai personality that will try to do this.
 
Sorry I've read only dev posts so maybe somebody already asked this, but:
Could you fix the bonus from difficulty not applying to vassals?
 
  • 3
Reactions:
Sorry I've read only dev posts so maybe somebody already asked this, but:
Could you fix the bonus from difficulty not applying to vassals?
That's deliberate.

You're not supposed to be able to leverage AI difficulty bonuses.
 
  • 4
  • 1
Reactions:
That's deliberate.

You're not supposed to be able to leverage AI difficulty bonuses.
One issue is if you vassalise someone they suddenly lose all their bonuses and their economy collapses. They need to either keep their bonuses or enter some kind of emergency mode that facilitates the transition to a bonusless future.
 
  • 5Like
  • 1
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?

My suspicion is that everyone is kind of sick of new content that just increases the game's tech debt (especially after the lackluster reception for Nemesis), which is why the Custodians generated such a buzz. So you got downvoted for asking about a new DLC when the current mood here is for more free patches to improve the AI and fix bugs.
 
  • 7
  • 3Like
Reactions:
For me the AI was pain my eye for quite some time. I am glad that devs seem to know what would improve the game. I love those changes but I would fully satisfied if the AI started handeling the ship design more in the later game. They usually forget to upgrade to final techs, change up fleet compositions and there are probably few other changes needed.
This would fully satisfied me.
I had a lot of trouble doing some achievments due to AI being too stupid to cooperate.
Many mods that improve the AI have issues in other sections like diomacy or galactic community and it kinda sucks to lose such aspect of the game.
Anyway thanks for your hard work!!! :)
 
One issue is if you vassalise someone they suddenly lose all their bonuses and their economy collapses. They need to either keep their bonuses or enter some kind of emergency mode that facilitates the transition to a bonusless future.
No more special modes, thanks. It should react just the same as if it lost a resource planet in a war. The AI needs to be made more generalised, not more situational.
 
  • 1Like
Reactions:
I would like to see the AI become more war-like with other players, human or AI. In every game I play, I get maybe one or two notifications of conflict with the rest of the galaxy at peace until the middle game. I think the AI was designed that way so as to give the player time to expand his empire, but it makes for a very boring early game where nothing ever happens. I would like to see more opportunities for conflict, much like in CK3 where a minor incident can snowball into a war at any time. I guess I am asking for not necessarily a more aggressive AI as much as more tempting opportunities for AI to go to war (if that makes sense).
 
The AI should certainly have some goals, but the end goal can't be to just do nothing. Improving alloy and energy production can always be a goal in order to go over the fleet cap. Except maybe for pacifists.

I'd like to see differentiation in the outward behavior though, depending on ethics and/or personalities. Militarists focus on fleet power and conquest. Xenophiles try to make lots of treaties and a federation. Materialists focus on science. Certain empires should make vassals instead of conquering. Things like that. That can all run on the same economic AI.
 
Last edited:
  • 1Like
Reactions:
I love all that this has the potential to do, so thank you.

Do you think there’s any scope to helping the AI to be better in terms of working with its federation members or at least make the AI more reliable in using federation ships ‘responsibly’ and in keeping with the purpose of the federation type? This is important to me for my single player games and I would hope would have a big impact to other peoples games too.
 
I would like to see the AI become more war-like with other players, human or AI. In every game I play, I get maybe one or two notifications of conflict with the rest of the galaxy at peace until the middle game. I think the AI was designed that way so as to give the player time to expand his empire, but it makes for a very boring early game where nothing ever happens. I would like to see more opportunities for conflict, much like in CK3 where a minor incident can snowball into a war at any time. I guess I am asking for not necessarily a more aggressive AI as much as more tempting opportunities for AI to go to war (if that makes sense).
What are your galaxy settings? Anecdotally, I've seen a lot more AIs declaring war with a high number of empires (e.g. 15 on a 600 star galaxy) with normal aggression than I do with a low-medium number of empires on high aggression. When the AI gets boxed in and can't expand anymore, it gets pretty upset with its neighbors and will likely declare war. With the upper end of the empire count scale, that happens frequently well before 2250.

Also, I think the war declaration notifications may be locked behind a certain amount of intel (which personally I'm fine with). I've noticed a lot of my neighbors go to war in the early game without me noticing, possibly because I haven't discovered their opponent, which can contribute to the early game seeming more peaceful than it really is.
 
  • 3Like
Reactions:
Resources are negative penalties are very serious, will allow other production to reduce more than 50%, adjusted to represent ai resources very large enhancements
 
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
}
Seems a bit low for a endgame target (beside the research)

also i am not uite sure, but does the AI try to achieve these in parallel or one after the other?

what is the income target for the plan before this one?