17 play_random_game(struct playout_setup
*setup
,
18 struct board
*b
, enum stone starting_color
,
19 struct playout_amafmap
*amafmap
,
20 struct board_ownermap
*ownermap
,
21 struct playout_policy
*policy
)
23 assert(setup
&& policy
);
25 int gamelen
= setup
->gamelen
- b
->moves
;
30 policy
->setboard(policy
, b
);
32 enum stone color
= starting_color
;
34 int passes
= is_pass(b
->last_move
.coord
) && b
->moves
> 0;
36 while (gamelen
-- && passes
< 2) {
38 coord
= policy
->choose(policy
, b
, color
);
42 /* Defer to uniformly random move choice. */
43 /* This must never happen if the policy is tracking
44 * internal board state, obviously. */
45 assert(!policy
->setboard
);
46 board_play_random(b
, color
, &coord
, (ppr_permit
) policy
->permit
, policy
);
50 m
.coord
= coord
; m
.color
= color
;
51 if (board_play(b
, &m
) < 0) {
53 fprintf(stderr
, "Pre-picked move %d,%d is ILLEGAL:\n",
54 coord_x(coord
, b
), coord_y(coord
, b
));
55 board_print(b
, stderr
);
62 /* For UCT, superko test here is downright harmful since
63 * in superko-likely situation we throw away literally
64 * 95% of our playouts; UCT will deal with this fine by
66 if (unlikely(b
->superko_violation
)) {
67 /* We ignore superko violations that are suicides. These
68 * are common only at the end of the game and are
69 * rather harmless. (They will not go through as a root
71 if (group_at(b
, coord
)) {
73 fprintf(stderr
, "Superko fun at %d,%d in\n", coord_x(coord
, b
), coord_y(coord
, b
));
75 board_print(b
, stderr
);
80 fprintf(stderr
, "Ignoring superko at %d,%d in\n", coord_x(coord
, b
), coord_y(coord
, b
));
81 board_print(b
, stderr
);
83 b
->superko_violation
= false;
89 fprintf(stderr
, "%s %s\n", stone2str(color
), coord2sstr(coord
, b
));
91 board_print(b
, stderr
);
94 if (unlikely(is_pass(coord
))) {
97 /* We don't care about nakade counters, since we want
98 * to avoid taking pre-nakade moves into account only
99 * if they happenned in the tree before nakade nodes;
100 * but this is always out of the tree. */
102 if (amafmap
->map
[coord
] == S_NONE
|| amafmap
->map
[coord
] == color
)
103 amafmap
->map
[coord
] = color
;
104 else if (amafmap
->record_nakade
)
105 amaf_op(amafmap
->map
[coord
], +);
106 amafmap
->game
[amafmap
->gamelen
].coord
= coord
;
107 amafmap
->game
[amafmap
->gamelen
].color
= color
;
109 assert(amafmap
->gamelen
< sizeof(amafmap
->game
) / sizeof(amafmap
->game
[0]));
115 if (setup
->mercymin
&& abs(b
->captures
[S_BLACK
] - b
->captures
[S_WHITE
]) > setup
->mercymin
)
118 color
= stone_other(color
);
121 float score
= board_fast_score(b
);
122 int result
= (starting_color
== S_WHITE
? score
* 2 : - (score
* 2));
125 fprintf(stderr
, "Random playout result: %d (W %f)\n", result
, score
);
127 board_print(b
, stderr
);
131 board_ownermap_fill(ownermap
, b
);