# Civ3's random number generator

Discussion in 'Civ3 - General Discussions' started by Plume, Dec 9, 2002.

1. ### sumthinelseciv investigator

Joined:
Mar 20, 2002
Messages:
1,333
Location:
Austin Texas USA
But if it's a loaded die you might roll 6 100% of the time. Yes, your statement is true since you said "fair die."

I agree with your point though. If we know what the odds are in civ3 combat it doesn't matter what the previous results are (except in the sense that a unit's strength or experience may be affected by previous combat).

For some events we don't know what the probability is, and previous results do affect it. I couldn't understand why I had 200 elite victories without generating an leader until I discovered that all my elites had already created leaders and the odds were then 0%. (Since then firaxis put a * by such elite units in patch 1.21f).

2. ### anarresanarchist revolutionary

Joined:
Apr 22, 2002
Messages:
6,069
Location:
www.civ3duelzone.com
OK, now I understand the figures. But isn't .597 cubed just the probability that you don't lose ALL swordsmen, not that of all 3 winning. That would be (1-0.597) cubed = 0.403 cubed = 0.0655. So the odds of all 3 winning are about 7%.

Also, does the calulator take in to account the number of hit points, or just give you the odds for each combat round? This is relevant, to take an extreme example: chance of win = 0.9

With 1 hit point, chance of losing = 1- P(win) = 1- 0.9 = 0.1
With 2 hit points, chance of losing = 1- ( P(win,win) + P(win,lose,win) + P(lose,win,win) )
= 1 - (0.9x0.9 + 2x0.9x0.9x0.1) = 1 - ( 0.81 + 0.162 )
= 0.028
(here, P(win,lose) refers to winning or losing each round of combat)

Sorry if this has all been resolved before elsewhere...

3. ### sumthinelseciv investigator

Joined:
Mar 20, 2002
Messages:
1,333
Location:
Austin Texas USA
Yes. You have to select the hit points for each unit in a pull-down list.

The only problem is fast-moving units which can retreat. I don't think it takes retreat into account, so if a fast-moving attacker goes down to 1 hit point the results are incorrect.

4. ### Grey FoxMaster of Points

Joined:
Dec 19, 2001
Messages:
8,726
Gender:
Male
Location:
Sweden
Anarres, why don't you try the calculator.

It will show you the percentage of winning the battle, the percentage of winning with 1hp left, 2hp left etc...

And yes you can set it to up to 15HP. (3*5HP army, they should change it to 20HP.)

5. ### anarresanarchist revolutionary

Joined:
Apr 22, 2002
Messages:
6,069
Location:
www.civ3duelzone.com
There is a saying: 'Ask a mathmatician a question, and get a mathmaticians answer.'

200 leaders? You're beginning to scare me

Joined:
Sep 19, 2002
Messages:
3,352
I love this stuff, one additional factor is time. What Yndy says is correct if before winning the lottery you say "I will win the lottery twice" (or as Yndy puts it "a once in a lifetime event". In that case the probability is squared (e.g. a 1 in 10^9 becomes 1 in 10^18), and thus much less likely. Thus the number of people who have won 1,000,000 bucks in the lottery twice will be much much smaller than the number of people who have won it once. After you have won it once, the chance is the same again (as you say anarres) and you may as well play again.

The same holds for dice (or coins), if before rolling any dice I say "I will get 6 ones in a row", the chance is very small (1/6^6), but if after I have just rolled 5 dice and gotten all sixes I say "now I will roll another six" then the chance is 1 in 6.

I think this is the "trap" people often fall into. They are thinking in terms of one event instead of six discrete events. This falacy can cause loss of much cash at the casino.

7. ### Grey FoxMaster of Points

Joined:
Dec 19, 2001
Messages:
8,726
Gender:
Male
Location:
Sweden
Haha! I think he might have meant 20 victories each with 10 different units... but of course you already knew that...

8. ### sumthinelseciv investigator

Joined:
Mar 20, 2002
Messages:
1,333
Location:
Austin Texas USA

9. ### anarresanarchist revolutionary

Joined:
Apr 22, 2002
Messages:
6,069
Location:
www.civ3duelzone.com

The odds are 0.0655 (6.55%) of the 3 swordsmen taking the city. You have approx. 4/5 chance of _not_ losing all 3 swordsmen.

This makes sense - there is much more chance of losing all 3 than winning all 3 (as the odds of losing are greater than the odds of winning for each battle).

10. ### sumthinelseciv investigator

Joined:
Mar 20, 2002
Messages:
1,333
Location:
Austin Texas USA
I think I know what you mean. You are thinking of 3 separate combats where there are 3 swordsmen and 3 spearmen. Your probability is correct for that case, and it would be the height of folly to make such an attack!

There is only one spearman defending (not 3), so if an attacking swordsman wins, the city falls. Thus the probability of the swordsmen "winning all 3" is zero.

If I don't lose all 3 swordsmen I take the city. That is, I lose either 0, 1, or 2. The chance of that (I take the city) is about 4/5. How would I fail to take the city without losing all 3? (There are some military games where the defender can retreat, but I have never seen that in civ3/ptw.) So there is only one win possible for the attackers, since there is only one defender.

One other point: the odds of taking the city are affected by possible hit points lost by the defender and possible promotions for the defender. I assumed that these factors would cancel each other out, but I am not sure about this. I would guess that the real odds are slightly more favorable to the attacker than 4/5. This also is affected by whether the defender's civ is militarist.

11. ### BeamupHiggs boson

Joined:
Jun 8, 2001
Messages:
1,318
Location:
Boston
There is a point here I think should be mentioned.

If I roll a die 100 times and get 100 6's, what are the odds of getting a 6 next time I roll? Well, I can't be exact, but I'd say at least 99.9%. Note that I did not specify that the die was fair - I just said it was "a die." If I roll 100 6's in a row, it is far more likely the die is loaded than that it is fair.

The point of this? While mathematical abstractions such as fair dice or independent identically distributed variables are very useful, one has to be very careful applying them to the real world because the assumptions may not be met. For example, the only-one-leader-per-elite thing. Subsequent battles by the same elite are NOT independent. Since there may be things in the combat system of which we are not aware, this possibilities should be kept in mind when discussing these questions. Nobody has ever, to my knowledge, presented credible evidence that any such effects exist, but the possibility still exists.

P.S. While I'm not as much of an expert as Anarres, I do hold a B.S. in mathematics. My specialty, however, is physics - so I am very familiar with the pitfalls of trying to apply mathematics to the real world.

12. ### anarresanarchist revolutionary

Joined:
Apr 22, 2002
Messages:
6,069
Location:
www.civ3duelzone.com
@sumthinelse:
Sorry, man. I've been doing calculations in 2 threads and I must have got confused. I really need to read the posts properly.

@Beamup:
Rolling a die. The analogy is a simple logical model, and using a 'die' instead of straight algebra is to make it more friendly.

I agree that in a casino where you roll a die 100 times and you get 100 six's, you will get a six the next time, but there is a relation of what I said to reality. Someone rolling a die alot of times (about 6 to the power 100 times).

I agree this won't happen with a person (not enough time), but a machine can emulate it perfectly. And it will get 100 six's in a row, eventually. And why is a computer in this test not equivalent to a person?

Where this does relate to the real world, is to our battles. A good example is swordmen attacking spearmen, where the spearman has a (total) defence of 3. Threre is an even chance of winning, but how often do 5 win in a row? The odds say 1 in 32, I think that about what I experience. How often do 6 win in a row? The odds say one in every 64 times, and again, this approximates to what I see.

I think if any significant part of the formulas were missing more discrepancies would be noticed, unless those programmes were very clever with their maths. But I doubt it.

13. ### Four Four SevenSpearman

Joined:
Feb 20, 2002
Messages:
83
Location:
Massachusetts, USA
However, you're not going to roll a fair die 100 times and get 100 6's in a row. The odds are (1/6)^100 of this particular event occurring (yes, and (1/6)^99 of 100 of anything in a row). This is a 1 in 6.5*10^77 chance.

How big is this number? Just to put it in perspective, suppose you had pairs of dice the size of a single atom in a line across the entire universe. Now imagine these dice can be rolled a trillion times per second. You would need these dice to roll for many many times longer than the entire age of the universe before you get 100 6's in a row. (If anyone is interested in how I got these figures, let me know and I'll provide them)

In other words, the odds are, for all intents and purposes, zero, unless the die is fixed. It's not a fair die if you see this happen.

Reminds me of a story in a post I made a while back - I'll repost it here:
A fool, a mathematician, and a statistician are watching a roulette wheel. It comes up black 30 times in a row. What do each of them do?
-The fool bets on red because it's "due."
-The mathematician doesn't bet - both red and black are equally likely and are bad bets.
-The statistician knows it's overwhelminly likely the wheel is biased and bets on black.

14. ### Sukiyou will get nothing

Joined:
Oct 23, 2002
Messages:
509
Location:
guys what needs is to be noninear in it's randomness, I think this is what you are orrigionally suggesting but just don't realise it. if you are generating random numbers from 1-5 an RNG will give you an equal probability of 1,2,3,4 or 5 but what we want here isn't equat probablilties what we want is 3 as the average. sure equal probabliities gives it but ot gives a lot of 1's and a lot of 5's. what we want is a bell curve of probabilities, usually 3's, some 2&4, few 1&5. this way the luck factor is lessened because things "usually" go "normally".

15. ### YndyEmperor

Joined:
Jun 29, 2002
Messages:
1,415
Location:
Romania
yes Suki, I thought that this is how the dice thing works but when annares started talking binomial distributions and discrete matehmatics these lit a bulb in my head and i realised i was wrong. True you can not predict the future die.

Even if I studied probabilities a lot last year and i still have to study them i tryed to reduce the whole theory to the t Student distribution and bell shaped curves as it would work if the real distribution is 'unknown'. But actually the binomial distribution is known.

What I understand and would change my strategy a bit is that my normal attack order is wrong. Say I have a large stack of cavalries attacking regular unfortified riflemen on grassland.
*I will disregard the ability of cavs to retreat, ability which improves the survival rate of my units.
*Please do not advise me not to use reg cavs in actual combat cause I dont. This is just theory.

According to the combat calculator the odds I win are

For reg cav: 45.6% - 54.5%
For vet cav: 61.1% - 38.9%
For elite cav: 73.3% - 26.7%

Until now I would attack with regulars, then vets then elites as I thought if I lose with the first I have greater chances to win with the last and more chances to get a leader. This led to high casualty rate in reg and vet troops and a more elites.

Seeing that the past performance has absolutely nothing to do with future performance I would now attack with elites first and regs last, or even better Id look for a weak enemy unit to train my reg cavs on.

I understand this will lead to a higher survival rate of my units although number of elites will be diminished. But higher survival of vets could lead to more elites so the effect over the no. of elites will be diminished.

Is this correct?

16. ### Lt. 'Killer' M.Deity

Joined:
Dec 5, 2001
Messages:
7,475
Suki: been saying that for a long time: what we see in real life is average things being more common than extremes.

Take this example: roll two dice - you get more 7s then 6s and 8s and 2 and 12 are rare. Simple example for a bell curve. This would do the combat results good, as results like 1,1,7,1,1,5,2,3,1 out of 1024 would then never happen - and in Civ3 I see them extremely often.

sumthinelse:

actually I meant that I see 'extreme' streaks v3ery often, like 10 attacking warriors (opponent: unfortified warrior, same HP, 10% terrain) win 8 fights, then it goes 1:1 for a while, then decidedly for the defenders - well take a standard map and this decides the game!

I'll mail you some of the results of the tests (need one more night of testing ) and the setup along with the .bix - I was quite shocked (once again) how 'random' the results are.

As for the example you chose: I see my swordsmen NOT taking the town (all three dead) far more often then not in some games - well, however well i played, a mortality of 50% against 1 defender is too much! Then again I win 10 fights in a row with less than 5% probability - however inept I am I can't help being successfull in these games

17. ### willebraChieftain

Joined:
Dec 4, 2002
Messages:
10
Location:
Finland
In Civ3, however, there is a feature that "remembers" (some)earlier combat results and which has been included in the game for what I think is the same reason that Plume started his comment.

It's the hitpoints (regulars 3 and so on). They actually reflect real world: badly damaged units cannot defend themselves as well as undamaged ones. Of course, if a unit doesn't lose any hitpoints and the other one loses all hitpoints, they won't "remember" anything. But this can happen in real world too (the Stalingrad example and many others).

Of course, one can make arguments that units should remember more (= they should have e.g. ten times as much hitpoints) or less (= e.g. only one hitpoint/unit).

It's true that in early game, when you have only a couple of units (let's say 6 units, on the average 3.5 hitpoints each, totalling to 21 hitpoints divided into 6 units) your army is much more affected by good/bad luck than later on (e.g. 210 hitpoints divided into 60 units). This is somewhat natural but not entirely, but it's a game (it isn't natural that several cilizations start with identical population at almost the same time either).

Personnally I think that units could (in the early game at least) "remember" more, i.e. have higher hitpoints, but towards later stages not (because otherwise "Stalingrad" will be too improbable). This should of course be somehow balanced so that the early units won't get any advantage in relation to later game units because of higher hitpoints.

But the math should be as random as possible and any "remebering" should be made by transparent, natural like mechanisms (like hitpoints).

18. ### anarresanarchist revolutionary

Joined:
Apr 22, 2002
Messages:
6,069
Location:
www.civ3duelzone.com
All this talk about bad luck in the early game being a bad think ignores the good luck inthe early game that lets you take the ememy that bit quicker.

Life is not uniform, and in the Ancient times, armies were smaller and the wins and losses greater. You make the game too easy if there is less randomness earlier on. Can you imagine if the spanish armarda hadn't been sunk? That would have changed history in a massive way for everyone (including you US people), and in the end it only happend from some very good favourable condition for the English, that would not have been repeated on a different day.

In short, if the weaker side never won, fighting would be boring.

@Lt. 'Killer' M:
I would like to see the results of your testing. I am not convinced that the good/bad luck streaks are so long, and without the normalising factor.

19. ### TheNiceOneEmperor

Joined:
Feb 6, 2002
Messages:
1,372
Location:
Norway
Killer: The average results are more common than extremes, this is accomplished by using hit points. It don't change the underlying numbers (as going from 1 to 2 dice would), but it changes the final outcome. As an example, consider a warrior, infantry and tank attack vs a rifleman. If all have the same number of HPs, the chances for attacker wins (disregarding any A/D modifiers) are:

1 HP:
Warrior: 14.3%
Ingantry: 50.0%
Tank: 72.7

2HP:
Warrior: 5.5%
Infantry: 50.0%
Tank: 81.8%

4HP:
Warrior: 0.9%
Infantry 50%
Tank: 90.7%

10 HP:
Warrior: < 0.1%
Infantry 50%
Tank: 98.3%

As you see (and I know you already knew this, Killer), adding HPs gets you exactly that: results where the extreme results become even less likely. Now I know that Killer has done this already, and if there was a way of doing this easily with ancient units only I would consider it as well.
Because I do think the randomness factor is a bit too high during the ancient age when there are very few units, and taking/loosing one city is much more important than later. During later ages the random factor is perfectly fine IMO.

BTW, if you flip a coin 10 times, you will get a streak of 4+ heads/tails almost 50% of the time, so real world randomness is streaky.

To sum up: There's two different things we're discussing.
* Whether the chance of a weak unit beating a stronger unit is too high (too much randomness)
* Whether the results are too streaky, that there are too many good or bad results in a row.

The first is subjective, and those that answer yes can do something about this by increasing the number of HP and/or increasing the A/D factors of stronger units.

The second is a basic result of true random results, and there's no way of taking away streakiness from results without adding a memory (i.e. increasing the chance of a good result after a bad one and vice versa).

20. ### Lt. 'Killer' M.Deity

Joined:
Dec 5, 2001
Messages:
7,475
TNO: I know, and you knew that 8and wrote that, too ), but my probelm is that too many battles are decided by too few HP.

Personally, I still prefer the doubled HP.

Overall, a two-dice system would probably have done Civ3 better IMO, considering I have seen several 3-elite-double-HP Cavalry armies die to single Spearmen in size 8 or so towns w/o river or any other bonus....

I'd say there is 1 freak result (freak, not luck) in each game, and if that is early one it can decide the game on a small map.....

not to say the AI is favored: yesterday 1 of my Sowordsmen in the open held back 6 Med Inf. and I got a leader. Freak! Playing on a tiny map wiht 3 cities per civ this broke Romes back!