2 Initialization of game wide constants based on board size.
4 To use declare as external:
6 u8 out_neighbors8[TOTAL_BOARD_SIZ];
7 u8 out_neighbors4[TOTAL_BOARD_SIZ];
8 move_seq neighbors_side[TOTAL_BOARD_SIZ];
9 move_seq neighbors_diag[TOTAL_BOARD_SIZ];
10 move_seq neighbors_3x3[TOTAL_BOARD_SIZ];
11 bool border_left[TOTAL_BOARD_SIZ];
12 bool border_right[TOTAL_BOARD_SIZ];
13 bool border_top[TOTAL_BOARD_SIZ];
14 bool border_bottom[TOTAL_BOARD_SIZ];
15 u8 distances_to_border[TOTAL_BOARD_SIZ];
16 move_seq nei_dst_3[TOTAL_BOARD_SIZ];
17 move_seq nei_dst_4[TOTAL_BOARD_SIZ];
18 u8 active_bits_in_byte[256];
32 d16 komi
= DEFAULT_KOMI
;
33 u8 out_neighbors8
[TOTAL_BOARD_SIZ
];
34 u8 out_neighbors4
[TOTAL_BOARD_SIZ
];
35 move_seq neighbors_side
[TOTAL_BOARD_SIZ
];
36 move_seq neighbors_diag
[TOTAL_BOARD_SIZ
];
37 move_seq neighbors_3x3
[TOTAL_BOARD_SIZ
];
38 bool border_left
[TOTAL_BOARD_SIZ
];
39 bool border_right
[TOTAL_BOARD_SIZ
];
40 bool border_top
[TOTAL_BOARD_SIZ
];
41 bool border_bottom
[TOTAL_BOARD_SIZ
];
42 u8 distances_to_border
[TOTAL_BOARD_SIZ
];
43 move_seq nei_dst_3
[TOTAL_BOARD_SIZ
];
44 move_seq nei_dst_4
[TOTAL_BOARD_SIZ
];
46 u8 active_bits_in_byte
[256];
47 bool black_eye
[65536];
48 bool white_eye
[65536];
50 static bool board_constants_inited
= false;
52 static u8
count_bits(u8 v
) {
63 An eye is a point that may eventually become untakeable (without playing
64 at the empty intersection itself). Examples:
70 static u8
_out_neighbors4(
75 if (p
[1][0] == ILLEGAL
) {
78 if (p
[2][1] == ILLEGAL
) {
81 if (p
[1][2] == ILLEGAL
) {
84 if (p
[0][1] == ILLEGAL
) {
91 static u8
_black_neighbors4(
96 if (p
[1][0] == BLACK_STONE
) {
99 if (p
[2][1] == BLACK_STONE
) {
102 if (p
[1][2] == BLACK_STONE
) {
105 if (p
[0][1] == BLACK_STONE
) {
112 static u8
_white_neighbors4(
117 if (p
[1][0] == WHITE_STONE
) {
120 if (p
[2][1] == WHITE_STONE
) {
123 if (p
[1][2] == WHITE_STONE
) {
126 if (p
[0][1] == WHITE_STONE
) {
133 static u8
_black_neighbors8(
136 u8 ret
= _black_neighbors4(p
);
138 if (p
[0][0] == BLACK_STONE
) {
141 if (p
[2][0] == BLACK_STONE
) {
144 if (p
[0][2] == BLACK_STONE
) {
147 if (p
[2][2] == BLACK_STONE
) {
154 static u8
_white_neighbors8(
157 u8 ret
= _white_neighbors4(p
);
159 if (p
[0][0] == WHITE_STONE
) {
162 if (p
[2][0] == WHITE_STONE
) {
165 if (p
[0][2] == WHITE_STONE
) {
168 if (p
[2][2] == WHITE_STONE
) {
175 static void init_eye_table() {
178 for (u32 i
= 0; i
< 65536; ++i
) {
179 string_to_pat3(dst
, i
);
181 if (_out_neighbors4(dst
) == 0) {
182 black_eye
[i
] = (_black_neighbors4(dst
) == 4) && (_white_neighbors8(dst
) < 2);
183 white_eye
[i
] = (_white_neighbors4(dst
) == 4) && (_black_neighbors8(dst
) < 2);
185 black_eye
[i
] = (_black_neighbors4(dst
) + _out_neighbors4(dst
) == 4) && (_white_neighbors8(dst
) == 0);
186 white_eye
[i
] = (_white_neighbors4(dst
) + _out_neighbors4(dst
) == 4) && (_black_neighbors8(dst
) == 0);
192 Initialize a series of constants based on the board size in use.
194 void board_constants_init() {
195 if (board_constants_inited
) {
199 board_constants_inited
= true;
201 /* Adjacent neighbor positions */
202 init_moves_by_distance(neighbors_side
, 1, false);
204 memset(border_left
, false, TOTAL_BOARD_SIZ
);
205 memset(border_right
, false, TOTAL_BOARD_SIZ
);
206 memset(border_top
, false, TOTAL_BOARD_SIZ
);
207 memset(border_bottom
, false, TOTAL_BOARD_SIZ
);
209 /* Diagonal neighbor positions */
210 for (d8 x
= 0; x
< BOARD_SIZ
; ++x
) {
211 for (d8 y
= 0; y
< BOARD_SIZ
; ++y
) {
212 move a
= coord_to_move(x
, y
);
215 border_left
[a
] = true;
217 if (x
== BOARD_SIZ
- 1) {
218 border_right
[a
] = true;
221 border_top
[a
] = true;
223 if (y
== BOARD_SIZ
- 1) {
224 border_bottom
[a
] = true;
228 for (d8 i
= 0; i
< BOARD_SIZ
; ++i
) {
229 for (d8 j
= 0; j
< BOARD_SIZ
; ++j
) {
230 if (abs(x
- i
) == 1 && abs(y
- j
) == 1) {
231 move b
= coord_to_move(i
, j
);
232 neighbors_diag
[a
].coord
[c
] = b
;
238 neighbors_diag
[a
].count
= c
;
242 /* 3x3 positions excluding self */
243 memcpy(neighbors_3x3
, neighbors_side
, TOTAL_BOARD_SIZ
* sizeof(move_seq
));
244 for (move m
= 0; m
< TOTAL_BOARD_SIZ
; ++m
) {
245 copy_moves(&neighbors_3x3
[m
], &neighbors_diag
[m
]);
248 memset(out_neighbors4
, 0, TOTAL_BOARD_SIZ
);
249 memset(out_neighbors8
, 0, TOTAL_BOARD_SIZ
);
251 for (u8 i
= 0; i
< BOARD_SIZ
; ++i
) {
252 out_neighbors4
[coord_to_move(i
, 0)] = out_neighbors4
[coord_to_move(0, i
)] = out_neighbors4
[coord_to_move(BOARD_SIZ
- 1, i
)] = out_neighbors4
[coord_to_move(i
, BOARD_SIZ
- 1)] = 1;
253 out_neighbors8
[coord_to_move(i
, 0)] = out_neighbors8
[coord_to_move(0, i
)] = out_neighbors8
[coord_to_move(BOARD_SIZ
- 1, i
)] = out_neighbors8
[coord_to_move(i
, BOARD_SIZ
- 1)] = 3;
256 out_neighbors4
[coord_to_move(0, 0)] = out_neighbors4
[coord_to_move(BOARD_SIZ
- 1, 0)] = out_neighbors4
[coord_to_move(0, BOARD_SIZ
- 1)] = out_neighbors4
[coord_to_move(BOARD_SIZ
- 1, BOARD_SIZ
- 1)] = 2;
257 out_neighbors8
[coord_to_move(0, 0)] = out_neighbors8
[coord_to_move(BOARD_SIZ
- 1, 0)] = out_neighbors8
[coord_to_move(0, BOARD_SIZ
- 1)] = out_neighbors8
[coord_to_move(BOARD_SIZ
- 1, BOARD_SIZ
- 1)] = 5;
259 for (u16 i
= 0; i
< 256; ++i
) {
260 active_bits_in_byte
[i
] = count_bits(i
);
263 for (u8 i
= 0; i
< BOARD_SIZ
; ++i
) {
264 for (u8 j
= 0; j
< BOARD_SIZ
; ++j
) {
265 distances_to_border
[coord_to_move(i
, j
)] = DISTANCE_TO_BORDER(i
, j
);
269 init_moves_by_distance(nei_dst_3
, 3, false);
270 init_moves_by_distance(nei_dst_4
, 4, false);