UCT Prior: Enable b19, cfgd by default
[pachi.git] / playout.h
blob179110e5bba71b5cf170e57c3c72ca8ccc99be2e
1 #ifndef ZZGO_PLAYOUT_H
2 #define ZZGO_PLAYOUT_H
4 struct board;
5 struct move;
6 enum stone;
7 struct prior_map;
10 struct playout_policy;
11 typedef coord_t (*playoutp_choose)(struct playout_policy *playout_policy, struct board *b, enum stone to_play);
12 /* Set number of won (>0) or lost (<0) games for each considerable
13 * move (usually a proportion of @games); can leave some untouched
14 * if policy has no opinion. The number must have proper parity;
15 * just use uct/prior.h:add_prior_value(). */
16 typedef void (*playoutp_assess)(struct playout_policy *playout_policy, struct prior_map *map, int games);
17 typedef bool (*playoutp_permit)(struct playout_policy *playout_policy, struct board *b, struct move *m);
19 struct playout_policy {
20 int debug_level;
21 /* We call choose when we ask policy about next move.
22 * We call assess when we ask policy about how good given move is.
23 * We call permit when we ask policy if we can make a randomly chosen move. */
24 playoutp_choose choose;
25 playoutp_assess assess;
26 playoutp_permit permit;
27 void *data;
31 struct playout_amafmap {
32 /* Record of the random playout - for each intersection:
33 * S_NONE: This move was never played
34 * S_BLACK: This move was played by black first
35 * S_WHITE: This move was played by white first
37 enum stone *map; // [board_size2(b)]
39 /* the lowest &0xf is the enum stone, upper bits are nakade
40 * counter - in case of nakade, we record only color of the
41 * first stone played inside, but count further throwins
42 * and ignore AMAF value after these. */
43 #define amaf_nakade(item_) (item_ >> 8)
44 #define amaf_op(item_, op_) do { \
45 int mi_ = item_; \
46 item_ = (mi_ & 0xf) | ((amaf_nakade(mi_) op_ 1) << 8); \
47 } while (0)
49 /* Additionally, we keep record of the game so that we can
50 * examine nakade moves; really going out of our way to
51 * implement nakade AMAF properly turns out to be crucial
52 * when reading some tactical positions in depth (even if
53 * they are just one-stone-snapback). */
54 struct move game[512];
55 int gamelen;
56 /* Our current position in the game sequence; in AMAF, we search
57 * the range [game_baselen, gamelen]. */
58 int game_baselen;
60 /* Whether to record the nakade moves (true) or just completely
61 * ignore them (false; just the first color on the intersection
62 * is stored in the map, nakade counter is not incremented; game
63 * record is still kept). */
64 bool record_nakade;
68 /* 1: starting_color wins, 0: starting_color loses
69 * -1: superko inside the game tree */
70 int play_random_game(struct board *b, enum stone starting_color, int gamelen, struct playout_amafmap *amafmap, struct playout_policy *policy);
72 #endif