4 #define MAX_GAMELEN 600
10 struct board_ownermap
;
13 /** Playout policy interface: */
15 struct playout_policy
;
16 typedef coord_t (*playoutp_choose
)(struct playout_policy
*playout_policy
, struct board
*b
, enum stone to_play
);
17 /* Set number of won (>0) or lost (<0) games for each considerable
18 * move (usually a proportion of @games); can leave some untouched
19 * if policy has no opinion. The number must have proper parity;
20 * just use uct/prior.h:add_prior_value(). */
21 typedef void (*playoutp_assess
)(struct playout_policy
*playout_policy
, struct prior_map
*map
, int games
);
22 typedef bool (*playoutp_permit
)(struct playout_policy
*playout_policy
, struct board
*b
, struct move
*m
);
24 struct playout_policy
{
26 /* We call choose when we ask policy about next move.
27 * We call assess when we ask policy about how good given move is.
28 * We call permit when we ask policy if we can make a randomly chosen move. */
29 playoutp_choose choose
;
30 playoutp_assess assess
;
31 playoutp_permit permit
;
36 /** Playout engine interface: */
40 /* Get probability distribution of next move to play, given the current board.
41 * As a special protocol, pd[coord 0] is probability of defering to the policy
42 * choice; if there is no probability distribution available, the callback
43 * should simply set this to 1. */
44 /* Note that this callback is guaranteed to be called on each move. */
45 typedef void (*playoutc_probdist
)(struct playout_setup
*playout_setup
, struct probdist
*pd
, struct board
*b
);
47 struct playout_setup
{
48 int gamelen
; /* Maximal # of moves in playout. */
50 /* Engine callback interface: */
51 playoutc_probdist probdist
;
56 struct playout_amafmap
{
57 /* Record of the random playout - for each intersection:
58 * S_NONE: This move was never played
59 * S_BLACK: This move was played by black first
60 * S_WHITE: This move was played by white first
62 enum stone
*map
; // [board_size2(b)]
64 /* the lowest &0xf is the enum stone, upper bits are nakade
65 * counter - in case of nakade, we record only color of the
66 * first stone played inside, but count further throwins
67 * and ignore AMAF value after these. */
68 #define amaf_nakade(item_) (item_ >> 8)
69 #define amaf_op(item_, op_) do { \
71 item_ = (mi_ & 0xf) | ((amaf_nakade(mi_) op_ 1) << 8); \
74 /* Additionally, we keep record of the game so that we can
75 * examine nakade moves; really going out of our way to
76 * implement nakade AMAF properly turns out to be crucial
77 * when reading some tactical positions in depth (even if
78 * they are just one-stone-snapback). */
79 struct move game
[MAX_GAMELEN
+ 1];
81 /* Our current position in the game sequence; in AMAF, we search
82 * the range [game_baselen, gamelen]. */
85 /* Whether to record the nakade moves (true) or just completely
86 * ignore them (false; just the first color on the intersection
87 * is stored in the map, nakade counter is not incremented; game
88 * record is still kept). */
93 /* >0: starting_color wins, <0: starting_color loses; the actual
94 * number is a DOUBLE of the score difference
95 * 0: superko inside the game tree (XXX: jigo not handled) */
96 int play_random_game(struct playout_setup
*setup
,
97 struct board
*b
, enum stone starting_color
,
98 struct playout_amafmap
*amafmap
,
99 struct board_ownermap
*ownermap
,
100 struct playout_policy
*policy
);