Make damage() use roundavg()
Turns damage() into a one-liner. damage() now uses random() % 32768 in chance() instead of random() % 100 inline, therefore can round differently for the same pseudo-random number. Update expected smoke test results accordingly. Aside: "random() % n" distributes evenly only when n is a power of two. 100 isn't. However, because random() yields at least 31 bits, and 100 is so much smaller than 2^31, the error is vanishingly small.
This commit is contained in:
parent
5bf310e6b0
commit
c53158eee0
2 changed files with 5 additions and 12 deletions
|
@ -163,16 +163,9 @@ nukedamage(struct nchrstr *ncp, int range, int airburst)
|
|||
int
|
||||
damage(int amt, int pct)
|
||||
{
|
||||
int tmp;
|
||||
int lost;
|
||||
|
||||
if (amt <= 0)
|
||||
return 0;
|
||||
tmp = amt * pct;
|
||||
lost = tmp / 100;
|
||||
if (roll0(100) < tmp % 100)
|
||||
lost++;
|
||||
return amt - lost;
|
||||
return amt - roundavg(amt * (pct / 100.0));
|
||||
}
|
||||
|
||||
/* asymptotic damage to commodities, efficiency, and sectors */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue