15 #define PLDEBUGL(n) DEBUGL_(policy->debug_level, n)
19 play_random_game(struct playout_setup
*setup
,
20 struct board
*b
, enum stone starting_color
,
21 struct playout_amafmap
*amafmap
,
22 struct board_ownermap
*ownermap
,
23 struct playout_policy
*policy
)
25 assert(setup
&& policy
);
27 int gamelen
= setup
->gamelen
- b
->moves
;
32 policy
->setboard(policy
, b
);
34 enum stone color
= starting_color
;
36 int passes
= is_pass(b
->last_move
.coord
) && b
->moves
> 0;
38 while (gamelen
-- && passes
< 2) {
40 coord
= policy
->choose(policy
, b
, color
);
44 /* Defer to uniformly random move choice. */
45 /* This must never happen if the policy is tracking
46 * internal board state, obviously. */
47 assert(!policy
->setboard
);
48 board_play_random(b
, color
, &coord
, (ppr_permit
) policy
->permit
, policy
);
52 m
.coord
= coord
; m
.color
= color
;
53 if (board_play(b
, &m
) < 0) {
55 fprintf(stderr
, "Pre-picked move %d,%d is ILLEGAL:\n",
56 coord_x(coord
, b
), coord_y(coord
, b
));
57 board_print(b
, stderr
);
64 /* For UCT, superko test here is downright harmful since
65 * in superko-likely situation we throw away literally
66 * 95% of our playouts; UCT will deal with this fine by
68 if (unlikely(b
->superko_violation
)) {
69 /* We ignore superko violations that are suicides. These
70 * are common only at the end of the game and are
71 * rather harmless. (They will not go through as a root
73 if (group_at(b
, coord
)) {
75 fprintf(stderr
, "Superko fun at %d,%d in\n", coord_x(coord
, b
), coord_y(coord
, b
));
77 board_print(b
, stderr
);
82 fprintf(stderr
, "Ignoring superko at %d,%d in\n", coord_x(coord
, b
), coord_y(coord
, b
));
83 board_print(b
, stderr
);
85 b
->superko_violation
= false;
91 fprintf(stderr
, "%s %s\n", stone2str(color
), coord2sstr(coord
, b
));
93 board_print(b
, stderr
);
96 if (unlikely(is_pass(coord
))) {
99 /* We don't care about nakade counters, since we want
100 * to avoid taking pre-nakade moves into account only
101 * if they happenned in the tree before nakade nodes;
102 * but this is always out of the tree. */
104 if (amafmap
->map
[coord
] == S_NONE
|| amafmap
->map
[coord
] == color
)
105 amafmap
->map
[coord
] = color
;
106 else if (amafmap
->record_nakade
)
107 amaf_op(amafmap
->map
[coord
], +);
108 amafmap
->game
[amafmap
->gamelen
].coord
= coord
;
109 amafmap
->game
[amafmap
->gamelen
].color
= color
;
111 assert(amafmap
->gamelen
< sizeof(amafmap
->game
) / sizeof(amafmap
->game
[0]));
117 if (setup
->mercymin
&& abs(b
->captures
[S_BLACK
] - b
->captures
[S_WHITE
]) > setup
->mercymin
)
120 color
= stone_other(color
);
123 float score
= board_fast_score(b
);
124 int result
= (starting_color
== S_WHITE
? score
* 2 : - (score
* 2));
127 fprintf(stderr
, "Random playout result: %d (W %f)\n", result
, score
);
129 board_print(b
, stderr
);
133 board_ownermap_fill(ownermap
, b
);