uct_search(): Move state to struct uct_search_state, setup in uct_search_start()
[pachi/derm.git] / probdist.c
blob4f08d5260f30d0af69bb09da591b8b6e3126e641
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"
9 #include "board.h"
11 int
12 probdist_pick(struct probdist *pd)
14 double total = probdist_total(pd) - PROBDIST_EPSILON;
15 assert(total >= 0);
16 /* TODO: float random */
17 double stab = fast_frandom() * total;
18 //fprintf(stderr, "stab %f / %f\n", stab, total);
19 for (int i = 0; i < pd->n; i++) {
20 //struct board b = { .size = 11 };
21 //fprintf(stderr, "[%s] %f (%f)\n", coord2sstr(i, &b), pd->items[i], stab);
22 if (stab <= pd->items[i])
23 return i;
24 stab -= pd->items[i];
26 fprintf(stderr, "overstab %f (total %f)\n", stab, total);
27 assert(0);
28 return -1;