1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

[Vanilla] Hans Lemurson figures out the Combat Formula

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

  1. notque

    notque Artificially Intelligent

    Joined:
    Nov 13, 2005
    Messages:
    1,654
    Do you guys not know how to use find? it's line 1442 that starts the function.

    Download the program everything to find files on your system.
    Download WinGrep to search over your civ files
    Use Find in sublime text.
    Use Goto Line in sublime text to get to the line
     
  2. Lord Yanaek

    Lord Yanaek Chieftain

    Joined:
    Aug 15, 2003
    Messages:
    1,438
    Of course i can use the find function of Notepad++ and i can search in every file and mark every line containing CombatResultParameters and then try to figure where those come from and find references to the unitData table and FilterUnitStatsFromUnitData function and finally track that to ReadUnitData function that uses call methods from the unit object within the dll

    Now, i must admit i'm not a professional coder and my Lua is a bit rusted so maybe you can point us to the exact line that actually does the calculation
     
  3. Sun Tzu Wu

    Sun Tzu Wu Chieftain Supporter

    Joined:
    Mar 26, 2007
    Messages:
    7,920
    Thank you, Lord Yanaek!
     
  4. notque

    notque Artificially Intelligent

    Joined:
    Nov 13, 2005
    Messages:
    1,654
    There is no exact line. It goes through the process to display the combat results in the panel, so you can use that to view it. But you have to do the work. It basically confirms what has been said previously utilizing the globals. After that, it's a lot of DLL calls which obviously become opaque to us.
     
  5. Lord Yanaek

    Lord Yanaek Chieftain

    Joined:
    Aug 15, 2003
    Messages:
    1,438
    Which is almost exactly what i said previously so not sure why you had to be condescending.
     
  6. notque

    notque Artificially Intelligent

    Joined:
    Nov 13, 2005
    Messages:
    1,654
    I wasn't being condescending. I think if you read my response in good faith, you'll find I was just being helpful.
     
  7. Lord Yanaek

    Lord Yanaek Chieftain

    Joined:
    Aug 15, 2003
    Messages:
    1,438
    Well, that part looked condescending to me but it's often hard to grasp the tone of someone when you read them on a forum. Modern mass communication platforms sometimes makes communicating much harder. Maybe you were tired when you wrote this, or maybe i was tired when i read it (probably), or maybe both.

    Thanks for pointing us to this file anyway, even if it wasn't probably as useful as you thought/hoped it would be. :)
     
  8. notque

    notque Artificially Intelligent

    Joined:
    Nov 13, 2005
    Messages:
    1,654
    It's all good. If you read it in a nice tone, you'll find it's a simple misunderstanding. I'm a professional engineer, and I don't do a particularly good job understanding how my comments will impact others. Will try to do better.

    I'm not sure I thought it'd be hugely useful, but there are some interesting parts in there. Like the fact the panel displays half of the randomized combat.

    I'm currently working on combat scaling changes for the MP mod I work on, so was just on my mind, and thought I'd add that there is detail there. Sounds like you guys already understand it.
     
  9. TheMeInTeam

    TheMeInTeam Top Logic

    Joined:
    Jan 26, 2008
    Messages:
    23,252
    Not nearly enough likes on this thread so have another :).

    If you have the production/resources the corps/armies and great generals are important boosts. Elite units with these modifiers are devastating.
     
    Sun Tzu Wu likes this.
  10. Hans Lemurson

    Hans Lemurson Chieftain

    Joined:
    Jan 2, 2006
    Messages:
    469
    Location:
    Silicon Valley
    Yay! Other people have taken over the hard work now and I can still take credit! :)

    Yeah, given that Corps can be built at 1.5x the cost (with an Academy) and deal 1.5x damage and have 1.5x the effective HP, that is amazingly powerful. +5 Strength (1.22x) on top of that and it's monstrously powerful.

    The "combat power" of a unit is it's Firepower * HP. e^(2*1.04*StrengthDiff) will tell you how many lesser units your unit can take on in combat. Every +9 strength doubles the number of enemies that a unit can take on.

    I'm not sure this applies to ranged units though, since they don't get attacked as often, so their HP will be less important. I would be more worried about 2 Crossbows than a Crossbow Corps, but a 2 Knights will certainly lose to a Knight Corps (actually it depends on how flanking bonuses come into play, come to think of it).
     
    Last edited: May 20, 2017
    jollywonk and Sun Tzu Wu like this.
  11. TheMeInTeam

    TheMeInTeam Top Logic

    Joined:
    Jan 26, 2008
    Messages:
    23,252
    Flanking matters and it can stack (actually great generals can stack too, thought it's impractical to do that usually). GG + flanking + oligarchy is pretty nasty early on, it adds an era basically. 50+ strength classical era units are no joke, and it takes a long time before cities resist that so you wind up having no trouble with a siege tower or even a battering ram.

    Artillery armies with grape shot line are actually pretty darned effective, which is good because ranged of later eras starts to suck.
     
    Sun Tzu Wu likes this.
  12. Zuizgond

    Zuizgond Chieftain

    Joined:
    Oct 24, 2016
    Messages:
    385
    You know there is a problem with strategy games where most in-game mechanisms are not explained and you have to guess them...
     
    Sun Tzu Wu and KrikkitTwo like this.
  13. KrikkitTwo

    KrikkitTwo Immortal

    Joined:
    Apr 3, 2004
    Messages:
    12,308
    This is a massive problem with civ 6.... it has always been a problem with civ, but it seems like it has gotten worse with each entry.
     
    Zuizgond and Sun Tzu Wu like this.
  14. Karmah

    Karmah Chieftain Supporter

    Joined:
    Mar 3, 2011
    Messages:
    627
    @Mods : This discussion should be pinned imho.
     
  15. Andesco

    Andesco Chieftain

    Joined:
    Nov 18, 2015
    Messages:
    2
    Solved (more or less):

    Combat Damage Dealt = exp[ 3.369311+ ( Attacker Strength - Defender Strength) x 0.037637 + U(-.27,.23) ]

    U ~ a random sample from the uniform distribution with bounds -.27, +.23 (the uniform distribution)

    Yes, I know it's asymmetrical; one of two things is happening. One, the devs are putting 'boxing gloves' on combat, with a modest negative bias to damage dealt to make units slightly harder to kill without HP-inflation. Two, our modest sample just happens to be in that part of the sample space, while the underlying distribution is in fact random.

    This is based on analysis of the data set provided by OP, those parameter estimates for base damage (3.36...) and relative strength effect (.037...) might tighten up to a more reasonable number with increased data collection. It's quite possible (based on the standard error for those value estimates) that the base damage factor is actually +/- up to .04 and the strength effect is +/- up to .001. Overall, the model accounts for roughly 90% of the variation within the source data with the base damage and relative strength effects 'highly significant', or in layman's terms, 'mathematically legit'.

    Based on this we'll 'reliably' (in 50%+ of cases) see 1-damage for a Strength Difference of -89.52124 (that is, Attacker Strength 89.5 points below Defender Strength, possibly something like -90) and 100-damage for a Strength Difference of 32.83628 (probably 33). In the source data we only saw four 100-damage cases:
    Crossbowman wrecks Scout with a 39-point advantage,
    Crossbowman wrecks Scout with a 41-point advantage,
    Horseman wrecks Barb Horse Archer with a 40-point advantage (taking 6 damage)
    Roman Legion wrecks Slinger with a 40-point advantage (taking 6 damage, again, possibly there's a floor on attacker damage for melee?).

    Supporting this idea about damage floors, there is the fact that the lowest Defender damage we saw in the data is 13 (double a 6.5 damage attacker floor, perhaps?). There were seven cases of this in the data, four were District City Centers (versus other District City Centers, strangely), with strength differences ranging from -16 to -22. In our data however, we didn't see any "terrible generalship" and the data didn't have late-game units getting attacked by scouts and other trash, so it's not surprising that we didn't see any 1-damage pew-pew nonsense.

    The range on the uniform distribution is based on the residuals of the model fit using the parameter estimates above. Those residuals have quartiles:
    0%: -0.26960892
    25%: -0.10573067
    50%: 0.01500539
    75%: 0.11655122
    100%: 0.22684554

    Those are pretty flat (as a uniform distribution should be) and supported by the Quantile/Quantile Plot below (against the aforementioned Uniform distribution). A nice diagonal line between the bottom left and top right corner of the plot indicates a 'good' fit.
    QQResid.png

    And below we have observed and theoretical ranges of Attacker Damage:
    AttackerDmg.png
    ...and Defender Damage:
    DefenderDmg.png

    Here we have a plot of the source data, attacker and defender damage shown separately. Notice ranged units chilling at the bottom.
    DmgSamp.png
    And here we have paired damage outcomes from our source data - notice how few outcomes we see above the 'tie' line (the line indicates attacker damage equal to defender damage, above the line indicates attacker damage higher than defender damage), showing at least that the AI and our intrepid player favors 'winning' battles. (Though I think we all agree that the A.I. could use a little more of the 'lose the battle, win the war' maxim).
    DmgOption.png

    In any case, more data collection yields better estimates, but I think these give a pretty good understanding of the damage calculation.

    Source: Statistician is my day job.
     
    Hrothbern likes this.
  16. Hans Lemurson

    Hans Lemurson Chieftain

    Joined:
    Jan 2, 2006
    Messages:
    469
    Location:
    Silicon Valley
    That is a good analysis which is well in line with all the other results we have gotten.

    The presentation of the formula, though mathematically correct, is a little unintuitive. Most of the Constants are probably calculated outside of the Exponent in the formulation likely used in the game.

    exp(3.369) = 29.06 which is close to the reasonable and wholesome number of 30.
    exp(0.23) = 1.259 which is close to the reasonable and wholesome ratio of 1.25
    exp(-0.27) = 0.763 which is close to the reasonable and wholesome ratio of 0.75

    The most likely damage formula (based on values found in the XML) uses a uniform distribution between 24 and 36 which occurs outside of the exponential function.
     
  17. Damus Maximus

    Damus Maximus Chieftain

    Joined:
    Dec 22, 2016
    Messages:
    16
    Gender:
    Male
    Well, I'm aware of the concept of trying to turn homework into a game and it'll become more enjoyable, but turning a game into homework???? that's a new one for me.

    Credit where its due, very good work that i'm sure MANY players (myself included) will find extremely useful.

    Thank you.
     
  18. Hrothbern

    Hrothbern Warlord

    Joined:
    Feb 24, 2017
    Messages:
    2,533
    Gender:
    Male
    Location:
    Amsterdam
    With the math experts on combat here on this thread I have a question.
    Very informative :)

    I use walls a lot to fight the AI, luring them in my crossfire of cities and encampments.
    I know that my wall/garrison strenght goes up with the strongest (melee) unit I have (and had) in my army.

    But how about the ranged strenght of the garrisons ?
    Does that go up with the highest melee strength of one of my units ?
    Or is it determined by the highest range strenght I have in my army ?
     
  19. Victoria

    Victoria Regina Supporter

    Joined:
    Apr 11, 2011
    Messages:
    6,669
  20. Hrothbern

    Hrothbern Warlord

    Joined:
    Feb 24, 2017
    Messages:
    2,533
    Gender:
    Male
    Location:
    Amsterdam
    Thanks :)

    I hoped for that (incl navies)
     

Share This Page

Ebates: Get Paid to Shop