How are chosen retaliation attacks? AI behavior

Share and discuss strategies for playing the game, and get help and tips from other players.

Moderator: Forum Moderators

User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

How are chosen retaliation attacks? AI behavior

Post by tekelili »

I had this situation in a recent ladder game:

I was elves with druid as leader vs ud. when final battle started I wanted to fill a spot with my leader to reincorce my line and slow a skull. But that move was offering my oponent a ctk on my leader. I started to do quick mental maths ("he firts must remove my fighter from 2 spots, go 2/2 with his leader and avoid my first slow attack, then go 2/3 with skull... :doh: I think he have less than 15%... ok, lets go with her").

He finally didnt try that ctk in game and I forgot issue. But I recently watched replay again and suddenly a terrific thought invaded my mind:"how could I be sure my druid would use slow attack as retaliation?" I never gave any importance to this issue. I think druid is probably the only case where this matters. I play lot of druids in world conquest multiplayer campaign and in rare ocasions, AI surprises me chosing the magical attack instead slow one as retaliation... but well, is wc and I didnt care too much. But if I am playing a ladder game, I think I should be more carefull and be sure about how AI take this decision.

Anyone knows wich algoritm is used to decide this?

As side note, may be would be good idea set always slow attack as retaliation.

Edit: of course vs more than 1 strike ranged attacks, no sense slow thunders :lol2:

Edit2: Thinking more about this... could be this some kind of "reduction in power leveled units is bad" vilolation? Would a resilent chaman have more chances to survive to a 3/3 hit of a lieche than if she levels and ai decide retaliate with magical one? (I am not sure about this, but may be someone can find a case where this could happens if lieche dont suit)
Last edited by tekelili on May 9th, 2011, 10:59 pm, edited 2 times in total.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: How are chosen retaliation attacks?

Post by Dixie »

Code exists to force (or increase the likeliness of) a certain attack to be picked (when ther eis more than one choise, obviously). I do not know if this is used in mainline, however. Appart from that, AFAIK, the AI chooses the attack that can cause the maximum amount of damage, regardless of cth, specials or whatever. But I may be wrong, though...
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Joram
Posts: 366
Joined: September 2nd, 2008, 5:36 am

Re: How are chosen retaliation attacks?

Post by Joram »

I think the AI takes into account chance to kill enemy vs chance to die.

If you have a good chance of dieing unless you use slow, it should use slow (based on my experience). The exception would be if one hit from your magical attack would kill the enemy, thus giving you a better chance of surviving that enemies attacks by killing it than by slowing it.

I don't know for sure, but that's my experience.
The Fires of Pride 0.3, a heavily story based campaign.
On hold while I try and finish my book
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: How are chosen retaliation attacks?

Post by zookeeper »

The last I remember is that the attack which gives you the greatest chance of survival is used, with the second criteria after that being the highest expected damage.
User avatar
Wendek
Posts: 72
Joined: February 24th, 2007, 6:27 pm
Location: In a chaotic world

Re: How are chosen retaliation attacks?

Post by Wendek »

Doesn't seem to factor in Drain very nicely, though.
In a campaign (To Lands Unknown, so it's both custom faction and campaign, so it might not be that relevant), my unit was swarmed by bats (lvl 1/2 ones) and kept using a 16-2 or something attack to kill them instead of his less powerful one (8-3 or so, numbers are wrong but you get the idea) that has drain. As a result it was close to death for quite a lot of turns, because in said scenario there's an endless stream of bats, hence killing them just allows for more to hit.

Maybe it could use the "average hitpoints at the end of the fight" instead ? (say, if one retaliation has 36% to kill the enemy but also leaves you 20 hps on average, and the other one has 0% chance to kill but leaves you with 30 hps on average, it'd choose the latter)
Means that Druids and the like would only use slow as retaliation, though, maybe it'd be problematic. (though it'd help if the enemy tricks the druid into using her magical attack, and then attacks with a second unit who can kill said druid in one hit, making the slow part useless)

P.S. Sorry if I got a bit offtopic there.
"You see, it's not about what you take with you, it's about what you leave behind." (Turisas, The Bosphorus Freezes Over)
"A man chooses, a slave obeys." (Andrew Ryan, BioShock)
Caphriel
Posts: 994
Joined: April 21st, 2008, 4:10 pm

Re: How are chosen retaliation attacks?

Post by Caphriel »

zookeeper wrote:The last I remember is that the attack which gives you the greatest chance of survival is used, with the second criteria after that being the highest expected damage.
This is how it works, I am pretty sure. I tested it a while back. If your unit has a chance to die, it chooses the attack that minimizes that chance. If there is no difference in chances to die (including 0% ctd), it maximizes expected damage. This is why dwarf fighters that are at risk of dying often use the hammer to counter-attack.

Wendek, changing the algorithm to prefer maximizing the defending unit's HP at end of combat over minimizing the attacking unit's HP would significantly alter the behavior of units with slow attacks or drain attacks. Whether or not this is desirable is arguable, but I lean toward not. For instance, consider the vampires from Era of Myths, which have a strong melee attack and a weak drain melee attack that also has backstab. If the algorithm was altered as you suggest, you'd be favoring 5-2 retaliation over 7-3 retaliation, which I suspect most players would find undesirable. This would also alter the balance of high level shaman line units in forest. However, I suspect you can control what attack is used for retaliation using WML.
User avatar
Wendek
Posts: 72
Joined: February 24th, 2007, 6:27 pm
Location: In a chaotic world

Re: How are chosen retaliation attacks?

Post by Wendek »

Oh yes, forgot about vampires. My idea would sure weaken them, sadly.
The problem is that sometimes you want your retaliating unit to deal maximum damage, and other times you just want it to act like a wall and stall the upcoming enemies so your main force can advance without getting sandwiched. In campaigns (which is what I play most, though I believe more people prefer multiplayer), I often use the latter, especially in scenarios where enemies have a kind of "reinforcements" coming in your back.
But I'm aware that "case-by-case" would be very heavy and tedious to use... so I guess in the end I shouldn't have mentioned that because there's no real solution, heh ?
"You see, it's not about what you take with you, it's about what you leave behind." (Turisas, The Bosphorus Freezes Over)
"A man chooses, a slave obeys." (Andrew Ryan, BioShock)
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: How are chosen retaliation attacks?

Post by tekelili »

Caphriel wrote: This is how it works, I am pretty sure. I tested it a while back. If your unit has a chance to die, it chooses the attack that minimizes that chance. If there is no difference in chances to die (including 0% ctd), it maximizes expected damage. This is why dwarf fighters that are at risk of dying often use the hammer to counter-attack.

Wendek, changing the algorithm to prefer maximizing the defending unit's HP at end of combat over minimizing the attacking unit's HP would significantly alter the behavior of units with slow attacks or drain attacks. Whether or not this is desirable is arguable, but I lean toward not. For instance, consider the vampires from Era of Myths, which have a strong melee attack and a weak drain melee attack that also has backstab. If the algorithm was altered as you suggest, you'd be favoring 5-2 retaliation over 7-3 retaliation, which I suspect most players would find undesirable. This would also alter the balance of high level shaman line units in forest. However, I suspect you can control what attack is used for retaliation using WML.
For default era, I am totally sure I prefer all my units retaliate with slow before current behavior. No matter if I am playing campaing or multiplayer.

With current behavior I am almost sure must be situations where a lvl1 shaman has more chance of survive to a 2 spot attack than a lvl2 druid that wont retaliate with slow to first spot attack because has "0% ctd".

Edit: And thanks Caphriel for solve my doubt, I forgot it at 1st intance :)
I wonder if developers would consider add this psudocode to AI behavior:

[if]
Unit has a retaliation attack that slows
[and]
attacker has more than 1 strike
[/and]
[then]
Use highest damage available attack with slow
[/then]
[else]
Use current behavior
[/else]
[/if]
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Caphriel
Posts: 994
Joined: April 21st, 2008, 4:10 pm

Re: How are chosen retaliation attacks?

Post by Caphriel »

You're welcome. I hope that it isn't changed. I like the current behavior, both playing as and against the rebels.
Last edited by Caphriel on May 9th, 2011, 1:33 pm, edited 1 time in total.
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: How are chosen retaliation attacks?

Post by tekelili »

I just watched a direwolf retaliate with poison attack vs a unit with 0 blade resistance. It looks like AI behavior is a little more complicated than you explained Caphriel :?

EDIT: This was in 1.8.5
Last edited by tekelili on May 9th, 2011, 1:48 pm, edited 1 time in total.
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
Velensk
Multiplayer Contributor
Posts: 4002
Joined: January 24th, 2007, 12:56 am

Re: How are chosen retaliation attacks?

Post by Velensk »

The AI has recently been taught to factor in poison damage.
"There are two kinds of old men in the world. The kind who didn't go to war and who say that they should have lived fast died young and left a handsome corpse and the old men who did go to war and who say that there is no such thing as a handsome corpse."
monochromatic
Posts: 1549
Joined: June 18th, 2009, 1:45 am

Re: How are chosen retaliation attacks?

Post by monochromatic »

From AI behavior, if the unit can't be killed or be almost killed, it'd use poison if possible. Now we just need to help the AI understand stacking poison isn't going to poison the unit faster..
Caphriel
Posts: 994
Joined: April 21st, 2008, 4:10 pm

Re: How are chosen retaliation attacks?

Post by Caphriel »

In 1.8 or 1.9, tekelili? Also, keep in mind that, as I said, I tested it a while back. Probably in 1.6.

Getting the AI to not poison a poisoned unit doesn't sound that hard... :lol2:
User avatar
tekelili
Posts: 1039
Joined: August 19th, 2009, 9:28 pm

Re: How are chosen retaliation attacks?

Post by tekelili »

I consulted with a developer in MP server and he was agree with Caphriel in keep current AI behavior in retaliation with slow chances, so I wont go further in this issue. Just for the records if anyone browse this tread in future, I will say that if I am playing a multiplayer game vs humans players with default settings, a lvl2 druid or sorceress unit is likely to be my leader. And if my oponent uses range attack on my leader, it likely to be a leader kill try and my oponent will be very happy of my leader not using slow as retaliation.

I find hard lose my leader just because... she is stupid. And also looked to me kinda RIPWLIB that when shamans lvl, take less care of her own live than when she was lvl1. I also find quite difficult calculate ctk on your druid or sorceress leader when deciding put her in front line. And very odd that to protect a spot that offers 2 possible attacks in some situations where you have 2 druids to do that job, the one with less hp is actually better to do it. But I must be the only one that think so.

Edit: If AI was taught to factor poison, my only hope is also become taught to factor slow in future, so AI can understand how stupid is use hiest retaliation damage with a shyde vs a sharpshoter in terms of total hp losed/inflicted.

Edit2: this thread becomed me to think that if is expected players plan their units moves, and their units will be totally "controled" by AI on oponents turns, may be would be desirable AI behavior was explained in Wesnoth help (sorry if it already is, I couldnt find it)
Be aware English is not my first language and I could have explained bad myself using wrong or just invented words.
World Conquest II
The Black Sword
Posts: 373
Joined: October 13th, 2008, 4:35 pm

Re: How are chosen retaliation attacks? AI behavior

Post by The Black Sword »

The AI's behavior makes sense on most units where the objective is to maximise your hp dealt/hp received ratio.
But perhaps in the special case of leaders it would be better to minimise hp received? Might be an idea and shouldn't be too hard to change I think.
Post Reply