Battle AI Part 3 - CREATURE ATTACKS

[size=75]Continuing the Battle AI discussion threads (links to the other topics here). The rules presented here will be split in 3 categories:
**Basic **– should ensure a decent AI until better rules are put in place
**Advanced **– the minimum on the long term, so that VCMI AI is at least as good as the one in H3
**Expert **– sophisticated rules, which should make the computer an worthy opponent
[/size]

[size=150]Battle AI Part 3 - CREATURE ATTACKS[/size]

3.A. RANGE
(magic projectiles included)
1 (Basic) GOLDEN RULE would be enough for starters: shoot the target on which they can inflict the maximum damage.

With range penalty implemented, the above rule will probably give use 90% chance that AI makes the best, or at least the 2nd best choice. But for now that should be more than enough. If an enemy creature comes next to them, blocking their shooting ability, the melee rules should apply.

Advanced & Expert rules for shooters to follow.

Advanced rules would involve the use of Wait and make differences between shooters w/ or w/o melee penalty and take into consideration the retaliation of their potential targets. Expert rules would analyze probabilities, spell effects, make long term plans and consider the use of Defend.

3.B. MELEE
Basic rules (ideally to be implemented before 0.9, or at least before 1.0)

  1. Go for the most “profitable” attack (let’s call it MPA). The formula would be MPA = ADI - ADR, where:
    ADI = Average damage inflicted
    ADR = Average damage received in retaliation (if applicable)
    For starters, the formula should at least be based on the creature stats, specific creature abilities (no retaliation, always retaliates, max. damage always, etc) and whether the enemy wasted their retaliation for the turn already or not. As a 2nd step, the formula should be enhanced by taking into account all the temporary buffs & debuffs on both attacker & attacked (bless, curse, prayer, counterstrike, fire shield etc)

  2. Assess best choice when creature turn comes, based on the current situation, not at the beginning of battle round (or any other time earlier)

  3. Apply rule #1 by analyzing only the enemies reachable at the moment. If none reachable in that round, select target only among the creatures reachable within the least amount of rounds, and move towards it.

  4. Block shooters: if you have the choice of attacking the as per above selected target from multiple hexes, and one of this hexes is adjacent to an enemy shooter, then attack from there (to be further elaborated in the Advanced/Expert rules)

  5. Avoid castle trap as much as possible:

  • Walkers should not step into a castle trap as long as there is any other way to get to a target, e.g.: gate down, enemy on their side of walls, landmine already detonated in other hex at Tower (where applicable). And even if attacker has no path to a target, they should not step into the trap if the wall on the other side of the trap hex is not destroyed.
  • Flyers who can’t reach an enemy in 1 turn should only go as far the closest-to-target available hex other than a trap hex (this rule also covers the risk of becoming dead meat behind enemy lines, when flying just over the walls, but not close enough to reach the target)
  • Shooters/Casters – needless to say they should keep on shooting as long as they can. :slight_smile:

Advanced rules (only listed for now, to be detailed later on)

  1. Once multiple attacks are implemented (firebreath/fireball/death cloud/multi-head attacks/etc), take them into account when calculating MPA (#1 above) as well as all other rules.

  2. Avoid vulnerable hexes (shooters’ range, fire breath, area spells)

  3. Use enemy’s firebreath/fireball/death cloud in your advantage

  4. Use Wait if no enemy in range AND the enemy still has creatures to move UNLESS the only enemy creatures left to move are shooters who ALREADY have us in full

  5. If AI walker/flyer cannot reach any enemy in 1 go AND is however vulnerable to one (i.e.: full shooter range or reachable in 1 go by walker/flyer) AND AI creature has any chance to get Morale (hence a chance for an extra move, to reach the enemy before they move), then they should move towards target. ELSE use Wait (if target is a shooter AND Wait still available, ELSE move) or Defend (if target is a walker/flyer).

Expert rules would really be very specific rules, which take into consideration:

  • Enemy hero spell points left
  • Whether enemy wasted their casting turn
  • Probabilities of enemy owning/casting certain spells (depending on alignment, level, owned castles etc) > or better, AI should know exactly what spells the enemy has in the book and only calculate the probability of enemy choosing one spell or another
  • Strategic troop placement, planning more than 1 battle round in advance, depending on possible enemy moves
  • etc