Heroes of Might and Magic Community
visiting hero! Register | Today's Posts | Games | Search! | FAQ/Rules | AvatarList | MemberList | Profile


Age of Heroes Headlines:  
5 Oct 2016: Heroes VII development comes to an end.. - read more
6 Aug 2016: Troubled Heroes VII Expansion Release - read more
26 Apr 2016: Heroes VII XPack - Trial by Fire - Coming out in June! - read more
17 Apr 2016: Global Alternative Creatures MOD for H7 after 1.8 Patch! - read more
7 Mar 2016: Romero launches a Piano Sonata Album Kickstarter! - read more
19 Feb 2016: Heroes 5.5 RC6, Heroes VII patch 1.7 are out! - read more
13 Jan 2016: Horn of the Abyss 1.4 Available for Download! - read more
17 Dec 2015: Heroes 5.5 update, 1.6 out for H7 - read more
23 Nov 2015: H7 1.4 & 1.5 patches Released - read more
31 Oct 2015: First H7 patches are out, End of DoC development - read more
5 Oct 2016: Heroes VII development comes to an end.. - read more
[X] Remove Ads
LOGIN:     Username:     Password:         [ Register ]
HOMM1: info forum | HOMM2: info forum | HOMM3: info mods forum | HOMM4: info CTG forum | HOMM5: info mods forum | MMH6: wiki forum | MMH7: wiki forum
Heroes Community > Library of Enlightenment > Thread: Base damage calculation
Thread: Base damage calculation
Ecoris
Ecoris


Promising
Supreme Hero
posted January 20, 2007 07:28 PM bonus applied.
Edited by angelito at 20:22, 20 Jan 2007.

Base damage calculation

from my todo-list

I guess most players are familiar with how damage calculation is done and how all the possible modifiers like A/D, offense, etc. are treated. It has been posted many times in various threads but if you want me to I'll include it in this one such that everything that concerns damage calculation can be gathered here.

Warning: The section below is a long and boring description of tests, data analysis and also some programming . You can skip this and jump to the conclusion further down.

In the damage calculation formula the term 'base damage' (or BD) is used. The H3 manual apparently describes how the base damage is calculated on page 43:
Quote:
1. Each creature type has a damage range. A random number is chosen within this range for the attacking creature type.
2. This number is multiplied by the number of creatures in the attacking troop.
A random number? So if my griffin (3-6 points of damage) attacks its base damage will be either 3,4,5 or 6? Or will 3.1416... or some other non-integer be allowed and the rounding done later?
I have yet to encounter a non-integer random number generator in H3 so I'll assume that base damage is an integer. 2. tells us to multiply the value we get with the number of creatures in the stack. When one thinks about this it becomes absurd. E.g. 100 halberdiers: a halberdier deals 2-3 points of damage. So the base damage will be 200 or 300, i.e. the halberdiers will either do minimum or maximum damage, because there are only two possible outcomes? No way.

But how does BD calculation work then? Is a random integer selected in the damage range for each creature in the stack and then all of them are added together? There are two reasons that this is irrational too:
1. If the stack consisted of several hundred creatures, several hundred random integers would have to be generated. A programmer would never have his computer do such a tremendous amount of work; making the computer 'roll' e.g. 500 random numbers would simply be torture in his eyes.
2. If there are many creatures in the stack it is very unlikely that the BD deviates much from the average (mean) BD. The more creatures there are the more it will be centered around the average. This would undermine the idea of damage intervals.

Another explanation could be that the damage interval was multiplied with the number of creatures in the stack before a random number was selected. E.g. 100 halberdiers would have a damage range of 200-300. A random number was then generated in that interval. That sounds more reasonable, but it would imply that all values were equally likely.

So I decided to find out how it's really done. I ran some tests with two heroes. Both heroes had 0 attack and 0 defense, no offense, no armorer or anything else that could affect damage in any way. One had a stack of harpy hags (attack = 6) the other had a stack of pikemen. The harpies move forward and the pikemen defend raising their defense to 6. In this way the final damage will be the base damage. I started with 100 harpies (BD = 100-400) and made them attack the pikemen 100 times, the pikemen doing nothing else than defending. (I forgot to set the animation speed to max... ).
I quickly saw that the only possible damage values were all multiples of 10 (170,180,190 and so on). It also turned out that values near the average damage, 250, appeared more frequently.
I therefore guessed that the comp only selects 10 random numbers in the range 1-4 and adds them up (you could say that it rolls 10 4-sided dice). Then it multiplied that number by 10.
In order to confirm this I wrote a small program that runs through all ordered combinations of 10 'die rolls' (there are 4^10 = 1048567 different ones; 1111111111,1111111112,... up to 4444444444), calculates their sum and counts how many times each of the values 10,11,...,40 (the base damage range for 10 harpies) appears.
I plotted the probabilities computed like this and the observed probabilities obtained through the combat tests in a chart displayed below.



E.g. on sees that the probability of rolling a total of 25 with ten 4-sided dice is about 11%. The model seems to fit well with the data.

To confirm this model in another way I tried fighting the battle in the exact same way, only changing the number of harpies in the stack. Thus the rolled value should be the same each time. I started with 100 harpy hags; they did 190 points of damage. I reloaded dismissed 90 of them such that I had 10 left and this time they did 19 points of damage. 20 harpies dealt 38 points of damage, 9 harpies dealt 18 points of damage (i.e. only 9 random numbers were selected; the tenth one must have been 1 for at total of 19). 11 harpies dealt 20 points of damage. This is interesting: The 19 points of damage have now been multiplied by 11/10 resulting in 20.9 which is rounded down to 20; no random number is selected for harpy no. 11.
All this points to the following model for calculating base damage:

Conclusion: Base damage calculation

i. If there are 10 or fewer creatures in the stack one random number is selected in the damage range for each creature. The sum is the base damage.
ii. If there are more than 10 creatures in the stack the base damage is calculated as if there are 10 creatures and this value is then multiplied by N/10, where N is the number of creatures in the stack. Finally, this value is rounded down.

So what can we use that knowledge for? Let me make an example: Suppose you have 100 halberdiers. Their BD is 200-300. Suppose that it is also their final damage. What is the chance that they'll deal 225 points of damage or less? It's not 25% since values near the average (250) are more likely. In fact one can compute that the probability is only 5.5%. On the other hand, the probability that they'll deal more than 275 points of damage is also only 5.5%. That may be handy to know when you choose your target.
The good news is that these probabilities are the same no matter how many damage modifiers apply (e.g. A/D difference, offense, armorer, range penalty for ranged attackers, etc); all these modifiers are just linear scalings; they don't affect the distribution.
The bad news is that these probabilities depend on how many values the damage range contains; the halberdiers have two: 2 and 3.
This means that for ANY creature whose damage range contains two values, there will only be a 5.5% chance that the resulting damage will be among the lowest 25% of the damage values (the first quartile) no matter what.
The greater the creature's damage range is, the lower this probability will be:

The probability that the resulting damage will be in the lowest 25% / highest 25% is (approximately):
5.5% when the damage range contains 2 values
4.0% when the damage range contains 3 values
1.6% when the damage range contains 4 values
1.6% when the damage range contains 5 values
0.9% when the damage range contains 6 values
the decrease slows down quickly from now on. The probabilities only hold true if the attacking stack contains at least 10 creatures, otherwise they increase, (to 25% in case there is only one creature in the stack).

For those interested in programming
It becomes extremely time consuming to run through all the combinations for larger damage ranges. A hydra for example deals 25-45 points of damage; 21 values. That means that there are 10^21 = 1.67 *10^13 combinations to evaluate. Even though my algorithm could be made more efficient it would still be very time consuming.

If you want a little challenge you can figure out how to run through all combinations when the amount of numbers that have to be selected and the number of possibilities for each of them is arbitrary. Or: how can you process all possible sequences when you make X rolls with a Y-sided die?






Edit by angelito
Nice research as usual Ecoris. +QP applied.Keep up the good work!

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
yasmiel
yasmiel


Supreme Hero
Former Chessmaster
posted January 20, 2007 08:03 PM

Wow, nice job.. i always thought its only one die roll in H3 (and as many rolls as there are creatures in stack in H5).

So, figuring out that there is "up to 10" dice rolls to calculate damage  for a stack is nice and useful information indeed.

IMHO, this deserves a Q point.
____________

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
HeymlicH
HeymlicH


Famous Hero
posted January 20, 2007 11:50 PM

I just was asking myself the same question after reading the thread about DK and luck. Thanks alot for doing all this work

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
God2
God2


Adventuring Hero
Your benevolent deity
posted January 21, 2007 03:33 AM
Edited by God2 at 03:34, 21 Jan 2007.

Very nice! I actually discussed how damage was calculated with a friend earlier today, so it is a rather odd coincidence that on the same day you post this.
____________
www.shoryuken.com


 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Binabik
Binabik


Responsible
Legendary Hero
posted January 21, 2007 01:22 PM

I'm really tired and it's way past bedtime, so just a couple quick comments for now.

Here's some similar test results. When doing the tests for luck, I recorded all non-luck damage as well.
http://heroescommunity.com/viewthread.php3?TID=16975

I just found the spreadsheet I did for those tests, but haven't had time to review it in detail yet.

One thing to consider with something like this is that the method(s) used must work for a very wide range of damage. Damage can be over a million in homm (yes, I've seen it that high). I strongly suspect there is some type of initial litmus test to determine which method of calculation is used.

The idea of the number of creatures beings divided into smaller groups makes sense. But I'm not sure if it's the number of creatures, or the damage that's divided. I've seen evidence to support both methods.


Examples (att does *NOT* equal def):

Marksmen
sample size = 279 attacks
damage = 800-1200
slices = 10
damage increment = 40
damage = 800, 840, 880, 920, etc

Zealot
sample size = 154 attacks
damage = 1000-1200
slices = 20
damage increment = 10
damage = 1000, 1010, 1020, etc

Dread Knight
sample size = 75 attacks
damage = 4650-9300
slices = 150
damage increment = 31
damage = 4650, 4681, 4712, etc


Also, the slices in all my tests were nice round numbers. But the damage increment can be fractional.

---------------------------

This is a compilation of 1024 attacks under a variety of conditions and damage ranges, including the three mentioned above. Again, the damage has a very high probability of being in the middle of the range. This was also in the link above, but it's a year old and I've forgotten the details of how I did my tests. So all I have is a bunch of raw data.

*Approximate for quick in-game estimates*

Bottom quarter is 2.5%
Middle half is 95%
Top quarter is 2.5%
____________

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Ecoris
Ecoris


Promising
Supreme Hero
posted January 21, 2007 02:27 PM

Binabik, see your old thread. I've made a reply there.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Laser70
Laser70


Adventuring Hero
posted October 07, 2015 02:20 AM
Edited by Laser70 at 02:48, 07 Oct 2015.

An old thread.

Ecoris said:
from my todo-list
So if my griffin (3-6 points of damage) attacks its base damage will be either 3,4,5 or 6? Or will 3.1416... or some other non-integer be allowed and the rounding done later?


The speed effects of haste and/or prayer isn't rounded at all, it chops it off completely. I think that they chop off damage values too. Which means that if the damage value is 2.9, the damage value will be 2.

Ecoris said:

So the base damage will be 200 or 300, i.e. the halberdiers will either do minimum or maximum damage, because there are only two possible outcomes? No way.


That's true, there will be only two possible outcomes. When the attack range is 1-3 (Troglodyte for example) you will only get 3 possible damage values, and there is a very good reason for this, it's because if you used floats in the game it would be unpredictable to the player. It uses integer to make it predictable, and therefore more manageable. This may seem ackward or "annoying" to some people because of the narrow set of numbers you get, but trust me this has a very good place in the game, it's actually a very nice feature to have integers, it's not a problem at all.

Ecoris said:

Is a random integer selected in the damage range for each creature in the stack and then all of them are added together? There are two reasons that this is irrational too:
1. If the stack consisted of several hundred creatures, several hundred random integers would have to be generated. A programmer would never have his computer do such a tremendous amount of work; making the computer 'roll' e.g. 500 random numbers would simply be torture in his eyes.


I'm one of the programmers who have reproduced super fast random algorithms, it's my specialty, I've pushed the code to produce over 3 billion high quality random numbers per second, it produces 3 million random numbers in just 1 millisecond worth of time, before you had a chance to blink your eye one time, there would be hundreds of millions of random numbers "on the table", trust me, there is absolutely no performance issue there. None whatsoever. Pre-calculation of random numbers may also be the case during the load screen of the battlefield, they may have huge arrays running on different cores that does it in time gaps you're not doing anything.

If you plan to re-code the game or alter it, don't try to improve on the game mechanics, traditional way of knowing the game is way more valuable to heroes players than a new type of mechanic. It's a huge mistake to do that, huge one, even if you correct a bug in the game may risk some players to don't use it. Bugs are not just bugs, they are features to old players. Over time, bugs become features. Always remember that, don't ever change the mechanic of the game, don't even touch the bugs it has. Reproduce the bugs too.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
moko86
moko86


Hired Hero
posted December 21, 2015 06:09 PM

Thsnk you I needed that. Good job

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
p_romm
p_romm

Tavern Dweller
posted January 21, 2019 04:56 PM

Hi,
I have created damage simulator/calculator for HoMM 3. It is available under url:

[url=http://homm3.plazacraft.com/damagesymulator]http://homm3.plazacraft.com/damagesymulator[/url]

I would appreciate any comments for it.
Enjoy
____________

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
NimoStar
NimoStar


Responsible
Legendary Hero
Modding the Unmoddable
posted January 22, 2019 03:16 AM

Interesting, I did not know about the "ten creatures" shotrcut the game uses.

Although upon examination it should have been clear that calculating the damage of thousands of creatures individually would not be such a trivial task when every single one of them would be randomized...
____________
Never changing = never improving

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Jump To: « Prev Thread . . . Next Thread »
Post New Poll    Post New Topic    Post New Reply

Page compiled in 0.0740 seconds