Made Attacker Win Probability Page

Originally posted by shirleyrocks
If you modify the defender to be a barbarian, however, it shows the attacker strength to be 5 and the defender is at 1.1.

I tried this out with a few other combinations and attacker v. barbarian always gets a 5x modifier. Is this correct or an error? If that's correct I was completely unaware of that but it WOULD explain my stellar record against the raging hordes.

Also, I was wondering as to why a defender in that situation would be a 1.1 as opposed to a 1.

You do receive a bonus for combating barbarians, but it varies with difficulty level. I've since tweaked the calculator a bit to incorporate the different bonuses for different difficulty levels. You can download it from this post.

The defender virtually always receives some bonus for the terrain, ranging from 10% to 100% (with perhaps the only exception being air combat?). Hence, in Grasslands, a defender rated 1 would actually defend at 1.1.
 

Attachments

Originally posted by Meneer Popken
Just a bit of info for the people who want to know the exact chance of winning or think they get too few wins.

According to the editor Civilians and buildings each add 4% defense bonus, and since most people will play Chieftain the first game they probably attack enemy cities and find themselves losing, because they forgot to take bonuses in account.

I don't think anyone's discounting the importance of defensive bonuses in combat. Experienced civers always fortify units when possible for extra defensive bonuses. Also, that's the reason we build city walls (although, the jury is still out on their importance in this version - by the time they get built, your town may almost be a city...)

Nonetheless, combat calculators still serve a purpose. It allows players to get a general feel for the different combat elements in the game (ie. the effects of terrain, experience, etc...), and it also provides developers with a quick way of making sure their new units don't unfairly interact with the existing ones.

As far as defensive bonuses for population and city improvements, the general consensus is that since there is already a bonus for overall size of the city (ie. population number), those defensive numbers for buildings and population as seen in the editor are for bombardment purposes only. Of course, the general consensus may be wrong.
 
Civilizator:

Yes, combat results are calculated in advance, and after some testing I found out how the system works.

Beginning of the turn:
I had a Marine attack enemy city which had fortified spearman inside. My marine lost the fight every time I reloaded and tried again, so the result wasn't random but pre-calculated and saved,

I then reloaded, placed Marine to wait, and bombed enemy territory with 4 bombers from a carrier. After that I tried to attack with Marine again and he won without losing any hit point at all!

So I think results for all units that could theoretically attack one another are recalculated when any attack action occurs anywhere on the globe. Movement doesn't affect attack results.

So if you're having problems with inconsistent fighting results, wait with that unit a bit and do other actions, as the situation may improve.

-- Leo
 
Meneer Popken:
So you checked out the Civ3 Mod file and saw the value of 4 entered under population and a value of 4 under improvements.....but I must ask how you know when they are plugged into the equation to determine a battle outcome for units defending in a city? Remember this is a chart of values listed in the mod, it does not tell you when that are used.

Currently, most people those 2 numbers are used in BOMBARDMENT calculations since bombardment can also hit population and improvements and normal melee units can not. So basicaly you claim that the 4% for improvements and population for normal melee attacks is unfounded.

Assumption is a terrible thing ;)
 
PaleHorse76 (and all others interested)--

If you want to calculate the probabilities of winning a battle with a certain number of HP remaining, I've got the mathematics all worked out. It's up to Xerxes314 or somebody other than me to make a program out of this. :) Though right now I do have it humming on my TI graphing calculator...

The short version:
a = Attacker's attack rating (after terrain, etc, modifiers are accounted for)
b = Attacker's HP
x = Defender's defense rating (after modifiers)
y = Defender's HP
z = How many rounds the defender wins, or, equivalently, how many HP the attacker loses in a battle

Probability of attacker winning with a z-HP loss:
(a / (a+x))^y * (x / (a+x))^z * nCr(y+z-1, y-1)
Where nCr(i, j) = "i choose j"

Basically, the formula is the probability of the attacker winning y (= defender's HP) rounds, times the probability of the defender winning z rounds, times the number of ways that arrangement can happen.

If this formula is right, then the sum of all those probabilities from z=0 to z=b-1 (attacker loses none to all but one HP) should equal the attacker's probability of winning. I checked this against Xerxes314's program for a bunch of cases, and our programs agree! :goodjob:

That's all you need to know. :) But if you're interested, the long version, or "What I did instead of my homework yesterday," will follow:

Using the same variables as above (a=A rating, b=A HP, x=D rating, y=D HP, z=losses):

First, the probability of the attacker winning one round (causing a HP loss in the defender) is a/(a+x). This is the familiar Civ1 formula. Equivalently, the probability of the defender winning one "round" is x/(a+x).

So, trivially, this formula can be used to determine the odds of a 1 HP vs. 1 HP battle. With multiple HP involved, it basically becomes a question of combining those simple probabilities. From now on, unless otherwise specified, my examples will be between two 3-HP units.

For example, the probability of the attacker winning a 3 HP vs. 3 HP battle without suffering any losses is (a / (a+x))^3, the probability of winning 3 rounds in a row.

The probability of an attacker winning 3 rounds to the defender's 1 is (a / (a+x))^3 * (x / (a+x)) * (the number of ways this can happen). The number of ways that can happen in this case is 3: DAAA, ADAA, AADA.

Similarly, the probability of an attacker winning 3 rounds to the defender's 2 is (a / (a+x))^3 * (x / (a+x))^2 * (the number of ways this can happen). The number in this case is 6: DDAAA, DADAA, DAADA, ADDAA, ADADA, AADDA.

In general, the probability of an attacker winning y (= defender's HP) rounds to the defender's z is (a / (a+x))^y * (x / (a+x))^z * (the number of ways this can happen).

The number of ways an attacker can win the battle with y (= defender's HP) victories and z losses is nCr(y+z-1, y-1), or "y+z-1 choose y-1." This is the number of ways to get y-1 victories out of y+z-1 rounds.

Intuitively, it might seem like the proper number of combinations is nCr(y+z, y), or the number of ways to get y victories out of y+z rounds, which is how long the battle is (attacker's wins + defender's wins). However, in every battle where the attacker wins, the attacker wins the last round. In other words, a combination like AAAD will never happen because the attacker will have won before that 4th round. So the number of combinations become the number of ways to get y-1 victories (all but the last round) out of y+z-1 rounds (all but the last round again).

Note that the probability of that last round still factors into the equation with (a / (a+x))^y, so it's not like we're throwing out that last round entirely.

Now we're ready to combine all that into a lovely formula. :D The probability of the attacker winning while suffering z-HP losses is

(a / (a+x))^y * (x / (a+x))^z * nCr(y+z-1, y-1)
a = Attacker's attack rating (with all modifiers)
b = Attacker's HP
x = Defender's defense rating (with all modifiers)
y = Defender's HP
z = Defender's victories or attacker's HP losses

Again, this is the probability of the attacker winning y rounds, times the probability of the defender winning z rounds, times the number of ways that arrangement can happen.

If you just want a straight-up calculation of what the chances are to win the battle regardless of the HP loss (like Xerxes314's nifty calculator), then sum up that formula from z=0 to z=b-1 (attacker loses 0 to all but 1 HP).

Of course, these formulas don't take into account retreat by a faster unit and assume a fight to the death. I'm not certain of the exact rules involved in retreating (sometimes a faster attack unit fights to the death if the defender is damaged enough), but I'm sure I'll spend another class period or two figuring that out... :p

Enjoy.
 
So what if people do cheat by reloading??????????????

Why try to stop this by not useing a random number generator????????

I paid 59.99 for this game if i want to cheat I should have every right to do so!!!!!!!!!!!!!!!!!!!!!!!!!!!

Why not at least make it defile your final score with (cheat mode) in the hall of fame???

Instead civ3 causes unnessasary frustration for the 90+% who have at some point or another reloaded our games and attempted the battle again.
 
Originally posted by Traquenard-fx
I just want to know why you have the avatar of the battleship???

I day ago, I have send you a e-mail for include the battleship in list of the avatars.
You are a traitor!!!!!!:mad:
P.S.: don't banned me (I say this because you have banned poeple for less than that):D

...
This message is for if I am banned:
Boycut Civfanatics for let me free and for the liberty of expression
(and for you Thunderfall, you have rub my AVATAR!!!)
Ha Ha Ha!!!!
How have the power now!!!!:p

Tranquiliser, get real!
Insults to the site owner are not effective when rendered
in crazed gibberish!

The sole use of the Battleship is TF's right as site owner.
Just pick the destroyer, or something...
An in regards to boycotting CFC? Not in this life-time pal!!!

What a crazy potato!:lol:
 
FortyJ,

Nice work on the calculator. What might be a nice addition is the ability to swap the Attacker and Defender so you can see what would happen both ways OR, better yet, just calculate it both ways and show the results for attack going in both directions.

Again, nice work dude!
 
Originally posted by lion575
Why try to stop this by not useing a random number generator????????

All random number generators work this way.

To a computer, there is no such thing as a random number. A random number generator is a math formula. If you give it the same starting number, you'll always get the same sequence out of it. Usually when a game loads up, it starts the random number generator by feeding it the time of day, down to hundredths of a second. That's suitably random that you won't likely be seeing the same sequence twice.

The only thing Civ3 does different is when it saves the game, it also saves the current random number. So when you reload the game, you're at the same place in the same sequence.

Rather clever, really. I imagine they did it because they didn't want "cheaters" to consistantly beat the game doing that, and then go out on the net and tell everyone "civ3 sux, I beat it on the hardest level all the time".

Personally I can't imagine ever wanting to do that. If one battle is going to make or break you, you were probably doing something wrong anyway!
 
Sorry for the length here, it's hard to word this in a fashion that is precise and exact, so as to avoid confusion, without being wordy.

Originally posted by Valant2
Thunderfall:

Will do a runthrough of my program for you using your example

Attacker: Veteran Immortal (4/2/1): 4 HP
Defender: Veteran Spearman (1/2/1): 4 HP

Since you do not state if the spearman is fortified, is or is not in a city, city does or does not have walls, is or is not in a fortress, if the attacker is crossing a river to attack, nor what terrain the unit is defending on in your experiment I will pick something for you for my walkthrough.

Hmm...lets say the defender is stationed in a city of a population of less than 7, which has city walls and the city is build on grassland but the defending unit is not fortified. Also the defending unit does not have the great wall wonder built. Also the attacker is not crossing a river to get to the defending unit.

So the defending spearman gets the following bonuses to its defensive power:
+50% city walls
+0% city (since its less than 7)
+10% terrain (grassland)
+0% defending unit not fortified
+0% attacker is not crossing a river

Which results in +60% bonus for the spearman. So the spearmans defense power is 3.2

So we enter these values.......
n = 4 + 4 - 1 = 7
k = 4
p = 4 / (4 + 3.2) = 4/7.2 = 0.556

Now click on calculate and then check the value in the box at the bottom of the screen...which is.....give me a second typing it in.... okay the result is 0.621

Now we multiply this value by 100 to get 62.1%

So the probability of the attacker winning and the defending dying is 62.1%


Valant2 (and maybe CC: to Xerexs314 too):
First let me say kudos to you and thanks for the work on the Calculators- Good stuff and way better then my ability. So this isn't a criticism, and maybe even its not right, but let me know what you think, thanks!

Maybe this is not the way it REALLY works, but according to the manual (pg. 110 in mine, next to last sentence on the page) "Terrain bonuses are figured in BEFORE THE CITY SIZE AND WALLS TAKE EFFECT." (Emphasis mine.)

In the example you were working for Thunderfall (to whom much thanks NEEDS TO BE EXTENDED FOR CREATING AND RUNNING THIS FORUM!!), you've got a Defense bonus of +50 % for the city or town walls, and +10% for the Grasslands, and a base defense strength of 2 for the spearman. It appears that the method is to take the base 2, add 50% of 2 ie 1, and then add 10% of 2 or 0.2, to sum up to the modified defense strength of 2+1+0.2 = 3.2. But if the walls/city size effect of +50% occurs AFTER the terrain grasslands +10 % increase has been done (" ... terrain bonuses are figured in BEFORE ...") then shouldn't we be adding to the base defense strength 2, 50% of not just the original 2, but of the increased defense strength due to the terrain (ie 50% applied to the 0.2 as well)? That is, 2+1+0.2+0.1 = 3.3. In other words, by having the terrain bonus occur first and THEN applying the city wall/size effect, the +10% gets compounded by the +50%. This will always result in tougher odds for the attacker. Although this might seem a little strange, look below at a different way of calculating this, it might make more sense. In this example, if we compound the terrain increase with the city walls effects, and the final strength is 3.3 rather then 3.2, the next part of your example changes from 0.556 to 0.548.

Now that is a small change, here. But if the defender had been more powerful, or if the terrain had been hills or mountains, and it had been a metropolis rather then a city or town walls, the effect would have been greater. If we had a 100% defense bonus for a metropolis, and a +50 for hills, then to the base 2 an increase for the +50% hills terrain adds 1 yielding 3, which if done BEFORE the 100% city size bonus, gives a final modified defense strength of 6 (100% increase of the 3 to 6). But if we just add to the base defense strength, 50% of the base 2 and 100% of the base 2, we get 2 + 1 + 2 =5. The first way would then produce 4/(4 + 6) = 0.40, the second gives 4/(4+5) = 0.444. Again not gigantic but it IS different.

The point is the way the calculation is done, not the size of the value in these examples. Perhaps, instead of adding a % of the defense strenth to the inital defense strength to get the modified value, maybe we should multily the defense strength by (1+ the decimal % numerical value), e.g. instead of 2 + 10% of 2 = 2.2, multiply 2 by 1.1 (ie 1 + 10% expressed as a decimal). If we do it this way, we would calculate the examaple as 1.5 X (2 X 1.1) = 3.3 rather then as 2+ (50% X 2) + (10% X 2) = 3.2. In the example with a metropolis on hills, we would use 2.0 ( ie 1 + 100% = 1+1) for the 100% increase due to the metropolis, and 1.5 for the 50% increase due to the hills, in this fashion: modified Defense strength = 2.0 X ( 2 Defense strength X 1.5) = 6, rather then 2 D.S. + (100% of 2 D.S.) + (50% of 2 D.S.) = 5.

This would seem to mostly apply to where defenders are in citys. One question is multiple terrain effects- defender behind rivers + on hills for example. Or fortifications. Are these just additive? I would think so, if true, then only city defenders get this compounding effect. The manual suggests that ALL terrain effects occur prior to the walls/city size effect, as it uses the plural, as in bonuses not bonus. But terrain and combos of terrain I would guess are just additive, as the manual does NOT say anything other then that all terrain effects are cumulative.

Maybe this would be an easy change in the spreadsheet- just correct the formula/calculational method? I dunno as you guys are the experts there. Two methods, current for most cases, a new one if the defender is in a city?

Anyway sorry for the long post and tell me if I am in left field. If this is the way it actually works, then the effect is to even more weaken attackers when the defender is in a city- a reasonable thing, compared to real life (can we say Stalingrad?)

Thanks for your efforts on the calcuator, and you too Xerexes314. You guys are awesome- I respect anyone who can figure out this Statistics and Probablity stuff!

Peace and have fun with Civ III.
 
After reading Grendel's post with interest about the formula for caluclating how many hit points will be left on an attacker (or defender) I've created an excel spreasheet to play with. It shows the probability of all the possible hit points remaining from an attack, but does not cater for mobile units where the defender retreats before they have no HP left. (Attachment is xls when uncompressed)
Enjoy.

Originally posted by Grendel
PaleHorse76 (and all others interested)--

If you want to calculate the probabilities of winning a battle with a certain number of HP remaining, I've got the mathematics all worked out. It's up to Xerxes314 or somebody other than me to make a program out of this. :) Though right now I do have it humming on my TI graphing calculator...

The short version:
a = Attacker's attack rating (after terrain, etc, modifiers are accounted for)
b = Attacker's HP
x = Defender's defense rating (after modifiers)
y = Defender's HP
z = How many rounds the defender wins, or, equivalently, how many HP the attacker loses in a battle

Probability of attacker winning with a z-HP loss:
(a / (a+x))^y * (x / (a+x))^z * nCr(y+z-1, y-1)
Where nCr(i, j) = "i choose j"

Basically, the formula is the probability of the attacker winning y (= defender's HP) rounds, times the probability of the defender winning z rounds, times the number of ways that arrangement can happen.

If this formula is right, then the sum of all those probabilities from z=0 to z=b-1 (attacker loses none to all but one HP) should equal the attacker's probability of winning. I checked this against Xerxes314's program for a bunch of cases, and our programs agree! :goodjob:

That's all you need to know. :) But if you're interested, the long version, or "What I did instead of my homework yesterday," will follow:

Using the same variables as above (a=A rating, b=A HP, x=D rating, y=D HP, z=losses):

First, the probability of the attacker winning one round (causing a HP loss in the defender) is a/(a+x). This is the familiar Civ1 formula. Equivalently, the probability of the defender winning one "round" is x/(a+x).

So, trivially, this formula can be used to determine the odds of a 1 HP vs. 1 HP battle. With multiple HP involved, it basically becomes a question of combining those simple probabilities. From now on, unless otherwise specified, my examples will be between two 3-HP units.

For example, the probability of the attacker winning a 3 HP vs. 3 HP battle without suffering any losses is (a / (a+x))^3, the probability of winning 3 rounds in a row.

The probability of an attacker winning 3 rounds to the defender's 1 is (a / (a+x))^3 * (x / (a+x)) * (the number of ways this can happen). The number of ways that can happen in this case is 3: DAAA, ADAA, AADA.

Similarly, the probability of an attacker winning 3 rounds to the defender's 2 is (a / (a+x))^3 * (x / (a+x))^2 * (the number of ways this can happen). The number in this case is 6: DDAAA, DADAA, DAADA, ADDAA, ADADA, AADDA.

In general, the probability of an attacker winning y (= defender's HP) rounds to the defender's z is (a / (a+x))^y * (x / (a+x))^z * (the number of ways this can happen).

The number of ways an attacker can win the battle with y (= defender's HP) victories and z losses is nCr(y+z-1, y-1), or "y+z-1 choose y-1." This is the number of ways to get y-1 victories out of y+z-1 rounds.

Intuitively, it might seem like the proper number of combinations is nCr(y+z, y), or the number of ways to get y victories out of y+z rounds, which is how long the battle is (attacker's wins + defender's wins). However, in every battle where the attacker wins, the attacker wins the last round. In other words, a combination like AAAD will never happen because the attacker will have won before that 4th round. So the number of combinations become the number of ways to get y-1 victories (all but the last round) out of y+z-1 rounds (all but the last round again).

Note that the probability of that last round still factors into the equation with (a / (a+x))^y, so it's not like we're throwing out that last round entirely.

Now we're ready to combine all that into a lovely formula. :D The probability of the attacker winning while suffering z-HP losses is

(a / (a+x))^y * (x / (a+x))^z * nCr(y+z-1, y-1)
a = Attacker's attack rating (with all modifiers)
b = Attacker's HP
x = Defender's defense rating (with all modifiers)
y = Defender's HP
z = Defender's victories or attacker's HP losses

Again, this is the probability of the attacker winning y rounds, times the probability of the defender winning z rounds, times the number of ways that arrangement can happen.

If you just want a straight-up calculation of what the chances are to win the battle regardless of the HP loss (like Xerxes314's nifty calculator), then sum up that formula from z=0 to z=b-1 (attacker loses 0 to all but 1 HP).

Of course, these formulas don't take into account retreat by a faster unit and assume a fight to the death. I'm not certain of the exact rules involved in retreating (sometimes a faster attack unit fights to the death if the defender is damaged enough), but I'm sure I'll spend another class period or two figuring that out... :p

Enjoy.
 
Probability of attacker winning with a z-HP loss:
(a / (a+x))^y * (x / (a+x))^z * nCr(y+z-1, y-1)
Where nCr(i, j) = "i choose j"

That formula's correct (hey, I didn't spend 4 years of my life doing a PhD in statistics for nuttin!). To make things a bit easier, let's write it like this

W(z) = Pr(Attacker Win with z-hp loss for equal-speed defender)
= (a / (a+x))^y * (x / (a+x))^z * nCr(y+z-1, y-1)

For attackers of equal speed (where none has a chance to flee), the overall probability of the attacker winning the battle is:
Pr(Attacker Win) = W(0)+W(1)+...+W(b-1).

W(z) doesn't take into account one minor point: a faster attacker may flee at 1 HP, with a 50/50 probability (in 1.17, anyway).

For a faster attacker there are 4 possibilities:
1. Win, losing b-2 or fewer HP (last roll is a win)
2. Retreat with 1HP (last roll is a loss)
3. Win by not retreating after losing b-1 HP (last roll is a win)
4. Lose

Let's also calculate F(z) = Pr(faster defender flees after taking z HP from defender). (F is for flee.) This is a sequence of z attacker wins and b-1 defender wins, with the last event being a defender win. That gives a similar equation:

F(z) = (a/(a+x))^z*(x/(a+x))^(b-1) *nCR(z+b-1,b-1)

So, for a fast attacker, the probabilities are:

1. W(0)+W(1)+...+W(b-2)
2. 0.5*(F(0)+F(1)+...+F(y-1))
3. 0.5*W(b-1)
4. 1-everything above

The 0.5 factors for 2. and 3. come about because the attacker retreats or not with 50% probability.

The probabilities for a slow attacker defeating a faster defender I leave as an exercise for the reader. :)

- rev
 
Hi,
I dont have Civ3, but I was involved in some work about the Civ2 formula.
I suppose the only difference between Civ2 and Civ3 might be the firepower that is out from Civ3.

In Civ2 the probability to win one round was not a / (a+x) although the manual states it.

Civ2 threads that are related to the problem:
Info: Combat
Modifiers for Attack/Defense
The Civ2 Battle Equation Solution
 
Originally posted by lion575
So what if people do cheat by reloading??????????????

Why try to stop this by not useing a random number generator????????

I paid 59.99 for this game if i want to cheat I should have every right to do so!!!!!!!!!!!!!!!!!!!!!!!!!!!

Why not at least make it defile your final score with (cheat mode) in the hall of fame???

Instead civ3 causes unnessasary frustration for the 90+% who have at some point or another reloaded our games and attempted the battle again.

Did you know that you can have it either way on patch 1.21f? When you start a new game, you can just uncheck the "preserve random seed" on the 2nd screen "Player Setup." Then you can reload as many times as you like and the game will generate a different random number each time. And, of course, if you don't want to be able to reload with a different result, leave the option alone.

The thought occurred to me that Firaxis put this in to help test the game so they could see what % of the time a certain result occurred, but that's just speculation on my part.

So don't worry, your wish has already been granted.
 
Back
Top Bottom