Do not prevent node expansion later when more memory becomes available.
[pachi/derm.git] / probdist.c
blob4c8260a06c477f3fd2c6ad54e772ab5cc586e058
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 float 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;
21 //fprintf(stderr, "overstab %f (total %f, sum %f)\n", stab, pd->items[pd->n - 1], sum);
22 assert(0);
23 return -1;