forked from michiguel/Ordo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rating.c
795 lines (670 loc) · 18.9 KB
/
rating.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
/*
Ordo is program for calculating ratings of engine or chess players
Copyright 2013 Miguel A. Ballicora
This file is part of Ordo.
Ordo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Ordo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Ordo. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include "rating.h"
#include "encount.h"
#include "indiv.h"
#include "xpect.h"
#include "datatype.h"
#include "mymem.h"
#include "fit1d.h"
#include "mytimer.h"
#define START_DELTA 100
#define MIN_DEVIA 0.0000001
#define MIN_RESOL 0.000001
#define START_RESOL 10.0
#define ACCEPTABLE_RESOL MIN_RESOL
#define PRECISIONERROR (1E-16)
#define DRAWRATE_RESOLUTION 0.0000001
#if !defined(NDEBUG)
static bool_t is_nan (double x) {if (x != x) return TRUE; else return FALSE;}
#endif
static double adjust_drawrate (double start_wadv, const double *ratingof, gamesnum_t n_enc, const struct ENC *enc, double beta);
static void
ratings_copyto (player_t n_players, const double *r_fr, double *r_to)
{
player_t j;
for (j = 0; j < n_players; j++) {
r_to[j] = r_fr[j];
}
}
// no globals
static double
deviation (player_t n_players, const bool_t *flagged, const double *expected, const double *obtained, const gamesnum_t *playedby)
{
double accum = 0;
double diff;
player_t j;
for (accum = 0, j = 0; j < n_players; j++) {
if (!flagged[j]) {
diff = expected[j] - obtained [j];
accum += diff * diff / (double)playedby[j];
}
}
assert(!is_nan(accum));
return accum;
}
// no globals
static double
unfitness ( const struct ENC *enc
, gamesnum_t n_enc
, player_t n_players
, const double * ratingof
, const bool_t * flagged
, double white_adv
, double beta
, const double * obtained
, const gamesnum_t *playedby
, double * expected /*@out@*/
)
{
double dev;
calc_expected (enc, n_enc, white_adv, n_players, ratingof, expected, beta);
dev = deviation (n_players, flagged, expected, obtained, playedby);
assert(!is_nan(dev));
return dev;
}
static double
calc_excess ( player_t n_players
, const bool_t *flagged
, double general_average
, const double *ratingof)
{
player_t j, notflagged;
double accum, average, excess;
for (notflagged = 0, accum = 0, j = 0; j < n_players; j++) {
if (!flagged[j]) {
notflagged++;
accum += ratingof[j];
}
}
average = accum /(double) notflagged;
excess = average - general_average;
return excess;
}
static void
correct_excess ( player_t n_players
, const bool_t *flagged
, double excess
, double *ratingof)
{
player_t j;
for (j = 0; j < n_players; j++) {
if (!flagged[j]) ratingof[j] -= excess;
}
return;
}
// no globals
static double
adjust_rating ( double delta
, double kappa
, player_t n_players
, player_t anchored_n
, const bool_t *flagged
, const bool_t *prefed
, const double *expected
, const double *obtained
, const gamesnum_t *playedby
, double *ratingof /*@out@*/
)
{
player_t j;
double d;
double y = 1.0;
double ymax = 0;
assert (kappa > 0);
/*
| 1) delta and 2) kappa control convergence speed:
| Delta is the standard increase/decrease for each player
| But, not every player gets that "delta" since it is modified by
| by multiplier "y". The bigger the difference between the expected
| performance and the observed, the bigger the "y". However, this
| is controled so y won't be higher than 1.0. It will be asymptotic
| to 1.0, and the parameter that controls how fast this saturation is
| reached is "kappa". Smaller kappas will allow to reach 1.0 faster.
*/
for (j = 0; j < n_players; j++) {
assert(flagged[j] == TRUE || flagged[j] == FALSE);
assert(prefed [j] == TRUE || prefed [j] == FALSE);
if (flagged[j])
continue;
if (anchored_n > 1) {
if ( flagged[j] // player previously removed
|| prefed[j] // already set, one of the multiple anchors
) continue;
}
assert(playedby[j] > 0);
// find multiplier "y"
d = (expected[j] - obtained[j]) / (double)playedby[j];
d = d < 0? -d: d;
y = d / (kappa + d);
if (y > ymax) ymax = y;
// execute adjustment
if (expected[j] > obtained [j]) {
ratingof[j] -= delta * y;
} else {
ratingof[j] += delta * y;
}
assert(!is_nan(ratingof[j]));
}
// Return maximum increase/decrease ==> "resolution"
return ymax * delta;
}
// no globals
static void
adjust_rating_byanchor (player_t anchor, double general_average, player_t n_players, double *ratingof /*@out@*/)
{
player_t j;
double excess = ratingof[anchor] - general_average;
for (j = 0; j < n_players; j++) {
ratingof[j] -= excess;
}
}
//========================= WHITE ADVANTAGE FUNCTIONS ===========================
static void
white_cal_obt_tot ( gamesnum_t n_enc
, const struct ENC *enc
, const double *ratingof
, double beta
, double wadv
, double *pcal /*@out@*/
, double *pobt /*@out@*/
, gamesnum_t *ptot /*@out@*/
)
{
gamesnum_t e, t, total=0;
player_t w, b;
double f;
double W,D;
double cal, obt; // calculated, obtained
for (cal = 0, obt = 0, e = 0; e < n_enc; e++) {
w = enc[e].wh;
b = enc[e].bl;
W = (double)enc[e].W;
D = (double)enc[e].D;
t = enc[e].W + enc[e].D + enc[e].L;
f = xpect (ratingof[w] + wadv, ratingof[b], beta);
obt += W + D/2;
cal += f * (double)t;
total += t;
}
*pcal = cal;
*pobt = obt;
*ptot = total;
return;
}
static double
overallerrorE_fwadv (gamesnum_t n_enc, const struct ENC *enc, const double *ratingof, double beta, double wadv)
{
gamesnum_t tot;
double cal, obt; // calculated, obtained
double dp2;
white_cal_obt_tot (n_enc, enc, ratingof, beta, wadv, &cal, &obt, &tot);
dp2 = (cal - obt) * (cal - obt);
return dp2/(double)tot;
}
struct UNFITWADV {
gamesnum_t n_enc;
const struct ENC *enc;
const double *ratingof;
double beta;
};
static double
unfit_wadv (double x, const void *p)
{
double r;
const struct UNFITWADV *q = p;
assert(!is_nan(x));
r = overallerrorE_fwadv (q->n_enc, q->enc, q->ratingof, q->beta, x);
assert(!is_nan(r));
return r;
}
static double
adjust_wadv (double start_wadv, const double *ratingof, gamesnum_t n_enc, const struct ENC *enc, double beta, double start_delta)
{
double delta, wa, ei, ej, ek;
struct UNFITWADV p;
delta = start_delta;
wa = start_wadv;
p.n_enc = n_enc;
p.enc = enc;
p.ratingof = ratingof;
p.beta = beta;
do {
ei = unfit_wadv (wa - delta, &p);
ej = unfit_wadv (wa + 0 , &p);
ek = unfit_wadv (wa + delta, &p);
if (ei >= ej && ej <= ek) {
wa = quadfit1d (MIN_RESOL, wa - delta, wa + delta, unfit_wadv, &p);
break;
} else
if (ej >= ei && ei <= ek) {
wa -= delta;
delta *= 1.5;
} else
if (ei >= ek && ek <= ej) {
wa += delta;
delta *= 1.5;
}
} while (
delta > MIN_RESOL
&& -1000 < wa && wa < 1000
);
return wa;
}
//=================== DRAW RATE FUNCTIONS ===============================
static double
overallerrorE_fdrawrate (gamesnum_t n_enc, const struct ENC *enc, const double *ratingof, double beta, double wadv, double dr0)
{
gamesnum_t e;
player_t w, b;
double dp2, f;
double W,D,L;
double cal, obt; // calculated, obtained
double dexp;
for (cal = 0, obt = 0, e = 0; e < n_enc; e++) {
w = enc[e].wh;
b = enc[e].bl;
W = (double)enc[e].W;
D = (double)enc[e].D;
L = (double)enc[e].L;
f = xpect (ratingof[w] + wadv, ratingof[b], beta);
dexp = draw_rate_fperf (f, dr0);
obt += D;
cal += dexp * (W + D + L);
}
dp2 = (cal - obt) * (cal - obt);
return dp2;
}
struct UNFITDRAWRATE {
gamesnum_t n_enc;
const struct ENC *enc;
const double *ratingof;
double beta;
double wadv;
};
static double
unfit_drawrate (double x, const void *p)
{
double r;
const struct UNFITDRAWRATE *q = p;
assert(!is_nan(x));
r = overallerrorE_fdrawrate (q->n_enc, q->enc, q->ratingof, q->beta, q->wadv, x);
assert(!is_nan(r));
return r;
}
static double
adjust_drawrate (double start_wadv, const double *ratingof, gamesnum_t n_enc, const struct ENC *enc, double beta)
{
double delta, ei, ej, ek, dr;
double lo,hi;
struct UNFITDRAWRATE p;
p.n_enc = n_enc;
p.enc = enc;
p.ratingof = ratingof;
p.beta = beta;
p.wadv = start_wadv;
delta = 0.5;
dr = 0.5;
do {
ei = unfit_drawrate (dr - delta, &p);
ej = unfit_drawrate (dr + 0 , &p);
ek = unfit_drawrate (dr + delta, &p);
if (ei >= ej && ej <= ek) {
dr = quadfit1d (DRAWRATE_RESOLUTION, dr - delta, dr + delta, unfit_drawrate, &p);
break;
} else
if (ej >= ei && ei <= ek) {
dr -= delta;
delta *= 1.1;
} else
if (ei >= ek && ek <= ej) {
dr += delta;
delta *= 1.1;
}
hi = dr+delta > 1.0? 1.0: dr+delta;
lo = dr-delta < 0.0? 0.0: dr-delta;
dr = (hi+lo)/2;
delta = (hi-lo)/2;
} while (delta > DRAWRATE_RESOLUTION);
return dr;
}
//============ CENTER ADJUSTMENT FUNCTIONS ==================================
static void
mobile_center_apply_excess (double excess, player_t n_players, const bool_t *flagged, const bool_t *prefed, double *ratingof)
{
player_t j;
assert(!is_nan(excess));
for (j = 0; j < n_players; j++) {
if (!flagged[j] && !prefed[j]) {
ratingof[j] += excess;
}
}
return;
}
static double
unfitness_fcenter ( double excess
, const struct ENC *enc
, gamesnum_t n_enc
, player_t n_players
, const double *ratingof
, const bool_t *flagged
, const bool_t *prefed
, double white_adv
, double beta
, double * obtained
, double * expected
, gamesnum_t * playedby
, double *ratingtmp)
{
double u;
assert(!is_nan(excess));
ratings_copyto (n_players, ratingof, ratingtmp);
mobile_center_apply_excess (excess, n_players, flagged, prefed, ratingtmp);
u = unfitness ( enc
, n_enc
, n_players
, ratingtmp
, flagged
, white_adv
, beta
, obtained
, playedby
, expected
);
assert(!is_nan(u));
return u;
}
static double absol(double x) {return x >= 0? x: -x;}
struct UNFITPAR {
const struct ENC * enc;
gamesnum_t n_enc;
player_t n_players;
const double * ratingof;
const bool_t * flagged;
const bool_t * prefed;
double white_adv;
double beta;
double * obtained;
double * expected;
gamesnum_t * playedby;
double * ratingtmp;
};
static double
unfitf (double x, const void *p)
{
double r;
const struct UNFITPAR *q = p;
assert(!is_nan(x));
r = unfitness_fcenter ( x
, q->enc, q->n_enc, q->n_players, q->ratingof, q->flagged, q->prefed
, q->white_adv, q->beta, q->obtained, q->expected, q->playedby, q->ratingtmp);
assert(!is_nan(r));
return r;
}
static double
optimum_centerdelta ( double start_delta
, double resolution
, const struct ENC *enc
, gamesnum_t n_enc
, player_t n_players
, const double * ratingof
, const bool_t * flagged
, const bool_t * prefed
, double white_adv
, double beta
, double * obtained
, double * expected
, gamesnum_t * playedby
, double * ratingtmp
)
{
double lo_d, hi_d;
struct UNFITPAR p;
p.enc = enc;
p.n_enc = n_enc;
p.n_players = n_players;
p.ratingof = ratingof;
p.flagged = flagged;
p.prefed = prefed;
p.white_adv = white_adv;
p.beta = beta;
p.obtained = obtained;
p.expected = expected;
p.playedby = playedby;
p.ratingtmp = ratingtmp;
lo_d = start_delta - 1000;
hi_d = start_delta + 1000;
assert(!is_nan(resolution));
assert(!is_nan(lo_d));
assert(!is_nan(hi_d));
return quadfit1d (resolution, lo_d, hi_d, unfitf, &p);
}
//============ MAIN RATING FUNCTION =========================================
#if 0
static double
ratings_rmsd(player_t n, double *a, double *b)
{
player_t i;
double d, res;
double acc = 0;
for (i = 0; i < n; i ++) {
d = a[i] - b[i];
acc = d * d;
}
res = sqrt(acc/(double)n);
return res;
}
#endif
static double
get_outputdev (double curdev, gamesnum_t n_games)
{
return 1000*sqrt(curdev/(double)n_games);
}
gamesnum_t
calc_rating_ordo
( bool_t quiet
, bool_t adjust_white_advantage
, bool_t adjust_draw_rate
, bool_t anchor_use
, double *ratingtmp_buffer
, double BETA
, double general_average
, player_t anchor
, struct ENCOUNTERS *encount
, struct PLAYERS *plyrs
, struct GAMES *g
, struct RATINGS *rat
, double *pWhite_advantage
, double *pDraw_date
)
{
gamesnum_t n_games = g->n;
double * ratingtmp = ratingtmp_buffer;
double olddev, curdev;
int i;
int rounds;
double delta;
double kappa;
double damp_delta;
double damp_kappa;
double KK_DAMP;
int phase;
int n;
double resol;
int max_cycle;
int cycle;
double white_adv = *pWhite_advantage;
double wa_previous = *pWhite_advantage;
double wa_progress = START_DELTA;
double min_devia = MIN_DEVIA;
double draw_rate = *pDraw_date;
double * expected = NULL;
// translation variables for refactoring ------------------
struct ENC * enc = encount->enc;
gamesnum_t n_enc = encount->n;
player_t n_players = plyrs->n;
int * Performance_type= plyrs->performance_type;
bool_t * flagged = plyrs->flagged;
bool_t * prefed = plyrs->prefed;
const char ** name = plyrs->name;
double * obtained = rat->obtained;
gamesnum_t * playedby = rat->playedby;
double * ratingof = rat->ratingof;
double * ratingbk = rat->ratingbk;
player_t anchored_n = plyrs->anchored_n;
//----------------------------------------------------------
//double RAT[20000];
assert(ratings_sanity (n_players, ratingof));
if (NULL == (expected = memnew(sizeof(double) * (size_t)(n_players+1)))) {
fprintf(stderr, "Not enough memory to allocate all players\n");
exit(EXIT_FAILURE);
}
max_cycle = adjust_white_advantage? 4: 1;
for (resol = START_RESOL, cycle = 0;
resol > ACCEPTABLE_RESOL || (cycle < max_cycle && wa_progress > 0.01);
cycle++) {
bool_t done = FALSE;
KK_DAMP = 1000;
rounds = 10000;
delta = START_DELTA;
kappa = 0.05;
damp_delta = 1.1;
damp_kappa = 1.0;
phase = 0;
n = 1000;
calc_obtained_playedby(enc, n_enc, n_players, obtained, playedby);
assert(playedby_sanity (n_players, playedby, flagged));
olddev = curdev = unfitness ( enc, n_enc, n_players, ratingof, flagged, white_adv, BETA, obtained, playedby, expected);
if (!quiet) printf ("\nConvergence rating calculation (cycle #%d)\n\n", cycle+1);
if (!quiet) printf ("%3s %4s %12s%14s\n", "phase", "iteration", "deviation","resolution");
while (!done && n-->0) {
bool_t failed = FALSE;
double kk = 1.0;
double cd;
double last_cd = 100;
assert(ratings_sanity (n_players, ratingof)); //%%
// adjust white advantage and draw rate at the beginning
if (adjust_white_advantage) {
white_adv = adjust_wadv (white_adv, ratingof, n_enc, enc, BETA, resol);
wa_progress = wa_previous > white_adv? wa_previous - white_adv: white_adv - wa_previous;
wa_previous = white_adv;
}
if (adjust_draw_rate) {
draw_rate = adjust_drawrate (white_adv, ratingof, n_enc, enc, BETA);
}
for (i = 0; i < rounds && !done && !failed; i++) {
cd = 0;
ratings_copyto (n_players, ratingof, ratingbk); // backup
olddev = curdev;
assert(ratings_sanity (n_players, ratingof)); //%%
assert(playedby_sanity (n_players, playedby, flagged)); //%%
resol = adjust_rating
( delta
, kappa*kk
, n_players
, anchored_n
, flagged
, prefed
, expected
, obtained
, playedby
, ratingof
);
curdev = unfitness ( enc, n_enc, n_players, ratingof, flagged, white_adv, BETA, obtained, playedby, expected);
failed = curdev >= olddev;
if (failed) {
ratings_copyto (n_players, ratingbk, ratingof); // restore
curdev = unfitness ( enc, n_enc, n_players, ratingof, flagged, white_adv, BETA, obtained, playedby, expected);
assert (i == 0 || absol(curdev-olddev) < PRECISIONERROR ||
!fprintf(stderr, "i=%d, curdev=%.10e, olddev=%.10e, diff=%.10e\n", i, curdev, olddev, olddev-curdev));
} else {
cd = 0; // includes the case (anchor_use && anchored_n == 1)
if (anchored_n > 1) {
cd = optimum_centerdelta
( last_cd
, MIN_RESOL
, enc
, n_enc
, n_players
, ratingof
, flagged
, prefed
, white_adv
, BETA
, obtained
, expected
, playedby
, ratingtmp
);
}
last_cd = cd;
if (absol(cd) > MIN_RESOL) {
mobile_center_apply_excess (cd, n_players, flagged, prefed, ratingof);
}
curdev = unfitness ( enc, n_enc, n_players, ratingof, flagged, white_adv, BETA, obtained, playedby, expected);
kk *= (1.0-1.0/KK_DAMP); //kk *= 0.995;
}
done = get_outputdev (curdev, n_games) < min_devia && (absol(resol)+absol(cd)) < MIN_RESOL;
} // end rounds
delta /= damp_delta;
kappa *= damp_kappa;
if (!quiet) {
printf ("%3d %7d %16.9f", phase, i, get_outputdev (curdev, n_games));
printf ("%14.5f", resol);
// printf ("%10.5lf",ratings_rmsd(n_players, ratingof, RAT));
printf ("\n");
}
phase++;
} // end n-->0
if (!quiet) printf ("done\n");
if (adjust_white_advantage) {
white_adv = adjust_wadv (white_adv, ratingof, n_enc, enc, BETA, resol);
wa_progress = wa_previous > white_adv? wa_previous - white_adv: white_adv - wa_previous;
wa_previous = white_adv;
}
if (adjust_draw_rate) {
draw_rate = adjust_drawrate (white_adv, ratingof, n_enc, enc, BETA);
}
if (!quiet) printf ("\nWhite Advantage = %.1f", white_adv);
if (!quiet) printf ("\nDraw Rate (eq.) = %.1f %s\n\n", 100*draw_rate, "%");
if (anchored_n == 1 && anchor_use)
adjust_rating_byanchor (anchor, general_average, n_players, ratingof);
} //end cycles
if (anchored_n == 0) {
double excess = calc_excess (n_players, flagged, general_average, ratingof);
correct_excess (n_players, flagged, excess, ratingof);
}
timelog("Post-Convergence rating estimation...");
encounters_calculate(ENCOUNTERS_FULL, g, flagged, encount);
enc = encount->enc;
n_enc = encount->n;
calc_obtained_playedby(enc, n_enc, n_players, obtained, playedby);
timelog("rate_super_players...");
rate_super_players(quiet, enc, n_enc, Performance_type, n_players, ratingof, white_adv, flagged, name, draw_rate, BETA);
encounters_calculate(ENCOUNTERS_NOFLAGGED, g, flagged, encount);
enc = encount->enc;
n_enc = encount->n;
calc_obtained_playedby(enc, n_enc, n_players, obtained, playedby);
timelog("done with rating calculation.");
*pWhite_advantage = white_adv;
*pDraw_date = draw_rate;
memrel(expected);
return n_enc;
}