1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. Photobucket has changed its policy concerning hotlinking images and now requires an account with a $399.00 annual fee to allow hotlink. More information is available at: this link.
    Dismiss Notice
  3. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  4. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  5. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  6. Dismiss Notice
  7. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Hans Lemurson figures out the Combat Formula

Discussion in 'Civ6 - Strategy & Tips' started by Hans Lemurson, Nov 25, 2016.

  1. Hans Lemurson

    Hans Lemurson Chieftain

    Joined:
    Jan 2, 2006
    Messages:
    467
    Location:
    Silicon Valley
    So, I've been searching a while to see if anybody had figured out the Civ6 combat formula and, finding nothing, I took it upon myself to have fun with spreadsheets so you don't have to.

    I have long suspected that the damage formula was Exponential in nature, given that the relative Power of units is based on their difference in strength rather than the ratio. But to actually test this I needed to gather a LOT of combat data from various unit-strength pairings in order get a large enough data set to yield believable answers. I would need to record the data from each and every combat in my game, minimizing after every battle so I could enter the data in a spreadsheet before I forgot what the message said. And do that 100 times. BOOORING!!!!.

    Say hello to my little friend here: Documents/My Games/Sid Meier's Civilization VI/Logs/CombatLog.csv

    And with that, I was off to the races.
    A little bit of spreadsheet manipulation and...

    Yep, looks exponential to me.

    Also noteworthy is the fairly large variance, but also that it appears to be directly proportional to the amount of damage dealt, flaring out like a trumpet as the damage increases. This suggests that there is a simple random multiplier to the final damage. Judging by eyeball, the upper limit seems to be 125% and the lower limit 75%.

    I tried to use clean and easy to understand numbers, and I arrived at this approximate formula for what each unit does to each other in combat:

    Damage = 30 * e^(StrengthDifference / 25) * Random(0.75, 1.25)

    The base damage is 30, doubles every ~17 strength, and then gets a +/-(0-25)% damage bonus/penalty.
    The random factor is applied to each unit independently.

    I might be wrong about the magnitude of the Random Factor, and may not have gotten the exponent exactly right (and I wish I could have converted it into more intuitive numbers), but this is probably close enough to get a picture of what's going on.

    For the purposes of "rules of thumb" I will make a chart for the expected damage at various intervals.
    Code:
     +0  30  30   1.00x
     +1  31  29   1.04x
     +3  34  27   1.13x
     +5  36  25   1.22x
    +10  45  20   1.49x
    +17  59  15   1.97x
    +30  99  10   3.32x
    
    From these bonuses, we can see what we already knew: Combat strength differences are only relevant from 0-30, after that it's all 1-hit kills.
    +10 is a good solid bonus where you deal 150% damage and take only 67%.

    An easier to use formula might be: 30 * 1.041^StrengthDifference
    (since only nerds like me know that e = 2.71828)

    I have added the CombatLog.csv file that I used as my source of data.
     

    Attached Files:

    Last edited: Nov 26, 2016
  2. BomberEscort

    BomberEscort Don't be alarmed; this is a kindness

    Joined:
    Jul 28, 2003
    Messages:
    1,102
    Gender:
    Male
    Location:
    Kansas City
    Nice work. My combat log only shows religious units for some reason.
     
  3. Gtdead

    Gtdead Chieftain

    Joined:
    Oct 31, 2016
    Messages:
    51
    Thanks for this. I wanted to give a try at that myself but I didn't know how to collect enough data.
     
  4. Hans Lemurson

    Hans Lemurson Chieftain

    Joined:
    Jan 2, 2006
    Messages:
    467
    Location:
    Silicon Valley
    CombatLog.csv seems to just contain the last 128 combats that occurred (fought by anyone), so if there was a religious conflict anywhere in the world, that could certainly fill it up.
    Yeah, if I hadn't found the combat log, there's no way in heck I would have done this. It's not too hard to analyze the data on a spreadsheet, you just gotta do a little math and prune all the 100 damage combats, because those will skew your results since they are clipped off from their true value.

    If anybody wants to double-check my results to make sure I didn't make some stupid error, feel free!
    Alternately, if anybody figures out a good simple way to phrase the exponential formula that even an idiot can understand, that would also be great.

    The best I can come up with is +10 Strength = 150% damage and resistance.
     
  5. MyopicCat

    MyopicCat Chieftain

    Joined:
    Jan 6, 2014
    Messages:
    73
    Great! Would you mind uploading your version of CombatLog.csv so that I can play with your data too? I turtled for a Science victory last game and hardly fought at all.
     
  6. player1 fanatic

    player1 fanatic Fanatic

    Joined:
    Mar 19, 2002
    Messages:
    2,629
    Gender:
    Male
    Location:
    Belgrade, Serbia
    It is not coinciedence that corps add +10 and armies +17 combat strength. That translates well to +50% and +100% damage bonus.
     
  7. Hans Lemurson

    Hans Lemurson Chieftain

    Joined:
    Jan 2, 2006
    Messages:
    467
    Location:
    Silicon Valley
    Even your CombatLog file should contain a variety of combats from Apostle fights to AIs fighting barbarians. However, there's no reason not to make my data public, so I added the file to my original post.

    Yes, I'd been expecting that something strange like +17 would turn into a simple multiple.

    With an Army dealing 2x damage and receiving 1/2 damage (compared to its base unit), this means that has 4x the combat power, and so it would take 4 normal units to kill it! In a 4v1 fight the army would probably die due to flanking bonuses and the accumulated damage penalty, but it would be a close fight. It would kill 3/4 of them and could definitely win a 3v1 fight. Talk about cost effective!!!
     
  8. teks

    teks Chieftain

    Joined:
    Nov 21, 2008
    Messages:
    330
    Location:
    Florida
    Shh...
    We don't want people to figure out that war academies are OP.
    That's our secret. :goodjob:
     
  9. Hans Lemurson

    Hans Lemurson Chieftain

    Joined:
    Jan 2, 2006
    Messages:
    467
    Location:
    Silicon Valley
    Hehe.

    At a minimum, this understanding of the Combat Formula goes a long way towards justifying the massive ramp-up in cost for units as you go through the eras.
     
  10. Victoria

    Victoria Regina Supporter

    Joined:
    Apr 11, 2011
    Messages:
    5,093
    I am confused.. I do not play domination so am no expert so excuse my ignorance but hopefully you can appreciate that challenging a theory is important.

    First off the +50% and +100% are vert strong arguments.

    I am interested in the .csv as it is the empirical way to validate it. The one attached seems to have no AttackerDmg DefenderDmg data. EDIT: Oh OK the columns **** 2 to the right.

    Off to check .csv file! and if I can fight a 2 player MP and control what is in the file.
     
    Last edited: Nov 26, 2016
  11. Victoria

    Victoria Regina Supporter

    Joined:
    Apr 11, 2011
    Messages:
    5,093
    Yup I just ran through for a while and saved 3 CSV's when I have been viotent and checked for player 0 and they are all fine and within your ranges on all 3. So if your formula is not right, it seems close. Have not tried all the way to modern day though
     
  12. GKrause

    GKrause Chieftain

    Joined:
    Oct 2, 2007
    Messages:
    52
    Math and Civ, two great tastes that taste great together!

    Thanks for all the work, especially the +10 and +17 summaries.
     
  13. Sun Tzu Wu

    Sun Tzu Wu Chieftain Supporter

    Joined:
    Mar 26, 2007
    Messages:
    7,917
    Thanks, Hans Lemurson for the combat formula and supporting data. Extremely well done analysis!
     
  14. KrikkitTwo

    KrikkitTwo Immortal

    Joined:
    Apr 3, 2004
    Messages:
    12,308
  15. Hans Lemurson

    Hans Lemurson Chieftain

    Joined:
    Jan 2, 2006
    Messages:
    467
    Location:
    Silicon Valley
    Yeah, the shifted headings threw me for a bit when I first tried to tackle the data, but you can figure out which number are which based on their behaviors and distribution.

    Yeah, I'm pretty sure my equation is at least 98% correct. Equations in programs are almost always based on simple numbers, but you can never be totally sure.

    Yeah, until I ran the numbers and saw that +17 meant 2x, the number for armies made no sense at all.

    I do like analyzing games, and I saw that nobody had done this yet, so why not try to milk it for all the self-aggrandizing glory I can get?

    I wish I could have found a more intuitive way of stating it than e^x, since nobod- um, most people, don't have e memorized.

    30 * 2^(StrengthDiff/17) is another valid representation, as is
    30 * 10^(StrengthDiff/58) and
    30 * 1.041^(StrengthDiff)
     
  16. ShinigamiKenji

    ShinigamiKenji Chieftain

    Joined:
    Nov 8, 2016
    Messages:
    921
    I'd think that quite a few people that care about the damage formula would have e memorized... Anyway, maybe using exp(x) would help (since it's the Excel function for exponential).
     
    Leyrann likes this.
  17. Hans Lemurson

    Hans Lemurson Chieftain

    Joined:
    Jan 2, 2006
    Messages:
    467
    Location:
    Silicon Valley
    It's not so much the calculation itself being hard to do as it is that it can be hard to get an intuitive sense for the numbers when they aren't simple integers. I myself have little sense for what the 1.08x damage of +2 strength actually means. "Double" or even "1.5x" on the other hand are much clearer. I wish I could find clear numbers for the whole formula and its results.
     
  18. Victoria

    Victoria Regina Supporter

    Joined:
    Apr 11, 2011
    Messages:
    5,093
    I am not sure many people are going to calculate that formula each combat. To me the thing I will remember are

    Armies, corps, fleets and armadas are very strong and very worth the investment
    The difference makes the difference and autokills at 30 everytime.
    Hans Lemurson is da man, milk it, you deserve it
     
  19. Lord Yanaek

    Lord Yanaek Chieftain

    Joined:
    Aug 15, 2003
    Messages:
    1,408
    Trying to square the circle aren't you?:p
    If you really want something easy to understand for whoever have no mathematical background you probably need to drop your formula completely and go for something visual.
    DamageGraph_400.png
    Graph edited to include suggestion from icon41gimp
    OK, i took my own combat log and plotted the results. Here's what i have (roughly what you have)

    Unit vs Unit Both attacker and defender damage considered for a total of 748 samples after removing 100 and 0 damage (attacker always takes 0 when it's a ranged unit)
    UnitVsUnit.png

    District vs Unit (unit bombarded by City Center or Encampment with walls) Obviously only defender damage is used (126 samples)
    DistrictVsUnit.png

    Unit vs District. I used only the damage dealt by the unit to the district and removed the 200 damage (cap for max city wall). Only 79 samples unfortunately.
    UnitVsDistrict.png

    So both for unit vs unit and district vs unit i get very similar results. For unit vs district however, my results differ a lot but the distribution doesn't even show a clear exponential curve, i just fitted an exponential curve because it's what we have for normal combat. It's possible that the formula used to damage cities is different. Interestingly, the fitted curve has 15 baseline damage, half the normal baseline for unit vs unit, so it might be good despite the low number of samples.

    EDIT. Just to let you know the log doesn't really tell you a district is under attack but there is a value set to either 1 or 3 to identify the object type of the attacker and defender. "AttackerObjType" 3 is clearly identified as a district (city center or encampment) while "DefenderObjType" 3 is "UNKNOWN" but given that city walls can grow to 200 and i see some 200 damage when defender is 3 i guess they used the same numeric identifier for defender and attacker and "DefenderObjType" 3 means a district (city center or encampment) was under attack at that time.
     
    Last edited: Nov 28, 2016
    juanpavo and Victoria like this.
  20. Victoria

    Victoria Regina Supporter

    Joined:
    Apr 11, 2011
    Messages:
    5,093
    Not knowing the unit attacking does not help...and if it attacking walls or city?
    It also looks like there is not enough samples in that one and you need to combing a few .csv's.
    On the right track and very impressed as a non mathematician myself
     

Share This Page