pattern_match_spatial(): Use the incrementally matched hashes
[pachi/json.git] / probdist.h
blobb9a9f6f75e00dcdaefb134a51e2845490fd82826
1 #ifndef ZZGO_PROBDIST_H
2 #define ZZGO_PROBDIST_H
4 /* Tools for picking a move according to a probability distribution. */
6 #include "move.h"
8 struct probdist {
9 int bsize2;
10 float *moves; // [bsize2]
11 float total;
14 struct probdist *probdist_init(struct probdist *pd, int bsize2);
15 static void probdist_add(struct probdist *pd, coord_t c, float val);
16 static void probdist_mul(struct probdist *pd, coord_t c, float val);
17 static void probdist_punch(struct probdist *pd, coord_t c); // Remove c from probability distribution
18 coord_t probdist_pick(struct probdist *pd);
19 void probdist_done(struct probdist *pd); // Doesn't free pd itself
22 /* We disable the assertions here since this is quite time-critical
23 * part of code, and also the compiler is reluctant to include the
24 * functions otherwise. */
26 static inline void
27 probdist_add(struct probdist *pd, coord_t c, float val)
29 #if 0
30 assert(c >= 0 && c < pd->bsize2);
31 assert(val >= 0);
32 #endif
33 pd->moves[c] += val;
34 pd->total += val;
37 static inline void
38 probdist_mul(struct probdist *pd, coord_t c, float val)
40 #if 0
41 assert(c >= 0 && c < pd->bsize2);
42 assert(val >= 0);
43 #endif
44 pd->total += (val - 1) * pd->moves[c];
45 pd->moves[c] *= val;
48 static inline void
49 probdist_punch(struct probdist *pd, coord_t c)
51 assert(c >= 0 && c < pd->bsize2);
52 pd->total -= pd->moves[c];
53 pd->moves[c] = 0;
56 #endif