| 1362 | | /* Move was not allowed because of komaster. We want to check, if this |
| 1363 | | * situation is double ko and when it is, we won semeai. |
| 1364 | | */ |
| 1365 | | int libs[MAX_LIBERTIES]; |
| 1366 | | int n; |
| 1367 | | int nlib; |
| 1368 | | int sworm; |
| 1369 | | int worm_color; |
| 1370 | | |
| 1371 | | for (sworm = 0; sworm < s_worms; sworm++) { |
| 1372 | | worm_color = board[semeai_worms[sworm]]; |
| 1373 | | if (worm_color == color && *this_resulta == 0) { |
| 1374 | | /* We only check up to MAX_LIBERTIES, due to performance reasons. When we |
| 1375 | | * have more liberties we have some outside liberties to fill and these |
| 1376 | | * moves will be tried later (and double ko situation will be found). |
| 1377 | | */ |
| 1378 | | nlib = findlib(semeai_worms[sworm], MAX_LIBERTIES, libs); |
| 1379 | | if (nlib > MAX_LIBERTIES) |
| 1380 | | return 0; |
| 1381 | | |
| 1382 | | for (n = 0; n < nlib; n++) |
| 1383 | | if (is_ko(libs[n], OTHER_COLOR(color), NULL)) { |
| 1384 | | /* Our dragon has double ko, but we have to check if opponent dragon |
| 1385 | | * doesn't have outside liberties or double ko. |
| 1386 | | */ |
| 1387 | | *this_resulta = WIN; |
| 1388 | | *this_resultb = WIN; |
| 1389 | | } |
| 1390 | | } |
| 1391 | | else if (worm_color == OTHER_COLOR(color)) { |
| 1392 | | nlib = findlib(semeai_worms[sworm], 2, libs); |
| 1393 | | if (nlib > 2) |
| 1394 | | /* In double ko situation the opponent can have only |
| 1395 | | * a single eye and a ko outside liberty to be sure that we |
| 1396 | | * will always win double ko. */ |
| 1397 | | return 0; |
| | 1362 | int kpos; |
| | 1363 | if (is_ko(move, color, &kpos)) { |
| | 1364 | /* Move was not allowed because of komaster. We want to check, if this |
| | 1365 | * situation is double ko and when it is, we won semeai. |
| | 1366 | */ |
| | 1367 | int libs[MAX_LIBERTIES]; |
| | 1368 | int n; |
| | 1369 | int nlib; |
| | 1370 | int sworm; |
| | 1371 | int worm_color; |
| | 1372 | int other = OTHER_COLOR(color); |
| | 1373 | |
| | 1374 | for (sworm = 0; sworm < s_worms; sworm++) { |
| | 1375 | worm_color = board[semeai_worms[sworm]]; |
| | 1376 | if (worm_color == color) { |
| | 1377 | /* We only check up to MAX_LIBERTIES, due to performance reasons. When we |
| | 1378 | * have more liberties we have some outside liberties to fill and these |
| | 1379 | * moves will be tried later (and double ko situation will be found). |
| | 1380 | */ |
| | 1381 | nlib = findlib(semeai_worms[sworm], MAX_LIBERTIES, libs); |
| | 1382 | if (nlib > MAX_LIBERTIES) |
| | 1383 | return 0; |
| | 1384 | |
| | 1385 | for (n = 0; n < nlib; n++) |
| | 1386 | if (is_ko(libs[n], other, NULL)) { |
| | 1387 | /* Check if situation is not a nested ko capture. */ |
| | 1388 | if (DIAGONAL_NEIGHBORS(libs[n], kpos)) |
| | 1389 | return 0; |
| | 1390 | |
| | 1391 | /* Our dragon has double ko, but we have to check if opponent dragon |
| | 1392 | * doesn't have outside liberties or double ko. |
| | 1393 | */ |
| | 1394 | *this_resulta = WIN; |
| | 1395 | *this_resultb = WIN; |
| | 1396 | } |
| | 1397 | } |
| | 1398 | else if (worm_color == other) { |
| | 1399 | if (countlib(semeai_worms[sworm]) > 2) |
| | 1400 | /* In double ko situation the opponent can have only |
| | 1401 | * a single eye and a ko outside liberty to be sure that we |
| | 1402 | * will always win double ko. */ |
| | 1403 | return 0; |
| | 1404 | } |