Welcome to Unknown Horizons
How the settlement AI works
During this year's Google Summer of Code I worked on a computer player (artificial intelligence) for Unknown Horizons. In this post I will give a quick overview of how it works from the player's perspective.
The first task of any player is to choose an island and found a settlement. The AI's primary motivator for choosing an island is the amount of available flat land but other factors such as the positions of existing settlements and available resource deposits are taken into account. The final choice is made randomly with a larger probability for choosing the better islands. This tends to make it more fun for the human and spread out the computer players. At this stage the AI also decides which part of the island it is going to be using for the village and which part for resource production.
Once the settlement has been founded, the AI starts building tents for the settlers. It will keep building more tents until the village area is full or it notices that it isn't producing enough of some resource. To satisfy the resource demands it uses the game's internal data to find out its estimated resource production capacity and the settlers' current resource usage along with the data about which building produces what. This is one of the parts where the AI has an advantage since the human player doesn't have direct access to it.
When the AI knows that it wants to build a specific building, it has to decide where to put it. For tents and village producers (pavilions, schools, taverns) this is decided when the settlement is first founded by dividing the village area into sections with one main square each and then trying to place as many tents as possible. The village producers then replace some tents to achieve maximum coverage. Most other buildings are placed without a prior plan by trying to put them into a sensible place. This depends on the exact building type but most of the time it is influenced by alignment (causes new buildings to be pulled towards existing boundaries) and distances to resource producers (weavers should be close to farms with pastures). Farms and lumberjacks are special because they must be right next to their input resource producers which is why field positions are decided when farms are built.
There are many reasons why the AI could choose to add storages. It could be trying to increase settlement storage capacity, extend the settlement area to some fixed position, enlarge area reachable by collectors, or improve collector coverage. The first three are relatively easy while the last one is a bit trickier. The chosen solution was to add better statistics about collector utilisation and production building capacity utilisation. The AI uses this information to find out the buildings that could most benefit from an extra storage and then places it in a badly serviced area.
Basically the AI is trying to play like a human player who wants to have as many settlers as possible and make them as happy as possible. We hope you enjoy playing with the new AI; it should be a lot more fun than just watching the pirate and trader move around.
Next page: The idea of Unknown Horizons