Skip to content

AIV: How AI build their AIV

Gynt edited this page Sep 10, 2024 · 4 revisions

Game ticks (First things first)

Every 50 game ticks is a day, every 200 ticks is a week (4 days), every 4 weeks is a month, every 12 months is a year.

The 200 ticks that constitute a week is a load balancing feature, such that every tick something else is (re)computed. e.g. every week at a specific tick in that week ale rate is recomputed, or crowding, etc.

Every day, one of the 50 day ticks is dedicated to an AI player think about whether it should build something. To be specific tick 1-8 of a day are for player 1 - 8. So every day, an AI player thinks about placing buildings (or destroying e.g. houses).

AI building plan

Imagine what is written here as a function. When I mean "nothing is done", I mean, the function returns.

First it checks if a delay is being applied. If a building was destroyed, a counter is set to 1. Every day (50 ticks), the delay counter is increased by 1 and the function returns, so nothing further is done. As soon as it reached AIC:ResourceRebuildDelay, it thinks further about what to build (and will not get delayed again until another building is destroyed).

Then, it considers gold. If gold is over 16000, it considers itself rich. If over 5000, medium-rich, else, it is poor. If poor, it increments a counter and doesn't do anything that day, until it reaches AIC_BuildInterval, which means it has been poor for that many days, then it will build despite being poor.

Then, it considers which resource type to focus on (wood, food, stone, iron, oil) and builds those buildings if it considers it necessary.

Then it continues. It considers the AIV pause value. If the pause step is lower than the current step it is aiming to build (until this step, sort of like a build step goal, e.g. if 100 it desires to build the first 100 steps of its AIV), the pause value is applied and nothing is build this day. Every day it reaches this bit of code, the pause value is decremented until 0.

While the pause lasts (> 0), it doesn't increment its step goal, halting the AIV progression (it does build buildings that still have to be build until this goal). Furthermore, it only builds houses. Note that if there is no pause value (==0), the step goal is increment by 2 if rich so it is building its aiv faster if it considers itself rich.

Then it considers whether to destroy houses, if it does destroy, it considers itself done for today.

Only now, it builds It goes through every build step up until the goal.

For positive fear factor, it has a "delay" of 200, so the first 200 times it reaches this code, it doesn't do any positive fear factor building. 200 times isn't 200 days though. As, depending on how many previous steps also are about positive fear factor, it could be less. So if an AIV has 10 positive fear factor buildings in its steps (let's say, steps 1 to 10) and we are currently at step goal 11 (we try to build everything up to step 11), then this code is reached 10 times per day, so we only need to wait 200/10 = 20 days.

For negative fear factor this delay is 100 or if popularity is below 50, it never builds more negative fear factor

Clone this wiki locally