Rounding in Warbarons Battles

Discuss anything related to warbarons.

Rounding in Warbarons Battles

Postby Chazar » Thu May 16, 2013 8:28 pm

tl;dr: Tiny rounding bug which imho is beneficial as it is and should not be fixed.

Warbarons calculates propabilites in floating point, but rolls integer dice. However, instead of rounding probely, the probabilites are apparently truncated to the lower value.

This manifests itself in various ways, for example:
  • Heroes with UL10 such as a HorseLord will never die against Skeletons (Str 3) in Level 1 ruins (Dice 12), calculation follows below.
  • 8 elves (12/2) attacking 4 minotaurs (25/2) in the open have on average a success chance of 65.8%, but vice versa, 4 minotaurs attacking 8 elves have a success chance of 38.2%. Note that 65.8%+38.2% = 104%, although the battle ought to be symmetric (no ambush, no defense or attack boni).
Note that I actually created a testing map, where I fought these battles several times, and sifted through the protocols. The detailed explanation is as follows:

Instead of possible infinite die rolls, Warbarons calculates a single percentage for the next hit through this formula:
a * (1-d) / (a * (1-d) + (1-a) * d)


So in the case of Str10 versus Str3 at Ruin Dice 12 we have:
10/12 * (1-3/12) / (10/12 * (1-3/12) + (1-10/12) * 3/12) = 0.9375

Now we must scale back to the die used:
0.9375 * 12 = 11.25

And indeed, inspecting the die rolls show us 11.25 attached for the attacking hero and 0.75 for the poor defending Skeleton. The die delivers correctly a number between 1 and 12, with 1 being the worst outcome for our hero.
Unfortunately for the Skeleton: 1 > 0.75, so the Skeleton cannot win.

And here is the picture proof (scroll to the right and look at the top line saying "Battle roll: 1/12" and see who takes the hit:
UL10vs3.jpg
HorseLords don't loose against Skeletons
UL10vs3.jpg (99.19 KiB) Viewed 31744 times

The calculations for the Elves vs Minotaurs follows similarly, but given the large die, the effect is barely noticeable (well about 2% in favor of the attacker, but assymetrically distributed, but the 1000 simulations vary by more than that any way).

In fact, I would not want a fix, since I like it that there is a tiny advantage for the attacker.
However, I would suggest increasing the skeletons strength, so that skeletons are not a guaranteed win for heroes with UL 10 already.

Another simple fix possibility would be to cap the probability from below at 1, so that there is always a chance to take a hit, but then even heoroes with UL30 could die in L1 ruins (although extremly rare) which I would not like so much.
Chazar
 
Posts: 670
Joined: Tue Feb 28, 2012 7:51 pm

Re: Rounding in Warbarons Battles

Postby KGB » Thu May 16, 2013 10:36 pm

Chazar,

Fantastic detective work here on this!

Unfortunately it's got to get fixed because reaching 100% when you aren't 100% isn't a good thing. I've been wondering why I've never had a 10 or 11 strength hero manage to die to skeletons in a ruin and now I know why. I just thought I was incredibly lucky.

I'm also wondering if it's affecting the regular battle combat in ways we don't recognize either. In a recent game for example I had a maxed Barbarian (75 str, 5 hits) who survived more than 12 battles against enemy Wolfriders (1 or 2 of them) when I was on average about 80-85% likely to win each one. It was either an incredible run of luck or something affected all those battles in some subtle manner.

The easiest way to fix seems to be to fix the rounding to round up at .5 or above and down at less than .5. That would make those 11.25's turn into 11's where they should be. Then add another check of logic where the weaker unit gets at least 1 dice face unless the opponent is guaranteed victory (this handles the case of Ghouls at str 5 battling a hero with 32 str in a L3 ruin because otherwise the Ghouls hit chance is .001 and doesn't even get 1 dice face even on rounding up).

KGB
KGB
 
Posts: 3030
Joined: Tue Feb 16, 2010 12:06 am

Re: Rounding in Warbarons Battles

Postby Chazar » Fri May 17, 2013 6:07 am

KGB wrote:Chazar,
I'm also wondering if it's affecting the regular battle combat in ways we don't recognize either. In a recent game for example I had a maxed Barbarian (75 str, 5 hits) who survived more than 12 battles against enemy Wolfriders (1 or 2 of them) when I was on average about 80-85% likely to win each one. It was either an incredible run of luck or something affected all those battles in some subtle manner.
No, this bug should have not affect your barbarian. Ambush is a percentage and the die roll is 1..100, so no rounding involved. However, it does affect the opposed strength checks, but overall I get the 84% that would be expected against a lone wolf.

As for the fix, I don't know how expensive rounding would be - it happens a lot in these battles.

I would rather suggest avoiding these small dice roll, using the same die everywhere, i.e. 100-sided die for all ruins. Of course, one would have to adjust undead lore values and the defenders to obtain similar propabilities for ruin search.

This would be highly beneficial for new players, since once they understand ordinary battles, they would also understand uin search probabilites - ie. one thing less to learn, without changing the game at all (the probabilites are the same)!
Chazar
 
Posts: 670
Joined: Tue Feb 28, 2012 7:51 pm

Re: Rounding in Warbarons Battles

Postby KGB » Fri May 17, 2013 2:42 pm

Chazar wrote:No, this bug should have not affect your barbarian. Ambush is a percentage and the die roll is 1..100, so no rounding involved. However, it does affect the opposed strength checks, but overall I get the 84% that would be expected against a lone wolf.


You right. But what I meant was more related to the other thread where you were talking about the 10% rule. I am wondering if the 10% rule is causing Barb's to survive single unit ambush if the combat part (non-ambush) results in a <10% chance for the lone unit. in other words the 84% might be the battle outcome but the 10% rule may cause it to be re-rolled until the Barb wins. Unless it's applied to the Ambush part too. Which I don't know since I haven't seen the actual code used. I was just very very surprised to see my Barb survive over 12 encounters with Wolfriders during the course of that game. I can't recall the last time I saw a high level Barb (65+ strength) lose to a single lone weak ambush unit that would on it's own have <10% chance to win the combat part of the battle.

Chazar wrote:As for the fix, I don't know how expensive rounding would be - it happens a lot in these battles.


Me either. However if speed is an issue then what Piranha should do is create a lookup table of 4900 entries (70x70 covering 5-75 strength range). Then run every combo from 5-75 strength and work out the dice numbers and load the lookup table. This is something that has to be done one time offline and saved on the server. After that in every battle you simply look up in the table what your dice numbers are. That's MUCH faster than working out the probability of a hit every time by comparing strengths.

KGB
KGB
 
Posts: 3030
Joined: Tue Feb 16, 2010 12:06 am

Re: Rounding in Warbarons Battles

Postby tabanli » Sat May 18, 2013 12:26 am

I already have the table on excel, I used the same formula Chazar presented. That formula gives the relative hit ratio.

This also explains why the info button for undead battles only gives the probability. I was wondering about why there is no sampling for Undead battles. Great work Chazar.
tabanli
 
Posts: 283
Joined: Thu Jan 31, 2013 4:47 am

Re: Rounding in Warbarons Battles

Postby piranha » Sat May 18, 2013 6:40 am

Ambush is included in the simulation. So if a high level barbarian faces a lone wolf it should be possible to die.

Would it still be possible with a lookup table with ambush instead of simulation?
The lookup table you describe is just for the dice roll? The number of units must also impact the table size?
User avatar
piranha
Site Admin
 
Posts: 1188
Joined: Fri Feb 12, 2010 9:44 pm

Re: Rounding in Warbarons Battles

Postby KGB » Sat May 18, 2013 5:36 pm

Piranha,

piranha wrote:Ambush is included in the simulation. So if a high level barbarian faces a lone wolf it should be possible to die.


Good to know. He must have been the luckiest Barbarian in the world. A true Conan to have survived all those encounters :D

piranha wrote:Would it still be possible with a lookup table with ambush instead of simulation?
The lookup table you describe is just for the dice roll? The number of units must also impact the table size?


Unfortunately no. I can't figure out any table that would easily replace the simulation. Not just because of ambush but because sometimes the unit that survives and moves on has 1 hit or 2 hits or 3 hits or even 4 hits left. So you'd need an almost infinitely large table to handle all that.

The table I mentioned and the one Tabanli has simply replaces doing this calculation:

a * (1-d) / (a * (1-d) + (1-a) * d)

for both units in order to determine what their chances of getting a hit are. Then multiplying that by the dice (D100) to get the dice roll numbers for the unit. The table simply has the final dice roll number stored in it. So for example when a 5 strength unit faces a 5 strength unit (upper left most square in the table) the number stored would be 50. That would indicate 1-50 = hit rolls for the 5 strength unit. When a 5 strength unit faces a 75 strength unit (upper right most square in the table) the number stored would be 2 (1.72% rounded up). That would indicate 1-2 = hit rolls for the 5 strength unit.

KGB
KGB
 
Posts: 3030
Joined: Tue Feb 16, 2010 12:06 am


Return to Game discussion

Who is online

Users browsing this forum: No registered users and 9 guests

cron
Not able to open ./cache/data_global.php