Announcement

Collapse
No announcement yet.

The Civ IV Combat System

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

  • #46
    Originally posted by DeepO
    2. calculate the chance of A winning the battle with exactly R hits (where R obviously is below max_A). e.g. exactly hit twice (so not once or three times). This is done, by adding up all combinations e.g. hit twice means 7 out of 9 plus 8 out of 10 plus...
    IMHO that total probability will be far more than 1.
    Also, if our unit needs 7 hits to kill a target, then there can't be 8 out of 10.
    Knowledge is Power

    Comment


    • #47
      Originally posted by Ellestar

      IMHO that total probability will be far more than 1.
      No, I calculated it above. It adds up to 1 quite nicely.

      Also, if our unit needs 7 hits to kill a target, then there can't be 8 out of 10.

      Sorry to not have been clear, or even using not the best example. But it's two different rounds that are playing here: on one hand you need e.g. 4 hits for the attacker to kill the defender. On the other, the attacker can sustain 6 hits. So, you can have results where the attacker stays standing with 0,1,2,3,4 or 5 hits lost. Which means you can have 4 out of the first 4, 4 out of 5, etc.

      Hmmm... I see what you mean. 4 out of 4 is part of 4 out of 5... I must think on that, as I was sure that at the time of making the formula, I took it into account. Maybe I need to do the derivation again...

      DeepO

      Comment


      • #48
        Okay, I've read through this thread... And I haven't seen an answer to this question here. Maybe I missed it, but I don't think so.

        Does anyone know what the chance of a First Strike occurring in a combat is if a unit has ONLY the Drill 1 promotion? (That is, the unit has a "chance" of a first strike... What is that chance?)

        Comment


        • #49
          Originally posted by Simplicity
          Okay, I've read through this thread... And I haven't seen an answer to this question here. Maybe I missed it, but I don't think so.

          Does anyone know what the chance of a First Strike occurring in a combat is if a unit has ONLY the Drill 1 promotion? (That is, the unit has a "chance" of a first strike... What is that chance?)
          AFAIK, it's the same as one round of battle. Drill 1 means 1 fs, so the first battle round will never be negative for the attacker. Either he wins it and delivers a blow (exactly the same as in the other cases), or he loses it and nobody is hurt.

          For an attacker with strength A, the chance of hitting 1 fs is thus A/(A+D)

          DeepO

          Comment


          • #50
            Originally posted by DeepO
            Also, if our unit needs 7 hits to kill a target, then there can't be 8 out of 10.

            Sorry to not have been clear, or even using not the best example. But it's two different rounds that are playing here: on one hand you need e.g. 4 hits for the attacker to kill the defender. On the other, the attacker can sustain 6 hits. So, you can have results where the attacker stays standing with 0,1,2,3,4 or 5 hits lost. Which means you can have 4 out of the first 4, 4 out of 5, etc.
            As i understand, 4 out of 4 means that you kill with 4 hits while sustaining 0 hits, and that is a probability that you'll sustain 0 hits right?
            So, if you sustain 1 hit it will be 4 out of 5 but it can't be 5 out of 6 like in your post above (or maybe i don't understand it?)

            Originally posted by DeepO Hmmm... I see what you mean. 4 out of 4 is part of 4 out of 5... I must think on that, as I was sure that at the time of making the formula, I took it into account. Maybe I need to do the derivation again...

            DeepO
            Yes, and so total probability will be more than 1.

            ************

            By the way, in our case last hit is always a killing hit. IMHO it should be counted separately. Chance to be hit with X attacks when attacker shoud hit with A strikes and defender should hit with D strikes, attacker wins a round with probability P
            ChanceToBeHitWithX(X,A)=C(A-1+X,X)*((1-P)^X)*(P^(A-1))*P
            or
            ChanceToBeHitWithX(X,A)=C(A-1+X,X)*((1-P)^X)*(P^A)

            Edit: C(A-1+X) should be C(A-1+X,X)

            That way, sum of ChanceToBeHitWithX when X=0..(D-1) is equal to a chance that this unit will win, as it should be.

            Edit2: X=0..(B-1) should be X=0..(D-1)
            Last edited by Ellestar; October 31, 2005, 17:17.
            Knowledge is Power

            Comment


            • #51
              Originally posted by Ellestar

              As i understand, 4 out of 4 means that you kill with 4 hits while sustaining 0 hits, and that is a probability that you'll sustain 0 hits right?
              So, if you sustain 1 hit it will be 4 out of 5 but it can't be 5 out of 6 like in your post above (or maybe i don't understand it?)
              That was more or less the idea, yes. 4 out of 5 means that the first 4 rounds, only 3 hits were taken. 4 out of 6 means that in the first 4 rounds, not 4 hits were taken and in the first 5 rounds you have 3 hits.

              5 out of 6 can happen to, though, but it will fall under the 4 out of 5 chance.

              Yes, and so total probability will be more than 1.

              I've got to see that in detail, I thought I took it into account (so the 4 out of 4 does not fall within the 4 out of 5 chance I'm using above). I'm not sure, though.

              At any rate, this only applies to the average strength left over after a battle, but that is important when quantifying fs as opposed to other promotions. I mean, it's obvious from how combat works that fs means more lefotver strength (and not a vastly increased chance of success of actually winning a battle), but if you want to have exact numbers for specific situations you need a working formula.

              By the way, in our case last hit is always a killing hit. IMHO it should be counted separately. Chance to be hit with X attacks when attacker shoud hit with A strikes and defender should hit with D strikes, attacker wins a round with probability P
              ChanceToBeHitWithX(X,A)=C(A-1+X)*((1-P)^X)*(P^(A-1))*P
              or
              ChanceToBeHitWithX(X,A)=C(A-1+X)*((1-P)^X)*(P^A)

              That way, sum of ChanceToBeHitWithX when X=0..(B-1) is equal to a chance that this unit will win, as it should be.
              Euh, can you write out the formula of C(A-1+X), please? I think it is included in my formula, you might be splitting out cases that can be combined again. The A-1+X factor does show up in my formulae as well, so perhaps we're talking about the same thing here.

              DeepO

              Comment


              • #52
                Originally posted by DeepO
                Euh, can you write out the formula of C(A-1+X), please? I think it is included in my formula, you might be splitting out cases that can be combined again. The A-1+X factor does show up in my formulae as well, so perhaps we're talking about the same thing here.

                DeepO
                Ops it should be C(A-1+X,X)
                C(n,k) is the binomial coefficient, C(n,k)=(n!)/(k!*(n-k)!) from your post
                Knowledge is Power

                Comment


                • #53
                  Originally posted by DeepO


                  AFAIK, it's the same as one round of battle. Drill 1 means 1 fs, so the first battle round will never be negative for the attacker. Either he wins it and delivers a blow (exactly the same as in the other cases), or he loses it and nobody is hurt.

                  For an attacker with strength A, the chance of hitting 1 fs is thus A/(A+D)

                  DeepO
                  That wasn't the impression I was getting from the label of Drill I... I was under the impression that there was some probability that was checked *before* you even do a before battle strike.

                  Drill I says there's a "chance of getting a first strike" (IIRC). Drill II says there's "+1 first strike."

                  If Drill I were just a normal first strike... Why wouldn't it say: "+1 first strike" for both of them?

                  Comment


                  • #54
                    Originally posted by Ellestar

                    Ops it should be C(A-1+X,X)
                    C(n,k) is the binomial coefficient, C(n,k)=(n!)/(k!*(n-k)!) from your post
                    Isn't this what I was saying? My factor n is comparable to your factor A-1+X if I'm reading it right. Only, you use A in a different context than I do, which might lead to some confusion.

                    DeepO

                    Comment


                    • #55
                      Originally posted by Simplicity


                      That wasn't the impression I was getting from the label of Drill I... I was under the impression that there was some probability that was checked *before* you even do a before battle strike.

                      Drill I says there's a "chance of getting a first strike" (IIRC). Drill II says there's "+1 first strike."

                      If Drill I were just a normal first strike... Why wouldn't it say: "+1 first strike" for both of them?
                      I can tell you what I'm certain of, and what I don't know. That might help...

                      1. I'm certain that somehow, the number of first strikes is calculated for a unit. This at least includes the difference in fs between the 2 units: if one has 3 and the other 1, I'm sure the one gets 2fs, the other none.

                      2. I'm also certain that once you get that number, it is calculated as a battle round you can't lose, as described above.

                      3. What I'm not sure about, is how the display translates into the actual number of fs a unit is legible to get. I always assumed that the higher number on the display is the actual number of fs. So, Drill II saying 1-2 fs means in reality 2 fs, period. I've seen reports as well that there might be a separate chance algorithm, so that '1-2' actually means at least 1, maybe 2 fs, but I don't see the point in doing it like that: why would you stack probabilities like that?

                      4. What I'm also not sure about, but does make sense, is why you would display '1-2' for Drill II while it always is 2. There always has been a lot of confusion about fs, in that people thought that those fs were always hits without failure. It's easier to indicate '1-2', as that gives an idea that you are probably going to hit once, but it also could be twice. The display suggests a chance is at work there.

                      But those last 2 points are entirely speculation.

                      DeepO

                      Comment


                      • #56
                        I'm not sure where the "1-2 fs" label is being seen...
                        But one question I would have then is: Does a non-first strike unit with only Drill I say "1 fs" or "0-1 fs"?

                        Does an archer unit say "0-1 fs" or "1 fs"?

                        If there's a difference between a unit with only Drill I and no first strikes and a unit with only an inherent first strike, the question is answered.

                        "1-2 fs" makes it sound like Drill I does only give a chance of getting an additional fs.

                        Comment


                        • #57
                          Originally posted by DeepO

                          Isn't this what I was saying? My factor n is comparable to your factor A-1+X if I'm reading it right. Only, you use A in a different context than I do, which might lead to some confusion.

                          DeepO
                          Hmm. May you give a link to your post? It's hard to guess what exact formula you have in mind. Anyway, n is constant in your formulas IIRC (we're not counting first strike here), but A-1+X isn't constant.

                          ****

                          CIV4PromotionInfos.xml

                          PHP Code:
                          Drill 1
                          <iFirstStrikesChange>0</iFirstStrikesChange>
                          <
                          iChanceFirstStrikesChange>1</iChanceFirstStrikesChange>

                          Drill 2
                          <iFirstStrikesChange>1</iFirstStrikesChange>
                          <
                          iChanceFirstStrikesChange>0</iChanceFirstStrikesChange
                          It seems that it's not just a difference in a civilopedia. There are two kinds of first strikes here and two different variables for it in the game code.
                          Last edited by Ellestar; November 2, 2005, 02:06.
                          Knowledge is Power

                          Comment


                          • #58
                            Originally posted by Ellestar

                            Hmm. May you give a link to your post? It's hard to guess what exact formula you have in mind. Anyway, n is constant in your formulas IIRC (we're not counting first strike here), but A-1+X isn't constant.
                            It could be I made a mistake in that... here's the part I mean:

                            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.


                            I thought this was correct, though. You see, I don't take into account in which order the hits fall, I only keep in mind that no 5 hits out of 11 should go wrong. Which means at least 7 hits. Which leads to the formula above.

                            Is there something wrong with that?


                            CIV4PromotionInfos.xml

                            Drill 1
                            0
                            1

                            Drill 2
                            1
                            0

                            It seems that it's not just a difference in a civilopedia. There are two kinds of first strikes here and two different variables for it in the game code.

                            I agree, it looks like that. I don't know the mechanism to that, though... I'll see if I can find it somewhere.

                            DeepO

                            Comment


                            • #59
                              Originally posted by DeepO
                              I thought this was correct, though. You see, I don't take into account in which order the hits fall, I only keep in mind that no 5 hits out of 11 should go wrong. Which means at least 7 hits. Which leads to the formula above.

                              Is there something wrong with that?
                              Once again, it's correct if you want to know chance to win, but you shouldn't use it to calculate average damage recieved by a survived unit.
                              Knowledge is Power

                              Comment


                              • #60
                                I've been lurking around here for a bit and been paying attention to this thread because the math behind these things really interests me.

                                I think DeepO has a really good system but it seems to have a couple flaws... Using DeepO's system, if a unit has enough first strikes, the probability that it will win will increase beyond 100%. Not only is that impossible, but no unit is ever 100% guarnateed to win. I'd like to share my own similar method that takes this into account.

                                So we know the basic formulas already for determining chance to win the round and damage done for each attacker.

                                Note that for this entire system, we always assume that the attacker is the one that has first strikes, regardless of whether or not it is doing the attacking.

                                strA is the attacker's modified strength, and strD is the defender's modified strength.

                                winChance = strA / ( strA + strD );
                                dmgA = ( 3 * strA + strD ) / ( 15 * strD + 5 * strA )
                                dmgD is the same thing except swap the strA and strD in those equations.

                                (always round these numbers up)
                                hitsToWin = 1 / dmgA
                                hitsToLose = 1 / dmgD

                                These tell you the hits required to win and lose the combat. I'm not sure if these will give perfectly accurate numbers. If the in-game system actually determines an integer hitpoint damage level and subtracts it from a pool of HP in each round, the hits required to win can be slightly different in some cases. It can be adjusted to reflect that possible issue if needed, however we will assume this is right for now.

                                So, we know that the attacker has to land hitsToWin hits before the defender lands hitsToWin hits. Lets just use an example with two units of exactly the same strength. That means the attacker would have to land 5 hits before the defender lands 5 hits. So at most, the defender can land 4 hits (and as little as 0), and the attacker is going to land 5.

                                So first we need to know the probability that the attacker will simply land 5 hits in a row. That's simple, it's winChance ^ 5. There's only one way to do this so use this value to initialize our result probability.

                                Next we need to determine the probability that the attacker will land 5 hits and the defender will land 1. The probability is simple, it's ( winChance ^ 5 ) * ( ( 1 - winChance ) ^ 1 ). 1 - winChance is basically the chance for the defender to win. Raising it to the power of 1 here is obviously meaningless but you see now that a pattern will emerge. You simply raise the chance to a power equal to the number of hits needed to win, then multiply the chance to lose by the number of losing hits we are working with (in this case 1).

                                However we are not done with this one yet, we need to figure out how many different ways that we can land 5 hits and sustain 1. Obviously the 5th hit will always be the last one, so we can actually ignore that one. That means we have 5 wins + 1 loss - the last win we ignore, leaving us with the number 5. So we do C( 5, 1 ) where C is the binomial coefficient explained in previous posts. The 5 is that sum we came up with, and the 1 is the number of losses we incur. This gives us the result of 5. We multiply that by the probability we came up with above, then add this result to our overall win probability.

                                We then do the same for 5 hits and 2 misses. So we have C( 5 + 2 - 1, 2 ) * ( winChance ^ 5 ) * ( ( 1 - winChance ) ^ 2 ) and we add this to our total probability. We do the same again for 3 and 4 misses.

                                This basically boils down to:

                                Sum ( n = 0 to hitsToLose - 1 ) begin
                                C( hitsToWin + n - 1, n ) * ( winChance ^ hitsToWin ) * ( ( 1 - winChance ) ^ n )
                                end

                                This doesn't take first strikes into account.

                                We can treat first strikes like a whole seperate combat really... First we need to consider the chance that we fail all our first strikes, which means we need to do the full number of hits to win during normal combat. Then we consider the probability of winning one first strike which means we need one less hit to win during normal combat, then up to winning 2 first strikes etc up until we reach the max first strikes.

                                However there is a stipulation and this is where DeepO's formula breaks. What if we have enough first strikes so that we could defeat the opponent entirely with first strikes? For example, in our equal strength match-up, what if the attacking unit had 5 first strikes? He could defeat the other unit without ever going into normal combat (of course he may not too). What if the unit has more first strikes than it would need hits to win (say 7 in this example)? We can't consider situations where it wins 7 first strikes because it can't, the battle would be over by the time it wins 5 of them.

                                Also, we need to consider the situations in which it wins enough first strikes to win the whole battle differently than situations in which it does not do this, since we'll never see regular combat.

                                At this point it becomes kind of hard to represent the situation with pseudocode as it becomes pretty confusing. I will try however using some psuedocode adapted from the Java code I wrote to test this out.

                                Code:
                                for ( int s = 0; s <= ( firstStrikes > hitsToWin ? hitsToWin : firstStrikes ); s++ ) {
                                	if ( s == hitsToWin ) {
                                		for ( int n = 0; n <= firstStrikes - hitsToWin; n++ )
                                			result += C( hitsToWin + n - 1, n ) * ( winChance ^ hitsToWin ) *
                                								( ( 1 - winChance ) ^ n );
                                	}
                                	else {
                                		subSum = 0.0;
                                		for ( int n = 0; n < hitsToLose; n++ )
                                			subSum += C( hitsToWin + n - 1 - s, n ) * ( winChance ^ ( hitsToWin - s ) ) *
                                									( ( 1 - winChance ) ^ n );
                                		result += subSum * C( firstStrikes, firstStrikes - s ) * ( winChance ^ s ) *
                                						( ( 1 - winChance) ^ ( firstStrikes - s ) );
                                	}
                                }
                                The first line is basically going to iterate through all the possible first strike victory counts, from 0 up to a max that is the smaller of the total first strikes and the hits required to win (remember we can't win more first strikes than we need to win the whole battle).

                                The next line is checking to see if we're dealing with the situation where we're going to win entirely with first strikes. If we are, then the next line basically adds the probability of this happening. We basically treat this like normal combat. We have a minimum number of rounds which is hits to win, and a max which is the number of total first strikes.

                                If we're not going to finish the whole battle with first strikes, then we need to figure out how likely we are to win if we do win s first strikes. Since we've won that many first strikes, that's that many fewer wins we need during regular combat. We figure out how likely we are to win regular combat after winning that many first strikes, multiply by the chance of winning that many first strikes, and add it to our probability total.

                                The current thing I would like to know is how the game determines the first strikes a unit gets when it has a range. Many units are listed as having "1-2 first strikes" or such. Drill I gives you 1 first strike chance, where Drill II gives you 1 first strike. If you have Drill II then you have 1 guaranteed first strike and 1 first strike chance, which reads as 1-2 first strikes. How do you know how many first strikes the unit gets?
                                -Arkalius

                                Comment

                                Working...
                                X