add_prior_value(): Fix handling of negative values
[pachi.git] / uct / prior.h
blob5f3fd539a90e6965dd9e1135f8d1aa2e35d5e772
1 #ifndef ZZGO_UCT_PRIOR_H
2 #define ZZGO_UCT_PRIOR_H
4 #include "move.h"
5 #include "uct/tree.h"
7 struct tree;
8 struct tree_node;
9 struct uct;
10 struct board;
12 struct prior_map {
13 struct board *b;
14 enum stone to_play;
15 int parity;
16 /* [board_size2(b)] array, move_stats are the prior
17 * values to be assigned to individual moves;
18 * move_stats.value is not updated. */
19 struct move_stats *prior;
20 /* [board_size2(b)] array, whether to compute
21 * prior for the given value. */
22 bool *consider;
25 /* Wins can be negative to give losses; passing 0 wins is undefined. */
26 static void add_prior_value(struct prior_map *map, coord_t c, int wins, int playouts);
28 void uct_prior(struct uct *u, struct tree_node *node, struct prior_map *map);
31 static inline void
32 add_prior_value(struct prior_map *map, coord_t c, int wins, int playouts)
34 map->prior[c].playouts += playouts;
36 assert(wins != 0);
37 int w = wins * map->parity;
38 if (w < 0) w += playouts;
39 assert(w >= 0);
40 map->prior[c].wins += w;
43 #endif