is_bad_selfatari(): Don't check for suicides again
[pachi.git] / playout.h
blob92f4db33611189753092e42f9b5b4604473b7c4f
1 #ifndef ZZGO_PLAYOUT_H
2 #define ZZGO_PLAYOUT_H
4 struct board;
5 struct move;
6 enum stone;
9 struct playout_policy;
10 typedef coord_t (*playoutp_choose)(struct playout_policy *playout_policy, struct board *b, enum stone to_play);
11 /* number of won (>0) or lost (<0) games to seed the node with (usually a proportion of @games);
12 * can return 0 if policy has no opinion */
13 typedef int (*playoutp_assess)(struct playout_policy *playout_policy, struct board *b, struct move *m, int games);
14 typedef bool (*playoutp_permit)(struct playout_policy *playout_policy, struct board *b, struct move *m);
16 struct playout_policy {
17 int debug_level;
18 /* We call choose when we ask policy about next move.
19 * We call assess when we ask policy about how good given move is.
20 * We call permit when we ask policy if we can make a randomly chosen move. */
21 playoutp_choose choose;
22 playoutp_assess assess;
23 playoutp_permit permit;
24 void *data;
28 struct playout_amafmap {
29 /* Record of the random playout - for each intersection:
30 * S_NONE: This move was never played
31 * S_BLACK: This move was played by black first
32 * S_WHITE: This move was played by white first
34 enum stone *map; // [board_size2(b)]
36 /* the lowest &0xf is the enum stone, upper bits are nakade
37 * counter - in case of nakade, we record only color of the
38 * first stone played inside, but count further throwins
39 * and ignore AMAF value after these. */
40 #define amaf_nakade(item_) (item_ >> 8)
41 #define amaf_op(item_, op_) do { \
42 int mi_ = item_; \
43 item_ = (mi_ & 0xf) | ((amaf_nakade(mi_) op_ 1) << 8); \
44 } while (0)
46 /* Additionally, we keep record of the game so that we can
47 * examine nakade moves; really going out of our way to
48 * implement nakade AMAF properly turns out to be crucial
49 * when reading some tactical positions in depth (even if
50 * they are just one-stone-snapback). */
51 struct move game[512];
52 int gamelen;
53 /* Our current position in the game sequence; in AMAF, we search
54 * the range [game_baselen, gamelen]. */
55 int game_baselen;
57 /* Whether to record the nakade moves (true) or just completely
58 * ignore them (false; just the first color on the intersection
59 * is stored in the map, nakade counter is not incremented; game
60 * record is still kept). */
61 bool record_nakade;
65 /* 1: starting_color wins, 0: starting_color loses
66 * -1: superko inside the game tree */
67 int play_random_game(struct board *b, enum stone starting_color, int gamelen, struct playout_amafmap *amafmap, struct playout_policy *policy);
69 #endif