Pachi Dosaku 5.00
[pachi.git] / probdist.c
blobf2af2aae1faf5cbb64218ca6e87debd43e77449a
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 float 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;