ELO: Use probability distribution over available moves, not whole board
[pachi/json.git] / playout.h
blob93260b18b8ff748cc8a1ba04c65688c1b3c224dd
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;
10 struct board_ownermap;
13 /** Playout policy interface: */
15 struct playout_policy;
16 /* Initialize policy data structures for new playout; subsequent choose calls
17 * (but not assess/permit calls!) will all be made on the same board; if
18 * setboard is used, it is guaranteed that choose will pick all moves played
19 * on the board subsequently. The routine is expected to initialize b->ps
20 * with internal data. At the playout end, b->ps will be simply free()d,
21 * so make sure all data is within single allocated block. */
22 typedef void (*playoutp_setboard)(struct playout_policy *playout_policy, struct board *b);
23 /* Pick the next playout simulation move. */
24 typedef coord_t (*playoutp_choose)(struct playout_policy *playout_policy, struct board *b, enum stone to_play);
25 /* Set number of won (>0) or lost (<0) games for each considerable
26 * move (usually a proportion of @games); can leave some untouched
27 * if policy has no opinion. The number must have proper parity;
28 * just use uct/prior.h:add_prior_value(). */
29 typedef void (*playoutp_assess)(struct playout_policy *playout_policy, struct prior_map *map, int games);
30 /* Allow play of randomly selected move. */
31 typedef bool (*playoutp_permit)(struct playout_policy *playout_policy, struct board *b, struct move *m);
33 struct playout_policy {
34 int debug_level;
35 /* We call setboard when we start new playout.
36 * We call choose when we ask policy about next move.
37 * We call assess when we ask policy about how good given move is.
38 * We call permit when we ask policy if we can make a randomly chosen move. */
39 playoutp_setboard setboard;
40 playoutp_choose choose;
41 playoutp_assess assess;
42 playoutp_permit permit;
43 /* Particular playout policy's internal data. */
44 void *data;
48 /** Playout engine interface: */
50 struct playout_setup {
51 int gamelen; /* Maximal # of moves in playout. */
53 /* XXX: We used to have more, perhaps we will again have more
54 * in the future. */
58 struct playout_amafmap {
59 /* Record of the random playout - for each intersection:
60 * S_NONE: This move was never played
61 * S_BLACK: This move was played by black first
62 * S_WHITE: This move was played by white first
64 enum stone *map; // [board_size2(b)]
66 /* the lowest &0xf is the enum stone, upper bits are nakade
67 * counter - in case of nakade, we record only color of the
68 * first stone played inside, but count further throwins
69 * and ignore AMAF value after these. */
70 #define amaf_nakade(item_) (item_ >> 8)
71 #define amaf_op(item_, op_) do { \
72 int mi_ = item_; \
73 item_ = (mi_ & 0xf) | ((amaf_nakade(mi_) op_ 1) << 8); \
74 } while (0)
76 /* Additionally, we keep record of the game so that we can
77 * examine nakade moves; really going out of our way to
78 * implement nakade AMAF properly turns out to be crucial
79 * when reading some tactical positions in depth (even if
80 * they are just one-stone-snapback). */
81 struct move game[MAX_GAMELEN + 1];
82 int gamelen;
83 /* Our current position in the game sequence; in AMAF, we search
84 * the range [game_baselen, gamelen]. */
85 int game_baselen;
87 /* Whether to record the nakade moves (true) or just completely
88 * ignore them (false; just the first color on the intersection
89 * is stored in the map, nakade counter is not incremented; game
90 * record is still kept). */
91 bool record_nakade;
95 /* >0: starting_color wins, <0: starting_color loses; the actual
96 * number is a DOUBLE of the score difference
97 * 0: superko inside the game tree (XXX: jigo not handled) */
98 int play_random_game(struct playout_setup *setup,
99 struct board *b, enum stone starting_color,
100 struct playout_amafmap *amafmap,
101 struct board_ownermap *ownermap,
102 struct playout_policy *policy);
104 #endif