Announcement

Collapse
No announcement yet.

The Civ IV Combat System

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    If we derive that theory a bit further, we see, that if we multiply odds with damage, we can see the expected damage per round.

    It equals for our unit

    xS = (R / (R + 1)) * ((3R + 1) / (5R + 15))

    or

    xS = (3R² + R) / (5R² + 20R + 15)

    and equivalently

    xO = (R + 3) / (15R² + 20R + 5)

    If we take our example above, xS = 28% * 2/3 ~ 19%, and xO = 1/7 * 1/3 = 1/21 ~ 5%.

    Or, our unit is expected to kill the other unit in an average of about 5-6 rounds, while the other unit is expected to kill ours in 21 rounds.

    Theoretically only! Because if the fight would go over these 21 rounds and the other unit really wins 7 of them necessary to inflict 100% damage, our unit won 14 at the same time and inflicted 392% damage - hence the other unit would be dead long ago.

    So, what would be the real odds of the other unit to win? It has to win 7 rounds and can afford to lose only 3. Or we have to win 4 rounds and can afford to lose 20. I'll check the odds on this another time, when I have more time available. Unless one of you slackers does it.

    Sorry for my rambling.
    Last edited by Harovan; October 27, 2005, 10:27.

    Comment


    • #17
      Originally posted by Solver
      Originally posted by Jaybe Is a unit's strength and damage calculation dynamically recalculated each round, or all based on what they were at the start of the combat?
      Based on what they were at the start. The strength at the start of the combat is saved, and damage (and probability) are according to that.
      According to this a unit could be killed on a first strike but still manage to kill the attacker on defense. That doesn't seem right.

      Tom P.
      "If you are flamable and have legs you are never blocking a fire exit." - Mitch Hedberg

      Comment


      • #18
        SR, if you want to stay in one system, it may be easier to adjust Alex' formula to:
        If attacker wins:
        damage = 0.2 * D * (3*A + D) / (3*D + A)
        This way, you eliminate the hp's...

        Internaly, it does count with hp, but you can combine everything into strength. This ties in nicely: you will immediately get the end result and it will make true probability calculations possible. That was what I wanted to publish this weekend, but seeing that I initially made a mistake I'll need to adjust my formulae...

        I haven't looked in detail to the rest of your derivation...yet

        I'm not sure when, and if, but I thought the combat code will be released when the SDK arrives.

        DeepO

        Comment


        • #19
          Originally posted by padillah

          According to this a unit could be killed on a first strike but still manage to kill the attacker on defense. That doesn't seem right.
          What do you mean? If a unit dies during the first strikes, combat stops of course. That's why units with first strikes have a larger chance of escaping unharmed...

          DeepO

          Comment


          • #20
            OK, my mistake. I was confusing the "power" with the HP. you said earlier:
            Once first strikes are over, combat continues as usual. At most, B has been hit once (but it could be twice or not), which would mean its strength is now at 5. (the average would be a bit higher) A is still at 4. The numbers in the formula don't change, though, so B still has a .6 chance of winning the next round, while A only has .4. With those numbers, B is almost certainly going to win, even if he was hit a little during first strikes.
            This just seems a little odd to me, like First Strike doesn't matter unless you are already larger. And then you'll probably win anyway so I'm wondering, what's the point?

            Firt Strike should make combat for the other unit harder. It should be a "combat round" in and of itself. I.e. sort out all the First Strikes, deal damage, end of round; First normal combat round, deal damage, end of round; etc..

            This way if you are too big you will win anyway, but if you are only one or two points bigger you might want to think twice.

            Tom P.
            "I like refried beans. That's why I want to try fried beans, 'cause they may taste just as good and we're wasting time." - Mitch Hedberg

            Comment


            • #21
              Originally posted by padillah
              This just seems a little odd to me, like First Strike doesn't matter unless you are already larger. And then you'll probably win anyway so I'm wondering, what's the point?
              Correct, the characteristics of the battle won't change after first strikes, the chance of damage and the amount of damage are still the same.

              What the point is? The point is that when you're choosing your promotions, you've got to have some idea what the unit is going to be used for. Remember that when it comes to first strikes, you are dealing with promotions. For certain units, if you've got 5XP (e.g. from barracks and civic choices), you can either choose 2 combat promotions (a flat out +20%), or you choose 2 first strikes promotions (+2 fs). Now, what are you going to choose?

              If you want a defender, and you know he will have more strength than any attacker (e.g. because of fortification bonusses), chosing fs is better. If you will fight units of about equal strength, the +20% is better. If you know you're going to face stronger units, build another unit

              Firt Strike should make combat for the other unit harder. It should be a "combat round" in and of itself. I.e. sort out all the First Strikes, deal damage, end of round; First normal combat round, deal damage, end of round; etc..

              No, it should not be like that. This thing is balanced, why do you think its opponent is +10%? Why are type-specific promotions +25%? You really have a choice. Doing it like you suggest would break the system once you get to higher fs (IIRC you can get to 7 or 8). You wouldn't run into spearman-tank problems, but in archer-tank problems...

              This way if you are too big you will win anyway, but if you are only one or two points bigger you might want to think twice.
              That is exactly the border: one fs is in about equal situations comparable to +10%. You will want to think twice.

              DeepO

              Comment


              • #22
                A couple of simple questions on combat.

                In some review I thought I read there was a way of see the probability of success for a given attack. Is this true? and if so where in the heck do you find it? I have searched in vain to find it in game.

                Finally is there a reasonable simple formula for figuring out the probabilities given a modified A and D.

                I.e. is there a rule of thumb that a Strength 6 unit will beat a Strength 4 unit 60% of the time. I am pretty sure that isn't right.

                Comment


                • #23
                  Originally posted by Strollen
                  In some review I thought I read there was a way of see the probability of success for a given attack. Is this true? and if so where in the heck do you find it? I have searched in vain to find it in game.
                  I don't know, I don't have the final game yet.

                  Finally is there a reasonable simple formula for figuring out the probabilities given a modified A and D.

                  Yes there is, but no, it's not simple.

                  I.e. is there a rule of thumb that a Strength 6 unit will beat a Strength 4 unit 60% of the time. I am pretty sure that isn't right.

                  Whenever you get a ratio of strengths, you can calculate the possibility of success. But first strikes mess up this nice and easy rule of thumb. It most certain is not 60% in the above mentioned case, it will be closer to 99%.

                  DeepO

                  Comment


                  • #24
                    Okay. Let's see how much text we can pour into one post

                    This would not have been possible without the help of many others. Thank you.

                    Also, sorry Solver, but I'm changing 'the system' to a double value; strength and hp. While it might be a little harder to read, it is how it actually works. It also is in line with Alex' posts.

                    general description
                    Combat is a 'battle' between 2 values, the strength of the attacker A, and the strength D of the defender. These values are modified depending on promotions and situations, e.g. forest gives an extra 50% defense, which modifies D.

                    Once modification of A and D is taken into account, it doesn't matter whether the unit is defending or attacking, the rest of the formula is general for both parties.

                    Each unit starts out with 100 integer hitpoints, and will lose some of them after the end of the battle. Once it reaches zero, the unit is dead. If an archer of strength 3 loses 40 hp, and ends at 60 hp, it will be wounded to 3 * .6 = 1.8 strength. If that archer would have been wounded to 2.5 before starting battle, and would lose 40 hp, those hp are 'worth less'. It would end the battle at 60hp, being 2.5*.6 = 1.5. (I'm not 100% sure here, so correct me if the damage inflicted per hp is the same for normal and wounded units)

                    Combat is fought in rounds, each rounds being a dice roll between A and D. One side will lose, and hence loses part of his hitpoints. After this a next round is fought. Once one of the hitpoint values reaches zero or below, combat is over and the unit destroyed.

                    First strikes give 'free' rounds. This means that if the attacker has 2 first strikes, 2 rounds are fought where combat happens as normal, but in case the attacker would lose this result is ignored.

                    Retreat has no influence on the chance of success, retreat only happens when the unit would have died.


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

                    How many first strikes does a unit get, when it says e.g. 5-7? (That would be Drill III or IV, depending on the unpromoted unit)

                    For every unit, there are actually 2 parameters: let's call them first_strikes, and extra_first_strikes. Some units start with first_strikes already, but normally these parameters are changed by promotion.

                    In the case of Drill IV, a unit that displays as 5-7 first strikes means he will have 5 sure first strikes (so first_strikes=5), and 2 more possible first strikes (so extra_first_strikes=2).

                    --------

                    Before battle is fought, each unit has a step where the number of first strikes is computed. This total for the battle is equal to

                    first_strikes_battle = first_strikes + chance(extra_first_strikes).

                    Basically, it means that for the battle, anywhere between 5 and 7 first strikes will be assigned to the Drill IV unit.

                    (Note that I don't kow what kind of randomizer is used for the chance distribution, meaning I can't tell if 5-7 would leadmore to 6 first strikes then it would to 5.)

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

                    Once a battle is fought, the first thing to check is if the opponent has the immune-to-first-strikes property. If it doesn't, the total falls to 0.

                    Next, the two battle totals are compared, and the difference is taken. This difference is the number of first strikes the rest of the combat algorithm will use.

                    So, a Drill IV unit, attacking a Drill II unit, might get 6 first strikes initially (somewhere in between 5 and 7). It faces an opponent of 2 first strikes, which leads to a difference of 4 first strikes.


                    Basic formula

                    modifiers
                    Both attacker and defender get a bonus from promotions (e.g. Combat 1 = +10% strength) and situations (e.g. forest gives +50% defense for some defenders). These add up to the base value of a unit, which is a units wounded strength. Once this wounded strength value gets all modifiers, it becomes the modified strength. We'll call that number A for the attacker, and D for the defender. The moment modifiers are taken into account, there is no difference anymore between an attacker and defender though, it's all contained into the modified strength.

                    for the attacker:
                    Modifed_strength A = wounded_base_value * (sum_of_modifiers)

                    Thus, an archer with initially strength 3, but which was wounded and only has 2.5 left, with Combat 1 (+10%), and in a forest (+50%) gets a strength
                    D=2.5*(+10%+50%)=2.5*1.6=4


                    rounds
                    Chance of succeeding in each round is a pure die roll. This means that for the attacker, his chance of winning a round is A/(A+D). For the defender it is the dual D/(A+D).

                    Each round inflicts a fixed amount of damage. This damage is subtracted from the hitpoints, where hitpoints start at 100. The damage is dependent on the strengths of the units (see below). If the archer is attacked by a horse archer of strength A=6 (no modifiers as it is unpromoted), the damage done will be 16 hp. After losing that round, the strength of the archer will be 100 - 16 = 84.

                    damage in one round
                    The damage done in one round is always relative to 20 hitpoints. But there is one more factor, to 'increase the gap', that is, it will make stronger units hit even more damage on weaker ones.

                    For the attacker, the damage is 20 * (3 * A + D) / (3 * D + A)
                    For the defender, the damage is 20 * (3 * D + A) / (3 * A + D)


                    The result is rounded to integer results. So, for the archer A, he will inflict 20 * 9 / 11 = 16 hp of damage. The horse archer D will inflict 20 * 11 / 9 = 24 hp of damage.


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


                    number of possible hits
                    As each hit does a fixed amount of damage, it means that a unit can receive a fixed number of hits before dieing. This number is only dependent on the initial strengths of the units.

                    In a battle between a archer of D=4 and a horse archer of A = 6, each hit to the archer will amount to 24 hp as calculated above. Thus, an archer will die at the 5th hit. After 4 hits, it would have 100 - (4 * 24) = 4 hitpoints left, the 5th hit is fatal. (it would diminish hitpoints to 4 - 24 = -20)

                    Similarly, the horse archer dies after 7 hits, as the 6th hit would leave 100 - (6 * 16) = 6. The 7th hit would mean hitpoints equal to -10.

                    needed_hits_to_die = round_up(100/damage_done_in_round)
                    Where round_up() is a function that rounds a fraction to the next integer.

                    So, again for that archer:

                    hitpoints=4
                    damage_done_in_round = 24
                    needed_hits_to_die = round_up(100/24) = round_up(4.17) = 5

                    Note that this number is fixed, it is independent from the chance of actually getting hit. Once the archer is hit 5 times it is dead, no matter if the horse is hit once, or 6 times in the mean time.


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



                    basic chance of success
                    We now have everything together for the basic formula. We've got the chance of getting hit, and we've got the number of hits before someone dies. Also, we've got a fixed time frame: in order to win, the archer has to hit the horse archer 7 times, before getting hit 5 times himself.

                    This means, that the chance of success for the archer is the chance it wins at least 7 rounds out of 11 rounds of battle. The chance of winning one round is D/(A+D) for the defending archer. It doesn't matter in which order the rounds are won, it also doesn't matter whether the archer by sheer streak of luck would have won 11 rounds instead of only the first 8.


                    This is a Bernouilli process, where each event X0..Xn is equal to a round of battle. Each event has a chance p, where p=D/(A+D) for the defender. The chance of getting exactly k=7 hits out of n=11 rounds follows the binomial distribution, where f(k;n,p)=C(n,k)*(p^k)*((1-p)^(n-k))
                    C(n,k) is the binomial coefficient, which is (n!)/(k!*(n-k)!)



                    In the example of the archer hitting exactly 7 times out of 11, the chance is:
                    k = 7
                    n = 11
                    chance of success for one round = p=D/(A+D)= 4/(4+6)=0.4
                    C(11,7) = 330
                    f(7;11,0.4) = C(11,7)*(0.4^7)*((1-0.4)^(11-7)) = 0.0701

                    The chance of the archer hitting exactly 7 times is 7%


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


                    The easiest way to calculate the total chance of at least 7 wins out of 11 rounds is to add the chances together of 7, 8, 9, 10, and 11 wins. There is a complicated formula which does this automatically, but in a program it is easier with a simple for loop... Chance_of_destroying the horse archer = chance of hitting 7, 8, 9, 10, or 11 times.


                    So, the chance of success is
                    basic_chance_of_success = Sum_(for j = k to n)_of_( f(j;n,p) )
                    where
                    k = needed_hits_opponent
                    n = (needed_hits_opponent + needed_hits_yourself -1)
                    p = chance of winning 1 round (=D/(A+D) for the defender)
                    f(k;n,p)=C(n,k)*(p^k)*((1-p)^(n-k)) )
                    C(n,k) is the binomial coefficient, C(n,k)=(n!)/(k!*(n-k)!)



                    For the archer, this means that his chance of winning the battle is
                    chance_of_success = f(7;11,0.4)+f(8;11,0.4)+f(9;11,0.4)+f(10;11,0.4)+f (11;11,0.4) = 0.0701 + 0.02336 + 0.00519 + 0.000692 + 0.0000419 = 0.09935.
                    The archer has a 9.9% chance of destroying the horse archer.


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


                    hitpoints after battle
                    If the archer would have won, he would roughly have 70% chance of being hit 4 times, 23% chance of being hit 3 times, 5% chance of being hit 2 times. (forget the rest, you catch the drift) This works out to .7 * (100 - 4 * 24) + .23 * (100 - 3 * 24) + .05 * (100 - 2 * 24) + ... = 2.8 + 6.4 + 2.4 + .. = 11.64 hp. Which means, given his initial strength of 2.5, he would on average have 0.3 strength left. That is, assuming he has won, in 90% of the cases he would have lost...



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



                    first strikes
                    If an archer has a first strikes promotion, getting to 2 first strikes, it means that the order in which attacks happen does start to matter. If he loses the first 2 strikes, he doesn't lose hitpoints. If he wins one of this 2 first strikes, the damage to the horse archer is done just the same like normally. (okay, I know the horse archer ignores first strikes, so assume a swordsman, it also has strength 6)

                    If there would be two units with first strikes, the difference counts. E.g. a archer with 2 first strikes, against a longbow with 1, would get 1 first strike. The longbow gets none.

                    It is tempting to simply up the number_of _needed_hits_to_die for the horse archer in the example used, but that's not exactly correct.
                    Suppose the sword hits the first 2 rounds. The results are ignored, thus the sword needs to hit the archer 9 times, not 7. The n used above would increase from 11 to 13, virtually.

                    Suppose on the other hand that the archer hits the first 2 rounds. That means the sword needs to hit 7 times out of 9 of the following rounds. The total number of possible rounds n remains at 11.

                    The correct way of calculating it, is to calculate the chance of winning the first strike for the archer, times the chance of winning the rest of the battle. this has to be done for each combination of first_strike_wins, and added.

                    So, calculate the chance of winning none of the first strikes, times winning 8 out of 11 rounds after that. Add to that the chance of winning one first strike, times 7 out of 10 rounds. Add to that the chance of winning two first strikes, times 6 out of 9 rounds following it.

                    The chance of winning first strikes follows again a binomial distribution. (call it f_fs, to distinguish between first strikes and the 'normal' part of the formula.

                    complete formula

                    total_chance_of_success =
                    Sum_(for i = 0 to fs)_of_
                    ( f(i;fs,p)*
                    Sum_(for j = (k-i) to (n-i))_of_
                    ( f(j;(n-i),p)
                    )
                    )

                    where
                    k = needed_hits_opponent
                    n = (needed_hits_opponent + needed_hits_yourself -1)
                    p = chance of winning 1 round (=D/(A+D) for the defender)
                    fs = total number of first strikes for the unit
                    f(k;n,p)=C(n,k)*(p^k)*((1-p)^(n-k)) )
                    C(n,k) is the binomial coefficient, C(n,k)=(n!)/(k!*(n-k)!)


                    I know it seems complicated, but this formula is nicely divided into parts, which each in itself are reasonably simple. It's just that combining everything together makes it look like a mess.

                    Example
                    As an example, consider the archer of above, with 2.5 strength and 2 first strikes. It battles a sword of strength 6 (as a horse archer would ignore first strikes)

                    Chance for the archer to hit 0 first strikes = 0.36
                    Chance for the archer to hit at least 7 out of 11 rounds following the first strikes = 0.0707

                    Chance for the archer to hit 1 first strikes = 0.48
                    Chance for the archer to hit at least 6 out of 10 rounds following the first strikes = 0.114 + 0.067 + 0.013 + ... = 0.194

                    Chance for the archer to hit 2 first strikes = 0.16
                    Chance for the archer to hit at least 5 out of 9 rounds following the first strikes = 0.167 + 0.124 + 0.077 + 0.037 + ... = 0.404

                    Total chance of success is
                    0.36*0.0707 + 0.48*0.194 + 0.16*0.404 = 0.183


                    The archer has 18.3% chance of winning.


                    Retreat
                    Retreat is calculated in the last round for the attacker (defenders can't retreat). The round is fought like normal, but in case the attacker would have died, it's retreat chance is taken into account and possibly it can escape. If you somehow would have units with 100% retreat chance, they will never die on the offensive.

                    Retreat does not happen during first strikes, as long as the defender has first strikes left the attacker can never escape.


                    Suppose that the horse archer above has a 30% of retreating. If by coincidence the archer would hit the horse archer 7 times during the fight, the horse archer is one hit from dieing.
                    Next round starts. The odds are calculated, and the horse archer would die. At that moment, a random number is generated and weigthed against the 30% retreat chance... if it is higher the round continues like normal, and the horse archer dies. If it is lower, the round and the battle stops, and the horse archer retreats heavily wounded.

                    This has no effect on the chance of success for the attacker: it still has the same chance of destroying the defender. The defender's chance of destroying the attacker is however multiplied with (1-retreat_chance). Retreat happens in retreat_chance*chance_of_success_defender percentage of cases.


                    interpretation
                    While the archer is only 2/3 the strength of the horse archer, it only wins in 9.9% of the cases... that is a large difference, much larger than expected. And the archer is very lucky as due to roundings, he can survive 5 rounds. If the damage against him would have been 25 instead of 24 now, he would die after 4 rounds, meaning less than 2% chance.

                    More later. And you can virtually add some of the combats on first strikes in here as well

                    Sorry if any typos would have crept in, this was all done by hand

                    DeepO

                    [edit: added: how do first strikes get calculated]
                    Last edited by DeepO; November 1, 2005, 07:27.

                    Comment


                    • #25

                      Wow that is some explanation, bits you average stat text book.
                      Great work thanks.

                      Comment


                      • #26
                        Originally posted by Strollen
                        In some review I thought I read there was a way of see the probability of success for a given attack. Is this true? and if so where in the heck do you find it? I have searched in vain to find it in game.
                        ALT-mouseover the tile you want to attack (it will give you the odds of beating the best defender).
                        And her eyes have all the seeming of a demon's that is dreaming...

                        Comment


                        • #27
                          It's in? Wow! In case anyone would mind, I'd be interested if the numbers above are (about) correct... I'd check them myself, but that will have to wait until I get the game

                          DeepO

                          Comment


                          • #28
                            Deepo thanks a lot. If I had more than 4 hours of sleep I would even be able to follow the equations. But for my purposes knowing that a 50% strength advantage means a 90%+ chance of defeating an opponent. Is very helpfu.

                            My biggest complaint right now with Civ 4, is it is very difficult to get any kind of intuitive feel for how likely your are to succeed in an attack. I can do the math in my head for my units (swordsman with city raider II = 6* 1+(.2+.25+.1) = 9.3 ) but it is really hard for my opponents. I mean there are a zillion different icons for promotions + inherent unit advantages. How the heck do I know who is going to defend a city with an archer, spearman, and axeman all with a couple of promotions.

                            Just saw Domanie post Alt -T thank you I am going to try that now.

                            Comment


                            • #29
                              Strollen, without taking into account the rounding, you can have a simple table to see the numbers. Be aware that difference rapidly increases: a unit which is 2/3 of another one might have 10% of succeeding, units which are only half will have a rougher time (my guess is only 2% or even below that).

                              Also, Re: the intuitive feeling: Don't obsess with the numbers. Horses are good against archers, melee is good against horses, and archers are good against melee. That will get you far!

                              With promotions, it makes a lot of sense to specialize your units in different roles. Have static defenders, mobile defenders, pillagers, city raiders, scouts, and attackers and try to figure out what would work. It's one of the most fun parts of the game... and certainly not something which can be poured into numbers easily. What would be the effect of a medic vs a combat II promotion, for instance...

                              DeepO

                              Comment


                              • #30
                                I must be slow. What is the point of unit differentiation?

                                I have an army of many units and so does my opponent. Each army chooses(?) 1 unit which then fight. After one has lost the next one steps up.

                                How is this combined arms? How can an archer support an infrantryman?

                                Unless I am very wrong this is sounding sillier and sillier by the moment.

                                Comment

                                Working...
                                X