12 #include "uct/internal.h"
13 #include "uct/prior.h"
16 /* Applying heuristic values to the tree nodes, skewing the reading in
17 * most interesting directions. */
21 uct_prior_even(struct uct
*u
, struct tree_node
*node
, struct prior_map
*map
)
24 /* This may be dubious for normal UCB1 but is essential for
25 * reading stability of RAVE, it appears. */
26 foreach_point_and_pass(map
->b
) {
27 if (!map
->consider
[c
])
29 add_prior_value(map
, c
, 0.5, u
->even_eqex
);
34 uct_prior_eye(struct uct
*u
, struct tree_node
*node
, struct prior_map
*map
)
36 /* Discourage playing into our own eyes. However, we cannot
37 * completely prohibit it:
43 foreach_point(map
->b
) {
44 if (!map
->consider
[c
])
46 if (!board_is_one_point_eye(map
->b
, &c
, map
->to_play
))
48 add_prior_value(map
, c
, 0, u
->eqex
);
53 uct_prior_b19(struct uct
*u
, struct tree_node
*node
, struct prior_map
*map
)
56 /* Specific hints for 19x19 board - priors for certain edge distances. */
57 foreach_point(map
->b
) {
58 if (!map
->consider
[c
])
60 int d
= coord_edge_distance(c
, map
->b
);
63 /* The bonus applies only with no stones in immediate
65 if (board_stone_radar(map
->b
, c
, 2))
69 add_prior_value(map
, c
, d
== 3, u
->b19_eqex
);
74 uct_prior_grandparent(struct uct
*u
, struct tree_node
*node
, struct prior_map
*map
)
77 foreach_point_and_pass(map
->b
) {
78 if (!map
->consider
[c
])
80 if (!node
->parent
|| !node
->parent
->parent
)
82 struct tree_node
*gpp
= node
->parent
->parent
;
83 for (struct tree_node
*ni
= gpp
->children
; ni
; ni
= ni
->sibling
) {
84 /* Be careful not to emphasize too random results. */
85 if (ni
->coord
== node
->coord
&& ni
->u
.playouts
> u
->gp_eqex
) {
86 /* We purposefuly ignore the parity. */
87 stats_add_result(&map
->prior
[c
], ni
->u
.value
, u
->gp_eqex
);
94 uct_prior_playout(struct uct
*u
, struct tree_node
*node
, struct prior_map
*map
)
96 /* Q_{playout-policy} */
97 if (u
->playout
->assess
)
98 u
->playout
->assess(u
->playout
, map
, u
->policy_eqex
);
102 uct_prior_cfgd(struct uct
*u
, struct tree_node
*node
, struct prior_map
*map
)
104 /* Q_{common_fate_graph_distance} */
105 /* Give bonus to moves local to the last move, where "local" means
106 * local in terms of groups, not just manhattan distance. */
107 if (is_pass(map
->b
->last_move
.coord
))
110 int distances
[board_size2(map
->b
)];
111 cfg_distances(map
->b
, map
->b
->last_move
.coord
, distances
, 3);
112 foreach_point(map
->b
) {
113 if (!map
->consider
[c
])
115 // fprintf(stderr, "distance %s-%s: %d\n", coord2sstr(map->b->last_move.coord, map->b), coord2sstr(c, map->b), distances[c]);
116 if (distances
[c
] > 3)
118 assert(distances
[c
] != 0);
119 int bonuses
[] = { 0, u
->cfgd_eqex
, u
->cfgd_eqex
/ 2, u
->cfgd_eqex
/ 2 };
120 int bonus
= bonuses
[distances
[c
]];
121 add_prior_value(map
, c
, 1, bonus
);
126 uct_prior(struct uct
*u
, struct tree_node
*node
, struct prior_map
*map
)
129 uct_prior_even(u
, node
, map
);
131 uct_prior_eye(u
, node
, map
);
133 uct_prior_b19(u
, node
, map
);
135 uct_prior_grandparent(u
, node
, map
);
137 uct_prior_playout(u
, node
, map
);
139 uct_prior_cfgd(u
, node
, map
);