Battles aren't random, they're scripted

Originally posted by Chieftess
I've noticed something else. Try this:

Save the game just before a battle (without doing any trades, negotiations, etc.)

Now, do a battle without any trades and/or negotiations/treaties, then do one with any combination of the above. (like peace treatiies, alliences, etc.). The RNG -will change-.

Chieftess, what we are talking about is really a string of random numbers, each one dependent on the previous one. I think we all agree that the results will change if you use the random numbers in a different order, but that does not prove that the string of random numbers itself changes. Your phenomenon could be caused by some random numbers that are "used up" by the diplomacy actions.

Why would a trade use up a random number? Maybe because that could change the resource balance, making some resources change in the AI's "valuation" and the game uses random numbers to determine the AIs' next trade action.
 
Originally posted by TheNiceOne

This is interesting. I've heard similar before, but never tested it myself (should be easy to find out exactly what kind of diplomacy that uses RNGs).

My first guess is that if the AI suggests a deal (either if they contact you or if you select "what would you need for the xxx"), then civ3 first calculates the minimum accepted trade value, and then adds something (it tries to ask for more than the minimum it will accept).
This added value may well be partly random. I.e., if you want to buy a tech and asks what the AI will need, it may suggest the minimum price + 5-10%, where the 5-10% is randomly selected.

This is just a guess though.

I think that Chieftess is suggesting you actually have to do a trade of some sort (correct me if I'm wrong Chieftess). After the trade, the AI needs to re-evaluate everybodies position, to take account of any changes following the trade. I assume this then changes the RNG. I have noticed that this works.
 
Originally posted by TheNiceOne

Dave, this is actually wrong, but its a common misconception. The human mind expects a list of random numbers to be more evenly distributed than real random numbers are. The civ RNG has been tested by people knowing what they're doing, and found that the RNG gives you results that closely follows truly random numbers. There's no more patterns to see in civ3 than if we had a 100% perfect random generator.

"humans expect random numbers more evenly distributed"-
I don't think about a misconception here. Having drawn enough numbers from the
generator should just show this equal distribution (at least for the number
itself). Then the number could be combined or compared with a weighting
function that depends on unit stats (ok, dunno if programmed this way, but
could be similar). Other spreadings like Gaussian, "Indescribable" or others
would't be easy to handle. IMO, the RNG draws an equal distibuted number
(if it wasn't, ai would "cheat"), but I agree that human mind can't overlook
that distibution. And as we put our on weightings on our observations (e.g.
we won't forget spearman beating tank, but can't remember every single
swordsman winning against warrior), we arrive at the conclusion of "cheating"
ai.
Besides...
Originally posted by DaveMcW
This has always been a problem with random-number generators. To save computing power, the generator uses a relatively simple formula to come up with the "random" number. This creates more patterns than a sequence of truly random numbers.
However, the generator is set up so results always average out over a large number of trials.

RNGs in general don't calculate by a certain formula but pick numbers out of
pre-made list (e.g. intrinsic routine "call random_number" in FORTRAN90)
because a comp simply doesn't know what random numbers are. This routine will
show always the same numbers in a row (the list) if no initialization (by
system time or sth.) is set. But again, making enough draws should give a
certain "fair" distribution and I am content with civ3's RNG so far...
*...hoping not to lose 5 tanks vs 1 spearman in future.*

PS: Maybe someone will start a thread about lucky battles...
 
Originally posted by pompeynunn
I think that Chieftess is suggesting you actually have to do a trade of some sort (correct me if I'm wrong Chieftess). After the trade, the AI needs to re-evaluate everybodies position, to take account of any changes following the trade. I assume this then changes the RNG. I have noticed that this works.
But the only thing that affects the RNG is its seed. Initially, the seed is probably made up by your system clock, so it will be different each time you start a new game. After that, the output from the RNG (the random number) is also used as the seed for the next RNG. So the only thing that changes the outcome of the RNG is the use of the RNG itself, i.e., the use of a random number.

If you sell the AI the tech it is currently researching, then it may use a random number to calculate its next research goal, so you may be right. I doubt all trades will trigger random numbers though.
 
I play RL DND, and have developed random number gnerators to ease and speed game processes while GM. Many of the players prefer to roll the dice themselves, because they *know* that the RNG is seriously flawed. Never rolls, 0, for example.
Mevernimd that as proof I generated a series of *random* numbers -- 10,000 -- to plot X and Y coordinates and put a dot on the screen...

Make that, 'never rolls a 1'
 
Originally posted by Grille
"humans expect random numbers more evenly distributed"-
I don't think about a misconception here. Having drawn enough numbers from the generator should just show this equal distribution (at least for the number itself). Then the number could be combined or compared with a weighting function that depends on unit stats (ok, dunno if programmed this way, but could be similar).
I don't fully understand what you mean here, but since you seem to disagree with me, I'll try to clarify what I meant:

Assume 10 knights attacking 10 pikemen that have enough defense bonuses to reach a defense of 4 (equal to the knight's attack). Now for each single attack round, the RNG calculates its next number (0-1023) and calculates whether this means a knight win or loss. Since my example had equal A and D, there will be 50% chance of win/loss every single attack round.

If there were 50 combat rounds and 25 wins/25 losses, then the most even distribution would be win-loss-win-loss etc. The most uneven distribution would be 25 wins followed by 25 losses. A true random distribution would be somewhere in the middle, but most humans expect something much closer to the perfectly even distribution than true random numbers will give you.

RNGs in general don't calculate by a certain formula but pick numbers out of pre-made list (e.g. intrinsic routine "call random_number" in FORTRAN90) because a comp simply doesn't know what random numbers are. This routine will show always the same numbers in a row (the list) if no initialization (by system time or sth.) is set. But again, making enough draws should give a certain "fair" distribution and I am content with civ3's RNG so far...*...hoping not to lose 5 tanks vs 1 spearman in future.*
This is wrong. There is a certain formula that calculates the random numbers. But since this formula is in itself non-random and uses its previous number as input for the next, it would be possible to create a list of the numbers it will give if you know the formula and the start number (seed). The rest of what you write is correct though.
 
Originally posted by TheNiceOne

If you sell the AI the tech it is currently researching, then it may use a random number to calculate its next research goal, so you may be right. I doubt all trades will trigger random numbers though.

Indeed, trading maps or resources does not seem to change combat outcomes. At least, not always.
 
The seed (32 bit) is calculated as follows

Code:
seed = (seed * 1103515245) + 12345

And as I said before, numerous tests have been done, and each and every one of them have showed that the PRNG works like it should. And that means that you sometimes will be extremely unlucky, just as you sometimes will be extremely lucky. The bias to the unlucky side is probably due to two factors:

1) It is easier to remember those "regular tank loses against fortified veteran spearman" (4.3%) than "regular infantry wins against fortified veteran infantry on hills" (4.1%)

2) You don't attack when your odds are bad, which means that you more seldom get the chance to see very lucky results.
 
And here is an important post from the other forum Link :

Originally posted by vulture
Since Hurricane mentioned in another thread what the basic pseudo-random number generator used by civ3 was, I decided to test it for 'streakiness'.

First off, the exact algorithm wasn't revealed, but linear congruent generators all work in the same way AFAIK. My implementation was as follows (in C):

unsigned int seed; /* global variable */

unsigned int prng(void)
{
unsigned long long dummy;
unsigned int tmp;

dummy = ((unsigned long long) seed * 1103515245) + 12345;
seed = dummy & 0xffffffff;
tmp = seed & 0xffc00000;
return(seed >> 22);
}

(on my machine, int is 32 bits, long long is 64 bits).

The bottom 32 bits of 'dummy' are kept as the next seed, and the higest 10 bits of seed are returned are to generate a random number between 0 and 1023 inclusive. As I understand it, this is how the civ3 PRNG works. If any of the programmers wish to correct me...

This PRNG generates a nice flat distribution, with all values being equally likely. The question for combat in civ3 is whether the generator is streaky - whether it has a tendency to produce say 3 or 4 low numbers in a row. Of course there are various tests that can be done on this, but I set it up to simulate 100,000,000 combats in civ3 between a 4 hp, 6.0 attack unit attacking a 4 hp 2.75 defense unit (i.e. an infantry attacking a fortified spearman across a river).

The test is to compare the final hp's left for the winner vs. the distribution expected if the numbers were perfectly random. If there is any streakiness in the random numbers, then we expect to see an excess of results where one of the units is left on 4 hp, and a defecit of results where the surviving unit is left on 1hp (a fact which I confirmed by running 10,000,000 combats with a PRNG with streakiness deliberately inserted).

The results for 100,000,000 battles fought (numbers given are the percentage chance of a given outcome).

spearman
hp left expected prob observed prob
1 6.249 6.249 +/- 0.003
2 4.551 4.550 +/- 0.002
3 2.652 2.650 +/- 0.002
4 0.966 0.967 +/- 0.001

infantry
hp left
1 13.686 13.691 +/- 0.004
2 21.829 21.824 +/- 0.005
3 27.854 27.855 +/- 0.005
4 22.214 22.215 +/- 0.005

The uncertainties quoted in the observed probabilities are 1 sigma errors (meaning that you'd expect the 'expected' and 'observed' values to match within this error in roughly 2/3 of the cases).

Pretty obviously, there is no significant deviation away from the prediction of purely random numbers (i.e. no streakiness). I also did a simulation with the spearman fighting 2 attackers in a row, which also showed no significant deviation from the expected distribution.

So, assuming my version of the civ3 PRNG is accurate, it is pretty safe to say that there is no undue streakiness causing strange combat results in civ3; whatever streakiness there is in the generator doesn't show up in 100,000,000 combats (probably 20,000-200,000 games worth, depending on how often you go to war).


So, if you are convinced that you are getting unusual results too often, then you'll have to chalk it up to either a bug or a deliberate cheat on the part of the programmers (or more plausbily, the fact that our 'natural' understanding of randomness *very* badly underestimates the number of long streaks of odd results you can get).
 
There are many other types of random number generators, other than LCG, e.g. multiplicative, inversive, etc. Is there any basis for believing that Civ3 uses LCG?

Anyway, if you can see any (real, not imagined) patterns in the random numbers generated by Civ3, you're probably John Nash (and a very hardcore Civ player to boot :) )
 
Originally posted by TheNiceOne

I don't fully understand what you mean here, but since you seem to disagree with me, I'll try to clarify what I meant:
Assume 10 knights attacking 10 pikemen that have enough defense bonuses to reach a defense of 4 (equal to the knight's attack). Now for each single attack round, the RNG calculates its next number (0-1023) and calculates whether this means a knight win or loss. Since my example had equal A and D, there will be 50% chance of win/loss every single attack round.
If there were 50 combat rounds and 25 wins/25 losses, then the most even distribution would be win-loss-win-loss etc. The most uneven distribution would be 25 wins followed by 25 losses. A true random distribution would be somewhere in the middle, but most humans expect something much closer to the perfectly even distribution than true random numbers will give you.

This is wrong. There is a certain formula that calculates the random numbers. But since this formula is in itself non-random and uses its previous number as input for the next, it would be possible to create a list of the numbers it will give if you know the formula and the start number (seed). The rest of what you write is correct though.

I wasn't bearing on a sample's distribution like this 10 knights example.
But it's a nice example since A and D values are the same, we need no
-probably confusing- weighting by these unit stats.
Take 1000 knights & pikemen and get (very likely) 50% chance on win/loss
(if knights couldn't retreat). Then our random numbers are in fact disributed
evenly and this is fair and a must. So this what I meant by evenly distributed
random numbers. I was confused about "more evenly distributed than real random
numbers are" - but in the end I think we got the same point of view.--
about the calculation formula:
At least in mentioned FORTRAN90 subroutine, the "drawn" numbers (supposed to be
distributed evenly) aren't calculated but picked out of list. Here is an
example (maybe someone has a f90 compiler to reconstruct):

!_______________
program test
implicit none
integer::i
real::a

do i=1,10
call random_number(a) !"draw" number
print*,a !put on screen
enddo

end program test
!_______________

I compile on my machine and I ALWAYS get these numbers any
time I run the program in this order:
3.9208680E-07
2.5480442E-02
0.3525161
0.6669145
0.9630555
0.8382882
0.3353550
0.9153272
0.7958636
0.8326931

Of course I can get different numbers in other order by initialisation
by time and then I have a useful sort of RNG.
But it's definitely a "list"-thing, no formula (and as Hurrican stated,
comp-RNGs are "pseudo-RNGs").
edit: sorry, should have made 2 quotes; second abstract of quote doesn't refer to first, of course
 
Grille, that Fortran90 subroutine uses a seed number to calculate the next number also (that's why if it is seeded by time (or any other method) it produces a different set). I don't know why you think the number comes from a list.

Topic: I think in Civ3 that the random number generator is just fine [I guess someone would have to define scripted to me :)], however, how those numbers are used may cause some of the abnormalities that can be seen at times. Using those random numbers in formulas that are changing based on events and game situations that occur in the game can cause results to appear lopsided at times. Each formula that is used by the game; battles, diplomacy, and discovery (and more) should have their own random number generator so the random number sequence is not contaminated by the use of other game facets.
 
Originally posted by Bismarck
There are many other types of random number generators, other than LCG, e.g. multiplicative, inversive, etc. Is there any basis for believing that Civ3 uses LCG?

This is a fact. Maybe you should try to read the thread in the link I provided. :rolleyes:
 
Hurricane: Thanks for providing the link. I tried all the search words I could think of but couldn't find it (I see I used genarate instead of generator as search word though).


Grille, I see what you mean now. What I meant by "evenly distributed" was the opposite of "streakiness" if you see what I mean. There have been numerous complains about too many instances of one side loosing 4 HP in a row and then the other 4 in a row etc, while the truth is that this is exactly what one should expect to happen quite often with true random numbers.
 
Originally posted by Hurricane


This is a fact. Maybe you should try to read the thread in the link I provided. :rolleyes:

No need to be defensive. I did not follow the link, since I don't always follow every link out of every post I respond to.
 
Well maybe I am just being psychic and all, but I think I often predict which unit takes the next point of damage--but I think this has more to do with following the animation and so forth.
 
Well I know something dodgy is certainly going on in my current game:

I was fighting is archers or something, both me and my enemy each had 4 health bars each.

I Hit
I Hit
I Hit
Get Hit
Get Hit
Get Hit
Get Hit
Die

I'm not exagerating when I say this exact sequence happened 8 times in a row, and overall in the battle about 14 out of 20 times.

Now THAT isn't random :)

The same was happening when they attacked me, I successfully defended 3 times then got hit 4 times and died. Lost my entire fookin force and he (AI) lost about 4/5 units. - Only on regent difficulty too.

From what I could see everytime I got the first 2 hits it followed the sequence above. However my other games are fine, which suggests there may be a bug somewhere or something due to the seed value for that game?
 
Grille, that Fortran90 subroutine uses a seed number to calculate the next number also (that's why if it is seeded by time (or any other method) it produces a different set). I don't know why you think the number comes from a list.

There are random number generators that use lists. I don't know of any that are used in computer programs since its just so darn nice and easy to use a formula instead. However, in the days before computing they used to generate random numbers using a list. One time a math teacher showed us one of these lists in the back of our textbook.. I thought "How quaint." Hehe. Of course you could always use dice or something to get the random numbers but for experiments I guess it was important that other people could use your same seed and generate the same numbers as you to verify experiments and proofs.

Now how do you use lists in a textbook to get random numbers? I don't remember. ;)
 
You will often see the same patterns if you are often faced with battles between the same type of units on the same type of terrain.
 
Back
Top Bottom