Chosen type of attack

General feedback and discussion of the game.

Moderator: Forum Moderators

Post Reply
Sjoerd
Posts: 3
Joined: September 23rd, 2011, 9:44 am

Chosen type of attack

Post by Sjoerd »

Hi all, I was just wondering. How does the game pick the type of attack when there are more then one available? For example you can attack ranged or melee, or cold damage with three strikes while there is fire damage with two strikes. When the fire damage does a lot more damage per strike but not more then the three cold strikes combined it could mean a bigger chance to die. And the same goes for the ranged or melee choice. Does it go for more damage or higher chance to kill/lower chance to die?? I know for sure the game isnt always making the best choice!
User avatar
Astoria
Inactive Developer
Posts: 1007
Joined: March 20th, 2008, 5:54 pm
Location: Netherlands

Re: Chosen type of attack

Post by Astoria »

AFAIK in campaigns, this is dependant on how people have told the AI to attack.
Formerly known as the creator of Era of Chaos and maintainer of The Aragwaithi and the Era of Myths.
Caphriel
Posts: 994
Joined: April 21st, 2008, 4:10 pm

Re: Chosen type of attack

Post by Caphriel »

I think it works as follows: If your unit has a chance to die, the recommended attack is the one with the lowest chance to die. Otherwise, if your unit has a chance to kill, the recommended attack is the one with the highest chance to kill. Otherwise, the recommended attack is the one with the highest average expected damage, with retaliatory damage not taken into consideration.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Chosen type of attack

Post by mattsc »

Caphriel wrote:I think it works as follows: If your unit has a chance to die, the recommended attack is the one with the lowest chance to die. Otherwise, if your unit has a chance to kill, the recommended attack is the one with the highest chance to kill. Otherwise, the recommended attack is the one with the highest average expected damage, with retaliatory damage not taken into consideration.
That's pretty close, but not quite. The AI simulates attacks with all weapons of the attacker. It considers an attack better than another according to these criteria:
  1. Calculate (chance of enemy unit to die) - (chance of own unit to die) * (1 - aggression). Choose the attack with the larger value. If equal, go on to B.
  2. Calculate difference between (average hitpoints after attack - loss due to chance of being poisoned) of own unit [ *(1 - aggression) ] and enemy unit. Again, choose the weapon which gives the better result. If equal, go on to C.
  3. Choose weapon which does the most damage to enemy.
Here, 'aggression' is the parameter described at AiWML. Thus, for example, you can see that setting aggression = 1 means that damage to the AI's own unit is ignored, and only damage to the enemy unit is taken into consideration.

EDIT: I should add that this is only the algorithm for choosing the best weapon for a fixed attacker/defender pair. The method of choosing the best attack from all possible attackers and defenders is quite a bit more complex.
Caphriel
Posts: 994
Joined: April 21st, 2008, 4:10 pm

Re: Chosen type of attack

Post by Caphriel »

I'm pretty sure he was asking about the attack that gets recommended by the game when the player attacks an enemy unit, not which attack the AI-controlled sides select when they make an attack. I may have misunderstood, though.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Chosen type of attack

Post by mattsc »

Caphriel wrote:I'm pretty sure he was asking about the attack that gets recommended by the game when the player attacks an enemy unit, not which attack the AI-controlled sides select when they make an attack. I may have misunderstood, though.
Ah, yes, I might have misinterpreted that. I checked out the source code for the attack dialog, and it uses that same function, but with a hard-coded value of 0.5 for aggression.
Caphriel
Posts: 994
Joined: April 21st, 2008, 4:10 pm

Re: Chosen type of attack

Post by Caphriel »

Thanks :) That is good to know.
Sjoerd
Posts: 3
Joined: September 23rd, 2011, 9:44 am

Re: Chosen type of attack

Post by Sjoerd »

Thanks for the info all!!
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Chosen type of attack

Post by Sapient »

I attempted to rewrite your statement in a bit simpler language:

First consider only the chance to kill and chance to die, with chance to kill given twice the weight of chance to die.

Next consider only the expected damage to enemy and expected damage to self, with damage to enemy given twice the weight of damage to self.

Finally, with all else being equal, just choose the weapon that grants the highest expected damage to enemy.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
fabi
Inactive Developer
Posts: 1260
Joined: March 21st, 2004, 2:42 pm
Location: Germany

Re: Chosen type of attack

Post by fabi »

Sapient wrote:I attempted to rewrite your statement in a bit simpler language:

First consider only the chance to kill and chance to die, with chance to kill given twice the weight of chance to die.

Next consider only the expected damage to enemy and expected damage to self, with damage to enemy given twice the weight of damage to self.

Finally, with all else being equal, just choose the weapon that grants the highest expected damage to enemy.
You forgot about caution and aggression in case of the ai being in control.
Post Reply