Playout_*_init(): Take the board object pointer as an argument
[pachi.git] / probdist.c
blobd6bfa6b972e0df06a6054d2efa0c295e76e9cbc0
1 #include <assert.h>
2 #include <math.h>
3 #include <stdio.h>
4 #include <stdlib.h>
6 #include "move.h"
7 #include "probdist.h"
8 #include "random.h"
10 int
11 probdist_pick(struct probdist *pd)
13 assert(probdist_total(pd) >= 0);
14 /* TODO: float random */
15 double stab = fast_frandom() * probdist_total(pd);
16 //fprintf(stderr, "stab %f / %f\n", stab, pd->items[pd->n - 1]);
17 for (int i = 0; i < pd->n; i++) {
18 if (stab <= pd->items[i])
19 return i;
20 stab -= pd->items[i];
22 //fprintf(stderr, "overstab %f (total %f, sum %f)\n", stab, pd->items[pd->n - 1], sum);
23 assert(0);
24 return -1;