Announcement

Collapse
No announcement yet.

Civ 3 combat calculations - with retreat odds...

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

  • Civ 3 combat calculations - with retreat odds...

    Just for the heck of it, I've written a C program to calculate the odds of combat outcomes in Civ 3, including the effects of retreat for fast units. Hopefully, the program will be an attachment to this post... Compile with any C compiler, linking with the math library (if you have the gnu C compiler then the command is 'gcc comcal.c -lm -o comcal' to produce an exectuable called comcal). Unit statistics can either be edited in the program or specified on the command line. Read the comments at the start of the program for some explanations. 'comcal -h' prints out brief help information.

    To specify unit stats on the command line, use the following options:

    -a, to specify the stats for unit A (if one of the units is capable of retreat then this must be unit A). two number are given after -a. The first is the relevant combat strength (attack or terrain modified defence), the second is the number of hitpoint the unit has. So a healthy veteran cavalry on the attack would be specified by '-a 6.0 4', while the same cavalry being attacked whilst on plains (10% terrain defence bonus) would be '-a 3.3 4' (cavalry 6 attack, 3 base defence).

    -b, to specify the stats for unit B. Unit B never retreats, but it doesn't matter if you make the attacker unit A or B. Stats are given in the same way as for A.

    retreat probabilities are given in either of two ways:

    -e followed by a single integer value from 0 to 4 incusive. '-e 0' means no retreat is possible (2 slow units, 2 fast units, fast unit fortified in town etc.). Values 1 to 4 indicate the experience level of the unit (1 = conscipt, 4 = elite). THIS ONLY AFFECT RETREAT CHANCES, NOT HIT POINTS.

    or -

    -r followed by a number between 0.0 and 1.0. This is the retreat probability. Since (for example) elite units have a 0.66 probability of succesful retreat, '-e 4' and '-r 0.66' are completely equivalent.

    So, as an example, an elite cavalry (6 attack) attackes a regular infantry (10 base defense) on open ground (10% defense bonus), with both units initially on max hit points. The command specification would be:

    comcal -a 6.0 5 -b 11.0 3 -e 4
    or
    comcal -a 6.0 5 -b 11.0 3 -r 0.66
    and the output is:
    =====================

    A:
    hp: 5 combat strenth: 6.00
    retreat chance: 0.66
    B:
    hp: 3 combat strenth: 11.00

    Hit points remaining:
    A \ B 0 1 2 3
    0 - 16.5 6.8 3.9
    1 9.0 - 16.3 11.6
    2 11.9 - - -
    3 11.0 - - -
    4 8.5 - - -
    5 4.4 - - -

    A wins: 44.9 %
    A retreats: 27.9 %
    B wins: 27.2 %

    =====================

    The first bit summarises the stats you put in. The table in the middle gives the percentage chance of each possible outcome in terms of hit points remaining for each unit (useful for working out the probability that you do at least 1hp damage to a defender, so you can estimate how many attackers you need to bring to the party), and then there is the summary at the end. I hope the output is pretty self explanatory.

    IIRC when attacking a unit with only 1 hp left, fast units NEVER retreat. I've assumed this in the calculation, so if it's wrong, please let me know.

    As mentioned in the source code file, I'm not actually sure whether a retreat-capable unit gets more than one chance to run away (in the example above, suppose the cavalry loses the first 4 rounds of combat (so the cavalry has 1 hp left, the infantry 3 hp). The cavalry at this point tries to retreat. If this fails, and the cavalry wins the next round of combat (now on 1 hp, with the infantry on 2 hp) does it get a second chance to retreat? I've assumed not, mostly because it is easier to calculate. It doesn't make much difference in the cases where I've calculated both. If anyone has any Firaxian quotes on this subject I'll be glad to hear a definitive answer.

    (NOTE: I'm not allowed to have a file ending with a .c extension, so I've given it a .txt one. Rename to comcal.c once you've downloaded it)

    EDIT: proportional spacing has mangled the table output. It's designed for fixed width characters.
    Attached Files

  • #2
    new version

    Attatched is a newer version of the combat calculator. It now also gives information relevant to attacking cities. An example to illustrate: Consider the annoying example of a veteran cavalry unit attacking a fortified infantry in a size 7-12 city on a plain. Attack strength is 6, defense strength for the infantry is 6 * 1.1 * 1.1 * 1.5 = 18.15 (10% from being on plains, 10% from being fortified, 50% from being in a city, IIRC. I believe the factors combine together as I've done above, rather than adding together to give a 70% increase). So we type:

    comcal -a 6.0 5 -b 18.15 4 -r 0.66

    which gives:


    A:
    hp: 5 combat strenth: 6.00
    retreat chance: 0.66
    B:
    hp: 4 combat strenth: 18.15

    Hit points remaining:
    A \ B 0 1 2 3 4
    0 - 9.2 7.5 10.1 8.2
    1 3.1 - 13.0 20.9 21.1
    2 3.2 - - - -
    3 2.2 - - - -
    4 1.1 - - - -
    5 0.4 - - - -

    A wins: 10.0 %
    A retreats: 55.0 %
    B wins: 35.1 %

    Victory chance for n of unit A vs 1 unit B:
    (with expected no. of A units killed)
    n prob losses
    1: 10.0 % (0.35)
    2: 33.5 % (0.67)
    3: 59.3 % (0.90)
    4: 78.2 % (1.04)
    5: 89.4 % (1.12)
    6: 95.2 % (1.16)

    Victory chance for n of unit B vs 1 unit A:
    (with expected no. of B units killed)
    n prob losses
    1: 35.1 % (0.10)
    2: 99.3 % (0.16)


    ====================

    Look at the 'Victory chance for n of unit A vs 1 unit B:' section. This shows that, for example, with 4 veteran cavalry attacking, you have a 60.9% chance of taking down a single infantry, and on average will lose 1.16 of your cavalry in the process. If you want to be 90% certain of taking the city, you need about 7 attackers per defending infantry (this all ignores unit promotions for the defender, which gives it extra hit points).

    For a comparison of the benefits of retreat, compare that with a stack of elite infantry attacking the same fortified infantry in a city. The stats are the same, apart from the lack of retreat ability. (comcal -a 6.0 5 -b 18.15 4 -r 0.0).

    cavalry infantry
    n prob losses n prob losses
    1: 10.0 % (0.35) 1: 11.2 % (0.89)
    2: 33.5 % (0.67) 2: 41.1 % (1.68)
    3: 59.3 % (0.90) 3: 68.9 % (2.20)
    4: 78.2 % (1.04) 4: 85.9 % (2.48)
    5: 89.4 % (1.12) 5: 94.3 % (2.60)
    6: 95.2 % (1.16) 6: 97.8 % (2.65)

    You actually need a slightly lower number of infantry,
    but (no surprises) more of them get killed.
    Attached Files

    Comment

    Working...
    X