13 board_ownermap_fill(struct board_ownermap
*ownermap
, struct board
*b
)
17 enum stone color
= board_at(b
, c
);
19 color
= board_get_one_point_eye(b
, c
);
20 ownermap
->map
[c
][color
]++;
25 board_ownermap_merge(int bsize2
, struct board_ownermap
*dst
, struct board_ownermap
*src
)
27 dst
->playouts
+= src
->playouts
;
28 for (int i
= 0; i
< bsize2
; i
++)
29 for (int j
= 0; j
< S_MAX
; j
++)
30 dst
->map
[i
][j
] += src
->map
[i
][j
];
34 board_ownermap_estimate_point(struct board_ownermap
*ownermap
, coord_t c
)
36 assert(ownermap
->map
);
37 int b
= ownermap
->map
[c
][S_BLACK
];
38 int w
= ownermap
->map
[c
][S_WHITE
];
39 int total
= ownermap
->playouts
;
40 return 1.0 * (b
- w
) / total
;
44 board_ownermap_judge_point(struct board_ownermap
*ownermap
, coord_t c
, floating_t thres
)
46 assert(ownermap
->map
);
47 int n
= ownermap
->map
[c
][S_NONE
];
48 int b
= ownermap
->map
[c
][S_BLACK
];
49 int w
= ownermap
->map
[c
][S_WHITE
];
50 int total
= ownermap
->playouts
;
51 if (n
>= total
* thres
)
53 else if (n
+ b
>= total
* thres
)
55 else if (n
+ w
>= total
* thres
)
62 board_ownermap_judge_groups(struct board
*b
, struct board_ownermap
*ownermap
, struct group_judgement
*judge
)
64 assert(ownermap
->map
);
66 memset(judge
->gs
, GS_NONE
, board_size2(b
) * sizeof(judge
->gs
[0]));
69 enum stone color
= board_at(b
, c
);
70 group_t g
= group_at(b
, c
);
73 enum point_judgement pj
= board_ownermap_judge_point(ownermap
, c
, judge
->thres
);
74 // assert(judge->gs[g] == GS_NONE || judge->gs[g] == pj);
75 if (pj
== PJ_UNKNOWN
) {
76 /* Fate is uncertain. */
77 judge
->gs
[g
] = GS_UNKNOWN
;
79 } else if (judge
->gs
[g
] != GS_UNKNOWN
) {
80 /* Update group state. */
83 // Comparing enum types, casting (int) avoids compiler warnings
84 if ((int)pj
== (int)color
) {
86 } else if ((int)pj
== (int)stone_other(color
)) {
88 } else { assert(pj
== PJ_DAME
);
93 if (judge
->gs
[g
] == GS_NONE
) {
95 } else if (judge
->gs
[g
] != new) {
96 /* Contradiction. :( */
97 judge
->gs
[g
] = GS_UNKNOWN
;
104 groups_of_status(struct board
*b
, struct group_judgement
*judge
, enum gj_state s
, struct move_queue
*mq
)
106 foreach_point(b
) { /* foreach_group, effectively */
107 group_t g
= group_at(b
, c
);
108 if (!g
|| g
!= c
) continue;
110 assert(judge
->gs
[g
] != GS_NONE
);
111 if (judge
->gs
[g
] == s
)