board_is_false_eyelike(): Explain confusing double negation
[pachi.git] / playout.c
blob80d9d1f36e5b82c1387f0a00d7f0593e61fcba4f
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "board.h"
6 #include "debug.h"
7 #include "engine.h"
8 #include "move.h"
9 #include "playout.h"
12 int
13 play_random_game(struct board *b, enum stone starting_color, int gamelen,
14 struct playout_amafmap *amafmap,
15 struct playout_policy *policy)
17 gamelen = gamelen - b->moves;
18 if (gamelen < 10)
19 gamelen = 10;
21 enum stone color = starting_color;
22 coord_t urgent;
24 int passes = is_pass(b->last_move.coord);
26 while (gamelen-- && passes < 2) {
27 urgent = policy->choose(policy, b, color);
29 coord_t coord;
31 if (!is_pass(urgent)) {
32 struct move m;
33 m.coord = urgent; m.color = color;
34 if (board_play(b, &m) < 0) {
35 if (DEBUGL(8)) {
36 fprintf(stderr, "Urgent move %d,%d is ILLEGAL:\n", coord_x(urgent, b), coord_y(urgent, b));
37 board_print(b, stderr);
39 goto play_random;
41 coord = urgent;
42 } else {
43 play_random:
44 board_play_random(b, color, &coord, (ppr_permit) policy->permit, policy);
47 #if 0
48 /* For UCT, superko test here is downright harmful since
49 * in superko-likely situation we throw away literally
50 * 95% of our playouts; UCT will deal with this fine by
51 * itself. */
52 if (unlikely(b->superko_violation)) {
53 /* We ignore superko violations that are suicides. These
54 * are common only at the end of the game and are
55 * rather harmless. (They will not go through as a root
56 * move anyway.) */
57 if (group_at(b, coord)) {
58 if (DEBUGL(3)) {
59 fprintf(stderr, "Superko fun at %d,%d in\n", coord_x(coord, b), coord_y(coord, b));
60 if (DEBUGL(4))
61 board_print(b, stderr);
63 return -1;
64 } else {
65 if (DEBUGL(6)) {
66 fprintf(stderr, "Ignoring superko at %d,%d in\n", coord_x(coord, b), coord_y(coord, b));
67 board_print(b, stderr);
69 b->superko_violation = false;
72 #endif
74 if (DEBUGL(7)) {
75 fprintf(stderr, "%s %s\n", stone2str(color), coord2sstr(coord, b));
76 if (DEBUGL(8))
77 board_print(b, stderr);
80 if (unlikely(is_pass(coord))) {
81 passes++;
82 } else {
83 /* We don't care about nakade counters, since we want
84 * to avoid taking pre-nakade moves into account only
85 * if they happenned in the tree before nakade nodes;
86 * but this is always out of the tree. */
87 if (amafmap && amafmap->map[coord] == S_NONE)
88 amafmap->map[coord] = color;
90 passes = 0;
93 color = stone_other(color);
96 float score = board_fast_score(b);
97 bool result = (starting_color == S_WHITE ? (score > 0) : (score < 0));
99 if (DEBUGL(6)) {
100 fprintf(stderr, "Random playout result: %d (W %f)\n", result, score);
101 if (DEBUGL(7))
102 board_print(b, stderr);
105 return result;