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
23 probdist_add(struct probdist
*pd
, coord_t c
, float val
)
25 assert(c
>= 0 && c
< pd
->bsize2
);
32 probdist_mul(struct probdist
*pd
, coord_t c
, float val
)
34 assert(c
>= 0 && c
< pd
->bsize2
);
36 float t
= pd
->total
- pd
->moves
[c
];
38 pd
->total
= t
+ pd
->moves
[c
];
42 probdist_punch(struct probdist
*pd
, coord_t c
)
44 assert(c
>= 0 && c
< pd
->bsize2
);
45 pd
->total
-= pd
->moves
[c
];