How do you calculate combat odds?

Moonsinger

Settler
Retired Moderator
Joined
Apr 22, 2002
Messages
4,374
Location
Iowa
Ok, I have read Arathorn's article a couple times, but still couldn't come up with the correct odds. Since I'm not really good with numbers, would someone please explain to me in plain simple Math on how you calculate the odds.

The reason I'm asking this here is because you guys probably know more about the HOF logs than the people at the general forums. For example, according to the HOF combat log, my combat odds is as follows:

Moonsinger's Praetorian (8.80) vs Gandhi's Longbowman (4.08)
Combat Odds: 99.1%
(Extra Combat: -10%)
(Plot Defense: +3%)
(Fortify: +25%)
(City Defense: +25%)
(City Attack: -75%)
(Combat: -25%)

Base on those (+/-) numbers, how do you come up with the odds of 99.1% of winning? Thanks for any explaination in advance.
 
Moonsinger is asking for mathematical formulas? :eek:
I believe the odds showed in 1.61 is pretty much accurate btw.
 
Instead of writing the formula.. I will just quote from a thread on another board where someone went ahead and calculated the odds of a similar combat.. :

salqadri said:
Its a Negative Binomial Distribution. This distrubiton has 2 parameters, the number of successes required and the probability of each success. It is used to determine the probability distribution of the failures.
1) The probability of each success (according to article posted by Gyathar) is p = A/(A + D), where A is the attackers strength and D is the Defenders Strength.
2) The number of successes needed can be determined by determining the damage the attacker will do, and divide this from the current strength of the defender (and ceil the result).
The damage the attacker will do is (from the article; I verified it to be correct):
20*(3*A+D)/(3*D+A)

To determine the overall probability of winning a battle, we need to find the probability that the number of failures is less than the number of hits it will take to kill the attacker.

Thus we are looking at a Cumulative Negative Binomial Distribution with X = # of Failures to die - 1

The # of failures to die can be determined by dividing the current strength of the attacker by the damage done by the defender and ceiling the result.
The damage the defender will do is (from the article):
20*(3*D+A)/(3*A+D)

Now the math for the distribution for a particular number of failures:
P(X=x) = ((x+r-1) nCr (r-1)) * p^r * (1-p)^x

Thus for the cumulative:
P(X<x) = for i goes from 0 to x-1 { Result += P(X=i) }

So! Now lets apply the example of the Longbow and the Jaguar and lets see if our result is 20.0%! Because if they did their job right, they should get what Im gonna get.

So A = 6.5, D = 8.1
Thus Attacker Dmg = 17 (whenever the attacker wins he will do that much damage on the defender)
Defender Dmg = 22
# of Successes needed to kill the Defender = ceil(100/17) = 6
# of Failures to die = ceil(100/22) = 5
Max # of Failures allows = 4
p = Probability of Success = A/(A+D) = 0.445
r = # of Successed needed = 6

If the attacker loses the first strike, then 6 successes are needed and only 3 more failures are allowed:
P(X = 0) = 0.445^6 = 0.0078
P(X = 1) = 6*0.0078*0.555 = 0.0260
P(X = 2) = 21*0.0078*0.555^2 = 0.0505
P(X = 3) = 56*0.0078*0.555^3 = 0.0747
P(X < 4) = 0.159

If the defender loses the first strike, then 6 successes are needed and 4 failures allowed:
P(X = 4) = 126*0.0078*0.555^4 = 0.0932
P(X < 5) = 0.2522

P(winning the first strike) = p = 0.445.
Thus total probability = 0.445*0.2522+0.555*0.1590 = 0.2004

Thus the probability of winning = 20.0%.

Q.E.D


Cool. So basically Firaxis got the theory right. Good. Now lets look at the probability of the permutation in which the Jaguar wins 7 times in a row (because it must also beat the longbow in the first strike round, during which the longbow is immune).
P(Jaguar wins 7 times in a row) = 0.445^7 = 0.003 = 0.3%
So, its not 0.006% as I previously hastilly suggested, but rather its 0.3%. That means if you attack with that jaguar on that longbow, you will retain full health only once in 300 attacks (though u cant test that in the game unless u can recalculate the seed). But again, that is very unlikely. I think there is some bias in the function that generates their random numbers.
 
I understood what Gyathaar wrote under those probability formulas, but it might be a bit hard for an untrained mathematician to understand that the formulas actually work out. Furthermore, the formula is wrong, because using the current version, 1.61, firepower calculations got more complex as averaging needs to be done after each battle round between max possible strength of the unit and its current strength hit points. Probability calculations get more complex, but the basic idea remains the same. I don't have the time now to rewrite a fully updated 1.61 combat odds calculation post, but I will try to rephrase in simple words where the formula fails to do its job, at least in my head :D

Here is moonsinger's example. I am not sure how to get the strength numbers 8.80 and 4.08. Could someone explain how the get accurate A(ttack) and D(efence) values for the calculations? I tried to add up the +/-% attack defense values Moonsinger provided, but I don't understand how to come up with 4.08?

Let's say 4.08 is correct, but when calculating probability of success during each battle round, should not the odds of success change based on recalculation of defense and attack values with new damaged hit points values? I understand that this is not the math for the "damage done phase" of the calculation, but my understanding is that firepower change is taken into account when calculating probabilities of success, i.e. new A and D values, for each round of combat.

(Averaging between max full strength and current strength needs to be done to figure out current strength).

""2) The number of successes needed can be determined by determining the damage the attacker will do, and divide this from the current strength of the defender (and ceil the result).
The damage the attacker will do is (from the article; I verified it to be correct): 20*(3*A+D)/(3*D+A)""

The damage an attacker will do, its firepower, is no longer a constant based on max strength, rather an average of the max strength and current (damaged)strength that changes each battle round. To calculate the number of successes needed is no longer as simple as before, because firepower changes with each battle round.

I agree with the structure of the formula to come up with the combat odds, but firepower change needs to be taken into account to calculate 1.61 values. The real formula is going to look real ugly, but the old formula still can give a close value for the 1.61 combat odd calculation. Firepower change implies that units with firststrike are stronger, because they can also reduce enemy firepower in addition to damaging them. It also happens if you lost extra hp compared to your opponent in the first couple rounds of the battle, you are more likely to lose the overall combat, because your firepower will also be relatively weaker.

I started to upgrade drill for my units after the patch; high levels of drill can be extremely deadly allowing you win battles practically undamaged. Drill is extremely useful in beating huge stacks of attacking units; because very few units will be able to damage with their full power due to your 3-4 first strikes.

So Moonsinger, I would suggest you stop invenstigating the math, because it looks real ugly to me, just have faith in the bigger picture. :D
 
VirusMonster said:
I understood what Gyathaar wrote under those probability formulas, but it might be a bit hard for an untrained mathematician to understand that the formulas actually work out. Furthermore, the formula is wrong, because using the current version, 1.61, firepower calculations got more complex as averaging needs to be done after each battle round between max possible strength of the unit and its current strength hit points. Probability calculations get more complex, but the basic idea remains the same. I don't have the time now to rewrite a fully updated 1.61 combat odds calculation post, but I will try to rephrase in simple words where the formula fails to do its job, at least in my head :D
Actually.. you are not quite correct.. it only takes the average value at the beginning of combat.. not after each combat round... so you just need to calculate the adjusted firepower once (at start)
 
VirusMonster said:
I am not sure how to get the strength numbers 8.80 and 4.08. Could someone explain how the get accurate A(ttack) and D(efence) values for the calculations? I tried to add up the +/-% attack defense values Moonsinger provided, but I don't understand how to come up with 4.08?
Look at the link in Moonsingers post. There is some stuff there about how they're applied. Basically, (paraphrasing here ;) ) you have factors that only affect the unit but all the time, like combat I, and those that affect situationally, like City Raider III. All the situational ones are applied to the defender. The factors are added up for each unit before before applying them.
 
Denniz said:
Look at the link in Moonsingers post. There is some stuff there about how they're applied. Basically, (paraphrasing here ;) ) you have factors that only affect the unit but all the time, like combat I, and those that affect situationally, like City Raider III. All the situational ones are applied to the defender. The factors are added up for each unit before before applying them.

Yes.. in this case obviously the preatorian has combat I.. so it end up with

8 * (100 + 10)/100 = 8.8

the longbow is fortified (25%) on flat land (0%), inside a city (25%).. with no promotions.. in a city with no walls and some cultural defense (3%)..
it is attacked by a praetorian with has city attack 3 (75%) and cover (25%)

(25% + 25% + 3% -75% -25%) = -47%

here is where it goes a bit odd.. with negative numbers, instead of multiplying with (1 - 0.47 ) = 0.53, it seems to divide by (1 + 0.47) = 1.47.. so you get

6 / 1.47 = 4.08
 
Moonsinger said:
Ok, I have read Arathorn's article a couple times, but still couldn't come up with the correct odds. Since I'm not really good with numbers, would someone please explain to me in plain simple Math on how you calculate the odds.

The reason I'm asking this here is because you guys probably know more about the HOF logs than the people at the general forums. For example, according to the HOF combat log, my combat odds is as follows:

Moonsinger's Praetorian (8.80) vs Gandhi's Longbowman (4.08)
Combat Odds: 99.1%
(Extra Combat: -10%)
(Plot Defense: +3%)
(Fortify: +25%)
(City Defense: +25%)
(City Attack: -75%)
(Combat: -25%)

Base on those (+/-) numbers, how do you come up with the odds of 99.1% of winning? Thanks for any explaination in advance.

A city raider 3, combat 1, cover 1 praetorian versus an unpromoted longbowman who only has a 3% cultural defence bonus. That's not very fair, Moonsinger. That's like throwing Christians before the lions, you cruel roman!

But to get to the point:
First the strength values:
Only combat promotians are applied to the attacker, so the praetorian is 8 * (1+0.10) = 8.8 strength.

The various bonuses against the defender reduce the defenders strength:
Total bonus versus the longbowman: 0.03+0.25+0.25-0.75-0.25=-0.47. This means that the longbowman has strength 6/ (1 + 0.47) = 4.08 (rounded down). If the bonus was positive, then strength would have been multiplied by 1 + bonus like with the praetorian above.

Now how can a 2 to 1 strength advantage lead to a 100:1 chance of victory (99.1%)?

The main reason is that combat takes place in multiple rounds and each round the stronger unit does more damage and has a bigger chance to actually do damage. The chance that the weak unit wins enough rounds to kill the strong unit is small because it needs a lot of hits to do enough damage and the chance that it scores a hit is not that big.

Now the details (similar to Gyathaar):

All formulas that are used come from the article of Arathorn which you've already read.

The longbowman does 20 * (3*4.08 + 8.8)/(3*8.8 + 4.08) = 13 damage per succesful hit.
The praetorian does 20 * (3*8.8 + 4.08)/(3*4.08 + 8.8) = 28 damage per succesful hit.
The longbowman has a chance of 4.08/(8.8 + 4.08) = 31.68% to score a hit.
The praetorian has a chance of 8.8/(8.8 + 4.08) = 68.32% to score a hit.

A unit has 100 hitpoints to start with. If the damage exceeds 100, then it dies. So the praetorian needs 4 hits to kill the longbowman with 68.32% chance per hit and the longbowman needs 8 hits to kill the praetorian with 31.68% chance per hit.

The praetorian could win by hitting the longbowman 4 times in a row with chance: (0.6832)^4 = 0.2179
The praetorian could win by hitting the longbowman 4 times while getting hit once before the fourth hit. That means that one of the four first rounds is won by the longbowman and 3 by the praetorian. That can happen in 4 different ways (lppp, plpp, pplp, pppl).
chance: (0.6832)^4 * 0.3168 * 4 = 0.2761
The praetorian could win by hitting the longbowman 4 times while getting hit twice before the fourth hit. That means that 2 of the first 5 rounds are won by the longbowman and 3 by the praetorian which can happen in 10 different ways. chance: (0.6832)^4 * 0.3168^2 * 10 = 0.2187
The praetorian could win by hitting the longbowman 4 times while getting hit 3 times before the fourth hit. chance: 0.1385
The praetorian could win by hitting the longbowman 4 times while getting hit 4 times before the fourth hit. chance: 0.0768
The praetorian could win by hitting the longbowman 4 times while getting hit 5 times before the fourth hit. chance: 0.0389
The praetorian could win by hitting the longbowman 4 times while getting hit 6 times before the fourth hit. chance: 0.0185
The praetorian could win by hitting the longbowman 4 times while getting hit 7 times before the fourth hit. chance: 0.0084
Sum it all together and you get 0.9938 or 99.38% chance.

I think the small error between 99.38% and 99.1% has to do with some rounding errors.

You can find a calculator for civ4 combat here (for some reason, it loads slowly).

Fill in the strength values of this combat and you will recognize some of the numbers in this post in the outcome of the calculator.

If you include units with first strikes and chances of first strikes, then the calculations become a bit more complicated but essentially the same.

edit: After Gyathaar's comment, I decided to edit the post.

At a chance of 0.3168, the longbowman gets a first strike and then the praetorian can only sustain 6 further hits without dying. So if the first strike hits, the chance the praetorian wins is only 0.9938-0.0084= 0.9854. If the longbowman doesn't hit with the first strike (chance 0.6832), then the praetorian wins with the chance of 0.9938.

So, the chance for the praetorian to win becomes: 0.3168 * 0.9854 + 0.6832 * 0.9938 = 0.9911 or 99.1% :D :band: :clap: :rockon:
 
Roland Johansen said:
I think the small error between 99.38% and 99.1% has to do with some rounding errors.
Actually I think it is because you forget the longbow free shot chance :)
 
Gyathaar said:
Actually I think it is because you forget the longbow free shot chance :)

AAAARCHHH.:mad:

You're right (I'm not going to recalculate it).
 
Great job both and thank you for the explanations,

I can follow the formulas you provided and understand the probability calculations, but I am still not sure how the 1.61 firepower change affects the combat odds.

Gyathaar wrote:
Actually.. you are not quite correct.. it only takes the average value at the beginning of combat.. not after each combat round... so you just need to calculate the adjusted firepower once (at start)

Are you sure that the firepower change is taken into account only at the beginning of the combat and not after each combat round? I would believe you, but again, I am also curious how you arrived at that conclusion. Did you look up the Civ4 code yourself or just have observed many combat calculations that work out to be that way? If what you say is true, then Drill ability loses effectiveness, because the first strike damage done can't reduce firepower rate. I personally wished it did.

Roland wrote:
"The longbowman does 20 * (3*4.08 + 8.8)/(3*8.8 + 4.08) = 13 damage per succesful hit.
The praetorian does 20 * (3*8.8 + 4.08)/(3*4.08 + 8.8) = 28 damage per succesful hit."

I agree these values are correct for units with full health. Say my praetorian had only 50hp out of 100. Average hp is (50+100)/2=75. The damage it does would be 28x .75 =21. Don't you guys agree? And according to Gyathaar, these value would be only calculated once before the actual combat begins, and not for each individual combat round?!
 
The combat code is in the SDK, so you can easilly look it up :)
If I remember correctly it was in CvUnit.cpp

Also you can simply look in the combat logs.. units does the same damage with their hits after they are hurt as they did in beginning of fight
 
I edited my post, correcting the mistake Gyathaar pointed out. It was quite easy to fix after all.
 
Roland Johansen said:
But to get to the point:
First the strength values:
Only combat promotians are applied to the attacker, so the praetorian is 8 * (1+0.10) = 8.8 strength.

The various bonuses against the defender reduce the defenders strength:
Total bonus versus the longbowman: 0.03+0.25+0.25-0.75-0.25=-0.47. This means that the longbowman has strength 6/ (1 + 0.47) = 4.08 (rounded down). If the bonus was positive, then strength would have been multiplied by 1 + bonus like with the praetorian above.

Now how can a 2 to 1 strength advantage lead to a 100:1 chance of victory (99.1%)?

The main reason is that combat takes place in multiple rounds and each round the stronger unit does more damage and has a bigger chance to actually do damage. The chance that the weak unit wins enough rounds to kill the strong unit is small because it needs a lot of hits to do enough damage and the chance that it scores a hit is not that big.

Now the details (similar to Gyathaar):

All formulas that are used come from the article of Arathorn which you've already read.

The longbowman does 20 * (3*4.08 + 8.8)/(3*8.8 + 4.08) = 13 damage per succesful hit.
The praetorian does 20 * (3*8.8 + 4.08)/(3*4.08 + 8.8) = 28 damage per succesful hit.
The longbowman has a chance of 4.08/(8.8 + 4.08) = 31.68% to score a hit.
The praetorian has a chance of 8.8/(8.8 + 4.08) = 68.32% to score a hit.

A unit has 100 hitpoints to start with. If the damage exceeds 100, then it dies. So the praetorian needs 4 hits to kill the longbowman with 68.32% chance per hit and the longbowman needs 8 hits to kill the praetorian with 31.68% chance per hit.

The praetorian could win by hitting the longbowman 4 times in a row with chance: (0.6832)^4 = 0.2179
The praetorian could win by hitting the longbowman 4 times while getting hit once before the fourth hit. That means that one of the four first rounds is won by the longbowman and 3 by the praetorian. That can happen in 4 different ways (lppp, plpp, pplp, pppl).
chance: (0.6832)^4 * 0.3168 * 4 = 0.2761
The praetorian could win by hitting the longbowman 4 times while getting hit twice before the fourth hit. That means that 2 of the first 5 rounds are won by the longbowman and 3 by the praetorian which can happen in 10 different ways. chance: (0.6832)^4 * 0.3168^2 * 10 = 0.2187
The praetorian could win by hitting the longbowman 4 times while getting hit 3 times before the fourth hit. chance: 0.1385
The praetorian could win by hitting the longbowman 4 times while getting hit 4 times before the fourth hit. chance: 0.0768
The praetorian could win by hitting the longbowman 4 times while getting hit 5 times before the fourth hit. chance: 0.0389
The praetorian could win by hitting the longbowman 4 times while getting hit 6 times before the fourth hit. chance: 0.0185
The praetorian could win by hitting the longbowman 4 times while getting hit 7 times before the fourth hit. chance: 0.0084
Sum it all together and you get 0.9938 or 99.38% chance.

I think the small error between 99.38% and 99.1% has to do with some rounding errors.

You can find a calculator for civ4 combat here (for some reason, it loads slowly).

Fill in the strength values of this combat and you will recognize some of the numbers in this post in the outcome of the calculator.

If you include units with first strikes and chances of first strikes, then the calculations become a bit more complicated but essentially the same.

edit: After Gyathaar's comment, I decided to edit the post.

At a chance of 0.3168, the longbowman gets a first strike and then the praetorian can only sustain 6 further hits without dying. So if the first strike hits, the chance the praetorian wins is only 0.9938-0.0084= 0.9854. If the longbowman doesn't hit with the first strike (chance 0.6832), then the praetorian wins with the chance of 0.9938.

So, the chance for the praetorian to win becomes: 0.3168 * 0.9854 + 0.6832 * 0.9938 = 0.9911 or 99.1% :D :band: :clap: :rockon:

Wow! I'm totally speechless!:worship::worship::worship: Thanks a ton!:)
 
Good to hear that the explanation was clear. The Civ4 combat mechanism is more complicated than the combat mechanism of earlier versions of civ.
 
Back
Top Bottom