Experimental AI

From The Battle for Wesnoth Wiki

Experimental AI Summary

(Version 1.15.3 and later only) Several of the Experimental AI candidate actions (CAs) have been merged into the default (RCA) AI, see descriptions below for the individual CAs.

An Experimental AI is available for use in both MP maps and SP scenarios. At the moment, this AI contains the following candidate actions:

  • New and improved recruiting
  • More aggressive village grabbing
  • Healer placement behind injured units and more assertive retreating of injured units to healing locations.
  • Leader castle switching: useful on certain MP maps
  • Poison spreading
  • Moving toward any enemy, if there are no enemy leaders or villages
  • All the default RCA AI candidate actions except for recruiting

Experimental AI Setup

In multiplayer maps, this AI is available from the game setup menu as 'Experimental AI'. In single-player scenarios, it can be included by using the following code in a [side] tag

[ai]
    # Deprecated version (for Wesnoth 1.14 and earlier)
    {EXPERIMENTAL_AI}
[/ai]

(Version 1.15.0 and later only) The EXPERIMENTAL_AI Macro is deprecated now. The Experimental AI should be included as follows instead (this works in Wesnoth 1.14 already):

[ai]
    # Current version (works from Wesnoth 1.14 on)
    ai_algorithm=experimental_ai
[/ai]

Note that the EXPERIMENTAL_AI macro must be inside [side][ai], it does not work with [modify_side] or [modify_ai]. If the ai_algorithm version is used, the Experimental AI can also be added as

    [modify_side]
        side=2
        [ai]
            ai_algorithm=experimental_ai
        [/ai]
    [/modify_side]

or

    [modify_side]
        side=2
        switch_ai=ai/ais/ai_generic_rush.cfg  # Wesnoth 1.14 and earlier
        #switch_ai=ai/ais/ai_experimental.cfg # Wesnoth 1.15 and later
    [/modify_side]

Custom Parameter Setup

(Version 1.15.2 and later only) A small number of custom parameters can be passed to the Experimental AI. These cannot be set up using the ai_algorithm syntax, but require the use of a macro in the [side][ai] tag:

[side]
    [ai]
        {CUSTOMIZABLE_EXPERIMENTAL_AI (
            high_level_fraction=0.33
            randomness=0.2
        )}
    [/ai]
[/side]

Note that only the parameters one wants changed need to be defined in the macro, those omitted will take their default values.

Custom parameters:

  • high_level_fraction=0: (non-negative number) The approximate fraction of units of level 2 or higher to be recruited. This is defined as fraction of units on the map, not of new units being recruited during a turn or over several turns (which makes a difference if there are already units on the map). The effect is also cumulative per level (starting from level 2), meaning that 1/3 of L2 units will be recruited in the example above, 1/3*1/3=1/9 L3s etc. The default value is zero, which leaves the high-level unit recruiting to the default Experimental AI algorithm resulting usually in very few such units being recruited.
  • randomness=0.1: (number) A random number is applied to the Experimental AI recruiting score to prevent the recruitment pattern from being too predictable. 0 causes no randomness to be applied, while larger numbers increase the random effect. A value of 1-2 generates results in which the random effect is approximately equal to the scored effect. Extremely high values are essentially entirely random.

Experimental AI Details

The Experimental AI uses most of the candidate actions (CAs) of the RCA AI, the one exception being the recruitment CA which is replaced by another recruiting CA. In addition, it also adds a number of new CAs. The following are the differences between the Experimental AI and the default (RCA) AI:

Recruitment

(Version 1.15.3 and later only) At the moment, the recruiting CA remains the main difference between the default and the Experimental AI.

The Experimental AI has a completely different recruiting algorithm that was designed to emulate the choices of a human player, especially in the first few turns. As such, it tries to pick units that counter both what is on the battlefield and that the opponent could recruit. As it gains more units relative to the enemy, it picks harder hitting units, even at the cost of fragility, to break through enemy lines.

Unlike the default recruitment algorithm, it also chooses where the units are recruited in order to maximize the number of villages that can be captured and if it knows the leader will be moving to a "better" keep (see below), it will under-recruit at the first keep to project more forward power, recruiting just enough to capture all villages.

It also adjusts its recruitment based on map size, favouring faster units on larger maps, trusting that the economy advantage from capturing more villages will more than offset the price.

It knows about poison and avoids recruiting units that depend on it for damage if the enemy is immune.

It also looks at the expected cost of the unit over the next few turns, which prevents the recruitment of too many fast weak units unless the additional gold from an expected capture of a village is enough to offset the increased cost.

Time of day is taken into account and it prefers units that will reach the current closest enemy at the favoured time of day. This allows, for example, for a slight bias towards saurians during the day and drakes at night on small maps (because they will reach the fight at the right time).

Because the AI cannot use them well, it does not accurately measure the damage done by a unit with berserk, causing them to almost never be recruited.

There is also a small amount of randomness added to allow two units that are almost equally good according to the evaluation to be chosen evenly, instead of only picking the first one every time.

Configuration parameters: The [args] tag of the recruitment CA can take configuration parameters high_level_fraction, randomness and reset_cache_each_turn to modify its behavior. They are described under the Rush Recruitment AI entry on the Micro AI wiki page.

Villages

The Experimental AI prefers to capture villages over fighting. This weakens it somewhat in raw fighting but it tends to get enough extra gold that this is actually to its advantage vs. the default AI, although its current implementation is probably too focused on villages.

(Version 1.15.3 and later only) This CA has not been merged into the default AI. It is too simple to work in a general setting (and therefore not suited for the default AI) and there is a separate village grabbing CA in the default AI, so it does not make much of a difference. This CA needs to be either improved or removed.

Healing and Retreating

If a healer is not used to attack, the Experimental AI will try to heal units, instead of positioning to attack later.

In a separate CA, units retreat to villages/healers when injured.

(Version 1.15.3 and later only) These two CAs have been merged into the default AI.

Castle Switching

The leader will move to different keeps, providing a forward force. Usually this works very well, especially at the beginning of the game, but it keeps moving later, which sometimes might get it killed in some scenarios. In that case, it might be worth stopping this behaviour after several turn by removing this CA.

Enemy Poisoning

There is also an explicit poison attack routine that tries to poison unpoisoned units instead of repeatedly poisoning the same one.

(Version 1.15.3 and later only) This CA has been merged into the default AI.

Move to Any Enemy

This is a fall-back CA that kicks in only when no other actions are taken. Its purpose is to not let the AI units sit idle on maps without enemy leaders and villages.

(Version 1.15.3 and later only) This CA has been merged into the default AI.


See also: Wesnoth AI

This page was last edited on 22 June 2022, at 23:14.