• Anno 1800
  • DevBlog

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.

Comments

Leave a Reply

9 Comments
  1. N NyZuZ

    Hi

    After some time playing Anno 1800 I can say with no doubt, that AI DON’t follow any of the rules about tax and material production.
    You can completely blockade them and they “magically” generate whatever they need.

    It’s very disappointing.
    Are you going to change it?

  2. A Azuriel87

    Hello
    Can’t wait to match wits with narcissists like Zanchi, psychopaths like Lucius and Nadasky. Please make them like real, make them compliant, make them like the real people you would match wits against in real world. 🙂

  3. B Boldzmann

    Once I played in Anno 1404, i besieged the ai player’s island. I did not allow his merchant ships to unload the goods. I expected that the level of residents would fall because of a shortage of goods. However, the nobles and patricians remained in the city. Will it have any negative consequences for a ai player if I do not allow the ships with the goods to be unloaded in his port?

  4. a anno607

    What i always missed in older anno games was that the AI player didn’t give the people any food. When i did take a warehouse from a ai player the people where unhappy and needed almost everything. Also handel with ai was pointless, the ai never asks for a lot let alone asks for more when the city became bigger. And where i needed for example 10 mills the AI only has 4 with the same size city. So will the AI be smart enough this time!? and will the AI make a profit!

  5. H HannesDS

    When will the AI decide to move to another session? Will it wait for you? Or if you prefer a “my home is my castle” approach, will the other session be overtaken by an agressive AI?

  6. F FHackner

    Reading this makes me very happy. I loved admiring the AI creations in 1404, even if you could spot the repetitive patterns after a while.

  7. N Nox_29

    I feel like writing an AI for games has always been one of the most difficult tasks for game devs to do. As a programmer myself, I already get a headache thinking about how immensely complex the code for such an AI must be. I have a lot of respect for you guys !

    The way the AI decides where to place a building seems like quite a complicated algorithm. Is it a lot different/more complicated from other Anno games like 1404 for example? I also wonder if it requires a lot of computing power? Checking every square in every island the AI owns for every building it places sounds like a bit of a task.

    I also have a question about game AI outside of this iteration of the Anno series. I presume that the AI in the Anno games has always been a super complex algorithm, but not exactly the kind of AI that projects like Google Deepmind and OpenAI are working with. The kind of AI that learns in a human way. Do you think we’ll ever get that kind of an AI as opponents in our games? And if so, how long would you estimate before we do?

  8. o olblf

    This is really good news!! An AI that plays by the rules is something I’ve missed since 1404. Glad to hear you are bringing it back!! 😀

You may also be interested in