Originally posted by akots
I don't understand what you are talking about. Either you have to read something to understand the subject, or please make it more understandable in standard terms and may be equations. I don't see any rounding problem or any other problem at all with pRNG. There is no need for rounding. The cube can have as many sides as you want. It is a simulation after all...
Gladly!
Ok, please allow me to start with a general comment.
Combat in Civ is at least to a certain degree a simulation of what has happened or would have happened in the real world. For that reason, units have different unit stats.
If only these unit stats would be taken into account, a swordsman would win every time vs a spearman. As we all agree (at least the vast majority), this doesn't reflect our experience from history and real life. So, there has to be a feature to add unexpected outcomes of a battle between two given units. This is done via making use of the RNG.
Now, we have the combat stats and the RNG number. As we learned in CivI, that would cause annoying effects over and over (the famous battleship - spearman).
To level this, hitpoints have been added. Obviously, the expectation was that hitpoints would cause those "unexpected" results to happen seldom enough.
Nevertheless, at least a significant minority of players still complains, since they feel to observe so-called "streaks".
How may those streaks appear? (Under the assumption, that they are real, and not only a perception problem of the individual player)
That is, where my attempts to explain (see my previous posts) started.
If we were to roll a n-sided die and did this often enough, we would expect any of the numbers to appear 1/n times.
Let us stay with the 6-sided die, for making the understanding easier. With a given (very large) number of rolls, each number of the die is expected to appear 1/6 times of the total of rolls. So far, so good.
Now, this rolling of the die is to be simulated with a RNG.
A RNG will not come back with a value of 1, 2, ...., 6, but with a number in the interval of 0 to 0.9999 (actually, it will be 0.9999999... , depending on the bits reserved for it).
So, the RNG is expected to have 10,000 different values to offer as result, running from 0 to 0.1666 (!) as complement to the die's 1, 0.1667 (!) to 0.3332 as complement to the die's 2 .. and so on.
Now, depending on the calculation of the relation between attack and defense values, we may see that there are rounding problems.
Under the assumption that the attacker has A=4 and the defender has D=2 (no modifiers as fortification, defense value of the terrain, attack across a river are taken into account for the moment), the formula is: A/(A+D) = 4/(4+2) = 4/6.
So, any result of the RNG being in the sub-interval of 0 to 0.6664 would count as a win, everything in the sub-interval of 0.6665 to 0.9999 would be a loss.
As our combat formula tells us, the probability for a loss is 2/6 = 1/3.
If we calculate the probability of a loss as "counter-win", for the RNG it would be 0.9999 - 0.6664 = 0.3335 (!)
This already is a difference of 2/10.000
(Again, please take notice that the figures are very much simplified. Real figures will be much lower)
If we would assume that rounding takes place at the third decimal place (due to transforming integers into floats), the "counter-win" becomes 0.334 (!)
Now, we calculate again: 0.9999 - 0.334 = 0.6659 (upper threshold for a win)
This makes a difference of
0.6659 -0.6664 = 0.0005 => 0.05%
0.05% seem to be very low. Actually, it is very low.
Nevertheless, it is already an inaccuracy.
Now we will add the modifiers into the formula.
We have an attacker with A=4, and a fortified defender with D=2, sitting on the other bank of the river on plains.
The probability for a win would be:
4/(4+(2*(1+(0.25[fortified]+0.25[river]+0.1[plains])) =
4/(4+(2*(1+0.6)) = 4/(4+3.2) = 4/7.2 => 0.5556
Again, this may result in a win to be any number in the sub-interval of 0 to 0.5556 or in the sub-interval of 0 to (1-(0.9999 - 0.5556))=0.5557.
So, depending how the range for a win is calculated, we have already differences. You may look at it "bottom-up" or "upside-down" and will get different results for the probability.
If still the rounding would happen at the third decimal, we would have 0.556 or (1-(0.9999-0.556))=0.5561 or (1-(0.999-0.556))=0.557.
So, the biggest error due to rounding would be between the 0.5556 and the 0.557. It would be 0.0014 => 0,14 %
All this stands true under the assumption, that the divisor in our example is correctly translated into a float. Is it?
If our formula would be:
4/(4+3[3.2 not being a float, but kept as integer]) = 4/7
the range for the win would be: 0 to 0.5714 (of course, at a certain point we will have floats, forced by the use of the RNG)
Now, we would face a difference of
0.5556 - 0.5714 = - 0.0158 => 1.58 % difference.
Without taking into consideration, that the attacker could be an army with pentagon (0.1666 multiplier) under the influence of a radar tower (0.25 multiplier) what really would make for a worst case scenario, we may assume that both units are veterans.
So, the battle could last for 7 internal rounds (wwwlllw or the like). 7*1.58% = 11.06% difference!
Of course, here I assumed that the results of the RNG would always be around 0.5556 +/- 0.0001, just to make for the rounding differences.
Bottom line:
The whole example of course is just to display that the combat results are depending on:
a) when integers are transformed into floats
b) when rounding will occur (that is, how much decimals of the floats will be used)
c) how the interval in which the RNG results will be, is divided up into win and loss
[edit] Ok, since I am not willing to take responsibility for your death, I will give you some time to drink your milk
[second edit] All the above was under the assumption that we will have perfect random numbers. About the random numbers I might continue, if you wish....