The Let's Play Archive

Civilization 2

by Melth

Part 28: Mechanics: Final thoughts on modern units, multiplayer, and the hidden math of the combat system

Spoggerific posted:


I'm also curious how the game and strategies change when played in multiplayer. Are diplomats ever banned?

Rarely. Now most people playing multiplayer actually play Freeciv, which is somewhat different (and, if you ask me, has a much inferior metagame for reasons I talked about before). In multiplayer you typically have a turn time limit so you can't actually micro every single city every turn once you have a huge number. Also, there is serious competition for Science, so getting tons of that ASAP is essential. Oh and almost everyone plays on King or Emperor difficulty, so one doesn't have the whole epic struggle just to prevent Civil Disorder and can play much more freely. Oh and in Freeciv almost everyone plays with doubled unit actions and doubled Production per turn, which actually breaks tons of stuff and creates all kinds of crazy exploits that I can't really go into in this game.

There are precisely 2 viable multiplayer Civ 2 strats: Celebration smallpox with Republic -> Democracy -> conquest and Monarchy rush conquest. The latter is only viable in games with maybe 2 or 3 human players, and you have to pray you find the other guys early. In larger games, you lose if you don't play Celebration. If you do a Monarchy rush, you MIGHT be able to take out another player or two, but while you're working on that the other guys will have acquired high level military techs that you can't compete with.

The winner is basically the guy who got the best starting zone (Best meaning it had the most Whales in it) since that guy gets to Republic first, spins off more Settlers faster, etc. In fact, many high level Civ 2 matches end without anyone firing a shot. One guy celebrates hard before the others are able to, the others see that one person is now all 5 of the top 5 cities, and everyone quits because they know they're going to lose. Or one guy gets both Michaelangelo's Chapel and J.S. Bach's Cathedral and everyone quits.

Things are much more interesting and fun in multiplayer if no one knows how to play optimally. But honestly Civ 2/Freeciv multiplayer just doesn't work well for a dozen reasons. It was never built to be a multiplayer game and it's not balanced around that. Plus it just takes a ridiculously long time, so almost no one ever has the time to finish a game of it. It sounds cool, but it's basically not viable in practice.


Triskelli posted:

Reading this thread, it seems that Civ II might have the most to do with Civilization Revolution. The types of wonders and their effects, the way air units work and the availability of caravans and spies.

I've played Civilization Revolution a fair amount and I wouldn't have made the comparison. I disliked Civ Rev because it was dumbed down too much and also included tons of mechanics I dislike, such as Culture and Great People and especially different perks for different civs.


Glazius posted:

Well, even though we're never going to hit those advanced units in this LP, it's nice to know about them.

I just... I just don't understand Rome at all. What the heck were they doing there? Does the AI mostly rely on tech trading?

It relies mostly on cheating. And some enemy civs seem to cheat harder than others. In the Roman case, they can't have had contact with ANYONE except maybe the Americans, so it can't really have been tech trading. Later in the game, the AI does rely heavily on tech trading when they team up against you. Each of them will often work on a different tech with their cheated up Science rate and then they'll all immediately trade those once they get them, which multiplies their effective Science rates even further.


nielsm posted:

Yep that's also how I remember Fighters, as a defensive unit against air tactics. A Fighter stationed in a city or airbase should be thought to be patrolling the airspace around it.

There's about three reasons to move a Fighter: Relocating it, attacking a bomber relocating across two turns or one that just bombed, and attacking a Helicopter.


Oh and by the way, Submarines should also work as carriers for missiles, you can use them as launch platforms for nukes.

Regarding Submarines, you're quite right, though iirc the game mentions that nowhere. Because Submarines are usually invincible and because they have an actual combat use and because they're cheap, they're MUCH better for this kind of job than Carriers are. However, Nukes generally have a massive enough movement range that you shouldn't need much extra help to bring any target you want in range even without Submarines.

Regarding Fighters, I stand by what I said before about how your enemies should never, ever have air units in a singleplayer game, so they're not really useful. Even if your enemies do get air, the trouble Fighters have is that they're STILL just not often the best unit for the job.

For example, Fighters only have 4 Attack and Helicopters only have 3 Defense and can be attacked by ground units. A Fighter attacking a Helicopter gets some special perks, namely the Helicopter's Defense is halved and the Helicopter's Firepower is reduced to 1. So... it's 4 Attack against 1.5 Defense. Cool. You COULD just have a real unit, like a Tank with its 10 Attack, walk out and massacre the Helicopter even more effectively without those special bonuses. And it's not even like Tanks are that good. Heck, the Helicopter's Defense is so bad that units as primitive as a Rifleman don't shape up badly against it when they're on offense.

Regarding enemy Bombers that just bombed, there's actually a little trick you can do sometimes to wipe them out without fighting at all. It's often possible to just put about 3 units in the path the Bomber needs to take back to its city, thus making it impossible for the Bomber to return in one move. The Bomber can't bomb again before returning (and its turn would end anyway if it tried), so it's helpless and will crash and burn without you even needing to attack it.


Several People posted:

Firepower?


For the most complete explanation of combat in Civ 2 that exists, see this page: http://www.civfanatics.com/civ2/strategy/combatguide

It's still imperfect and incomplete and sometimes dead wrong and more often poorly written so that it seems to be dead wrong, but it's a start. Perhaps it's time I made an improvement to it- and actually showed the math of where their formulae came from.

On page 2 of this thread I explained a simple lies version of Civ 2's combat system and I never got around to the complicated truth because the difference never mattered. And also because I can't actually type out most of the probability and summation notation I'd need to give the formulae properly. Well it's past time to try anyway.


One of the big things I did leave out is that besides Attack, Defense, and HP there is also a 4th combat stat: Firepower. I'll try to explain how that fits in now. Just as a reminder before I begin, the game lists many units as having, say, 2 max HP. It actually means 20. The HP number is always 10x higher than stated. As another reminder, the Defense of the attacking unit is wholly irrelevant and so is the Attack of the defending unit. Defenders kill people with their Defense. Attackers stay alive with their Attack. As a final reminder, Attack and Defense can be affected by various multipliers like a unit being a veteran or the defender being on a Hill or fortified or the like (I told basically the whole truth about those before and the page I linked to includes them all accurately too, so there's no need for me to talk about those again). What matters is the final Attack of the attacker and Defense of the defender after all modifiers, and that's what I mean by "Attack" and "Defense" from now on.

A battle between 2 units in CIv 2 is always to the death and always has exactly 1 attacker and 1 defender. The tricky thing is that it actually takes place in a large number of hidden rounds. In each round, exactly 1 unit loses an amount of HP equal to the Firepower of the other unit. The battle has round after round until one unit hits 0 HP, at which point it dies and the other unit wins. That's what Firepower is; that's all it does. Now it's time to move beyond the basics.


This is about to get very long and very mathy. I'm going to try to explain things as simply and clearly as I can without losing all mathematical rigor, but it will doubtless make more sense if you already know about series, summation notation, and the more probability theory the better. Skip to the next page to jump to the thrilling conclusion if you'd prefer.

So a battle is a series of rounds. In each round exactly one unit loses HP equal to the Firepower of the other. This continues until one hits 0 HP and dies.

But which unit takes the damage each round? That's random and based on the Attack of the attacker and the Defense of the defender. Let me explain how it's determined:


Probably of Winning a Round

Every round, a random number is generated for the attacker which is equally likely to be any integer between 0 and ((8 x Attack) - 1 ). The same happens for the defender with Defense.

Imagine the simple case of Warriors (each with 1 Attack and 1 Defense) fighting each other. According to the above, each one basically rolls 1d8 -1 every round. The rolled results are compared and the unit who got the lower result loses HP. Ties are won by the defender. Note that the description given in the page I linked to is false as written; that page says the number generated for the attacker is between 0 and ((Attack - 1) x 8), which means guaranteed 0 for both Warriors in this combat. Which would mean the defender wins every round with 100% probability. Which means that every Warrior vs Warrior fight would end with the attacker dead and the defender completely unharmed. That's obviously and verifiably not what happens.

The general case is each unit rolling 1d(8 x Attack or Defense) -1 with the defender winning ties. For example, picture a 5 Attack Crusader hitting a 2 Defense Phalanx. Every round the Crusader essentially rolls a 40-sided die and subtracts 1 from it, so the Crusader has a 1/40 chance each of getting 0, 1, 2, etc. on up to 39. A random integer from 0 to 39. The Phalanx rolls a 16-sided die and subtracts 1, so the Phalanx has a 1/16 chance each of getting 0, 1, 2, etc. on up to 15. A random integer from 0 to 15. It should be immediately clear that the Crusader is quite likely to end up with a higher number and therefore win the round.

So the obvious question to ask is "Given the above, what is the actual probability of a unit winning a round of a battle?" Take the 1 Attack vs 1 Defense Warriors case again for a simple example. The attacker rolls a random integer from 0 to 7; call that integer "N". Given result N, what is the probability that the defender's result is less than N? Well if N is 0, the probability that the defender rolls lower (and thus takes damage) is 0/8 because none of the 8 possible numbers from 0 to 7 are less than 0. If N is 2, the probability that the defender rolls lower is 2/8 because 2 of the 8 possible numbers from 0 to 7 (specifically 0 and 1) are less than 2 . As you probably already see, the pattern is that the defender has an N/8 chance of rolling lower than any given N the attacker rolls. What we want is the average of these probabilities; that will be the overall probability that the defending Warrior loses a round to the attacking Warrior. In arithmetic terms we find the average by adding up all the numbers in the group (0/8, 1/8, 2/8, 3/8, 4/8, 5/8, 6/8, and 7/8) and then dividing by the number of numbers in that group (8). Go ahead and try it and simplify your fraction and you'll get a result of 7/16.

In probability terms we talk about finding the average of these probabilities a bit differently, but do fundamentally the same stuff. What we'd do is multiply the chance of the defender losing for any given N by the chance of that N occurring (always 1/8 here) and then add all of those products up. This would usually be described roughly as follows using summation notation: "Take the sum over N from N = 0 to N = 7 of ((1/8) x (N/8)." I'm going to need to use summation notation like this to describe some more complicated stuff later on, so I'm going to try to explain it thoroughly now for anyone who hasn't seen it before. The first phrase, "Take the sum over N" means that in the subsequent formula we are going to replace all Ns with various values and add up the resulting formulae. "From N = 0 to N = 7" tells us exactly which values to plug in for N: every integer from 0 to 7. Thus 0, 1, 2, 3, 4, 5, 6, and 7. Lastly "Of ((1/8) x (N/8)" gives the formula with the Ns that we plug in those values for.

So taken together "Take the sum over N from N = 0 to N = 7 of ((1/8) x (N/8)" means to plug in 0 for N in the formula and look at the result, which is 0. Then we plug in 1 and get a result of 1/64. We add that to the previous result. Then we plug in 2 and get a result of 2/64. We add that to the previous total and get 3/64. And so on until we plug in 7, get 7/64, and add that to the previous total for a grand total of 28/64 (check that you can get this result). This simplifies to 7/16. Which is of course the same as we got with the elementary school version of average taking. Perfect. Anyway, 7/16 is 43.75%. So there's a 43.75% chance of an attacker with 1 Attack winning a round against a defender with 1 Defense.


On to the general case: Attack and Defense other than 1. Well the attacker still rolls a random integer we can call "N" but now it's from from 0 to ( (8 x Attack ) - 1 ). What's the probability that the defender's result is less than N? Well it's NOT quite just N / (8 x Defense ) like you might expect . The reason that that doesn't work is that that formula could give values greater than 1 or less than 0 if the Attack and Defense values are different. For example, with 3 Attack it's possible that N could equal 20. With 1 Defense, this formula would give a 250% chance of the attacker winning that round when the true answer is 100% because you can't have probabilities over 100% or less than 0%. So the actual probability of the defender's result being less than N is N / (8 x Defense ) with maximum 1 and minimum 0. Now if we took the same approach as in the simple case, we would take each of those probabilities for a given N, multiply them by the probability of rolling that N in the first place (1 / ( 8 x Attack ) ) and sum those products up.

But the numbers can't actually just be crunched out due to the maximum and minimum involved; we need to use a different form of the formula to get a usable answer. The solution is to break things down into two situations. Situation 1 is the defender having Defense greater than or equal to the attacker's Attack. Situation 2 is Attack being greater than Defense. We would need a 3rd Situation if Attack could actually go below 1, but it can't (nothing with Attack 0 is allowed to start a fight in the first place). So just 2 situations.

Let's look at situation 1 first. So Defense is greater than or equal to Attack. As always, the attacker rolls a random integer we can call "N" from 0 to ( (8 x Attack ) - 1 ). The probability that the defender's result is less than N now really IS just N / ( 8 x Defense ) with no need to impose a maximum or minimum on it because 8 x Defense MUST be greater than N and therefore the fraction MUST be between 0 and 1 already. So here we can do what we did in the simple case: take each of those probabilities for different allowed Ns, multiply them by the probability of rolling that N in the first place- which is ( 1 / ( 8 x Attack ) ) - and sum those products up.

So in situation 1 we take the sum from N = 0 to N = ( ( 8 x Attack ) - 1 ) of ( ( 1 / ( 8 x Attack ) ) x ( N / (8 x Defense ) ) ) . So we have a sum from N equals 0 to N equals ( ( 8 x Attack ) - 1 ) of ( N / ( 64 x Attack x Defense ) ). There's no N in the denominator, 64 x Attack x Defense, so we can put that aside for now and try to figure out the sum of the numerators, N, as the different values of N are plugged in.

Now the sum of the numerators must be the series 0 + 1 + 2 + ... + ( ( 8 x Attack ) -1 ). The total of a series like that is easily calculated: it's equal to 1/2 the number of numbers times the sum of the first number plus the final number. To see this for yourself, note that 1 + 2 + ... + 100 = 5050, which is equal to 50 (which is 1/2 of 100, the number of numbers) times 101 (which is the sum of the first number plus the final number). Equivalently, the total of a series like this is equal to the average of all the numbers in the series times the number of numbers in the series. Anyway, back to our actual series, the number of numbers is 8 x Attack. And the first number is 0 and the last number is ( (8 x Attack ) -1 ). So the whole sum is ( ( 4 x Attack ) x ( (8 x Attack ) -1 ) ). Which multiplies down to ( ( 32 x Attack x Attack) - ( 4 x Attack ) ). So, that's the numerator! Now from before, the denominator of the fraction we're looking for is ( 64 x Attack x Defense ). Time for a new paragraph to put this stuff together.

To recap what we have so far, we're trying to find the general formula for the probability of the attacker winning a single round of a battle in the situation where Defense is greater than or equal to Attack. We separately figured out the numerator and denominator of this probability, so what remains is trying to simplify it down. The fraction is:
( ( 32 x Attack x Attack) - ( ( 4 x Attack ) ) / ( 64 x Attack x Defense ).

We can factor out an x4 and also factor out an xAttack from both the numerator and denominator. This leaves ( ( 8 x Attack) - 1 ) / ( 16 x Defense ). Which is in simplest form, so we're done with this part! Call this Formula One. What does it mean? It means that when you take the attacker's Attack, multiply by 8, then subtract 1, and then divide that by 16 times the defender's Defense you wind up with the probability that the attacker wins a round of a battle in the situation where the defender's Defense is greater than or equal to the attacker's Attack. Just to make sure it works, plug in Attack 1 and Defense 1 from our simple example. We get a result of 7/16, same as before!


On to situation 2! Here Attack is greater than Defense. What's the probability that the attacker wins a round of battle? Let's start in the familiar way. The attacker rolls a random integer we can call "N" from 0 to ( (8 x Attack ) - 1 ). Then for any given N, what's the chance the defender rolls lower? It's NOT just ( N / ( (8 x Defense ) ). The reason is that that formula could give values greater than 1 if N is sufficiently high relative to Defense and, once again, probabilities can't be greater than 1. This is a problem. But I see a workaround! We're looking at the probability that the attacker wins the round here. Since ties are impossible and every round has a winner, the probability of the attacker winning a round and the defender winning a round must sum to 100%. So the probability that the attacker wins the round must be equal to 1 minus the probability that the defender wins the round. So what's the probability that the defender wins a round of battle in the situation where Attack is greater than Defense?

Well looking at it this way, the DEFENDER rolls a random integer which we can still call "N" from 0 to ( (8 x Defense ) - 1 ), minimum 0. Now what we want is the probability that the attacker's roll is less than OR EQUAL TO this N. It should be ( ( N + 1) / ( (8 x Attack ) ). For example, if the defender rolled a 0, then the attacker could also still roll a 0 with probability 1 / ( 8 x Attack) and thus has that probability of still losing. Now because Attack is strictly greater than Defense in this situation and because Defense can never be negative, ( N + 1 / ( (8 x Attack ) ) is always between 0 and 1 and therefore works just fine. So this ( N + 1 / ( (8 x Attack ) ) is the probability that the defender wins a round of combat after rolling a number "N" from 0 to ( (8 x Defense ) - 1 ). If we multiply this by the probability of getting any given N, which is always 1 / (8 x Defense), and then sum all of those products we'll get the chance of the defender winning a round overall.

So in situation 2 the chance of the defender winning a round is a sum from N = 0 to N = ( ( 8 x Defense ) - 1 ) of ( ( 1 / ( 8 x Defense ) ) x ( (n + 1) / (8 x Attack ) ) ) . So we have a sum from N = 0 to N = ( ( 8 x Defense ) - 1 ) of ( (N + 1) / ( 64 x Attack x Defense ) ). Once again, there's no N in the denominator, so we can leave it aside for now and try to figure out the sum of the numerators as the various Ns are plugged in. Now the numerator series is a bit different this time: 1 + 2 + ... + ( 8 x Defense). But we can solve it in the same way; the whole sum should be ( ( 4 x Defense ) x ( (8 x Defense ) +1 ) ). Which multiplies down to ( 32 x Defense x Defense) + ( ( 4 x Defense ). So that's the numerator. From before, the denominator of the fraction we're looking for is ( 64 x Attack x Defense ).

So the entire fraction which gives the probability of the defender winning a round when Attack is higher than Defense is ( ( 32 x Defense x Defense) + ( 4 x Defense ) ) / ( 64 x Attack x Defense ) . This time we can factor out 4 x Defense instead of 4x Attack. And then we're left with ( ( 8 x Defense) + 1 ) / ( 16 x Attack ), which is in simplest form.

But we're not finished. Remember, this is the probability of the defender winning the round. What we wanted to find out was the probability of the ATTACKER winning. At long last, we can now see that that is 1 - ( ( 8 x Defense) + 1 ) / ( 16 x Attack ) ). So THIS is the probability of the attacker winning a round when Attack is greater than Defense. Call it Formula Two.

So! We have now derived formulae for the probability of any attacker winning a round against any defender. These formulae match up to the ones on the page I linked to under the "On to the real calculations" heading, except that they didn't show their work and didn't leave their formula in a form you can directly plug Attack and Defense numbers into.


Probability of Winning a Battle

But we're not done yet. This is where it actually gets complicated. All of that stuff was to find the chance that the attacker wins 1 round of a battle, but a battle is almost always made up of many rounds. The loser of a round loses HP equal to the Firepower of the winner and this process continues until one unit goes to 0 or negative HP, at which point it dies and the other one is the winner. The bad news is that we can't just predict exactly how many rounds a battle will take in advance (except for the trivial case where each unit goes in with initial HP less than or equal to the foe's Firepower and thus the fight must take exactly 1 round).

The good news is we don't need to. With some probability theory, there are only 3 things we need to know in order to come up with a formula for the probability of an attacker winning the battle. First, the chance of the attacker winning any given round. We found that out above in the 2 different possible cases. All that mattered there was Attack and Defense; HP and Firepower were irrelevant. Second, we need to know how many rounds the attacker must win in order to kill the defender. Third, we need to know how many rounds the defender must win in order to kill the attacker. For these last 2, all that matters is HP and Firepower (for both units), while Attack and Defense are irrelevant.

First consider the simple case of a Warrior fighting a Warrior by way of example. Each has 10 HP and 1 Firepower. So the attacker would need to win 10 rounds to kill the defender and the defender would need to win 10 rounds to kill the attacker. We know from before that with 1 Attack and 1 Defense, the attacker's chance of winning a round is 43.75%. So intuitively we expect the result of the battle to be something close to a draw with the survivor (probably the defender) being badly injured after something close to 20 rounds of fighting.

The more general case is that the attacker needs to win a number of rounds equal to the defender's initial HP divided by the attacker's Firepower. The defender needs to win a number of rounds equal to the attacker's initial HP divided by the defender's Firepower. Round up for both.

So once you know exact initial HP for both units, Firepower for both units, Attack for the attacker, and Defense for the defender, you have all the information you need to calculate an exact probability.


Or so I thought!

I dug out my old Mathematical Theory of Probability and Econometrics books from graduate school and after refreshing my memory it seemed clear to me that the Negative Binomial Distribution was the key to solving this problem. So I spent an hour or two working through that but my final formula was different from the one in the linked page and plugging in numbers seemed to give me wrong results. So I decided maybe I'd misremembered something about the Negative Binomial Distribution and thus all that work was worthless. Fortunately I didn't actually delete it. Two hours later I'd derived the same formula the linked page used, but when I plugged in unit stats I ended up with the exact same results as with my first version. More checks confirmed that the two must be equivalent; they just don't look like it. Also, I realized that the whole reason I seemed to get wrong results in the first place was poor wording on the linked page. Anyway, the upshot is that I now have 2 equivalent approaches to solving this problem for you, one more detailed than the other.


Negative Binomial Distribution Approach

In probability theory and statistics, the "Negative Binomial Distribution" is a formula that can tell us the probability of an event happening Y times before a complementary event happens Z times in a succession of independent trials.

I don't want to get too bogged down in terminology here, so I'll try to explain what that means by way of example. Imagine flipping a coin. The only two possible outcomes of one flip are "Heads" and "Tails". If one of these events does not happen, the other MUST happen. So the probability of Heads occurring + the probability of Tails occurring equals 100%, aka 1. This is what it means for 2 events to be complementary: exactly one of them MUST occur.

The coin flip is what would be called a trial, and multiple coin flips would be multiple trials. In every trial you get either heads or tails. And the chance of getting heads on the first flip would in no way impact the chance of getting heads on the second flip. That's what it means for the trials to be independent. So the Negative Binomial Distribution could tell you the probability that, say, you get 3 Heads before 4 Tails. Or 732 Heads before 17 Tails.

We're not talking about coin flips here, but what's going on is similar. In each round of a battle either the attacker wins or the defender wins. Exactly one of them will happen since there can be no ties or anything. So attacker winning and defender winning are complementary events, just like getting either heads or tails in a coin flip. And each round of battle the probability of the attacker winning (assuming both are still alive and fighting) is the same as in all previous rounds because it depends only on unchanging Attack and Defense, not on HP in any way. So each round is an independent trial. And we know the Y and the Z. Y is the number of rounds the attacker must win to be victorious and Z is the number of rounds the defender must win. So Y is the the HP of the defender divided by the Firepower of the attacker while Z is the HP of the attacker divided by the Firepower of the defender.

Thus the Negative Binomial Distribution can tell us the probability that the attacker wins enough rounds to kill the defender before the defender wins enough rounds to kill the attacker, which is all we want to know!


We want to find the probability that the attacker wins the battle, given that the attacker has probability "P" of winning a round and must win Y rounds before losing Z rounds to be victorious .

The "Probability Mass Function" of the Negative Binomial Distribution is the formula that actually tells us the probability of getting a specific number of successes before the last of another specific number of failures for a given probability of success. You'll need to recall from middle school that "!" after a positive integer means "factorial": take that integer and multiply it by 1 less than itself and then 2 less than itself and so on down to x1. So 5! = 5 x 4 x 3 x 2 x 1 = 120. Also, 0! and 1! are defined to be equal to 1. For P = probability of success & Z = number of failures, the Probability Mass Function of the Negative Binomial Distribution says that the likelihood of getting precisely k successes by the Zth failure is:

( (k + Z - 1)! / ( k! x (Z - 1)! ) ) x ( P ^ k ) x ( ( 1 - P ) ^ Z )

There are sort of 3 multiplied sections to that formula which it will help to look at individually.

The second section, ( P ^ k ), just tells you the probability of getting k successes in the first place. The third section, ( ( 1 - P ) ^ Z ), tells you the probability of getting Z failures. Multiplying those gives you the odds of getting k successes AND Z failures. The first section, ( (k + Z - 1)! / ( k! x (Z - 1)! ) ), is where the wizardry happens, it tells you the number of combinations of k successes that can be drawn from k + Z -1 trials (the number of trials that must have occurred for you to get k successes before the final trial ends in a failure). If you know even a little about probability theory, thinking about the complicated formula in those 3 pieces should make it make intuitive sense to you. At least it does for me.

There are two issues with applying this formula. First, the formula assumes that the Zth failure actually happens, but in Civ 2 it doesn't if the attacker wins. If k hits Y, the battle ends then and there and k could never be higher than Y. That doesn't actually matter though. This formula tells you the likelihood of getting every possible number of round wins before eventually being eliminated. The summed likelihoods of k = Y, k = Y+1, k = Y +2, and so on to infinity is what we want to find out. But of course, we can't add up an infinite number of things by hand. This is the second issue. The workaround is that the total of the probabilities of all possible values of k from 0 to infinity must sum to 1. And there are a finite number of possible integer ks between 0 and Y. Therefore to find the infinite number of summed likelihoods we actually want, we can just take 1 and then subtract a finite number of likelihoods. This is going to be long and messy and painstaking, but it IS possible.


To demonstrate just how messily and painstakingly, let's take our hitherto very simple example of a Warrior fighting a Warrior. We found out from earlier that the probability "P" of the attacker winning a given round is 43.75%. Each has 1 Firepower and is starting from full (10) HP, so Y and Z are both 10. What we want to find is the probability of at least Y successes occurring before Z failures. But we can't figure that out directly because we'd need to check an infinite number of numbers of 'possible' successes above Y. What we CAN check is the probability of every number of wins BELOW Y occurring. Then we can add those up and subtract them from 1 to get what we actually want.

For starters, what's the chance of k = 0 successes before Z = 10 failures (the worst possible outcome, where the defender isn't even scratched)?

Plug in and get ( (0 + 10 - 1)! / ( 0! x (10 - 1)! ) ) x ( .4375 ^ 0 ) x ( ( .5625 ) ^ 10 )
So ( 9! / ( 0! x (9)! ) ) x ( .4375 ^ 0 ) x ( ( .5625 ) ^ 10 )
So ( 362880 / ( 1 x ( 362880 ) ) x ( 1 ) x ( 0.003171212 )
So ( 1 ) x ( 1 ) x ( 0.003171212 )
So 0.003171212

This is the simplest possible situation. We are not even 1/10 done. Next we need to check the answer for k = 1, k = 2, k =3, k =4, k =5, k = 6, k = 7, k = 8, and k = 9. In all of those cases the answer will be far messier to find. Break out either pencil, paper, and a sophisticated calculator or your favorite statistics program! Mine is Excel, which makes me a heretic.

I got the following probabilities for each k:
k = 0) 0.003171212

k = 1) 0.013874052

k = 2) 0.033384438

k = 3) 0.058422767

k = 4) 0.083069872

k = 5) 0.101760593

k = 6) 0.111300648

k = 7) 0.111300648

k = 8) 0.103474821

k = 9) 0.090540469

So! I have now discovered the probabilities of a 1 Attack, 10 HP Warrior inflicting every possible amount of damage on a 1 Defense, 10 HP Warrior before dying. If I sum those probabilities, what I have is the probability of the attacker doing 9 or less damage to the defender before taking 10. That sum is 0.71029952

Therefore, 1 - 0.71029952 = 0.28970048 is the probability of the attacker dealing 10 or more damage to the defender before taking 10 damage and is therefore the probability of the attacker winning! https://www.youtube.com/watch?v=OjhC7sAaU5c&t=0m4s


Not-Quite Negative Binomial Approach

I'm not exactly sure how the linked to page got their "P = SUMn(COMB(n-1,dh-1) * (p^dh) * (1-p)^(n-dh))" equation, but I can derive the same thing using my own symbols and terminology.

Their formula for the probability of the attacker winning is going to have to have 3 sections to it which are analogous to those of the Negative Binomial Distribution formula, but are not quite the same.

Also, it has to be a summation. Of course, I used a summation over the values of the Negative Binomial Distribution's Probability Mass Function, but here I may as well use the summation from the beginning.

This summation will be over all possible numbers of rounds the battle can take and end in victory for the attacker. The minimum is Y = ( defender initial HP / attacker Firepower), rounded up. That's the number of rounds to kill the defender if the attacker wins every single round. The maximum is Y + Z - 1. That means the attacker loses Z -1 times and is therefore 1 defeat away from death, but does score Y victories and thus win the battle. So we have a summation of k from Y to Y + Z -1.

One piece of the formula must be ( P ^ Y ), the probability of getting enough round wins to secure the battle win at all.

Another piece must be one that will account for the probability of each possible number of defeats. That should look like ( 1 - P ) ^ ( k - Y ). Of course, 1 - P is the probability of the attacker losing a round, while k - Y is the number of rounds that were lost. Minimum 0 and maximum Z - 1, exactly as one would expect.

The third piece of the formula is the trickier one, the part that figures out the number of combinations for a given number of trials that can bring about the needed number of wins. The tricky part is that it's NOT just Y + Z -1 take Y combinations as one might expect; I believe it's actually Y + Z -2 take Y - 1.

Those 3 parts need to be multiplied together because multiplying the first two gives the probability of those 2 independent events both happening, and multiplying in the third one takes that small probability and magnifies it by the numerous different ways it could come about in the proper number of trials.

So rearranging to be more like typical probability distribution formulae, I get:


The sum over k from k = Y to k = Y + Z - 1 of ( k - 1 )! / ( ( Y - 1 )! x ( k - Y )! ) x ( P ^ Y ) x ( ( 1 - P ) ^ ( k - Y ) )

Where, as a reminder, Y is the number of round wins required for the attacker to kill the defender, Z is the number of round wins required for the defender to kill the attacker, P is the chance of a round win for the attacker, and k is a possible number of rounds the battle could take while ending in a win for the attacker. So this formula sums the product of the joint probabilities of the attacker winning with all possible numbers of losses times the number of ways those numbers of wins and losses could occur together. That's why it gives the final probability of the attacker winning the whole battle. You should b able to see that it's the same as the one in the linked page.

Let's try applying it to the Warrior vs Warrior case. Y and Z are both 10 since each warrior has 10 HP and 1 Firepower. P is .4375 according to Formula 1.

So we must take the sum over k from k = 10 to k = 19 of ( k - 1)! / ( ( 9 !) x (k - 10)! ) x ( 0.4375 ^ 10 ) x ( ( 0.5625 ) ^ ( k - 10 ) )

To demonstrate, start with k = 10 and plug in. We get:

9! / ( 9! x 0!) x 0.00025691 x ( 0.5625 ^ 0 )

Which simplifies to: 1 x 0.00025691 x 1 = 0.00025691

Next we need to check the answer for k = 11, k = 12, k = 13, ... , and k = 19. In all of those cases the answer will be far messier to find. Grab your paper or statistics program again!

k = 10) 0.00025691

k = 11) 0.001445117

k = 12) 0.004470832

k = 13) 0.010059371

k = 14) 0.018389788

k = 15) 0.028963916

k = 16) 0.040730507

k = 17) 0.052367795

k = 18) 0.06259588

k = 19) 0.070420365

Therefore the sum, 0.28970048, is the probability that the attacker wins the fight in that case. Which is exactly the same answer that my formula got, hooray! Remember, this is the simplest case that could reasonably occur, just 1 Warrior against another on no special terrain. The amount of work required to crunch the numbers can become truly enormous as HP grows. And it's already huge for something like this!


Comparing the Equivalent Formulae

So having realized that I hadn't actually made a mistake with my Negative Binomial Approach and that the two formulae were equivalent, I started wondering if I could prove that.


Here's the Negative Binomial version first, followed by the linked page's format with my variable names:

Sum over k from k = 0 to k = Y -1 of ( (k + Z - 1)! / ( k! x (Z - 1)! ) ) x ( P ^ k ) x ( ( 1 - P ) ^ Z )

Sum over k from k = Y to k = Y + Z - 1 of ( k - 1 )! / ( ( Y - 1 )! x ( k - Y )! ) x ( P ^ Y ) x ( ( 1 - P ) ^ ( k - Y ) )

About halfway through my proof I got bored and stopped. If any of you can prove it, I'd be interested to see how.


How Many Cavalry to Kill that Musketeer?

Now this whole question I've been answering is rarely important. I don't just mean because you can get away with approximately true answers instead; I mean because you rarely care about the odds of 1v1 matchups in the first place. Those are skirmishes. What actually matters big time is whether the units you have on hand can beat the defenders and thus take a city.

Very often you outnumber the defenders massively but because of their defensive multipliers you know that any individual unit of yours has a negligible chance to kill one. What matters is chipping down the defenders' HP with suicidal attack after suicidal attack until they're worn down and finally die.

For example, in the last game I knew any of my Veteran Cavalry attacking the Sioux Veteran Musketeers in City Walls on Rivers had basically a 0% chance to win outright (0.3% if you want to get technical). But I knew each of them would take a decent number of HP off the guy they died to, so if I could attack immediately with another Cavalry and another and another, I'd eventually kill the Musketeer. Then I could start chipping down the next one. But it wasn't clear to me how many Cavalry I needed. 15 or so often worked out, but I typically went with something much higher- like 40- to be sure.

How can we find a good answer to this question? Well a promising, simple start is to figure out the average amount of HP damage the attacker should do before dying and then divide the defender's starting HP by that much. Imagine that each Cavalier wins 3 rounds before losing 20 and thus dying, each Cavalier would thus deal 3 damage to the Musketeer before dying. Musketeers have 20 HP, so it would take 7 Cavaliers (rounding up) to kill 1 Musketeer.

I'm going to make a bunch of simplifying assumptions which are generally reasonable in this situation; such as that the defending unit does not become a veteran midway through the series of attacks (it's best to assume it starts off as a veteran because it will certainly become one quickly anyway), that the defenders and attackers all start at full HP, and that it's reasonable to just consider the average results here.

The first thing to figure out is how many rounds will pass on average before the attacker dies. Well how much HP does the attacker lose on average every round of combat? The answer is (1 - P) x (Defender's Firepower). In other words, the chance that the defender wins times the amount of damage inflicted by the defender when the defender wins. This makes intuitive sense. Divide the attacker's HP by that result and round up and we get the number of rounds that should pass before the attacker dies. ( Attacker HP ) / ( ( 1 - P ) x (Defender's Firepower), round up. Guess what? Attacker's HP / Defender's Firepower is just our Z from earlier, the number of rounds the defender must win to kill the attacker. So Z / ( 1 - P ), round up are the average number of rounds that will pass.

The attacker wins P proportion of those rounds and inflicts Attacker's Firepower worth of damage whenever it wins one. So the average damage the attacker should do before dying is
D = (Z x P x Attacker's Firepower) / (1 - P ). This is Formula Four


Let's look at the concrete example of my veteran Cavalry attacking veteran Musketeers which are in City Walls and on Rivers. The Cavalry have 12 total Attack, 20 HP, and 1 Firepower while the Musketeers have 20.25 Defense, 20 HP, and 1 Firepower. Z must be 20, Attacker's Firepower is 1. What's P? Well we need to apply Formula 1 from earlier. I ran the calculation and got P = 0.293209877, so 1 - P = 0.706790123. So the average amount of damage one of my Cavalry inflicted before dying is:

(20 x 0.293209877 x 1 ) / 0.706790123 = (5.86419754 / 0.706790123) = about 8.3 damage.

Each enemy musketeer SHOULD therefore have died to about 3 cavaliers. Each city had something like 5 defenders, most but not all of them musketeers, so 15 was approximately the right number to kill them all. And that's usually about the number of casualties I took.

At the time I was playing through I commented that it would be a catastrophe if the Sioux somehow stole Tactics from me and thus built Alpine Troopers because I would go from needing about 15 to about 50 Cavalry to take a city. That was pretty much just a shot in the dark since I hadn't done this math in detail then. Was I right?

The Cavalry still have 12 total Attack, 20 HP, and 1 Firepower. The City Walled, Rivered, veteran Alpine Troops have 33.75 Defense, 20 HP, and 1 Firepower. Z is still 20, Attacker's Firepower is still 1. I applied Formula One and got P = 0.175925926, so 1 - P = 0.824074074. So the average amount of damage one of my Cavalry would inflict before dying is:

(20 x 0.175925926 x 1 ) / 0.824074074 = about 4.2 damage.

So it would therefore take only about 5 Cavalry per Alpine Troop and thus about 25 per city. That's bad, but not nearly as bad as I thought.

Much more recently I dismissed Fanatics by saying it might have taken a thousand to take a city like the Sioux ones. That was hyperbole, but I'm now curious about how many it would actually take.

The Fanatics have 6 total Attack, 20 HP, and 1 Firepower while the Musketeers have 20.25 Defense, 20 HP, and 1 Firepower. Z must be 20, Attacker's Firepower is 1. P = 0.145061728, so 1 - P = 0.854938272. So each Fanatic would do:

(20 x 0.145061728 x 1 ) / 0.854938272 = about 3.3 damage. So it would actually only take 7 per Musketeer, so a bit over 35 per city. So I was actually pretty darned wrong (though they remain a very poor choice of unit all in all and only more so later).

Anyway, I've now found all of what I wanted to find.