bugBattle for Wesnoth - Bugs: bug #14076, Poor weapon selection when...

 
 
Show feedback again

bug #14076: Poor weapon selection when attacking berserk units

Submitted by:  Guillaume Melquiond <silene>
Submitted on:  Thu 06 Aug 2009 07:13:35 AM UTC  
 
Category: Feature RequestSeverity: 2 - Minor
Priority: 5 - NormalItem Group: Artificial Intelligence
Status: NonePrivacy: Public
Assigned to: Iurii Chernyi <crab>Open/Closed: Open
Release: 1.7Operating System: any

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Tue 17 Nov 2009 09:18:03 PM UTC, comment #7:

postponing this FR to 1.9, since it's not entirely clear what is the best way to deal with this situation.

Iurii Chernyi <crab>
Project MemberIn charge of this item.
Tue 03 Nov 2009 04:34:37 PM UTC, comment #6:

I don't understand your reply. The attack prediction code already follows the whole Markov chain. From a mathematical/statistical point of view, the predictions are exact. The problem is really with the weapon selection: although the engine knows that the unit will perform a suicide attack (again, the prediction computations are correct!), it still selects the suicide weapon. So reverting to the older title, since the odd computations are already optimal.

Guillaume Melquiond <silene>
Tue 03 Nov 2009 11:55:08 AM UTC, comment #5:

There's a way to do this right, by changing the expected-damage calculation to chase the whole Markov chain implied by the attack-defense sequence. But that would go beyond a bug fix and way beyond what we should be doing pre-1.8.

Changing to FR and retitling from "Poor weapon selection when attacking berserk units" to something more appropriate.

Eric S. Raymond <esr>
Project Member
Sun 09 Aug 2009 06:54:15 AM UTC, comment #4:

I'm not sure the Goblin Spearman is a relevant example. Indeed, it won't use its melee weapon until aggression is bigger than 0.85. And even if it were to use it, its melee weapon will perform a lot more damage than the ranged weapon.

To put things a bit more in perspective, consider the average damage (the example is still on plains at dawn). The Dark Sorceror will do 20 damage with ranged, 30 with melee. The Goblin Spearman will do 1.4 damage with ranged, 23 with melee. That means that, while the melee attack is suicidal in both cases, at least the Goblin Spearman will do +1500% damage with it!

To summarize, not only does the user interface not suggest the Goblin Spearman to use the melee attack, but if it were to, I'm sure most people would consider it a sensible course of action.

So, unless you find a cheap unit that has the same characteristics than the Dark Sorceror (that is, a massive ranged attack), unit cost doesn't seem to matter at all. And, for balance reason, I doubt you can find such a unit. So I don't see a compelling reason to introduce unit cost in the weapon selection equation.

By the way, lowering the aggression of the user interface is hardly a conservative change. You will change evaluation for all the units, although nobody complained about weapon selection in the general case lately. Fixing the weapon analysis for AI is fine, but that would make the AI at least twice slower. And if you wanted to be exhaustive, it could be 30x slower (a stack of 5 units with two attack weapons each).

Guillaume Melquiond <silene>
Sat 08 Aug 2009 03:35:56 PM UTC, comment #3:

>'Just consider the next unit attacking in the same turn.'

note that, for AI, this weapon selection only takes place when the AI has refused to select weapon (by passing -1 as 'selected weapon' to execute_attack_action).
also note that, at present, we have no way of 'grouping' attacks from 'point-&-click' user interface.
Therefore, at the point where this weapon selection is made, it's not possible to talk about 'next unit attacking at the same turn' - it is not known at this point (of course, we can try to guess by looking 'which attacks are available, but this complicates things, since the point of weapon selection in src/actions.cpp is just to 'select a reasonably good weapon in case no one bothered to select it'). I would prefer to keep that logic simple, as its purpose is just 'provide a fallback way of weapon selection if noone bothered to do it'.

> "In fact, the AI would not launch a suicide attack for naught, so it may have queued another unit already. As a consequence, the defending berserk unit will eventually die. But because of the current weapon selection, an attacking unit died too."

This case must be fixed by AI actually selecting the weapon used during attack analysis. The fact that it does not do this is a separate bug.

> "In particular, no need to introduce unit cost, since it is already taken into account elsewhere."

Is it so for human attacks ? How is the unit cost taken into account in that case ? Moreover, suiciding 9-gp goblin spearman (who, too, has both ranged and melee attacks) with 37% chance of success is a lot better then suiciding a 32-gp Dark Sorcerer with the same 37% chance of success.

> 'But there should be a conservative change to it, so that an attack of the attacking unit does not become overrated when it incurs a berserk defense (due to the defending unit necessarily having a nonzero chance of dying).'

What do you think about (in addition to considering unit cost):
1) for human: lowering aggression of human side
2) for ai: fixing weapon selection during attack analysis.

Iurii Chernyi <crab>
Project MemberIn charge of this item.
Sat 08 Aug 2009 02:42:37 PM UTC, comment #2:

My point was indeed that the formula is flawed when berserk units are involved. But note that you don't need to consider "next turn counterattack". Just consider the next unit attacking in the same turn. Since the first unit attacking is doing a suicide attack, the defending unit won't die, so the AI (or the player) will have to launch another attack.

In fact, the AI would not launch a suicide attack for naught, so it may have queued another unit already. As a consequence, the defending berserk unit will eventually die. But because of the current weapon selection, an attacking unit died too.

I'm not suggesting major changes to the current formula, as I think it works fine in almost every other cases. In particular, no need to introduce unit cost, since it is already taken into account elsewhere. But there should be a conservative change to it, so that an attack of the attacking unit does not become overrated when it incurs a berserk defense (due to the defending unit necessarily having a nonzero chance of dying).

Guillaume Melquiond <silene>
Sat 08 Aug 2009 10:28:10 AM UTC, comment #1:

the description of aggression in the wiki states:
'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. (''
so, to better align that description with current situation, it is possible to 'weight' those chances to kill by 'unit value' (e.g., by unit cost)

chance_to_kill*enemy_cost - (1 - aggression) * (chance_to_be_killed*my_cost)

for example, Ulf cost is 19, Dark Sorcerer cost is 32, so this formula (at aggression=0), will consider Dark Sorcerer somewhat more valuable than Ulf, and consider melee only at 62%+ to kill. But, with aggression 0.5, Dark Sorcerer's cost is effectively "16", so it will consider melee only at 45%+ chance to kill.
--

Also, is aggression=0.5 a good value for human side ? (basically, with aggression=0.5, "sacrifice two units to kill one" is ok)

---------
Another (independent) way to fix this is to say that the formula of weapon selection is inherently flawed when attacking berserk, as, it can be better to attack the berserker at range (to weaken it) and then take berserker's counterattack during next turn. So, if we take this 'next turn counterattack' into account, we can get the 'modified' chance of kill of 'ranged now, take counterattack next turn' sequence. Thus, ranged attack can get selected based on this modified chance of kill

Iurii Chernyi <crab>
Project MemberIn charge of this item.
Thu 06 Aug 2009 07:13:35 AM UTC, original submission:

The selected weapon is the one that maximizes
chance_to_kill - (1 - aggression) * (chance_to_be_killed)

This formula works well usually, except when the defender has berserk on one of its weapons. Indeed, the chance to kill is no longer related to the damage done in this case, which can skew the selection badly.

For instance, consider a dark sorcerer attacking an ulfserker at dawn on plains. The ranged attack of the sorcerer deals massive damage for free, but it has no chance to kill the ulfserker. The bare-handed attack is suicidal, but since it triggers berserk, it has a small chance (37%) of killing the ulfserker. Due to the formula above, as soon as the aggression is 0.5 or bigger, the dark sorcerer (lvl 2) will suicide itself!

(By the way, 0.5 is the aggression value of the user interface and 85% of the mainline campaigns have an even bigger aggression.)

To summarize, when attacking a berserker, if the safe attack can't kill, the berserk-triggering weapon will be selected:
- at aggression 0.0, if the chance of suicide is less than 50%,
- at aggression 0.5, if the chance of suicide is less than 63%,
- at aggression 1.0, if the chance of suicide is less than 99%.

Guillaume Melquiond <silene>

 

(Note: upload size limit is set to 1024 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by shadowmaster (Updated the item)
  • -unavailable- added by esr (Updated the item)
  • -unavailable- added by crab (Posted a comment)
  • -unavailable- added by silene (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 11 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 29 Jan 2012 09:35:39 PM UTCshadowmasterStatusPostponed=>None
    Tue 17 Nov 2009 09:18:03 PM UTCcrabStatusNone=>Postponed
    Tue 03 Nov 2009 04:34:37 PM UTCsileneSummaryImprove attack-odds calculation for berserk units=>Poor weapon selection when attacking berserk units
    Tue 03 Nov 2009 11:55:08 AM UTCesrCategoryBug=>Feature Request
      SummaryPoor weapon selection when attacking berserk units=>Improve attack-odds calculation for berserk units
    Sat 12 Sep 2009 06:55:05 AM UTCsileneStatusNeed Info=>None
      Open/ClosedClosed=>Open
    Sun 30 Aug 2009 08:25:23 PM UTCesrOpen/ClosedOpen=>Closed
    Sat 08 Aug 2009 10:28:10 AM UTCcrabSeverity3 - Normal=>2 - Minor
      StatusNone=>Need Info
      Assigned toNone=>crab
    Show feedback again

    Back to the top


    Powered by Savane 3.1-cleanup