Stellaris Dev Diary #172 - Reworking the AI

  • 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.
Showing developer posts only. Show all posts in this thread.

MatRopert

HoI4 Tech Lead
Paradox Staff
4 Badges
May 11, 2018
459
3.705
mropert.github.io
  • Hearts of Iron IV: Death or Dishonor
  • Hearts of Iron IV: Expansion Pass
  • Battle for Bosporus
Bonjour everyone, it’s the French Paradox speaking! For those who don’t know me, I’ve joined the Stellaris team this December after a year and a half as a programmer on Europa Universalis IV.

Today, we are gonna talk about AI.

pasted image 0.png

A good introduction for those new to the field

Fifty Shades of AI
There are several AI modules in Stellaris. For historical reasons we call them “ministers” as each one is supposed to handle a specific role in an AI empire.

There are 3 broad kinds:
  • The AI foreign minister handles diplomacy, federations, galactic community, peace deals and the like
  • The AI interior minister is in charge of the economy. He keeps budgets and order constructions, both civil and military.
  • The AI military minister is in command of all troops and military fleets, and also responsible for laying out strategic plans when at war.
For each of those ministries there are different “ministers” there are several options that can be selected for every empire in the game. All of those have generic one which behaves more or less like we’d expect a player to and is used for most AI empires. Then we have a bunch of specialized ones for special tags such as space monsters, fallen empires, crisis, marauders and the like.

As almost everything in our games, AI is configurable in script for our modders, although I’m not exactly sure what would happen if you assigned a space monster military AI to the caravaneers ;)

In guise of a welcoming gift when I joined the team, I was tasked with reworking the military one...

The Military AI
To give you a little bit of background, there were several generations of military AIs in Stellaris. The generic one (used by most “classic” empires) was redone by the great @sidestep last year, while the more specialized ones (crisis, space monsters) have kept close to what they were on release. In the midst of the sad and dark swedish winter, I managed to bring some improvements that I’ll showcase today.

First of all, I worked on visualization to help us debug how the AI “thinks”. Funny thing is, it already made it look “better” to audiences even if it didn’t actually change any behaviour. It’s actually something that’s been observed in video games: a good AI tells you what it does, which makes it look smarter. One of my favourite examples of that would be the enemies in FEAR.

So by typing 'debug_ai' in the console and observing an AI empire, you can see what it has in mind:

pasted image 0 (1).png

“I don't even see the code. All I see is blonde, brunette, redhead. Hey uh, you want a drink?”

As a simple analogy, imagine that the AI has a war minister that looks at the big picture and rates every potential target, a general staff who assign fleets to some of those objectives, and then admirals who try to lead those fleets on a tactical level to achieve those objectives.

The skulls on top of each system shows military objectives that the AI is considering (the war minister). Red ones are the ones they selected and committed some fleets to, while green ones are other options they haven’t retained for now. Finally for each individual fleet, in those task forces, you see what they are doing at present.

In our screenshot example, the AI decided that taking Tiralam was the most important objective with a score of 4500, and that they estimated that at least 11.2k fleet power was needed to accomplish this. They committed the Kilik Armada, the Jinki-Ki-Ti Armada and the the Grekki Armada to this. Since it makes little tactical sense to attack in a dispersed formation, the AI issued orders to regroup in Broon’s Singularity before proceeding on the attack (something we improved in this patch).

For convenience, the summary is also visible in the outliner:

pasted image 0 (2).png

As seen from the other side of that war

That change alone allowed us to see where the AI was a bit weak and also made evident a few bugs in the production AI that we promptly fixed. A funny one was that in some cases a fleet would end up assigned to two different fleet groups, nicely simulating two admirals fighting over command of a fleet and issuing contradictory orders every day.

Crisis AI
The next step was to rewrite the various crisis to use the generic AI, so that any effort spent on making better would benefit all. In patch 2.6 the specific AI of the Khan, the Prethoryn, the Unbidden and the Contingency will use the same AI as the “standard” empires, with a few twists to still retain their personality.

Without spoiling every secret, here’s a few ideas:
  • The Khan doesn’t really believe in defense and will try to beat the closest systems into submission
  • The Prethoryn will swarm in every direction they can
  • The Contingency will systematically try to stop the biggest threat to the galaxy, until nothing remains
  • The Unbidden will be harder to predict, but there’s reason behind their alien way of acting.
One of the biggest challenges we faced was assigning fleets to objectives. Matching X fleets with Y out of Z objectives is not an easy task. Do we try to accomplish as many objectives as we can at the risk of spreading too thin or accomplishing nothing of value? Should we instead focus on the most valuable target and possibly end up in a big fight that we could have avoided? How often should we reconsider our options?

The current version solves this by putting a fleet power value on every target, then grabbing fleets by order of priority until it either has enough to accomplish the objective, or go over the next one. This approach showed its limits when we plugged the crisis AI into it, as it relies a lot on the size of available fleets (it doesn’t know how to split them, it can only merge them).

Teaching the AI how to split fleets proved quite interesting:

pasted image 0 (3).png

What shall we do with this knowledge?

It took several tries to find a good balance, as the AI tended to split too much (most objectives don’t call for that much fleet power, unless you’re fighting your enemy main fleet). In the end, after trying some complex strategies such as keeping statistics on accomplished objectives and deriving a good target number from that, a simpler approach turned out more efficient: put all the nation’s offensive fleet power into one stack, and then consider splitting in 2,3 or more depending on how confident the AI feels about its military power versus its foes.

Knowing some of you like to mod our AI, here’s some new defines you may want to play with once all that hits the shelves.

Code:
# Objective values
HORDE_INVASION_PLANNING_DEPTH = 5    # How far out does the Horde AI looks for invasion targets (in system hops)
SWARM_INVASION_PLANNING_DEPTH = 5    # How far out does the Swarm AI looks for invasion targets (in system hops)
SWARM_POP_TARGET_MULT = 1.0            # Extra target scoring for swarm (multiplied by number of edible pop on the planet)
CONTINGENCY_MEGASTRUCTURE_EXTRA_VALUE = 4    # How attractive are megastructures to the Contingency (added to the base value of 1)
UNBIDDEN_PORTAL_EXTRA_VALUE = 20            # How much does the Unbidden want to defend their portal (compared to base value of 1)
UNBIDDEN_BYPASSES_EXTRA_VALUE = 4            # How attractive are bypasses to the Unbidden (added to the base value of 1)
UNBIDDEN_RIVALS_EXTRA_VALUE = 10            # Extra target scoring for rival invaders (Aberrant and Vehement)
UNBIDDEN_TARGET_EXTRA_VALUE = 10            # Extra target scoring for randomly chosen nemesis
UNBIDDEN_PSIONIC_CONQUER_DESIRE = 20        # Extra weight added to psionic empires when rolling a nemesis (base 1 + number of owned bypasses)
UNBIDDEN_CHOSEN_ONE_CONQUER_DESIRE = 50        # Extra weight added to empire lead by the chosen one when rolling a nemesis (base 1 + number of owned bypasses)

# Fleet sizing
OFFENSE_VS_DEFENSE_STRATEGY_ALLOTMENT = 0.75 # How much of its fleet power should a country with 1.0 aggressiveness should try to commit to offensive missions
AVERAGE_FLEET_SIZE_FACTOR    = 0.05            # Ballpark estimate of the minimum size a fleet should be in relation to total fleet power
OWN_FLEET_POWER_FACTOR = 1.0                # How much does AI count its own fleet power when evaluating forces
ALLY_FLEET_POWER_FACTOR = 0.5                # How much does AI count ally fleet power when evaluating forces
ENEMY_FLEET_POWER_FACTOR = 1.0                # How much does AI count enemy fleet power when evaluating forces
FLEET_SUPERIORITY_FACTOR = 1.5                # How stronger should the AI be before it starts considering splitting fleets (fleet count = relative strength / this factor)
CRISIS_FLEET_SUPERIORITY_FACTOR = 1.0        # Same as previous but will be compared to the strongest foe in the universe

Most of those changes will be delivered in the patch coming alongside the Federations release (2.6.0), but not all. As you may imagine, changes to the military AI are quite impactful and we don’t want to release the changes without enough testing, so some of them will be delivered in the first support patch (2.6.1).

And with that, I shall leave you with @sidestep one last time.
 
Last edited by a moderator:
  • 2Like
Reactions:
What is an economy AI and where do I buy one?
Hey all spacefarers, Zack aka. sidestep here. While The French Paradox has been hard at work on the military side of the AI I’ve been occupied with the AI economy, which is important as we all know that credits make the worlds go round.

all this ec.png


So what is an economy AI and how does it work in Stellaris? Well, that could be an entire dev diary in itself and differs from game to game. But in short an economy AI decides when and how the AI should spend its resources as well as how it should work to get more of those resources. In Stellaris specifically the AI handles things such as trade, mining bases, starbase modules, policies, edicts, job favoriting and more. But perhaps most importantly the economy AI handles what is constructed on your planets!

Construction is at the core of the Stellaris economy, buildings and districts fuel your economy and help grow more pops, which in turn means more resources. Previously the economy AI did construction on a planet-by-planet basis and with no long term goal in mind. At regular intervals it would go over all planets it owned and through scripted weights it would find something “good” to build, queue it, and then move on and do the same for the next planet and so on. There exists some fundamental problems with doing construction this way however.

The Problems
Firstly it’s very script intensive and requires lots of script maintenance and balancing. If you change how a building works or basically anything in-game which changes the economic balance then you would end up having to rewrite a lot of script. “Oh, if we change this then we would need more alloys but if I increase the weighting for foundries then that would mean that this other building was not built often enough and then if we change that then…”, you see the issue?

What we ended up with was huge, complex, and very explicit and static scripts for each building with a lot of hard to follow ( and expensive to compute ) if/else statements with different weights that nobody could keep track of in the end. Below is an example AI weight script for a single building.

Code:
ai_weight = {
        weight = 0
        modifier = {
            weight = 10
            OR = {
                planet_crime < 15
                has_building = building_hall_judgment
            }
            is_capital = no
            free_amenities > 2
            owner = {
                has_monthly_income = {
                    resource = minerals
                    value > 100
                }
                has_monthly_income = {
                    resource = alloys
                    value < 100
                }
                has_monthly_income = {
                    resource = alloys
                    value > 6
                }#Check for alloy shutdown
            }
        }
        modifier = {
            weight = 200
            planet = {
                is_capital = yes
                NOR = {
                    has_building = building_foundry_2
                    has_building = building_foundry_3
                }
                num_buildings = { type = building_foundry_1 value < 3 }
                has_building_construction = no
            }
        }
        modifier = {
            weight = 400
            OR = {
                AND = {
                    owner = {
                        OR = {
                            has_monthly_income = {
                                resource = consumer_goods
                                value > 0
                            }
                            country_uses_consumer_goods = no
                        }
                    }
                    NOR = {
                        num_buildings = { type = building_foundry_1 value > 1 }
                        has_building = building_foundry_2
                        has_building = building_foundry_3
                    }
                    owner = {
                        has_ai_personality_behaviour = conqueror
                        OR = {
                            has_ai_personality_behaviour = opportunist
                            has_ai_personality_behaviour = purger
                            has_ai_personality_behaviour = propagator
                        }
                    }#Agressive empires but not robot liberators as they tend to be erudite explorers and the like.
                }#Give agressive empires 2 alloy factories on planets early on.
                NOR = {
                    has_building = building_foundry_1
                    has_building = building_foundry_2
                    has_building = building_foundry_3
                }
            }
        }
        modifier = {
            factor = 0.5
            free_jobs > 3
        }
        modifier = {
            weight = 500
            has_building = building_foundry_1
            free_building_slots = 0
        }#Repairs
    }

How does weight 200, 400 and 500 compare to other weights of buildings in other files? I have no idea.

Another problem is that an AI working this way is extremely reactive, and not very proactive. It has low income of something which leads to a script evaluating a certain building very high and it then builds that, that’s fine. But what if you’re doing quite alright? How do you then determine what to build? You would have to add even more script that says something along the line of “if you’re doing okay in all these resources then this should be built, but don’t value it too high because maybe we are in need of some auxiliary resource, hmmmm…”, you can see how this would be hard to script and would easily conflict with other script. It’s also a problem because this would all have to be manually maintained and updated as well, in each script for each building.

Yet another issue is that by doing this on a planet-by-planet basis in script we have no real idea of what has been built on any other planet or for what reason. This means that if we on one planet evaluate that an energy producing district is needed because we are running low on energy and then queue that, we will most likely queue the exact same district on the next planet we check since the situation looks exactly the same to the evaluating script even though when construction is done of the first district we might be fine and the second district would then just add to an unnecessary surplus. This might sound like a small issue but imagine if this happened on 12 different planets, it could swing an AI economy completely in the wrong direction and have massive long term consequences. The AI could even end up having to destroy some of those districts to make room for something else, making the entire effort a wasted one.

There were other smaller issues as well, but these were the main ones I wanted to address:
  • Less complex and hard to maintain script
  • More proactive AI planning
  • No isolated planet-by-planet construction
  • Overall better economic AI performance
The Solution aka. The Plan™
The wonderful Stellaris QA had put together a list of economic metrics that they thought the AI should be able to achieve at a certain point in time. They had a set for the early game and one for the late game. I started designing and planning how I would do this rework and came to the conclusion that the AI needed to actually plan long term, and not just react to whatever happened to them economically. This tied nicely into these performance metrics that QA had compiled so I just thought “hey, why not make these actual goals in the game!?”, and so the AI Economic Plan was born. The economic plan is at the core of the new economic AI, from the plan the AI derives exactly what it needs to reach the plan goals and decides how to do it in the long term. Plans are fully scriptable objects that simply set goals that the AI should aim for and when. Plans can either be for the early, middle or late game. They also have potential triggers and AI weights so that you can script exactly who, when and why an AI should pick a certain plan ( plans are only replaced when they are fulfilled or no longer valid ).

Code:
early_default_plan = {
    type = early

    income = {
        energy = 50
        minerals = 200
        food = 50
        consumer_goods = 50
        alloys = 100
        unity = 50

        physics_research = 200
        society_research = 200
        engineering_research = 200

        exotic_gases = 1
        volatile_motes = 1
        rare_crystals = 1
        sr_living_metal = 1
        sr_zro = 1
        sr_dark_matter = 1
    }

    focus = {
        energy = 10
        minerals = 30
        alloys = 50
        food = 10
        consumer_goods = 20
    }

    pops = 500
    empire_size = 1.25

    potential = {
        country_uses_consumer_goods = yes
        country_uses_food = yes
    }

    ai_weight = {
        weight = 1
    }
}

Above is the default early economic plan used by regular empires. As you can see the potential trigger ensures that no hiveminds for example use this plan since that would mean that they started producing lots of consumer goods that they don’t need.

Below I will go through each scriptable field of the example plan, so if you’re not interested in scripting your own or more in-depth how the system works you can skip this part

‘type = early’
The type field determines during which part of the game this plan is considered valid, this particular one is valid for the early game so it will only be considered until you reach whatever year has been set as the mid-game start year in the game settings.

‘income = {}’
The income field contains the main economic plan goals that the AI will try to reach when having this plan. Here you can script any available strategic resource followed by how much net income the AI needs to have before it considers that resource goal fulfilled. NOTE: If a resource is not scripted here then that means that the AI will not actively try to build anything that produces that resource, it might do that because a certain building produces something else it needs though.

‘focus = {}’
The focus field can be used to set special focus goals ( net income ) for resources that the AI should specifically try to reach before anything else. This field is great to use to ensure that the AI never dips below a certain net income, and that it makes sure to produce certain resources early on even if there is no deficit of said resource. Minerals and alloys are good example of early game focus resources because the AI needs to produce a considerable amount of them to be competitive, just staying above 0 net income is not enough!

‘pops = 500’
The pops field is the goal number of pops that the AI will try to reach. It will not stop producing pops when this number is reached, however pop growth and assembly buildings will be weighted much lower in favor of more resource production when the goal has been reached.

‘empire_size = 1.25’
The empire_size field denotes, in percentage, a threshold under which the AI should try to keep its Empire Sprawl. In this case 1.25 means that the AI should try to keep its early game Empire Sprawl under 125% of capacity, so that it does not incur too many penalties but still can tolerate some.

‘potential = {}’
The potential field is a standard trigger field, scoped to the AI country, where you can script which type of countries are allowed to use this plan. The base plan potentials are just to ensure that different empire types produce only the resources they need, but you could also script things like special economic plans for when you are at war or if you are in a federation etc.

‘ai_weight = {}’
The ai_weight field is a standard weighting field that you can use to script how much the AI wants to use a certain plan. Since there is only one possible plan per country type and era right now all weights are just set to 1, but you could script up lots of different plans and weigh them differently for different empires based on for example personality, ethics or any other AI property.

Executing The Plan™
So how does the AI turn these plans into anything actionable? Good question! At regular intervals the AI will look at its current economic situation ( income, deficits, budgets etc. ) and compare it to the goals set in the currently active plan. From this it will derive exactly what it needs to reach those goals and create a build plan from that. The build plan is basically a prioritized list of buildings ( or districts ) that the AI wants to build on different planets.

build_plan.png

This build plan can be viewed in-game while hovering an empty or locked building slot with ‘debugtooltip’ enabled and can look something like the above image ( the number is the score that the AI has calculated for that building ). The AI will recalculate this plan at regular intervals as well, so that it does not stick to old plans that are no longer relevant.

The AI constructs this build plan by finding out exactly what it can build, what those buildings actually produce when built ( including resources from jobs ) and then try to mix and match buildings to as effectively as possible fulfill the goals identified from the economic plan. This of course takes into account any building upkeep costs or tech limitations present. A benefit of this system is that you no longer have to explicitly script when the AI should build a certain building, instead it will dynamically figure out what each building produces in code. This also means that it is way quicker to add new buildings that produce different resources since you don’t have to manually script how the AI should handle them. Moreover the build plan also tries to take into account on which planet a building would produce the most and build that building there, making the AI more likely to create specialized resource-production planets like “foundry worlds”. It will also not build anything on planets that already have several free jobs. Since this is now done on an empire-wide basis and not planet-by-planet the AI can keep track of and work towards an overarching goal instead of looking at planets in relative isolation. The AI will still go through all your planets to see if any of them are missing housing, amenities or any other planet-specific resources. These buildings are however still part of the economic plan and so if you REALLY need another resource then one of your planets might have to live with an amenities deficit for a while.

So how does the AI actually prioritize the different buildings in the build plan? Another great question! To answer that we need to look at how the AI scores different buildings and districts. The scoring function takes several parameters into account: income needed to reach plan goals, income needed to reach focus goals, current income and deficits, resources produced, miscellaneous resources ( amenities, crime, housing etc. ) produced and lastly if it contributes to pop growth or assembly. The given building gets a score for each of these parameters that is factored by how much we are currently currently missing in that category and how much this building would help to rectify that, along with a defined multiplier. We then add even more score to it if it produces a resource in which we currently have a deficit or if it brings us closer to our focus goal. NOTE: The system remembers all queued buildings so if we have queued 4 mineral districts and that would fix our current mineral deficit then the 5th mineral district would not get the extra deficit score!

Code:
AI_DEFICIT_SCORE_MULT = 50                    # AI will score buildings producing resources in deficit this much more
        AI_FOCUS_SCORE_MULT = 10                    # AI will score buildings producing focus resources this much more
        AI_AMENITIES_SCORE_MULT = 2                    # AI will score amenity buildings this much more than other misc resources
        AI_HOUSING_SCORE_MULT = 5                    # AI will score housing buildings this much more than other misc resources
        AI_CRIME_REDUCTION_SCORE_MULT = 2            # AI will score crime fighting buildings this much more than other misc resource
        AI_ADMIN_CAP_SCORE_MULT = 2                    # AI will score admin cap buildings this much more than other misc resource
        AI_POPS_SCORE_MULT = 5                        # AI will score pop growth and assembly buildings this much more ( already fairly high weighted  in code )
        AI_UPGRADE_SCORE_MULT = 40                    # AI will score building upgrades this much more ( since they don't take up a new building slot )

Above you can see the multipliers applied to each of these scoring parameters, these are all defines and can therefore be modded.

stellarist maths.png

This all sounds very complicated and “maths-y” so let’s do a quick example to illustrate. If Blorg currently has a steady income in all resources except for minerals where net income is -1, and is using the default plan as outlined above with a mineral income goal of 200 and a mineral focus goal of 30, then when the algorithm is scoring a mineral district it would…
  1. See that Blorg is currently missing ~200 net mineral income to reach is goal and would give this a very high base score since the relative amount of income missing is huge
  2. See that the mining district produces resources needed for a focus goal and multiply the score by a defined factor
  3. See that Blorg currently has a mineral deficit and yet again multiply the score by a defined factor
The algorithm would then give a score for the build plan to use when prioritizing buildings and a mining district ( or several ) would soon be constructed by the Blorg. This would work similarly no matter which building we’re looking at, the important thing is that it scores it relatively to how much you are missing from your goal, and deducts any planned building resources from said goals. Meaning that if you’re only missing 2 mineral income the score wouldn’t be that high and if you have queued a mineral producing building then the AI would no longer look at those buildings because the ones you have planned account for all you need to reach that goal.

Evaluating The Plan™
So, does this system manage to address all the issues that I set out to? Yes, it does! :D

You no longer need to do complex scripts for each building, instead you can tweak the overall plan to affect how important the AI thinks a resource is. The plans also ensure that the AI is always looking forward, being proactive, instead of just reacting to deficits and certain happenings. The AI no longer looks at planets in isolation but as part of a whole, all tied together by The Plan™.

This all sounds very fancy-like and good, but now for the real question; does the economic AI perform better overall? Well...yeah!

In our tests we have seen much more robust AI economies and a better handling of the economy overall. And I’m really happy with it! Of course this wasn’t all me, I had lots of help from QA and other devs, and am very thankful for that because without them this wouldn’t have been nearly as good. Now of course, with the release of Federations closing in I would love to see what you ( the community ) manage to do with this and how you will manage to mod this into oblivion ;)

Lastly, I of course did not forget all of the hard work you put into your mods when writing this. The old style of writing building scripts and weights still work IF there are no economic plans for the AI to use. This means that if you remove all the plans or if an AI fulfills all the plans that it can have, then it will fall back to the old system of building planet-by-planet and use the old building weights.

Thanks for reading, and good luck amongst the stars!
 
Last edited:
Interesting, and a good idea to give them distinct personalities, but is there anything about fixing the 'crisis is very slow and gets slower as their territory grows' issue? I had the Unbidden spawn and, despite 50 years of being unchallenged, they took 60 systems out of 1000!
I have a couple questions regarding this. Lets start with the crisis. One of its biggest issues that prevents the crisis from ever conquering the galaxy was apparently the fact that they expand slower and slower, because most of their time is spend sending construction ships all across their territory. Did you adress this? How long does it take for each Crisis to full conquer, lets say a medium galaxy now? If the Crisis can't conquer territory, then at worst you end up in a stalemate of both the crisis and the player throwing ships at each other.
As I mentioned the new military AI will be a continuous focus for this patch and probably the next one. So far we focused mostly on the local scale, and now we plan to sit back and try to gather some data to see how it goes in the long run, and adjust accordingly. I have lots of ideas on how to improve it further, but we felt it'd be better to let things crystallize a bit before changing it even more.

So if I'm reading this right psionic ascension puts a big bullseye on your forehead when facing the interdimensional invaders. This is cool narratively, but makes the already weakest ascension path a tad worse than it already was.
Being a psionic empire gives you a higher chance to be selected as a target, but it's not guaranteed. While the Contigency is quite deterministic in the way it plays (it's a machine, after all ;)), the Unbidden are a bit more random.

I would assume bypasses means wormholes and such?
Yes, gates, l-gates and wormholes.

1. Can the military AI target enemy fleets or just systems? As a player my highest priority is enemy fleets as after they have been neutralized I can focus on other objectives.
They have 3 target categories: fleets, systems and planets. Each as its owned scoring system and they pick what they think is more important.

As someone who plays both Stellaris and Imperator:Rome, this is the best Dev Diary I have ever read. It has enough "meat". That's what I expect: How to do something in the technical perspectives and why we need it done.
Thank you, I don't write DD often (last one was on EU4 tech debt) so it's nice to see you guys like it.
 
You mention 3 types of AI ministers, but only outlined 2. Will the foreign minister AI get its own dev diary, outlining the diplomatic changes between pre-2.6 and post-2.6?
The Foreign Minister was not in the scope of this DD (or patch). It got some additions to be able to handle Galactic Community and the other new diplomatic features of course, but no major changes.
Is anyone else unable to see the pictures ?
Yes, I foolishly copy-pasted from google drive without rehosting the pictures on Plaza. We're fixing it :oops:
 
Last edited:
D O G
...
Am I reading this right that the AI will never build more than 3 Foundries per world? That seems like a... not good thing.

... this is, uh, not a reassuring thing to hear.
...

The above points that you bring up are good examples of why the old system wasn't really working. The AI no longer follow those scripts and therefore you need not worry about me not knowing how the numbers compare etc :)
 
@sidestep I'm curious how much weight the economic AI puts on pop growth and assembly when forming its long term plans. Right now, those factors seem to be the most important in ensuring a snowballing economy.

Also, can you share any concrete metrics for what levels of economic output the AI is able to achieve by certain years in-game?
It weights pop growth and assembly heavily, its one of the highest weighted factors in the new economy.
Code:
AI_POPS_SCORE_MULT = 5                        # AI will score pop growth and assembly buildings this much more ( already fairly high weighted  in code )
This define makes sure that pops/assembly get a 5 times multiplier bonus when being selected. It's base weight is also very high since the pop goals are fairly large numbers
 
You're letting the AI PLAN!? Are you insane!? If you allow this to happen, there's no telling what will happen. What if the Stellaris AI starts planning to escape my computer into the internet? We need to kill it here and now before this thing becomes a threat to all of humanity,
If we give AI the controls of our missiles, I won't be surprised if it kills us all. Although I'd be surprised if it does it because it became sentient. It's way more likely to happen because it bugged, or computed that the best mathematical way to stop people from dying was to stop them from being born.
 
Very interesting read. Thank you.
About AI plans: Are there specific "builds" for empire types? For example, will a Technocracy empire focus more on science if it is not forced to invest into alloys and follow a set Ascension perk plan, just like the player would? So for example: Tech Ascendancy, Flesh is Weak (insert potential perk 3 like Arcology project), Synthethic Evolution?
Right now there exists no such specific plans, BUT the system is setup so that you can do that very easily. You could for example make a general "high science" plan and weight it higher for technocracy empires. Or make a Technocracy specific plan that is limited to them only via the potential = {} trigger!
 
Because you knew I'd ask ;)

If plans are moddable, does that mean modded assets can be integrated into plans, so they don't have to wait on vanilla plans to finish before they're considered?

(Also, genius solution, if yes. This is pretty much what EDAI did, but that was one plan for all. You went and did better. Thank you.)
Of course I knew that SPECIFICALLY you would ask ;)

Yeah, you can add any modded stuff to the existing plans, or just change them out completely if you want. The system does not rely on any static data that way and does not require the vanilla mods to function or anything.
 
Does the AI also factor in potential tech improvements to their economic plans? For example, if they have a mineral deficit, will they prioritize researching mining techs in addition to building more districts?

Also will the AI demolish/rebuild their districts as the game progresses? From what I've read, their general lack of an ability to do so is why they ever end up getting ecumenopoli on their own.

And finally, have habitat weights been looked at during this sweep? From my own experience, I find they spam useless trade habitats everywhere, and never fill them with more than a couple buildings. Similar point as before, I've read that they have a hard time deconstructing old orbital mining/research stations to build the more useful habitats over.
I did not touch the research AI for this, but that would be nice indeed!

When it comes to demolish/rebuild the AI still looks at the destroy = {} triggers and ai_weight = {} ( if weight is < 0 they will destroy iirc ) when looking to demolish buildings, so they should be destroying bad buildings via that script

Habitats work just like any other planet with this system and from what I've seen the AI handles them better now as well :)
 
@sidestep , for the mods that add additional mine-able or produce-able resources, do we need to make AI take a completely new plan once it's able to mine/produce those resources, or is it possible to "insert" a new resource as a sub-plan?
You can just add those resources to an existing plan in the income = {} field, it will try to read any resource key that is in there and since moddable resources are read into the game like other resources they should work out of the box
 
You're letting the AI PLAN!? Are you insane!? If you allow this to happen, there's no telling what will happen. What if the Stellaris AI starts planning to escape my computer into the internet? We need to kill it here and now before this thing becomes a threat to all of humanity,
It's too late. The Plan™ is already in effect. *bleep-bloop*
 
I don't know about this. Creating more pops (and thus jobs) seems like a cornerstone of building powerful economies and you lose ground when growth slows.
It seems to me that it'd be better to design economy AI plans around pop/job expansion rather than making it an incidental target number.
They won't ever stop growing/building pops, it just becomes less of a priority. In later plans that number is of course increased. See it more as something for the AI to work towards actively than a hard cutoff :)
 
Another small but significant and cool change we made to help the economic AI is make it possible to see which job a pop favours according to the job weightings using debugtooltips:

upload_2020-3-5_14-48-23.png

This specialist Artisan would like to be an Administrator, but an Artisan is the specialist job they are most suited to at the moment. Of course, worker jobs are beneath them and not worthy of consideration!

By making it much easier to see this information, we could fix a number of bugs where e.g. mining bots were not automatically favoured for mining jobs.
 
You said the economic performance is noticeably better. Is this evident at the rate at which other empires become inferior to you? As it is you don't need even need to look at AI planets to see how bad it is doing. In fact it can be better to spare oneself that horror. But one you make it out of the early game, you just need to look at the diplomacy screen to see that everyone else is soon "inferior" and "pathetic". Even without trying much. Sure, a good human player will always outperform the AI in the long run, but what I expect to see here is that it takes longer and that the AI sometimes can be a serious opponent at least into the mid game. Things like wars, federations and galactic communities are pointless when you are effortlessly dominating everyone.

As you say, a human player will always beat the AI, we can think in ways that the AI just cant. The goal was to make the AI more "competitive" ( whatever that means ) and for a longer time. The results weve been seeing is that the AI economy scales much better and does not stagnate in the same way it used to. Also on higher difficulties it can be quite dangerous beyond mid-late game :)
 
I'm very curious how much of a performance increase we can see from cutting down on the if/then statements that the AI uses for its decision making. We had the dev diary speaking about performance improvements not long ago; was that before or after this new AI was implemented?

Also hopefully the AI will be 'smart' enough not to put down multiple police stations on their planets. Playing crime syndicates was very underwhelming with that behaviour.
The AI is no longer capped at one police station per planet, if a planet has crime and nothing else crazy important is needed then they can build several stations.
If you do crime, you will do time!
 
This is the dev diary I've been waiting for for a long time now. Thank you very much. At a first glance it looks like there have been some huge improvements on the economic side I am very much looking forward to see in action. It seems that a lot of work has gone into the AI plans and I have no doubt that they are a sound basis to develop actually working AI empires.

However I can already see a couple problems coming:

1. What happens to a lithoid empire if it aquires a non-lithoid minority? Do the normal pops starve because the AI remains in a non-food-producing plan? Or does the AI switch to a plan that does produce a food surplus but is completely inadequate to produce the mineral surplus the lithoid population requires? Similar problems I can see for synthetically ascended empires while assimilating new pops, normal empires conquering lithoid planets and any machine empire with organic pops -pampered, enslaved or otherwise- .

2. I hate that there still are no planetary plans. Sure the AI can see a need for an alloy foundry and order one one the planet most suited, but the human player is still stuck with dozens of planets that the AI can't be trusted to take care of when we have no ability to assign an AI-plan specifically to a single world.

3. How well does the AI handle big numbers of pops switching jobs? If it upgrades an Alloy foundry and then all the former mining workers flock to the new improved jobs there is a sudden demand in minerals and CGs as well as a sudden drop in mineral production.

4.Does the AI take buildings under construction into account? Otherwise a mineral deficit will cause minign districts to be ordered en masse until the first ones are actually finished.
1. The triggers that check if you need food/consumer goods checks this, so it should not be an issue, it will switch plans!
2. Planetary plans would be really nice, and the planet automation and planed designations could be tied more into the economic AI, but as always: can't do everything :(
3. The AI will not build buildings if there are lots of free jobs on a planet, so there shouldnt be any massive shifts in jobs like this, it will however fluctuate a bit but then it can favorite jobs that are more critical
4. The AI will only plan for buildings that it needs and then wait until construction queues are empty before building more stuff, so this should be less of an issue now.
 
Great stuff, the potential to simplify stuff is tremendous.

Will the plans tie in with specific Authority Types, i.e, Imperial plans differ from Authoritarian and Egalitarian ones? Or even at the Government Type level, i.e, Representative Democracy plans differ from Communal Parity ones?
They can! Since plans are scriptable :) but the default plans do not take any of this into account
 
Just out of curiosity, what happens when the AI fulfills an economic plan? How do they decide what to build next - do they shift to the next plan? Also, can the plan shoot for "as high as possible"? One might imagine you want the late game AI to try to max out alloys, tech and unity, without a cap.
When the AI finishes a plan it will try to find another that it can take, if it cant find one it will just fallback to the planet-by-planet construction. They cant really shoot for "as high as possible" but that would be a nice improvement. For now I think the easiest way to do that is just to have a late game plan with impossibly high numbers in it that the AI can try to reach, haha.