How it works - Ai priorization
Posted: Sun Nov 15, 2020 6:57 pm
I make this while i am reading tru code how it works - so we have all the knowledge
(prelude:
- AI is running tru all units on game and assigns possible tasks to them (on enemies eg. attacking or asting a spell, on allies casting spells, on TC-s defending tasks so all that is fir to target unit)
- after that AI storts which task gets most score on that unit (one unit can have hundreds of possible tasks assigned to it) - this topic is about this step!
- after getting the highest score it assigns that task to the unit.
- and runs the tasks on all playe's units
)
so AI decides what task to give to a unit based on score if the given task in the given situation.
task can be, few examples: move, attack, use ability, occupy, goheal, mend, build things and such like this.
here are the defined tasks and their priorities so far
public static final int TASK_DO_WATER_CARRY = -1; //a carrier should do this
public static final int TASK_TC_GO_DEFEND = 0;
public static final int TASK_TC_ATTACK = 1;
public static final int TASK_TC_OCCUPY_ENEMY = 2;
public static final int TASK_TC_OCCUPY_NEUTRAL = 3;
public static final int TASK_ATTACK_ENEMY_UNIT = 4;
public static final int TASK_SUMMON_NEW_UNIT = 5; //
public static final int TASK_SPELL_ON_ENEMY_UNIT_OR_CONVERT = 6; //convert or any other enemy targeted spell
public static final int TASK_ATTACK_ENEMY_BUILDING = 7; //wall or tower
public static final int TASK_SAVE_OWN_ASS = 8; //if 40% or less power than do it, under 20%, harder
public static final int TASK_HEAL_UNIT = 9; //heal or mend
public static final int TASK_MEND_UNIT = 10; //mend wall or tower, mendable units
public static final int TASK_SPELL_ON_FRIENDLY_UNIT = 11; //cast buffers onto unit
public static final int TASK_TC_BUILD_DEFENSE = 12;
public static final int TASK_BUILD_FACTORY = 13;
public static final int TASK_WANDERING_AROUND = 19; //neutral annimals
score starts with 0
("i" = unit to set task to)
case TASK_TC_ATTACK, TASK_ATTACK_ENEMY_UNIT, TASK_ATTACK_ENEMY_BUILDING:
score = 0
- if target is one-hit killed: score = +10 + 10 * TargetUnitValue
- else if i can shoot target but that can not walk to me to hit: score = +3 + 2 * TargetUnitValue
- else if i am a mender or healer than: score = -10
- else if i am a transporter (like ship or wagon) having TRANSPORTING_VEIN: score = -100
- else score = 0
- if i have bonus agasisnt it: score = score +2
- if target is neutral than do not urge to kill score = -100
- if target is passive units like "wall"s score = -100
case TASK_SPELL_ON_FRIENDLY_UNIT, TASK_SPELL_ON_ENEMY_UNIT_OR_CONVERT:
score = 0
- score = effectPriority / 100 effect priorities are about 0..1000
case TASK_TC_GO_DEFEND:
score = 0
- if i can mend or heal: score = score -2
- else if i can carry units: score = score -1
- if i can attack: score = score +1
- if unit is already inside TC : score = score +10
- else if unit can go into tc with one move: score = score +5
- else if unit can go into tc with 1.5 move: score = score +1
case TASK_TC_OCCUPY_NEUTRAL, TASK_TC_OCCUPY_ENEMY:
score = 0
- if unit can occupy in one move: score = 50
- else if unit can occupy in 1.5 move: score = 10
- else if i can heal or mend score = -1
if TASK_TC_OCCUPY_NEUTRAL score = score +10
case TASK_SAVE_OWN_ASS:
if i am fatally injured: score = 3
else score = 1
case TASK_HEAL_UNIT, TASK_MEND_UNIT:
- i am nearby and target is underconstruction and is a factory: score = 9
- i am nearby and target is underconstruction and is NOT a factory: score = 7
- i am NOT nearby and target is underconstruction and is a factory: score = 8
- i am NOT nearby and target is underconstruction and is NOT a factory: score = 3
case TASK_BUILD_FACTORY:
- i am nearby score = 6
- else score = 2
case TASK_TC_BUILD_DEFENSE
- i am nearby score = 5
- else score = 1
- if i am close to enemies: score = score + 20
case TASK_DO_WATER_CARRY
score = 20
case TASK_WANDERING_AROUND
score = -1 (neutrals have only this task so scoring does not matter)
Distance modifier:
final score = ((biggest_task_prior(19) - current task prior) + score) / target_distance
(prelude:
- AI is running tru all units on game and assigns possible tasks to them (on enemies eg. attacking or asting a spell, on allies casting spells, on TC-s defending tasks so all that is fir to target unit)
- after that AI storts which task gets most score on that unit (one unit can have hundreds of possible tasks assigned to it) - this topic is about this step!
- after getting the highest score it assigns that task to the unit.
- and runs the tasks on all playe's units
)
so AI decides what task to give to a unit based on score if the given task in the given situation.
task can be, few examples: move, attack, use ability, occupy, goheal, mend, build things and such like this.
here are the defined tasks and their priorities so far
public static final int TASK_DO_WATER_CARRY = -1; //a carrier should do this
public static final int TASK_TC_GO_DEFEND = 0;
public static final int TASK_TC_ATTACK = 1;
public static final int TASK_TC_OCCUPY_ENEMY = 2;
public static final int TASK_TC_OCCUPY_NEUTRAL = 3;
public static final int TASK_ATTACK_ENEMY_UNIT = 4;
public static final int TASK_SUMMON_NEW_UNIT = 5; //
public static final int TASK_SPELL_ON_ENEMY_UNIT_OR_CONVERT = 6; //convert or any other enemy targeted spell
public static final int TASK_ATTACK_ENEMY_BUILDING = 7; //wall or tower
public static final int TASK_SAVE_OWN_ASS = 8; //if 40% or less power than do it, under 20%, harder
public static final int TASK_HEAL_UNIT = 9; //heal or mend
public static final int TASK_MEND_UNIT = 10; //mend wall or tower, mendable units
public static final int TASK_SPELL_ON_FRIENDLY_UNIT = 11; //cast buffers onto unit
public static final int TASK_TC_BUILD_DEFENSE = 12;
public static final int TASK_BUILD_FACTORY = 13;
public static final int TASK_WANDERING_AROUND = 19; //neutral annimals
score starts with 0
("i" = unit to set task to)
case TASK_TC_ATTACK, TASK_ATTACK_ENEMY_UNIT, TASK_ATTACK_ENEMY_BUILDING:
score = 0
- if target is one-hit killed: score = +10 + 10 * TargetUnitValue
- else if i can shoot target but that can not walk to me to hit: score = +3 + 2 * TargetUnitValue
- else if i am a mender or healer than: score = -10
- else if i am a transporter (like ship or wagon) having TRANSPORTING_VEIN: score = -100
- else score = 0
- if i have bonus agasisnt it: score = score +2
- if target is neutral than do not urge to kill score = -100
- if target is passive units like "wall"s score = -100
case TASK_SPELL_ON_FRIENDLY_UNIT, TASK_SPELL_ON_ENEMY_UNIT_OR_CONVERT:
score = 0
- score = effectPriority / 100 effect priorities are about 0..1000
case TASK_TC_GO_DEFEND:
score = 0
- if i can mend or heal: score = score -2
- else if i can carry units: score = score -1
- if i can attack: score = score +1
- if unit is already inside TC : score = score +10
- else if unit can go into tc with one move: score = score +5
- else if unit can go into tc with 1.5 move: score = score +1
case TASK_TC_OCCUPY_NEUTRAL, TASK_TC_OCCUPY_ENEMY:
score = 0
- if unit can occupy in one move: score = 50
- else if unit can occupy in 1.5 move: score = 10
- else if i can heal or mend score = -1
if TASK_TC_OCCUPY_NEUTRAL score = score +10
case TASK_SAVE_OWN_ASS:
if i am fatally injured: score = 3
else score = 1
case TASK_HEAL_UNIT, TASK_MEND_UNIT:
- i am nearby and target is underconstruction and is a factory: score = 9
- i am nearby and target is underconstruction and is NOT a factory: score = 7
- i am NOT nearby and target is underconstruction and is a factory: score = 8
- i am NOT nearby and target is underconstruction and is NOT a factory: score = 3
case TASK_BUILD_FACTORY:
- i am nearby score = 6
- else score = 2
case TASK_TC_BUILD_DEFENSE
- i am nearby score = 5
- else score = 1
- if i am close to enemies: score = score + 20
case TASK_DO_WATER_CARRY
score = 20
case TASK_WANDERING_AROUND
score = -1 (neutrals have only this task so scoring does not matter)
Distance modifier:
final score = ((biggest_task_prior(19) - current task prior) + score) / target_distance