1 #ifndef ZZGO_PROBDIST_H
2 #define ZZGO_PROBDIST_H
4 /* Tools for picking a move according to a probability distribution. */
10 float *moves
; // [bsize2]
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. */
27 probdist_add(struct probdist
*pd
, coord_t c
, float val
)
30 assert(c
>= 0 && c
< pd
->bsize2
);
38 probdist_mul(struct probdist
*pd
, coord_t c
, float val
)
41 assert(c
>= 0 && c
< pd
->bsize2
);
44 pd
->total
+= (val
- 1) * pd
->moves
[c
];
49 probdist_punch(struct probdist
*pd
, coord_t c
)
51 assert(c
>= 0 && c
< pd
->bsize2
);
52 pd
->total
-= pd
->moves
[c
];