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