1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Your experience with combat odds...?

Discussion in 'Civ4 - Strategy & Tips' started by Tobiyogi, Oct 21, 2019.

  1. Deathcrush

    Deathcrush Chieftain

    Joined:
    Mar 7, 2019
    Messages:
    38
    WELL. yeah usually cats are weak that's why we loose them a lot. it's part of the game . when u have a only mounted wars also be prepared to loose many.
    With canons it's completely different for example. I just had a game where i rushed with them and some knights and muskets - 5 wars - lost one or two canons. Before capitulating the last ai i was wih full health canons. It really depends what's on the other side. if the ai have had Cuirs or Cavalry then i would loose a lot but they are not defenders so again not very dangerous and again it's doable to take a city full of mounted.
     
    Last edited: Oct 22, 2019
  2. Fish Man

    Fish Man Emperor

    Joined:
    Feb 20, 2010
    Messages:
    1,144
    I can't recall where off the top of my head but I swear I saw a post by a computer scientist a while back on these forums explaining that the pseudorandom algorithm for IV was actually a pretty poor choice, because it was unusually prone to streakiness. Along with a code dive and a link to an explanation that was far beyond me (I'm talking like doctorate level mathematical concepts, IIRC). So I'm not sure if you'll accept this piece of hearsay as evidence but, yes, the RNG could be less than ideal (though that flaw is more of a nuisance than a major game-breaker).
     
  3. rah

    rah Deity Supporter

    Joined:
    Sep 12, 2005
    Messages:
    8,548
    Location:
    Chicago
    Just use stack attacks and any infatuation discussing displayed odds will end very quickly.
    I generally select group and then attack. (in MP it's the only way)
     
  4. Tobiyogi

    Tobiyogi Prince

    Joined:
    Nov 23, 2018
    Messages:
    385
    Gender:
    Male
    Location:
    Berlin, GE
    Not a good choice because sometimes you have to sacrifice very weak units first to soften up the defenders. The computer would never do that, but always choose the best-odd-unit first and if it's 80% you could sacrifice the best guy first. It is kind of an art to win equal-number fights with little losses or in some situations to find the entrance to the perfect scissors/paper/rock system, and it's fun. I use stack attacks only when the defenders are half-dead and I want to finish with a fresh stack of the same unit-type. Some civ 4 players even chose single guys in those situations to maximize promotions, for me, that is too much.
    Other examples for stack attacks from offensive defending: some delayed stupid guy wants to melee rush me and I have a bunch of crossbows. Or a mix from swords/spears against chariots.
     
    Last edited: Oct 23, 2019
  5. Kid R

    Kid R Emperor

    Joined:
    Jan 26, 2009
    Messages:
    1,483
    Here's the RNG code:
    Spoiler :
    Code:
    #define RANDOM_A      (1103515245)
    #define RANDOM_C      (12345)
    #define RANDOM_SHIFT  (16)
    
    unsigned short CvRandom::get(unsigned short usNum, const TCHAR* pszLog)
    {
        m_ulRandomSeed = ((RANDOM_A * m_ulRandomSeed) + RANDOM_C);
    
        unsigned short us = ((unsigned short)((((m_ulRandomSeed >> RANDOM_SHIFT) & MAX_UNSIGNED_SHORT) * ((unsigned long)usNum)) / (MAX_UNSIGNED_SHORT + 1)));
    
        return us;
    }
    Unreadable statement broken apart and commented:
    Spoiler :

    Code:
    //Commonly-used linear congruential RNG
    m_ulRandomSeed = ((1103515245 * m_ulRandomSeed) + 12345);            
    
    //Take high 16 bits only of the generated rand#, and use as low 16 bits
    unsigned long ulRand16 = (m_ulRandomSeed >> 16) & 0x0000ffff;  
    
    //The 16 bit range requested, put into a 32 bit number
    unsigned long ulReqd = (unsigned long)usNum;
    
    //The (16 bit) rand# multiplied by the (16 bit) requested number, with no overflow
    unsigned long ulResult = ulRand16 * ulReqd;
    
    //The high 16 bits of the above
    ulResult >>= 16;                                                      
    
    unsigned short us = (unsigned short) ulResult;                        
    return us;
    


    Those magic numbers are well known (see https://en.wikipedia.org/wiki/Linear_congruential_generator). E.g. that link shows they're the ones used in the GCC compiler's rand() implementation.

    The low bits are known to be less statistically "good" as random numbers than the high bits, so using only the high bits like this code does is apparently a common thing to do. Done like this it's also a neat way to avoid any overflow complications in 32 bit math at the same time.

    The combat code is mostly calling the function with parameters like 100, which is a small fraction of 65536, so rounding wouldn't be making the results uneven.

    I don't think the results of that code should be streaky, as used in Civ 4, in any noticeable way, but would be interested in what any math prof said:)

    I think most discussion of "good" and "bad" RNGs these days concerns cryptography and whether the output is suitable for that. A math prof might say some generator was garbage, but it might only be in ways totally irrelevant to how it'd be used in something simplistic like Civ 4 combat rolls.

    This is quite an interesting wikipedia page on tests a top quality RNG might pass and why:
    https://en.wikipedia.org/wiki/Diehard_tests
     
    sampsa and drewisfat like this.
  6. rah

    rah Deity Supporter

    Joined:
    Sep 12, 2005
    Messages:
    8,548
    Location:
    Chicago
    All depends on what you want. To attack or defend. If you want to attack you can't take any time or you will be attacked. So Selecting which unit you want to attack with usually takes too much time and their cannon stack hits you first and you're toast. It doesn't take much to select a whole group so this is the norm. (all cav or all cannons, etc.) MP reaction time is a totally different beast.
     
  7. dankok

    dankok Chieftain

    Joined:
    Sep 2, 2006
    Messages:
    92
    ^ MP with an 8 second turn timer is brutal until you get used to it.
     
  8. Tobiyogi

    Tobiyogi Prince

    Joined:
    Nov 23, 2018
    Messages:
    385
    Gender:
    Male
    Location:
    Berlin, GE
    Never player MP. 8 seconds per turn is a possible setting?
     
  9. f1rpo

    f1rpo plastics

    Joined:
    May 22, 2014
    Messages:
    484
    Location:
    Germany
    Could've been this thread. That
    ... is true, but, as Kid R wrote, the error is minuscule:

    If combat outcomes don't seem to match the displayed odds, then my first suspicion would be that combat resolution (the units exchanging blows as documented in the combat log) and the computation of survival/ withdrawal odds before combat are inconsistent with each other. The formulas (resolveCombat, getCombatOdds) aren't that complicated though; I'm assuming that they're correct.
     
  10. dankok

    dankok Chieftain

    Joined:
    Sep 2, 2006
    Messages:
    92
    It's not literally 8 seconds per turn but with many MP games played with "simultaneous turns" there is an 8 second delay between the end of last turn and the beginning of the next turn. So an enemy stack can move twice in 8 point something seconds (skilled players do this intentionally) and you have to respond very quickly. Without a sentry net, a stack of HA's can literally move 4 tiles and take your city without you even noticing them let alone being able to respond.
     
    Fish Man likes this.
  11. Fish Man

    Fish Man Emperor

    Joined:
    Feb 20, 2010
    Messages:
    1,144
    Ah, the good old first move abuse. Learned about it from watching way too much Filthyrobot Civ V multiplayer...love it or hate it, it's certainly fun to use (not so fun to face, though).
     
  12. Fish Man

    Fish Man Emperor

    Joined:
    Feb 20, 2010
    Messages:
    1,144
    Yes, thanks for finding it for me!

    So, really looks like the RNG is basically close enough to random, as stated by the code divers?
     
  13. rah

    rah Deity Supporter

    Joined:
    Sep 12, 2005
    Messages:
    8,548
    Location:
    Chicago
    We played a gentleman's rule where you couldn't wait for others to finish their turn, declare move and end the turn quickly. You had to give you enemy a chance to respond. But that was just for the DOW turn. After that it was a free for all.

    I once made the mistake of taking a smoke break and losing a city to a double move. Smoking does kill. :lol:
     
  14. TheMeInTeam

    TheMeInTeam Top Logic

    Joined:
    Jan 26, 2008
    Messages:
    25,123
    When tested odds in Civ 4 are consistent to outcomes. Note that you can't ALWAYS trust this, Pdox games have had a few examples of displaying inaccurate odds, and Civ 6 does so with spies (displayed capture % isn't even close)!

    That said, the design of odds in Civ 4 is one of its weaker interactions. For most of the game, you can soften/wash out RNG with collateral damage and larger unit counts. In the early game turns, which are the most crucial by reasonable measures, you can have your game swing very unfairly to unlucky or lucky rolls.

    In one of my YouTube games, a barb archer attacked an archer of mine in defensive terrain and killed it. It then immediately beat another archer in a city to capture the city from me. The odds against that were enormous, but it happened and randomly screwed me over drastically. I was able to win the game that time vs AI, but would have had no chance against say human opposition.

    Huge swings in position should not rest on small numbers of dice rolls. There's a reason most of the game's unit interactions aren't like that in practice.

    ~~~

    One of my "favorite" memories in Civ 4 was losing a full hp knight at 100% displayed odds when attacking a damaged catapult. Since then, Civ 4 was patched to never display odds higher than 99.9%. But back then, you could fairly conclude the UI lied because it wrongly displayed a guaranteed outcome.
     
    Tobiyogi likes this.
  15. rah

    rah Deity Supporter

    Joined:
    Sep 12, 2005
    Messages:
    8,548
    Location:
    Chicago
    Yes, if you use your GGs to mop up after cannons enough, one will eventually lose.
    When you do lose the GG at 99.9 you will remember and think you've been cheated for awhile.
     
  16. 6K Man

    6K Man Bureaucrat

    Joined:
    Jul 17, 2007
    Messages:
    2,126
    Location:
    in a Gadda Da Vida
    I’ve played Civ4 for over 10 years and I would never attempt to mentally determine the odds my City Raider 3 Swordsman (+75% for CR3, +10% for unit type) has against a CG1 (+25% defense) Archer (+50% City defense) in a hill city (+25% defense, +25% for unit type) that has 2.1 STR due to bombardment. I would bet that even the best, most experienced players couldn’t eyeball the odds for that combat within 10%.

    What the combat odds display does well is give you a pretty good indication of whether attacking is a good idea. Your stack of 6 chariots gets to Gilgamesh’s capital, with 3 Archers on a hill, and the combat odds generator says, hold up son. Cuirassiers versus Longbows? Full speed ahead, says the odds generator. These aren’t things an inexperienced player can figure out on his or her own, and with so many modifiers (unit type, promotions, terrain, first strikes, etc), nobody can reliably commit combat odds to memory. So I guess my point is that what the combat odds generator does is help the player make informed decisions on when to attack. It shouldn’t be viewed as an absolute predictor of combat outcomes, and IMO, it was a mistake by Firaxis to present it as such. Even aside from the question of whether it's possible to create a truly random number generator, too many people don't understand probabilities for an odds calculator to be well received.

    And for those who complain that Civ4 does a poor job at simulating combat - well, combat odds are probably the least immersive and most unrealistic feature in all of Civ4!
     
    krikav likes this.
  17. Fish Man

    Fish Man Emperor

    Joined:
    Feb 20, 2010
    Messages:
    1,144
    My idea for an implementation that allows for some variability due to RNG while not too much is making it that fights are certain wins and losses past certain thresholds. Say, any battle below 10% is an auto-loss and a "win" rolled would leave the defender within 1 hit of death while killing the attacker, while any battle above 90% with a "loss" rolled will leave the attacker within 1 hit of death while the defender still dies. It introduces certainty, not absolute, but to the point where if you make the right decisions then extremely bad luck doesn't have a chance to totally screw you. In the case above, if your archer was fortified on a hill (or a forested hill), the chance for the barb to kill it should've bee less than 2% (off the top of my head a strength ratio of 2:1 means about 98% chance to win), which means that it is a guaranteed victory - as it should be, because it eliminates the possibility of dumb luck screwing you even when you did everything right to the best of your ability. But this system also maintains that early rushes are high-risk high-reward, as they should be (after all, if combat was mostly deterministic you could scientifically determine how many axes/chariots to rush with, exactly, and guarantee yourself an AI capital in a lot of cases by t60, and that's wayyy too much of an advantage).
     
    dankok likes this.
  18. AcaMetis

    AcaMetis Prince

    Joined:
    May 21, 2018
    Messages:
    534
    Gender:
    Male
    It doesn't help that the game never clarifies that that combat boils down to (if I calculated things correctly) 6:strength: vs. 2.94:strength:+1 FS, rather than the more intuitive answer of 11.1:strength: vs. 4.725:strength:+1FS.
     
    rah and Fish Man like this.
  19. dankok

    dankok Chieftain

    Joined:
    Sep 2, 2006
    Messages:
    92
    This is a good idea. In the first game I posted on the Stock Swords thread, I had a warrior lose to a barb warrior with over 90% odds and I lost a city to the barbs as a result. Someone who put an Axe in that city would not lose it to barbs but that's one fewer attacker on the front. Right now with no guaranteed wins it also makes the strategies very difficult to compare in effectiveness.

    For instance I have 7 Chariots and plan to rush Isabella who has 2 Archers in her capital. She is already in Slavery and I can't get to Madrid in 1 turn after DOW so she is likely to whip one more defender. It's a holy city so 7 Chariots beating 3 Archers is far from safe. Do I chop 3 more Chariots to ensure the win? I mean if I only went along with 7 Chariots and succeeded I could use those chop hammers for a Library plus a Monument in my second city. So using 10 Chariots when 7 would suffice is inefficient because it will set me back in development but a 7 Chariot rush also has a solid chance of not succeeding. In this case which is the more optimal play? 7 Chariots or 10 Chariots... It's impossible to answer.

    And like TMIT said, sometimes the outcome of the entire game can hinge on one or two battles. In MP in particular if your neighbour rushes you with a Dog Soldier and you got an Archer in your capital you should be safe but that Dog still has like maybe a 10% chance of ending your game right there and then. And building a second Archer means you can't build a Settler in time to claim metal before enemy metal units come.
     
  20. Tobiyogi

    Tobiyogi Prince

    Joined:
    Nov 23, 2018
    Messages:
    385
    Gender:
    Male
    Location:
    Berlin, GE
    So many numbers and calculations here. I trust only those that I have tested on my own, like my probability test (with 100 knights against 100 longbows) that confirmed the displayed odds almost perfectly (72 wins with initial combat odds of 70,5%).

    A similar subject:
    Speaking of odds is not only about being death or alive. Winning a fight can injure you so heavily that the counter-attack means your death sentence. Again, I tend to believe that AI is more gifted here, they damage more heavily even when they lose and they have less of a scratch when they win a borderline fight. I CAN win 70/80% fights but sometimes at a very high cost. Don't know if THAT is linked to the difficulty, maybe not, I really don't know.

    As for the RNG, that one seems to be ok for me now, I don't think it is too unfair for the human player.
     

Share This Page