Author: Dieter Buerssner
Date: 11:52:41 07/26/03
Go up one level in this thread
On July 24, 2003 at 23:46:50, Tom Kerrigan wrote:
>int result(int r1, int r2)
>{
> double p;
> int r;
>
> p = (double)(r2 - r1);
> p /= 400.0;
> p = pow(10.0, p);
> p += 1.0;
> p = 1.0 / p;
> p *= 100.0;
> r = rand() % 101;
> if (r < (int)p)
> r = 2;
> else if (r == (int)p)
> r = 1;
> else
> r = 0;
>#ifdef DEBUG
> printf("%d vs. %d, winning percentage %f, r: %d\n", r1, r2, p, r);
>#endif
> return r;
>}
This is slightly flawed. But I think, it makes no bíg difference in this case,
it just hurts my eyes:-) You use 101 numbers, when 100 would be better. But one
can do it more elegant and exact, and while doing this even avoid that %
naturally. Because 101 is a prime, the % has a good chance to be not that bad in
this case, but in general one should really avoid it with a random number
generator, that one does not know well. (Dann used %, too, but he used a very
good PRNG).
Even very simple simulations can go wrong big time, when using a bad PRNG
combined with %.
Anyway, my suggestion would be something like (totally untested):
int result(int r1, int r2)
{
double p, pw, pd; /* Result from Elo formula, wins, draws */
double x;
int r;
p = (double)(r2 - r1);
p /= 400.0;
p = pow(10.0, p);
p += 1.0;
p = 1.0 / p;
/* When erf available the better formula is:
(Note, in Standard C 99 erf is included) */
/* p = 0.5 + 0.5*erf((r2-r1)/400.); */
/* Just give some wins and draws, for example for
p = 0.8, we use pd = 0.2 and pw = 0.7
for p = 0.5, use pd = 0.5 and pw = 0.25, etc. */
if (p > 0.5)
pd = 1.0-p;
else
pd = p;
pw = p-0.5*pd;
/* Random number between 0.0 (inclusive) and 1.0 (exclusive) */
x = rand() / (RAND_MAX+1.0);
if (x < pw)
r = 2;
else if (x < pw+pd)
r = 1;
else
r = 0;
return r;
}
BTW. Has anybody a good suggestion how wins/draws/losses should be distributed
(perhaps even taking color into account)?
Regards,
Dieter
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.