Currently Online

Latest Posts

Ai Training

The Genetic algorithm in Widelands

Up to Build 19 (including) the AI was fully rule-based. Internally, it used a lot of constants that had to be fine-tuned by hand - and that was time consuming for the developers. So, we are in the process of switching to a genetic algorithm where numerical constants are to be fine-tuned by a random process (mutations) and the best mutations must be selected by a supervisor. This process is to be referred to as "AI training".

How the AI's DNA is stored

The numbers used by the DNA are stored in separate text files with the suffix wai. Therefore, the training does not require recompilation but only copying the files. There are two location for these files:

  • data dir - contains 4 wai files representing 4 individuals with slightly different DNA
  • home dir - can contain dumped DNAs from initialized DNA players. Those files tend to be unique, due to a high "search space". They also depending on the mutation rate.

Training mode

While the DNA is mutated (and a unique DNA created) with each initialization of the AI player, it is usually not dumped in the home folder. So, there is a command line switch --ai_training to activate it. This switch will also increase the mutation rate.

The second useful switch is --auto_speed that will keep adjusting the speed of the game in real-time, in order to keep the current FPS around 14. The idea is to speed the game up as much as possible without badly affecting the AI due to lag.

Is the AI really trained during the game?

No, no actual training or learning is taking place. The learning here is just picking best AI from a group of randomly generated AIs, and copying it to the data folder, so that they could be used as a source for the next game.... This can be done by a human, or automated by a script based on score etc...

Content of wai files

The format of source and output wai files are exactly the same, when you open them you will see 4 arrays of integers.

Tagged with: Development, help