Difference between revisions of "AiWML"

From The Battle for Wesnoth Wiki
 
m (fixed formatting)
Line 1: Line 1:
== the [ai] tag ==
+
== AI phases ==
  
 
When the AI does its turn, it has several 'phases'.
 
When the AI does its turn, it has several 'phases'.
 
In debug mode, these phases are shown in the upper-left corner.
 
In debug mode, these phases are shown in the upper-left corner.
  
== Combat phase == it decides who is in range to attack, and whether it's worth attacking them
+
=== Combat phase ===
 +
It decides who is in range to attack, and whether it's worth attacking them
 +
 
 +
=== Healing phase ===
 +
It locates injured units and sees if they can be moved to villages to heal
 +
 
 +
=== Village capturing phase ===
 +
It locates units, and sees if they are in range of villages which they can capture
  
== Healing phase == it locates injured units and sees if they can be moved to villages to heal
+
=== Retreating phase ===
 +
It sees if any units are in grave danger/hopelessly outnumbered, and if they are, it retreats them
  
== Village capturing phase == it locates units,
+
=== Movement/targetting phase ===
and sees if they are in range of villages which they can capture
+
It decides upon 'targets', assigns those targets values, and moves units toward targets based on how easy it is to get to the targets, and how valuable the targets are.
  
== Retreating phase == it sees if any units are in grave danger/hopelessly outnumbered,
+
== the [ai] tag ==
and if they are, it retreats them
 
  
== Movement/targetting phase == it decides upon 'targets', assigns those targets values,
+
The following key/tags are accepted for '''[ai]''':
and moves units toward targets based on how easy it is to get to the targets,
+
* ''recruitment_pattern'' This key takes a list containing the possible inputs 'scout', 'fighter', 'archer', 'healer' and 'mixed fighter'. This tells the AI in what order it should recruit different types of units. The AI considers each unit to be one of these types. The type is listed in the unit file in data/units/ (See also [[UnitWML]]).
and how valuable the targets are.
 
  
The following key/tags are accepted for [ai]:
+
<ul><li> ''aggression'' This key affects how an AI player will fight.
* ''recruitment_pattern'' This key takes a list containing the possible inputs 'scout', 'fighter', 'archer', 'healer'
+
<br>
and 'mixed fighter'.
 
This tells the AI in what order it should recruit different types of units.
 
The AI considers each unit to be one of these types.
 
The type is listed in the unit file in data/units/ (See also [[UnitWML]]).
 
* ''aggression'' This key affects how an AI player will fight.
 
 
It determines how an AI considers the difference between its units and its opponents
 
It determines how an AI considers the difference between its units and its opponents
 
by taking the value ''1 - AI unit value in proportion to opponent unit value''.
 
by taking the value ''1 - AI unit value in proportion to opponent unit value''.
Line 44: Line 45:
 
The default is ''1 - 1/2 = 0.5'', which means the AI is content with dealing only
 
The default is ''1 - 1/2 = 0.5'', which means the AI is content with dealing only
 
half the damage to his opponent of that which he himself takes.
 
half the damage to his opponent of that which he himself takes.
* ''caution'' A number 0.0 or higher (default=0.25) that affects how cautious the AI is in various ways.
+
</ul>
If it is higher, the AI will want to retreat more (especially to a better defensive terrain), it will dislike moving out
+
 
of a defensive terrain to attack more, and, if
+
* ''caution'' A number 0.0 or higher (default=0.25) that affects how cautious the AI is in various ways. If it is higher, the AI will want to retreat more (especially to a better defensive terrain), it will dislike moving out of a defensive terrain to attack more, and, if grouping is enabled, it forms bigger groups to protect from enemies when going to a target.
grouping
+
 
is enabled, it forms bigger groups to protect from enemies when going to a target.
 
 
* ''village_value'' A number 0 or higher (default=1) which determines how much the AI tries to capture villages.
 
* ''village_value'' A number 0 or higher (default=1) which determines how much the AI tries to capture villages.
 
* ''leader_value'' A number 0 or higher (default=3) which determines how much the AI targets enemy leaders.
 
* ''leader_value'' A number 0 or higher (default=3) which determines how much the AI targets enemy leaders.
* ''villages_per_scout'' A number 0 or higher which determines how many scouts the AI recruits. Defaults to 4.  If 0,
+
* ''villages_per_scout'' A number 0 or higher which determines how many scouts the AI recruits. Defaults to 4.  If 0, the AI doesn't recruit scouts to capture villages.
the AI doesn't recruit scouts to
+
* '''[target]''' Any number of [target] tags can be used to set a target for the AI. For anything related to 'values', set them relative to other targets. An AI is willing to dedicate twice as many resources and travel twice as far to get a target worth '2.0' as it is a target worth '1.0'.
capture villages.
 
* '''[target]''' Any number of [target] tags can be used to set a target for the AI.
 
For anything related to 'values', set them relative to other targets.
 
An AI is willing to dedicate twice as many resources and travel twice as far to get a target worth '2.0' as it is a
 
target worth '1.0'.
 
 
** standard unit filter
 
** standard unit filter
** value: A number greater than 0 (default=1) which determines how much the AI tries to kill all units which pass the
+
** value: A number greater than 0 (default=1) which determines how much the AI tries to kill all units which pass the filter.
filter.
 
  
  
Line 66: Line 60:
  
 
* ''recruitment_ignore_bad_movement'' if 'yes', the AI will not analyse the terrain to see if the unit is suitable for it.
 
* ''recruitment_ignore_bad_movement'' if 'yes', the AI will not analyse the terrain to see if the unit is suitable for it.
* ''recruitment_ignore_bad_combat'' if 'yes', the AI will not analyse the units the enemy has fielded to see if the unit
+
* ''recruitment_ignore_bad_combat'' if 'yes', the AI will not analyse the units the enemy has fielded to see if the unit is suitable for fighting them.
is suitable for fighting them.
 
 
* ''passive_leader'' if 'yes' the AI leader will never move or attack, except to obey [leader_goal]s.
 
* ''passive_leader'' if 'yes' the AI leader will never move or attack, except to obey [leader_goal]s.
* ''attack_depth'' a number from 1 to 6, default 5.  This is how many units will be thought about to attack a single
+
* ''attack_depth'' a number from 1 to 6, default 5.  This is how many units will be thought about to attack a single unit.  If the attack is completed, the AI on another round of thinking may still decide to attack that unit again with other units.  Note that in battles, a unit usually can't be attacked from all six sides anyway, so any high attack_depth will be about the same.  If attack_depth is low, the AI won't want to attack unwounded units very much, because it doesn't think it can kill them in the attack.
unit.  If the attack is completed, the AI
+
* ''simple_targetting'' When the AI decides what targets to move towards with which units, it considers all its units that can move, sequentially.  For each unit, it decides what the best target for it to go towards is.  If not 'yes', it will check if any other units would be better to go towards that target than the unit it is currently considering.
on another round of thinking may still decide to attack that unit again with other units.  Note that in battles, a unit
+
* ''scout_village_targetting'' The AI multiplies the value of village targets for scouts by this value. The default is 3.
usually can't be attacked from all six
+
 
sides anyway, so any high attack_depth will be about the same.  If attack_depth is low, the AI won't want to attack
 
unwounded units very much, because it
 
doesn't think it can kill them in the attack.
 
* ''simple_targetting'' When the AI decides what targets to move towards with which units, it considers all its units
 
that can move, sequentially.  For each
 
unit, it decides what the best target for it to go towards is.  If not 'yes', it will check if any other units would be
 
better to go towards
 
that target than the unit it is currently considering.
 
* ''scout_village_targetting'' The AI multiplies the value of village targets for scouts by this value. The default is 3.
 
 
* ''grouping'' how the AI should try to group units
 
* ''grouping'' how the AI should try to group units
 
** 'offensive' (the default): Makes the AI try to group units together before attacking.
 
** 'offensive' (the default): Makes the AI try to group units together before attacking.
** 'defensive': Makes the AI group units together very conservatively, and only advances much beyond its castle if it
+
** 'defensive': Makes the AI group units together very conservatively, and only advances much beyond its castle if it has overwhelming force.
has overwhelming force.
 
 
** 'no': Makes the AI not use grouping behaviour. This is what it used to be like.
 
** 'no': Makes the AI not use grouping behaviour. This is what it used to be like.
* ''protect_leader'' and ''protect_leader_radius'' - the way these parameters work,
+
 
is to target any enemy units that come within 'protect_leader_radius' of the AI leader with a value of 'protect_leader'
+
* ''protect_leader'' and ''protect_leader_radius'' - the way these parameters work, is to target any enemy units that come within 'protect_leader_radius' of the AI leader with a value of 'protect_leader' on the units. The default for these values are 1.0 and 20.
on the units.
+
 
The default for these values are 1.0 and 20.
+
* '''[protect_location]''' gives the AI a location to protect. Note that the AI will NOT station any units around the location, it will only send units to attack any enemy units that come within the guarding radius of the target.
* '''[protect_location]''' gives the AI a location to protect.
+
** ''x'', ''y'' standard coordinates. These indicate the location the AI is protecting,
Note that the AI will NOT station any units around the location,
 
it will only send units to attack any enemy units that come within the guarding radius of the target.
 
** ''x//,//y'' standard coordinates. These indicate the location the AI is protecting,
 
 
** ''radius'' indicates the radius around it to protect
 
** ''radius'' indicates the radius around it to protect
 
** ''value'' indicates the importance of protecting this location
 
** ''value'' indicates the importance of protecting this location
* '''[protect_unit]''' gives the AI a set of units to protect
+
 
Note once again that the AI will not place units around the unit if there are no enemies nearby.
+
* '''[protect_unit]''' gives the AI a set of units to protect. Note once again that the AI will not place units around the unit if there are no enemies nearby.
 
** standard unit filter- the unit(s) to protect
 
** standard unit filter- the unit(s) to protect
 
** ''radius'' indicates the radius around it to protect
 
** ''radius'' indicates the radius around it to protect
 
** ''value'' indicates the importance of protecting this location
 
** ''value'' indicates the importance of protecting this location
 +
 
* '''[avoid]''' Makes the AI avoid a specific location or unit.
 
* '''[avoid]''' Makes the AI avoid a specific location or unit.
** ''x//,//y'' standard coordinates- A location for the AI to avoid moving to.  The AI will never move a unit to this
+
** ''x'', ''y'' standard coordinates- A location for the AI to avoid moving to.  The AI will never move a unit to this location except for trying to move its leader to a keep.
location except for trying to move its
+
** standard unit filter- A set of units for the AI to avoid moving to. This feature is currently not implemented.
leader to a keep.
+
 
** standard unit filter- A set of units for the AI to avoid moving to.
 
This feature is currently not implemented.
 
 
* '''[leader_goal]''' Makes the AI try to move its leader to a specific location (as in the goal of The Elves Besieged).
 
* '''[leader_goal]''' Makes the AI try to move its leader to a specific location (as in the goal of The Elves Besieged).
** ''x//,//y'' the location for the AI to move its leader to
+
** ''x'', ''y'' the location for the AI to move its leader to
* ''time_of_day'' the time(s) of day when the AI should use the parameters.
+
 
This applies to the entire [ai] tag, so multiple [ai] tags are usually used.
+
* ''time_of_day'' the time(s) of day when the AI should use the parameters. This applies to the entire [ai] tag, so multiple [ai] tags are usually used. Possible values are listed in data/schedules.cfg (See [[TimeWML]]).
Possible values are listed in data/schedules.cfg (See [[TimeWML]]).
+
 
* ''turns'' which turn numbers the AI tag applies during.
+
* ''turns'' which turn numbers the AI tag applies during. This applies to the entire [ai] tag, so multiple [ai] tags are usually used. This takes the same syntax of dashes(-) and commas(,) as is described under Filtering Locations in [[FilterWML]], except of course they apply to turns not locations.
This applies to the entire [ai] tag, so multiple [ai] tags are usually used.
 
This takes the same syntax of dashes(-) and commas(,) as is described under Filtering Locations in [[FilterWML]], except of
 
course they apply to turns not
 
locations.
 
  
 
== See Also ==
 
== See Also ==
  
 
* [[ReferenceWML]]
 
* [[ReferenceWML]]
 

Revision as of 11:48, 23 August 2005

AI phases

When the AI does its turn, it has several 'phases'. In debug mode, these phases are shown in the upper-left corner.

Combat phase

It decides who is in range to attack, and whether it's worth attacking them

Healing phase

It locates injured units and sees if they can be moved to villages to heal

Village capturing phase

It locates units, and sees if they are in range of villages which they can capture

Retreating phase

It sees if any units are in grave danger/hopelessly outnumbered, and if they are, it retreats them

Movement/targetting phase

It decides upon 'targets', assigns those targets values, and moves units toward targets based on how easy it is to get to the targets, and how valuable the targets are.

the [ai] tag

The following key/tags are accepted for [ai]:

  • recruitment_pattern This key takes a list containing the possible inputs 'scout', 'fighter', 'archer', 'healer' and 'mixed fighter'. This tells the AI in what order it should recruit different types of units. The AI considers each unit to be one of these types. The type is listed in the unit file in data/units/ (See also UnitWML).
  • aggression This key affects how an AI player will fight.
    It determines how an AI considers the difference between its units and its opponents by taking the value 1 - AI unit value in proportion to opponent unit value. ('Unit value' here means that the AI weights its decision on the chance to kill a unit or be killed, using a combination of its own units.) So, to make an AI which considers its units worthless i.e. only cares about how much damage attacks inflict, set aggression at 1 - 0 = 1.0. This is the highest meaningful value for aggression; although it is insane, it is used on many HttT levels. If an AI set on this value can inflict 1 damage and take 0, or inflict 2 damage and take 20 himself, he'll take the latter option. To make an AI which considers its units equally as valuable as its opponent's i.e. only attacks if he feels he can inflict more damage than he receives, set aggression at 1 - 1 = 0.0. Although an AI which considers its opponent's units worthless is impossible under this scheme, an AI which, for example, considers its units twice as valuable as its opponent's can be represented by aggression 1 - 2 = -1.0. having to be able to inflict more damage than he takes for it to be worth his while. The default is 1 - 1/2 = 0.5, which means the AI is content with dealing only half the damage to his opponent of that which he himself takes.
  • caution A number 0.0 or higher (default=0.25) that affects how cautious the AI is in various ways. If it is higher, the AI will want to retreat more (especially to a better defensive terrain), it will dislike moving out of a defensive terrain to attack more, and, if grouping is enabled, it forms bigger groups to protect from enemies when going to a target.
  • village_value A number 0 or higher (default=1) which determines how much the AI tries to capture villages.
  • leader_value A number 0 or higher (default=3) which determines how much the AI targets enemy leaders.
  • villages_per_scout A number 0 or higher which determines how many scouts the AI recruits. Defaults to 4. If 0, the AI doesn't recruit scouts to capture villages.
  • [target] Any number of [target] tags can be used to set a target for the AI. For anything related to 'values', set them relative to other targets. An AI is willing to dedicate twice as many resources and travel twice as far to get a target worth '2.0' as it is a target worth '1.0'.
    • standard unit filter
    • value: A number greater than 0 (default=1) which determines how much the AI tries to kill all units which pass the filter.


These AI controls are placed within a [ai] tag within a [side] tag:

  • recruitment_ignore_bad_movement if 'yes', the AI will not analyse the terrain to see if the unit is suitable for it.
  • recruitment_ignore_bad_combat if 'yes', the AI will not analyse the units the enemy has fielded to see if the unit is suitable for fighting them.
  • passive_leader if 'yes' the AI leader will never move or attack, except to obey [leader_goal]s.
  • attack_depth a number from 1 to 6, default 5. This is how many units will be thought about to attack a single unit. If the attack is completed, the AI on another round of thinking may still decide to attack that unit again with other units. Note that in battles, a unit usually can't be attacked from all six sides anyway, so any high attack_depth will be about the same. If attack_depth is low, the AI won't want to attack unwounded units very much, because it doesn't think it can kill them in the attack.
  • simple_targetting When the AI decides what targets to move towards with which units, it considers all its units that can move, sequentially. For each unit, it decides what the best target for it to go towards is. If not 'yes', it will check if any other units would be better to go towards that target than the unit it is currently considering.
  • scout_village_targetting The AI multiplies the value of village targets for scouts by this value. The default is 3.
  • grouping how the AI should try to group units
    • 'offensive' (the default): Makes the AI try to group units together before attacking.
    • 'defensive': Makes the AI group units together very conservatively, and only advances much beyond its castle if it has overwhelming force.
    • 'no': Makes the AI not use grouping behaviour. This is what it used to be like.
  • protect_leader and protect_leader_radius - the way these parameters work, is to target any enemy units that come within 'protect_leader_radius' of the AI leader with a value of 'protect_leader' on the units. The default for these values are 1.0 and 20.
  • [protect_location] gives the AI a location to protect. Note that the AI will NOT station any units around the location, it will only send units to attack any enemy units that come within the guarding radius of the target.
    • x, y standard coordinates. These indicate the location the AI is protecting,
    • radius indicates the radius around it to protect
    • value indicates the importance of protecting this location
  • [protect_unit] gives the AI a set of units to protect. Note once again that the AI will not place units around the unit if there are no enemies nearby.
    • standard unit filter- the unit(s) to protect
    • radius indicates the radius around it to protect
    • value indicates the importance of protecting this location
  • [avoid] Makes the AI avoid a specific location or unit.
    • x, y standard coordinates- A location for the AI to avoid moving to. The AI will never move a unit to this location except for trying to move its leader to a keep.
    • standard unit filter- A set of units for the AI to avoid moving to. This feature is currently not implemented.
  • [leader_goal] Makes the AI try to move its leader to a specific location (as in the goal of The Elves Besieged).
    • x, y the location for the AI to move its leader to
  • time_of_day the time(s) of day when the AI should use the parameters. This applies to the entire [ai] tag, so multiple [ai] tags are usually used. Possible values are listed in data/schedules.cfg (See TimeWML).
  • turns which turn numbers the AI tag applies during. This applies to the entire [ai] tag, so multiple [ai] tags are usually used. This takes the same syntax of dashes(-) and commas(,) as is described under Filtering Locations in FilterWML, except of course they apply to turns not locations.

See Also