Playout ELO: Use the BOARD_GAMMA probdist within playout if available
[pachi.git] / probdist.h
blobaddf2adbb57c8ed582af152b1e5d78cb15de038b
1 #ifndef ZZGO_PROBDIST_H
2 #define ZZGO_PROBDIST_H
4 /* Tools for picking an item according to a probability distribution. */
6 /* The probability distribution structure is designed to be once
7 * initialized, then random items assigned a value repeatedly and
8 * random items picked repeatedly as well. */
10 #include "move.h"
11 #include "util.h"
13 /* The interface looks a bit funny-wrapped since we used to switch
14 * between different probdist representations. */
16 struct probdist {
17 int n;
18 float *items; // [n], items[i] = P(pick==i)
19 float total;
21 #define probdist_total(pd) ((pd)->total)
22 #define probdist_one(pd, i) ((pd)->items[i])
24 static void probdist_set(struct probdist *pd, int i, float val);
26 int probdist_pick(struct probdist *pd);
29 /* We disable the assertions here since this is quite time-critical
30 * part of code, and also the compiler is reluctant to inline the
31 * functions otherwise. */
32 static inline void
33 probdist_set(struct probdist *pd, int i, float val)
35 #if 0
36 assert(i >= 0 && i < pd->n);
37 assert(val >= 0);
38 #endif
39 pd->total += val - pd->items[i];
40 pd->items[i] = val;
43 #endif