The hidden power of agg+cha (or, why Boudica is actually the best leader in the game)

You appear to be counting outcomes with that code? What does that have to do with anything?
 
No, I had a really hard time understanding what you are saying. What you are trying to point out is that Civ4 uses its own random number function (SorenRandom or something like that)? That's probably just some wrapper. Do you have any info why it wouldn't work properly? A random number generator is not that difficult to write, at least at level sufficient for a computer game.
 
Crikey, that was painful @Fippy :(

On lower difficulties it's possible to kinda abuse free wins. Attack with impossible odds, and gain a pile of XP. Naturally that is very different to what is being discussed here.

What makes all these losses in a row even worse, like Anysense is touching upon, is that with supreme winning odds, we also have a higher chance to win each combat round. So to then lose a bunch of those combat rounds, the fight itself, and then another 4-5 like that, takes extreme bad luck. Or a naughty RNG perhaps.

Found an image of it, but like I said, this is a different mechanic at play. Felt damn nice to get one back tho ;)
Spoiler :
Free win lol.jpg
 
Last edited:
@Fippy: I ran the combat 20k times and got 99,38% chance for the chariot. Seems close enough. (This used the dll code, though.) Damage numbers per hit are in the right ballpark but they are a bit involved to calculate.
 
Cheers, guess i just have a wrong image in my head when i see those combat lines.
This one was really just funny btw, was a future medic chariot who moved outside the great wall in search for some cheap xp. I didn't even realize at first that he lost, what happened..:lol:
At this point 30:hammers: were no biggie.
 
What if the RNG still averaged out to be about as accurate as displayed, but winning and losing streaks over multiple combats were still a thing because of faulty code? I feel it would be hard to objectively test for such a thing, but moreover, it would negatively impact the player far more than give a benefit since until the late game, the player has less units and hammers usually so not winning enough fights hurts more than winning harder by winning more than expected.
 
That should be relatively easy to demonstrate by observing many dice rolls and showing that the distribution of the length of winning/losing streaks does not match the expected probability distribution.

Edit: Looks like somebody did a test for such runs of numbers, and seems to conclude the behavior is normal. Unfortunately the pictures showing the results were deleted...
https://forums.civfanatics.com/threads/testing-civ4s-random-number-generator.339303/
 
Last edited:
In practical terms it doesn't make a difference if Civ4 RNG is truly random, it is what it is and (unless it can be patched/modded) its going to stay that way. Maybe its skews the answer to the question 'is it better to be lucky or good'?
 
I looked up the dll source code at https://forums.civfanatics.com/resources/cvgamecodedll-c-source-code-files-bts-3-19.16274/ and if I am reading the code correctly, then: CvGame.cpp|getSorenRandNum(..) calls CvRandom.cpp|Cm_sorenRand.get(..), which implements:

m_ulRandomSeed = ((RANDOM_A * m_ulRandomSeed) + RANDOM_C);

with A = 1103515245 and B = 12345 (followed by some code to take only the upper 16 bit and do some scaling)

According to https://en.wikipedia.org/wiki/Linear_congruential_generator these values for A and B are the same as in the glibc rand() function.

Most of the stuff on that page is abacadabra to me, but I noticed the following quote:

"One flaw specific to LCGs is that, if used to choose points in an n-dimensional space, the points will lie on, at most, nn!⋅m hyperplanes (Marsaglia's theorem, developed by George Marsaglia).[7] This is due to serial correlation between successive values of the sequence Xn."
 
Last edited:
...
Most of the stuff on that page is abacadabra to me, but I noticed the following quote:

"One flaw specific to LCGs is that, if used to choose points in an n-dimensional space, the points will lie on, at most, nn!⋅m hyperplanes (Marsaglia's theorem, developed by George Marsaglia).[7] This is due to serial correlation between successive values of the sequence Xn."

And George Marsaglia developed the Ziggurat Algorithm, which brings us back to Civ... I think we're onto something here!
 
Found an image of it, but like I said, this is a different mechanic at play. Felt damn nice to get one back tho ;)

Note that odds 0.1% is to win while getting <=3 hits. Odds for receiving <=1 hit are much longer. I know that RNG streaks but 9 to 1 is a hell of a lot of streaking, should be once in a lifetime event, but its not.
 
What makes all these losses in a row even worse, like Anysense is touching upon, is that with supreme winning odds, we also have a higher chance to win each combat round. So to then lose a bunch of those combat rounds, the fight itself, and then another 4-5 like that, takes extreme bad luck. Or a naughty RNG perhaps.

Although it seems obvious that with fights being decided in several rounds should result in more universal distribution, it may still be false. I compared deciding an outcome by rolling one random number with a fight until 5 successful hits and found that the distribution is almost exactly the same. It also streaks in the same way as pure RNG. Thought there could be some difference in streaking at least, but there isn't.
Spoiler :
Up to 24 win/loss streaks :eek2: Of course, it happened just once in a series of 10 million fights, and yet, it is mad that such a thing is possible at all.
rng2.jpg


Did not know that pic was a free fight. It shows correct 0.1% odds and a spearman made one hit. Thought they can't do it in free win fights.
 
Last edited:
What if the RNG still averaged out to be about as accurate as displayed, but winning and losing streaks over multiple combats were still a thing because of faulty code? I feel it would be hard to objectively test for such a thing, but moreover, it would negatively impact the player far more than give a benefit since until the late game, the player has less units and hammers usually so not winning enough fights hurts more than winning harder by winning more than expected.
I think this is exactly what happens. When checked over many iterations, like 10,000 or whatever, the odds comes out as correct/expected. But the RNG has a tendency for streaks of losses or wins. This becomes hidden over so many iterations, but if you attack with 7 units and lose 5 despite great winnings odds, you obviously get rather screwed. Like I said dryly above, the solution then is to have 10,000 unit stacks...
 
Did not that pic was a free fight. It shows correct 0.1% odds and a spearman made one hit. Thought they can't do it in free win fights.
I'm 100% sure it was a free win, but I don't know exactly how they work. The odds in-game showed something like 97,5%, which confused me rather a lot, until I realised we hadn't faced any barbs yet, so this must count as a free win. Maybe the game reports them a bit weirdly or something.
 
Freewins are coded as giving the (low level) player or (high level) AI a huge artificial combat strength advantage vs barbs. It is actually possible to lose a "freewin" battle. It's just very unlikely.
 
I lost 70% winning odds fights 5x in a row often enuf, feels like such outcomes happen with annoying frequency.
Any wizard around who can tell what the odds for that happening really are?

Ultimately it's always personal experience vs. "working as intended" or "we just forget normal results", however when we talk about 1:1000 chances or so they should barely be noticeable.
Yet i could swear something similar happens almost each and every game.

Just today i got a great artist at 400 :gp: points, by using one artist for one turn (6 gpp).
6 out of 400 points, or ~1.5% chance.
The last game where this happened as well isn't very far away..
 
Top Bottom