15 /* Whether to set global debug level to the same as the playout
16 * has, in case it is different. This can make sure e.g. tactical
17 * reading produces proper level of debug prints during simulations.
18 * But it is safe to enable this only in single-threaded instances! */
19 //#define DEBUGL_BY_PLAYOUT
21 #define PLDEBUGL(n) DEBUGL_(policy->debug_level, n)
25 play_random_game(struct playout_setup
*setup
,
26 struct board
*b
, enum stone starting_color
,
27 struct playout_amafmap
*amafmap
,
28 struct board_ownermap
*ownermap
,
29 struct playout_policy
*policy
)
31 assert(setup
&& policy
);
33 int gamelen
= setup
->gamelen
- b
->moves
;
38 policy
->setboard(policy
, b
);
39 #ifdef DEBUGL_BY_PLAYOUT
40 int debug_level_orig
= debug_level
;
41 debug_level
= policy
->debug_level
;
44 enum stone color
= starting_color
;
46 int passes
= is_pass(b
->last_move
.coord
) && b
->moves
> 0;
48 while (gamelen
-- && passes
< 2) {
50 coord
= policy
->choose(policy
, b
, color
);
54 /* Defer to uniformly random move choice. */
55 /* This must never happen if the policy is tracking
56 * internal board state, obviously. */
57 assert(!policy
->setboard
);
58 board_play_random(b
, color
, &coord
, (ppr_permit
) policy
->permit
, policy
);
62 m
.coord
= coord
; m
.color
= color
;
63 if (board_play(b
, &m
) < 0) {
65 fprintf(stderr
, "Pre-picked move %d,%d is ILLEGAL:\n",
66 coord_x(coord
, b
), coord_y(coord
, b
));
67 board_print(b
, stderr
);
74 /* For UCT, superko test here is downright harmful since
75 * in superko-likely situation we throw away literally
76 * 95% of our playouts; UCT will deal with this fine by
78 if (unlikely(b
->superko_violation
)) {
79 /* We ignore superko violations that are suicides. These
80 * are common only at the end of the game and are
81 * rather harmless. (They will not go through as a root
83 if (group_at(b
, coord
)) {
85 fprintf(stderr
, "Superko fun at %d,%d in\n", coord_x(coord
, b
), coord_y(coord
, b
));
87 board_print(b
, stderr
);
92 fprintf(stderr
, "Ignoring superko at %d,%d in\n", coord_x(coord
, b
), coord_y(coord
, b
));
93 board_print(b
, stderr
);
95 b
->superko_violation
= false;
101 fprintf(stderr
, "%s %s\n", stone2str(color
), coord2sstr(coord
, b
));
103 board_print(b
, stderr
);
106 if (unlikely(is_pass(coord
))) {
109 /* We don't care about nakade counters, since we want
110 * to avoid taking pre-nakade moves into account only
111 * if they happenned in the tree before nakade nodes;
112 * but this is always out of the tree. */
114 if (amafmap
->map
[coord
] == S_NONE
|| amafmap
->map
[coord
] == color
)
115 amafmap
->map
[coord
] = color
;
116 else if (amafmap
->record_nakade
)
117 amaf_op(amafmap
->map
[coord
], +);
118 amafmap
->game
[amafmap
->gamelen
].coord
= coord
;
119 amafmap
->game
[amafmap
->gamelen
].color
= color
;
121 assert(amafmap
->gamelen
< sizeof(amafmap
->game
) / sizeof(amafmap
->game
[0]));
127 if (setup
->mercymin
&& abs(b
->captures
[S_BLACK
] - b
->captures
[S_WHITE
]) > setup
->mercymin
)
130 color
= stone_other(color
);
133 float score
= board_fast_score(b
);
134 int result
= (starting_color
== S_WHITE
? score
* 2 : - (score
* 2));
137 fprintf(stderr
, "Random playout result: %d (W %f)\n", result
, score
);
139 board_print(b
, stderr
);
143 board_ownermap_fill(ownermap
, b
);
148 #ifdef DEBUGL_BY_PLAYOUT
149 debug_level
= debug_level_orig
;