Index: engine/aftermath.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/aftermath.c,v retrieving revision 1.29 diff -u -r1.29 aftermath.c --- engine/aftermath.c 6 May 2002 19:28:00 -0000 1.29 +++ engine/aftermath.c 16 May 2002 09:04:20 -0000 @@ -467,14 +467,14 @@ int important = 0; int safe_atari = 0; for (r = 0; r < 4; r++) { - int dlt = delta[r]; - if (!ON_BOARD(apos+dlt)) + int d = delta[r]; + if (!ON_BOARD(apos+d)) continue; - if (board[apos+dlt] == other - && dragon[apos+dlt].matcher_status == DEAD) + if (board[apos+d] == other + && dragon[apos+d].matcher_status == DEAD) important = 1; - else if (board[apos+dlt] == EMPTY - && !is_self_atari(apos+dlt, other)) + else if (board[apos+d] == EMPTY + && !is_self_atari(apos+d, other)) safe_atari = 1; } if (approxlib(pos, color, 3, NULL) > 2) { Index: engine/matchpat.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/matchpat.c,v retrieving revision 1.31 diff -u -r1.31 matchpat.c --- engine/matchpat.c 19 Apr 2002 17:13:25 -0000 1.31 +++ engine/matchpat.c 16 May 2002 09:04:20 -0000 @@ -774,9 +774,12 @@ /* The tree data structure is output with raw integer offsets * relative to a single array of tree_node_list and match_node - * elements. These offsets need to added to the actual base + * elements. These offsets need to be added to the actual base * address of the list of elements for the pointers to be * meaningful. + * + * FIXME: This code is not portable. On certain platforms the size of + * a pointer and the size of an int differ. */ void tree_initialize_pointers(struct tree_node_list *tnl, @@ -1170,8 +1173,8 @@ void matchpat_goal_anchor(matchpat_callback_fn_ptr callback, int color, - struct pattern_db *pdb, void *callback_data, - char goal[BOARDMAX], int anchor_in_goal) + struct pattern_db *pdb, void *callback_data, + char goal[BOARDMAX], int anchor_in_goal) { loop_fn_ptr_t loop = matchpat_loop; prepare_fn_ptr_t prepare = prepare_for_match; Index: engine/optics.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/optics.c,v retrieving revision 1.42 diff -u -r1.42 optics.c --- engine/optics.c 28 Apr 2002 14:46:43 -0000 1.42 +++ engine/optics.c 16 May 2002 09:04:20 -0000 @@ -865,7 +865,8 @@ && is_ko(pos, eye[pos].color == WHITE_BORDER ? BLACK : WHITE, NULL)) *pessimistic_min = 0; - DEBUG(DEBUG_EYES, " graph matching - max=%d, min=%d, pessimistic_min=%d\n", + DEBUG(DEBUG_EYES, + " graph matching - max=%d, min=%d, pessimistic_min=%d\n", *max, *min, *pessimistic_min); } @@ -1838,8 +1839,7 @@ if (board[eye_vertices[k]] == EMPTY && is_legal(eye_vertices[k], BLACK) && owl_does_attack(eye_vertices[k], str)) { - gprintf("%1m alive, but %1m attacks:\n", - str, eye_vertices[k]); + gprintf("%1m alive, but %1m attacks:\n", str, eye_vertices[k]); showboard(0); gprintf("\n"); } @@ -1853,8 +1853,7 @@ for (k = 0; k < eyesize; k++) { if (board[eye_vertices[k]] == EMPTY && !owl_does_defend(eye_vertices[k], str)) { - gprintf("%1m alive, but almost filled with nakade:\n", - str); + gprintf("%1m alive, but almost filled with nakade:\n", str); showboard(0); } } @@ -1870,8 +1869,7 @@ if (board[eye_vertices[k]] == EMPTY && is_legal(eye_vertices[k], WHITE) && owl_does_defend(eye_vertices[k], str)) { - gprintf("%1m dead, but %1m defends:\n", - str, eye_vertices[k]); + gprintf("%1m dead, but %1m defends:\n", str, eye_vertices[k]); showboard(0); gprintf("\n"); } @@ -1882,7 +1880,7 @@ * attack and defense points. */ if (board[attack_point] != EMPTY - || !is_legal(attack_point, BLACK)) { + || !is_legal(attack_point, BLACK)) { gprintf("Bad attack point %1m:\n", attack_point); showboard(0); } @@ -1892,7 +1890,7 @@ } if (board[defense_point] != EMPTY - || !is_legal(defense_point, WHITE)) { + || !is_legal(defense_point, WHITE)) { gprintf("Bad defense point %1m:\n", defense_point); showboard(0); } Index: engine/reading.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/reading.c,v retrieving revision 1.61 diff -u -r1.61 reading.c --- engine/reading.c 11 May 2002 15:40:11 -0000 1.61 +++ engine/reading.c 16 May 2002 09:04:21 -0000 @@ -49,14 +49,14 @@ #define ADD_CANDIDATE_MOVE(move, score, moves, scores, num_moves)\ do {\ - int la;\ - for (la = 0; la < num_moves; la++)\ - if (moves[la] == (move)) {\ - if (scores[la] < score)\ - scores[la] = score;\ + int u;\ + for (u = 0; u < num_moves; u++)\ + if (moves[u] == (move)) {\ + if (scores[u] < score)\ + scores[u] = score;\ break;\ }\ - if ((la == num_moves) && (num_moves < MAX_MOVES)) {\ + if ((u == num_moves) && (num_moves < MAX_MOVES)) {\ moves[num_moves] = move;\ scores[num_moves] = score;\ (num_moves)++;\ @@ -65,12 +65,12 @@ #define REMOVE_CANDIDATE_MOVE(move, moves, scores, num_moves)\ do {\ - int kr, lr;\ - for (kr = 0; kr < num_moves; kr++) {\ - if (moves[kr] == (move)) {\ - for (lr = kr; lr < num_moves-1; lr++) {\ - moves[lr] = moves[lr+1];\ - scores[lr] = scores[lr+1];\ + int u, v;\ + for (u = 0; u < num_moves; u++) {\ + if (moves[u] == (move)) {\ + for (v = u; v < num_moves-1; v++) {\ + moves[v] = moves[v+1];\ + scores[v] = scores[v+1];\ }\ (num_moves)--;\ break;\ @@ -251,7 +251,8 @@ origin = find_origin(str); if (search_persistent_reading_cache(ATTACK, origin, &result, &the_move)) { - if (move) *move = the_move; + if (move) + *move = the_move; return result; } @@ -273,7 +274,8 @@ store_persistent_reading_cache(ATTACK, origin, result, the_move, nodes); - if (move) *move = the_move; + if (move) + *move = the_move; return result; } @@ -303,14 +305,16 @@ * four liberties. */ if (countlib(str) > 4) { - if (move) *move = NO_MOVE; + if (move) + *move = NO_MOVE; return WIN; } origin = find_origin(str); if (search_persistent_reading_cache(FIND_DEFENSE, origin, &result, &the_move)) { - if (move) *move = the_move; + if (move) + *move = the_move; return result; } @@ -333,7 +337,8 @@ store_persistent_reading_cache(FIND_DEFENSE, origin, result, the_move, nodes); - if (move) *move = the_move; + if (move) + *move = the_move; return result; } Index: engine/utils.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/utils.c,v retrieving revision 1.46 diff -u -r1.46 utils.c --- engine/utils.c 10 May 2002 22:18:50 -0000 1.46 +++ engine/utils.c 16 May 2002 09:04:21 -0000 @@ -1070,7 +1070,7 @@ int found_one; int moves_played = 0; int save_moves; - int m, n; + int pos; int k; int libs[MAXLIBS]; int liberties; @@ -1081,69 +1081,65 @@ something_captured = 0; /* Visit all friendly strings on the board. */ - for (m = 0; m < board_size; m++) - for (n = 0; n < board_size; n++) { - int ii = POS(m, n); - if (board[ii] != color || !is_worm_origin(ii, ii)) - continue; + for (pos = BOARDMIN; pos < BOARDMAX; pos++) { + if (board[pos] != color || !is_worm_origin(pos, pos)) + continue; - /* Try to capture the worm at (m, n). */ - liberties = findlib(ii, MAXLIBS, libs); - save_moves = moves_played; - for (k = 0; k < liberties; k++) { - if (trymove(libs[k], other, "unconditional_life", ii, EMPTY, 0)) - moves_played++; - } - - /* Successful if already captured or a single liberty remains. - * Otherwise we must rewind and take back the last batch of moves. - */ - if (board[ii] == EMPTY) - something_captured = 1; - else if (findlib(ii, 2, libs) == 1) { - /* Need to use tryko as a defense against the extreme case - * when the only opponent liberty that is not suicide is an - * illegal ko capture, like in this 5x5 position: - * +-----+ - * |.XO.O| - * |XXOO.| - * |X.XOO| - * |XXOO.| - * |.XO.O| - * +-----+ - */ - int success = tryko(libs[0], other, "unconditional_life", EMPTY, 0); - gg_assert(success); + /* Try to capture the worm at (m, n). */ + liberties = findlib(pos, MAXLIBS, libs); + save_moves = moves_played; + for (k = 0; k < liberties; k++) { + if (trymove(libs[k], other, "unconditional_life", pos, EMPTY, 0)) moves_played++; - something_captured++; - } - else - while (moves_played > save_moves) { - popgo(); - moves_played--; - } } + + /* Successful if already captured or a single liberty remains. + * Otherwise we must rewind and take back the last batch of moves. + */ + if (board[pos] == EMPTY) + something_captured = 1; + else if (findlib(pos, 2, libs) == 1) { + /* Need to use tryko as a defense against the extreme case + * when the only opponent liberty that is not suicide is an + * illegal ko capture, like in this 5x5 position: + * +-----+ + * |.XO.O| + * |XXOO.| + * |X.XOO| + * |XXOO.| + * |.XO.O| + * +-----+ + */ + int success = tryko(libs[0], other, "unconditional_life", EMPTY, 0); + gg_assert(success); + moves_played++; + something_captured++; + } + else + while (moves_played > save_moves) { + popgo(); + moves_played--; + } + } } - + /* The strings still remaining are uncapturable. Now see which * opponent strings can survive. * * 1. Play opponent stones on all liberties of the unconditionally * alive strings except where illegal. */ - for (m = 0; m < board_size; m++) - for (n = 0; n < board_size; n++) { - int ii = POS(m, n); - if (board[ii] != color || !is_worm_origin(ii, ii)) - continue; + for (pos = BOARDMIN; pos < BOARDMAX; pos++) { + if (board[pos] != color || !is_worm_origin(pos, pos)) + continue; - /* Play as many liberties as we can. */ - liberties = findlib(ii, MAXLIBS, libs); - for (k = 0; k < liberties; k++) { - if (trymove(libs[k], other, "unconditional_life", ii, EMPTY, 0)) - moves_played++; - } + /* Play as many liberties as we can. */ + liberties = findlib(pos, MAXLIBS, libs); + for (k = 0; k < liberties; k++) { + if (trymove(libs[k], other, "unconditional_life", pos, EMPTY, 0)) + moves_played++; } + } /* 2. Recursively extend opponent strings in atari, except where this * would be suicide. @@ -1153,85 +1149,78 @@ /* Nothing found so far in this turn of the loop. */ found_one = 0; - for (m = 0; m < board_size; m++) - for (n = 0; n < board_size; n++) { - int ii = POS(m, n); - if (board[ii] != other || countlib(ii) > 1) - continue; - - /* Try to extend the string at (m, n). */ - findlib(ii, 1, libs); - if (trymove(libs[0], other, "unconditional_life", ii, EMPTY, 0)) { - moves_played++; - found_one = 1; - } - } - } - - for (m = 0; m < board_size; m++) - for (n = 0; n < board_size; n++) { - int ii = POS(m, n); - int aa; - int bb; - int aopen, bopen; - int alib, blib; - if (board[ii] != other || countlib(ii) != 2) - continue; - findlib(ii, 2, libs); - aa = libs[0]; - bb = libs[1]; - if (abs(I(aa) - I(bb)) + abs(J(aa) - J(bb)) != 1) + for (pos = BOARDMIN; pos < BOARDMAX; pos++) { + if (board[pos] != other || countlib(pos) > 1) continue; - - /* Only two liberties and these are adjacent. Play one. We want - * to maximize the number of open liberties. In this particular - * situation we can count this with approxlib for the opposite - * color. If the number of open liberties is the same, we - * maximize the total number of obtained liberties. - * Two relevant positions: - * - * |XXX. - * |OOXX |XXXXXXX - * |O.OX |OOXOOOX - * |..OX |..OO.OX - * +---- +------- - */ - aopen = approxlib(aa, color, 4, NULL); - bopen = approxlib(bb, color, 4, NULL); - alib = approxlib(aa, other, 4, NULL); - blib = approxlib(bb, other, 4, NULL); - - if (aopen > bopen || (aopen == bopen && alib >= blib)) { - trymove(aa, other, "unconditional_life", ii, EMPTY, 0); - moves_played++; - } - else { - trymove(bb, other, "unconditional_life", ii, EMPTY, 0); + + /* Try to extend the string at (m, n). */ + findlib(pos, 1, libs); + if (trymove(libs[0], other, "unconditional_life", pos, EMPTY, 0)) { moves_played++; + found_one = 1; } } + } + for (pos = BOARDMIN; pos < BOARDMAX; pos++) { + int apos; + int bpos; + int aopen, bopen; + int alib, blib; + if (board[pos] != other || countlib(pos) != 2) + continue; + findlib(pos, 2, libs); + apos = libs[0]; + bpos = libs[1]; + if (abs(I(apos) - I(bpos)) + abs(J(apos) - J(bpos)) != 1) + continue; + + /* Only two liberties and these are adjacent. Play one. We want + * to maximize the number of open liberties. In this particular + * situation we can count this with approxlib for the opposite + * color. If the number of open liberties is the same, we + * maximize the total number of obtained liberties. + * Two relevant positions: + * + * |XXX. + * |OOXX |XXXXXXX + * |O.OX |OOXOOOX + * |..OX |..OO.OX + * +---- +------- + */ + aopen = approxlib(apos, color, 4, NULL); + bopen = approxlib(bpos, color, 4, NULL); + alib = approxlib(apos, other, 4, NULL); + blib = approxlib(bpos, other, 4, NULL); + + if (aopen > bopen || (aopen == bopen && alib >= blib)) { + trymove(apos, other, "unconditional_life", pos, EMPTY, 0); + moves_played++; + } + else { + trymove(bpos, other, "unconditional_life", pos, EMPTY, 0); + moves_played++; + } + } + /* Identify unconditionally alive stones and unconditional territory. */ memset(unconditional_territory, 0, sizeof(int) * BOARDMAX); - for (m = 0; m < board_size; m++) - for (n = 0; n < board_size; n++) { - int ii = POS(m, n); - - if (board[ii] == color) { - unconditional_territory[ii] = 1; - if (is_worm_origin(ii, ii)) { - liberties = findlib(ii, MAXLIBS, libs); - for (k = 0; k < liberties; k++) - unconditional_territory[libs[k]] = 2; - } - } - else if (board[ii] == other && countlib(ii) == 1) { - unconditional_territory[ii] = 2; - findlib(ii, 1, libs); - unconditional_territory[libs[0]] = 2; + for (pos = BOARDMIN; pos < BOARDMAX; pos++) { + if (board[pos] == color) { + unconditional_territory[pos] = 1; + if (is_worm_origin(pos, pos)) { + liberties = findlib(pos, MAXLIBS, libs); + for (k = 0; k < liberties; k++) + unconditional_territory[libs[k]] = 2; } } - + else if (board[pos] == other && countlib(pos) == 1) { + unconditional_territory[pos] = 2; + findlib(pos, 1, libs); + unconditional_territory[libs[0]] = 2; + } + } + /* Take back all moves. */ while (moves_played > 0) { popgo();