RCS file: /sources/gnugo/gnugo/engine/combination.c,v
retrieving revision 1.57
diff -u -r1.57 combination.c
|
|
|
|
| 76 | 76 | gprintf("Combination attack for %C with size %d found at %1m\n", |
| 77 | 77 | other, aa_val, attack_point); |
| 78 | 78 | |
| 79 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) { |
| 80 | | if (ON_BOARD(pos) && defense_points[pos]) { |
| | 79 | scan_board(pos, |
| | 80 | if (defense_points[pos]) { |
| 81 | 81 | add_your_atari_atari_move(pos, aa_val); |
| 82 | 82 | if (save_verbose) |
| 83 | 83 | gprintf("- defense at %1m\n", pos); |
| 84 | 84 | } |
| 85 | | } |
| | 85 | ) |
| 86 | 86 | } |
| 87 | 87 | verbose = save_verbose; |
| 88 | 88 | } |
| … |
… |
|
| 93 | 93 | static void |
| 94 | 94 | find_double_threats(int color) |
| 95 | 95 | { |
| 96 | | int ii; |
| 97 | 96 | int k; |
| 98 | 97 | int l; |
| | 98 | int pos; |
| 99 | 99 | |
| 100 | | for (ii = BOARDMIN; ii < BOARDMAX; ii++) { |
| | 100 | scan_board(pos, |
| 101 | 101 | int num_a_threatened_groups; |
| 102 | 102 | int a_threatened_groups[MAX_THREATENED_STRINGS]; |
| 103 | 103 | #if 0 |
| … |
… |
|
| 105 | 105 | int d_threatened_groups[MAX_THREATENED_STRINGS]; |
| 106 | 106 | #endif |
| 107 | 107 | |
| 108 | | if (!ON_BOARD(ii)) |
| 109 | | continue; |
| 110 | | |
| 111 | 108 | /* Generate an EITHER_MOVE move reasons for each pair of the |
| 112 | 109 | * threatened strings. We must also remove the threats, because |
| 113 | 110 | * otherwise we would get followup points for them as well. |
| … |
… |
|
| 118 | 115 | * at the same point. Still, we should find a better way. |
| 119 | 116 | * - EITHER_MOVE should be generalized to more than two strings. |
| 120 | 117 | */ |
| 121 | | num_a_threatened_groups = get_attack_threats(ii, MAX_THREATENED_STRINGS, |
| | 118 | num_a_threatened_groups = get_attack_threats(pos, MAX_THREATENED_STRINGS, |
| 122 | 119 | a_threatened_groups); |
| 123 | 120 | if (num_a_threatened_groups > 1) { |
| 124 | | if (trymove(ii, color, "find_double_threats-A", ii)) { |
| | 121 | if (trymove(pos, color, "find_double_threats-A", pos)) { |
| 125 | 122 | for (k = 0; k < num_a_threatened_groups - 1; ++k) |
| 126 | 123 | for (l = k + 1; l < num_a_threatened_groups; ++l) { |
| 127 | 124 | /* Note: If we used attack_either() here instead of trymove() |
| … |
… |
|
| 131 | 128 | * Besides, attack_either is currently (3.1.11) not very good. |
| 132 | 129 | * |
| 133 | 130 | * The call to attack() is intended to detect the case |
| 134 | | * where the move at ii is a snapback capture. |
| | 131 | * where the move at pos is a snapback capture. |
| 135 | 132 | */ |
| 136 | 133 | if (board[a_threatened_groups[k]] == EMPTY |
| 137 | 134 | || board[a_threatened_groups[l]] == EMPTY) { |
| 138 | | if (!attack(ii, NULL)) { |
| | 135 | if (!attack(pos, NULL)) { |
| 139 | 136 | TRACE("Double threat at %1m, either %1m or %1m attacked.\n", |
| 140 | | ii, a_threatened_groups[k], a_threatened_groups[l]); |
| 141 | | add_either_move(ii, ATTACK_STRING, a_threatened_groups[k], |
| | 137 | pos, a_threatened_groups[k], a_threatened_groups[l]); |
| | 138 | add_either_move(pos, ATTACK_STRING, a_threatened_groups[k], |
| 142 | 139 | ATTACK_STRING, a_threatened_groups[l]); |
| 143 | | remove_attack_threat_move(ii, a_threatened_groups[k]); |
| 144 | | remove_attack_threat_move(ii, a_threatened_groups[l]); |
| | 140 | remove_attack_threat_move(pos, a_threatened_groups[k]); |
| | 141 | remove_attack_threat_move(pos, a_threatened_groups[l]); |
| 145 | 142 | } |
| 146 | 143 | } |
| 147 | 144 | else if (!defend_both(a_threatened_groups[k], |
| 148 | 145 | a_threatened_groups[l])) { |
| 149 | 146 | TRACE("Double threat at %1m, either %1m or %1m attacked.\n", |
| 150 | | ii, a_threatened_groups[k], a_threatened_groups[l]); |
| 151 | | add_either_move(ii, ATTACK_STRING, a_threatened_groups[k], |
| | 147 | pos, a_threatened_groups[k], a_threatened_groups[l]); |
| | 148 | add_either_move(pos, ATTACK_STRING, a_threatened_groups[k], |
| 152 | 149 | ATTACK_STRING, a_threatened_groups[l]); |
| 153 | | remove_attack_threat_move(ii, a_threatened_groups[k]); |
| 154 | | remove_attack_threat_move(ii, a_threatened_groups[l]); |
| | 150 | remove_attack_threat_move(pos, a_threatened_groups[k]); |
| | 151 | remove_attack_threat_move(pos, a_threatened_groups[l]); |
| 155 | 152 | } |
| 156 | 153 | } |
| 157 | 154 | popgo(); |
| 158 | 155 | } |
| 159 | 156 | } |
| 160 | | } |
| | 157 | ) |
| 161 | 158 | |
| 162 | 159 | |
| 163 | 160 | /* FIXME: |
| … |
… |
|
| 312 | 309 | * examine which of them really work. |
| 313 | 310 | */ |
| 314 | 311 | forbidden[apos] = 0; |
| 315 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) { |
| 316 | | if (!ON_BOARD(pos) || !defense_moves[pos]) |
| | 312 | scan_board(pos, |
| | 313 | if (!defense_moves[pos]) |
| 317 | 314 | continue; |
| 318 | 315 | |
| 319 | 316 | if (!trymove(pos, other, "atari_atari", NO_MOVE)) { |
| … |
… |
|
| 321 | 318 | if (save_verbose) |
| 322 | 319 | gprintf("%1m deleted defense point, illegal\n", pos); |
| 323 | 320 | continue; |
| 324 | | } |
| | 321 | } |
| 325 | 322 | |
| 326 | 323 | if (attack(pos, NULL)) { |
| 327 | 324 | defense_moves[pos] = 0; |
| … |
… |
|
| 329 | 326 | if (save_verbose) |
| 330 | 327 | gprintf("%1m deleted defense point, unsafe\n", pos); |
| 331 | 328 | continue; |
| 332 | | } |
| | 329 | } |
| 333 | 330 | |
| 334 | 331 | if (do_atari_atari(color, &apos, &dpos, NULL, NO_MOVE, |
| 335 | 332 | save_verbose, aa_val, NULL) > 0) { |
| 336 | 333 | if (save_verbose) |
| 337 | 334 | gprintf("%1m deleted defense point, didn't work\n", pos); |
| 338 | 335 | defense_moves[pos] = 0; |
| 339 | | } |
| | 336 | } |
| 340 | 337 | |
| 341 | 338 | popgo(); |
| 342 | | } |
| | 339 | ) |
| 343 | 340 | } |
| 344 | 341 | return aa_val; |
| 345 | 342 | } |
| … |
… |
|
| 372 | 369 | if (defense) { |
| 373 | 370 | /* Return one arbitrary defense move. */ |
| 374 | 371 | *defense = NO_MOVE; |
| 375 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) |
| 376 | | if (ON_BOARD(pos) && defense_moves[pos]) { |
| | 372 | scan_board(pos, |
| | 373 | if (defense_moves[pos]) { |
| 377 | 374 | *defense = pos; |
| 378 | 375 | break; |
| 379 | | } |
| | 376 | } |
| | 377 | ) |
| 380 | 378 | } |
| 381 | 379 | |
| 382 | 380 | return blunder_size >= minsize; |
| … |
… |
|
| 473 | 471 | compute_aa_values(other); |
| 474 | 472 | |
| 475 | 473 | memcpy(defense_moves, defense_points, sizeof(defense_points)); |
| 476 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) { |
| 477 | | if (!ON_BOARD(pos) || !defense_moves[pos] || pos == move) |
| | 474 | scan_board(pos, |
| | 475 | if (!defense_moves[pos] || pos == move) |
| 478 | 476 | continue; |
| 479 | 477 | |
| 480 | 478 | if (!trymove(pos, color, "atari_atari", NO_MOVE)) { |
| … |
… |
|
| 504 | 502 | popgo(); |
| 505 | 503 | decrease_depth_values(); |
| 506 | 504 | popgo(); |
| 507 | | } |
| | 505 | ) |
| 508 | 506 | } |
| 509 | 507 | |
| 510 | 508 | return after_aa_val - aa_val; |
| … |
… |
|
| 540 | 538 | * The worm status of empty points is set to UNKNOWN to signal |
| 541 | 539 | * that stones added along the way need special attention. |
| 542 | 540 | */ |
| 543 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) { |
| | 541 | scan_board(pos, |
| 544 | 542 | if (board[pos] == other) { |
| 545 | 543 | if (safe_stones) { |
| 546 | 544 | if (safe_stones[pos]) |
| … |
… |
|
| 565 | 563 | } |
| 566 | 564 | else if (ON_BOARD(pos)) |
| 567 | 565 | aa_status[pos] = UNKNOWN; |
| 568 | | } |
| | 566 | ) |
| 569 | 567 | |
| 570 | 568 | /* reclassify a worm with 2 liberties as INSUBSTANTIAL if capturing |
| 571 | 569 | * it does not result in a live group. |
| 572 | 570 | */ |
| 573 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) { |
| | 571 | scan_board(pos, |
| 574 | 572 | if (board[pos] == other |
| 575 | 573 | && worm[pos].origin == pos |
| 576 | 574 | && worm[pos].liberties == 2 |
| … |
… |
|
| 586 | 584 | |
| 587 | 585 | if (!owl_substantial(pos)) { |
| 588 | 586 | int pos2; |
| 589 | | for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) |
| 590 | | if (ON_BOARD(pos2) && is_worm_origin(pos2, pos)) |
| | 587 | scan_board(pos2, |
| | 588 | if (is_worm_origin(pos2, pos)) |
| 591 | 589 | aa_status[pos2] = INSUBSTANTIAL; |
| 592 | | } |
| | 590 | ) |
| | 591 | } |
| 593 | 592 | } |
| 594 | | } |
| | 593 | ) |
| 595 | 594 | |
| 596 | 595 | if (debug & DEBUG_ATARI_ATARI) { |
| 597 | 596 | gprintf("compute_aa_status() for %C\n", color); |
| 598 | 597 | gprintf("aa_status: (ALIVE worms not listed)\n"); |
| 599 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) { |
| | 598 | scan_board(pos, |
| 600 | 599 | if (board[pos] == other && is_worm_origin(pos, pos)) { |
| 601 | 600 | const char *status = "UNKNOWN (shouldn't happen)"; |
| 602 | 601 | if (aa_status[pos] == DEAD) |
| … |
… |
|
| 609 | 608 | if (aa_status[pos] != ALIVE) |
| 610 | 609 | gprintf("%1M: %s\n", pos, status); |
| 611 | 610 | } |
| 612 | | } |
| | 611 | ) |
| 613 | 612 | } |
| 614 | 613 | |
| 615 | 614 | sgf_dumptree = save_sgf_dumptree; |
| … |
… |
|
| 687 | 686 | gprintf("%odo_atari_atari: "); |
| 688 | 687 | dump_stack(); |
| 689 | 688 | gprintf("%oforbidden moves: "); |
| 690 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) |
| 691 | | if (ON_BOARD(pos) && forbidden[pos]) |
| 692 | | gprintf("%o%1m ", pos); |
| | 689 | scan_board(pos, |
| | 690 | if (forbidden[pos]) |
| | 691 | gprintf("%o%1m ", pos); |
| | 692 | ) |
| 693 | 693 | gprintf("\n"); |
| 694 | 694 | gprintf("%ogoal: "); |
| 695 | 695 | if (!goal) |
| 696 | 696 | gprintf("none"); |
| 697 | 697 | else { |
| 698 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) |
| 699 | | if (ON_BOARD(pos) && goal[pos]) |
| 700 | | gprintf("%o%1m ", pos); |
| 701 | | } |
| | 698 | scan_board(pos, |
| | 699 | if (goal[pos]) |
| | 700 | gprintf("%o%1m ", pos); |
| | 701 | ) |
| | 702 | } |
| 702 | 703 | gprintf("\n"); |
| 703 | 704 | } |
| 704 | 705 | |
| … |
… |
|
| 870 | 871 | int apos; |
| 871 | 872 | int other = OTHER_COLOR(color); |
| 872 | 873 | |
| 873 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) { |
| | 874 | scan_board(pos, |
| 874 | 875 | if (board[pos] != other) |
| 875 | 876 | continue; |
| 876 | 877 | |
| … |
… |
|
| 921 | 922 | get_aa_value(pos), pos); |
| 922 | 923 | return get_aa_value(pos); |
| 923 | 924 | } |
| 924 | | } |
| | 925 | ) |
| 925 | 926 | |
| 926 | 927 | return 0; |
| 927 | 928 | } |
| … |
… |
|
| 985 | 986 | if (goal != NULL) { |
| 986 | 987 | int pos; |
| 987 | 988 | gprintf("goal:"); |
| 988 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) |
| 989 | | if (ON_BOARD(pos) && goal[pos]) |
| 990 | | gprintf("%o %1m", pos); |
| | 989 | scan_board(pos, |
| | 990 | if (goal[pos]) |
| | 991 | gprintf("%o %1m", pos); |
| | 992 | ) |
| 991 | 993 | gprintf("%o\n"); |
| 992 | 994 | } |
| 993 | 995 | #endif |
| … |
… |
|
| 1210 | 1212 | int mx[BOARDMAX]; |
| 1211 | 1213 | int r, k; |
| 1212 | 1214 | |
| 1213 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) { |
| | 1215 | scan_board(pos, |
| 1214 | 1216 | if (board[pos] != other |
| 1215 | 1217 | || pos != find_origin(pos) |
| 1216 | 1218 | || aa_status[pos] != ALIVE) { |
| … |
… |
|
| 1244 | 1246 | aa_values[pos] = value; |
| 1245 | 1247 | if (1) |
| 1246 | 1248 | DEBUG(DEBUG_ATARI_ATARI, "aa_value for %1m = %d\n", pos, value); |
| 1247 | | } |
| | 1249 | ) |
| 1248 | 1250 | } |
| 1249 | 1251 | |
| 1250 | 1252 | /* The aa_value for a string is the sum of the aa_values for all |
| … |
… |
|
| 1326 | 1328 | * move is strictly equivalent to a played move in terms of goal |
| 1327 | 1329 | * mapping. I doubt it would be anything worth though... |
| 1328 | 1330 | */ |
| 1329 | | for (pos = BOARDMIN; pos < BOARDMAX; pos++) { |
| 1330 | | if (ON_BOARD(pos) && forbidden[pos]) { |
| | 1331 | scan_board(pos, |
| | 1332 | if (forbidden[pos]) { |
| 1331 | 1333 | dists[pos] = 1; |
| 1332 | 1334 | queue[queue_end++] = pos; |
| 1333 | 1335 | } |
| 1334 | | } |
| | 1336 | ) |
| 1335 | 1337 | #endif |
| 1336 | 1338 | |
| 1337 | 1339 | if (queue_end == 0) |