Uncategorized DevBlog: Construction AI 02.08.2018

We are Jonas (the fella with the glasses) and Johannes (Mr. Smirk) and we work as Gameplay Programmers on Anno 1800. Together we are 53 years young and have worked for roughly 9 years at Ubisoft Blue Byte. What we did the 44 years before that, you ask? We played Anno, of course!

But today, we’d like to give you some insights into a feature which has kept us both busy for many months now: the construction AI.

Teaching bits and bytes something about human behavior

For many Annoholics, sinking dozens of hours into trying to find the perfect city layout is a big part of the game’s draw. How can I make the best use of these last few remaining spaces, and is there any possible way I could fit my zoo in there?

Another fundamental part of the Anno experience is playing alongside and against computer-controlled – or as we say AI (artificial intelligence) – opponents. However, creating a believable AI is quite the task, as the AI views things through very different eyes than human players; that’s why it falls to us to teach it how to construct functional and believable cities in a language the program can understand.

Anno 1800 will go back to the roots of older Anno titles such as 1404, where the second party AI (the characters settling and building on islands) follows largely the same rules as the player. Hidden under the hood of the so-called construction AI system are algorithms, which mimic the behavior of a player. Similarly to the player, your AI neighbor will need to generate money from taxes, produce resources to construct buildings and to fulfill the needs of the population to make them happy or to advance into the next tier. The number one rule when working on the AI system is that your friendly, aggressive or even quirky AI controlled players should behave like, and follow the same rules as, the player.

Anno is a real beast when it comes to the sheer amount of features the game has to offer. Among them are some gameplay systems, which are too complex for the AI to use but still are important to compete with the player. To give you an example, it is not possible for AI characters to take on and finish quests and therefore, they cannot gain any items from this or similar systems. To avoid that the second party has to suffer a major handicap because of that restriction, we will provide ways to enable the AI to get other access to needed items.

Quite the character – a personal touch for every opponent.

By nature, programs like to calculate, compute and optimize things in split seconds, but transforming the AI into memorable characters like the envious robber baron von Malching is quite a task. We want that every second party character is memorable, from their diplomatic preferences to city layouts or what they focus on economically. All of these should be reflected in their construction behavior and result in a personal touch when observing their cities.

Every character will follow a specific strategy, which defines things like whether they invest more money and resources into the culture or prefer a strong military fleet. Furthermore, this deeply layered system also differentiates between their preferred types of military ships, investment in defensive structures or what kind of cultural buildings they prefer.

If a very rural looking island with plenty of golden fields of wheat fit a character, we will set parameters that the AI creates an overhead production in certain categories. In the case of the exploitative nature of von Malching, he will not show much love for vistas in his city and rather concentrate on mercilessly expanding his industry.

The way they build street networks and plan residential areas is also taken into account, as each AI simply building the same artificially optimized layout would feel cold and unnatural. That customization goes as far as even allowing AI characters to prefer specific types of ornaments.

In this simulation, we just let our AI build a city with unlimited resources (the green plots are ornaments)

This personal touch, behavior, and difficulty of a second party character depends on many different parameters which enable the AI to make decisions. These parameters define things like the general construction speed, which determines how many resource-producing buildings a character builds to generate construction materials or the previously mentioned fleet or defense construction.

To illustrate it better, we want to give you a few examples for some construction AI parameters:

– Difficult second parties will make use of construction materials as soon as they become available.

– Easier opponents will wait with their decision what to build, even if the material is available.

– We can decide what types of ships an AI favors for trading or military fleets.

– How fast will the AI expand? Will it try to capture a new island quickly or wait before the main island is well developed?

How to make decisions: location scores

While parameters are the general behavior rules, the AI also needs more specialized systems to be able to make a decision such as where is a good spot to place a building. While finding the right place to construct a production building might be trivial for us, an AI relies on various criteria to be able to make decisions, as it cannot rely on intuition as we do.

Let’s give you an example where the AI wants to construct a windmill for its bread production. Firstly the AI rates possible spots by the following criteria:

– Try to avoid wasting construction space on the island, by not leaving small empty plots between production buildings or street layouts.

– The windmill should be within the influence radius of a warehouse.

– It should be close to other buildings of the same production chain.

– As the windmill is a production building, it should be outside of the residential city center.

The system will now check the whole grid and will assign scores based on these criteria. Location scores tell the AI where the best, acceptable or bad places are to place the building. There might also be scenarios where the island is so densely populated, that the AI has to rely on acceptable but not perfect areas. But there are additional factors to consider when deciding where to place a building- for example, what happens if the AI has several islands? Could it make more sense to outsource certain productions within the controlled archipelago, or perhaps even to a different session?

Here you see the score system through the eyes of our AI.



Programmers: Teacher and problem solver

Such a complex system is neither done in a week nor can it be completed in the early stages of development. The programming team needs to tell our AI to react to constantly changing development builds and newly implemented features.

When Game Design implements something new, the AI simply does not know how to deal with it, so we need to help it to adapt to the new situation. Imagine fire incidents were just implemented and the AI has no idea how to deal with the inferno as we need to tell it to construct fire stations beforehand. Without this criteria or knowledge so to speak, the AI would just have to watch its city turning into a cinder.

There is another good recent example, which shows how a new feature can create seemingly unsolvable issues for the construction AI.

We just implemented rivers into the game, which adds a completely new construction layer for bridges but blocks other constructions. As our AI has no clue what the new system is all about, it might try to place buildings into the river or completely ignore the landmass on the other side. Our job here is to teach the program why and when it needs a bridge, and where to place it. What sounds easy in theory is creating a new simulation including a lot of working hours and code work.

In our job, we always chase after the latest feature implementations to keep the AI up to date and allow the AI to use all the available game features to compete against you, the player.



This gif visualizes how the AI maps out construction space, determining where it can be build, which areas are blocked and the distances between them

The sum of its parts

When you think about the ton of intertwining features in Anno, creating a believable AI is an enormous task where every new content might interfere with something else. Construction AI is obviously only one aspect to create a lively and challenging second party, among many others such as military behavior or diplomacy.

When setting the scope for our Anno 1800 construction AI, we had a lot of feedback from our community to work with. We hope that we are not only in a good way to deliver a believable but also fair and charming construction AI.

We hope that we were able to give you some interesting insight into our work and looking forward to your feedback, as the construction AI is a joint effort between our experience and feedback from our fans.