Skip to content

Design: AI

Quintillus edited this page Jun 7, 2022 · 1 revision

under-constructionunder-construction This area under construction! under-constructionunder-construction

This page will be updated after #266 and #137 to discuss more about how the AI works.

The AI is going to have several different layers (components) that interact with each other. How many is TBD, and it will likely change as more components are added.

Where feasible, these components will be pluggable. Interfaces will have to be defined, since one component of the AI may refer to another component of the AI to help make a decision.

An example of this is that the CityProductionAI, which decides what cities will build, will reference the StrategicPriorityAI, which contains information about (and decides upon) strategic priorities for the AI. If the strategic priority is expansion, building settlers is more likely; if it's the space race, building libraries is more likely; if it's securing a source of horses, military units are more likely.

It's important to remember that this is all still very early in its lifecycle, and the 1995-style intro to this page is intentionally pointing that out.

We'll now cover the specific parts that have already been built out (to some extent).

Strategic Priority AI

The Strategic Priority AI decides what the AI's high-level goals are. As currently defined, the AI re-evaluates its strategic priorities every 15-24 turns (the interval will eventually be made configurable). It goes through all possible priorities, asks them to calculate a weight of how important they are based on the AI player's current game knowledge, and then uses those weights to choose one of them as its top priority.

It then repeats this process for a secondary priority, and, if the weights for possible priorities are close enough together, potentially for a tertiary and quaternary priority.

Although as of right now (6/6/22) the priorities are only calculated and not used, we expect that to change, initially with the City Production AI allowing the chosen priorities to affect the likelihood of constructing units. Each strategic priority that has been chosen will be able to affect a multiplier to the likelihood of choosing a particular unit. The effect of this multiplier will be lessened for secondary and lower priorities.

There are currently three possible strategic priorities. We plan to add more, and they are designed so that once we figure out how mods can be added, more could be added via mods. I suspect moving a strategic priority AI out into a separate mod module will be an early proof-of-concept mod.

Current Strategic Priorities

Expansion Priority

This strategic priority will encourage the AI players to build settlers, and will be very common early in the game.

Eventually, expansionist civilizations will be even more likely to choose this priority.

Exploration Priority

This strategic priority will encourage building fast units for exploration, and will also be common early in the game. At some point, the unit AI will be more likely to assign units to exploration (versus defense or offense) if this priority is active.

Eventually, Seafaring civilizations will be more likely to choose this priority if they have the appropriate technology to explore by sea.

War Priority

This strategic priority indicates that the AI is or is planning to be at war. Currently, it will only be chosen once the expansion phase is finished, and future enhancements are needed to make it have an effect. It will also need more AI components to be built to result in an effective combat AI.

Currently, once the expansion phase is over, a random enemy is chosen to go to war with. As we evolve, this will be chosen more intelligently.

Eventually, Militaristic civilizations will be more likely to choose this priority; the likelihood will also be impacted by the civilization's Aggressiveness setting.

Eventually, there will be separate Military AI modules who will


Future Strategic Priorities

Many other strategic priorities are envisioned. This is not an exhaustive list, and items on this list may be modified or dropped as the situation evolves.

Clear Barbarians

Currently, the AI doesn't try to clear barbarian camps near their cities. Sometimes they do by chance, but not by planning. This should be a priority whose likelihood is highly influenced by the proximity of barbarian camps.

Invest in Science

AIs should have an awareness of how advanced or not advanced they are, just as the human does through the Science Advisor. My vision for this is using the same tiers (backwards/moderately advanced/advanced), and having the backwards one, and if it's late game, the advanced one, make this priority more likely. The "scientific" AI trait will also make this one more likely. It will result in building more science-producing buildings, as well as roads.

Boost Economy

This will be a primarily mid-game priority that the AI is more likely to choose if they cannot sustain a high science rate. They'll build more roads and commerce-boosting buildings. It will also be more likely to be chosen by Commercial civilizations.

Boost Productivity

This will focus on improving city productivity, by either building mines or constructing buildings to do so. An AI may choose this if it ranks poorly in productivity, if it's in war and feels it has the luxury of focusing on long-term productivity over short-term unit production, or simply because it is Industrious.

This may be combined to some extent with Boost Economy.

Pursue (Victory Type) Victory

If an AI believes it can win a certain victory condition, it may choose that victory type as a strategic priority. This will make it take actions that further that goal, such as building more cultural buildings, building spaceship components, or refusing to trade away space-related technologies.

Prevent Player Victory

Conversely, if an AI believes another player is getting close to victory, it may choose as its priority preventing that outcome. This could take a variety of forms, such as attempting to capture relevant cities to slow or stop the victory, trying to boost its culture enough to prevent another player from winning a cultural victory, or seeking alliances (defensive or otherwise), or being more willing to enter into diplomatic agreements with rivals of the player who is approaching victory.