Index: engine/Makefile.am =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/Makefile.am,v retrieving revision 1.17 diff -u -r1.17 Makefile.am --- engine/Makefile.am 2 Jan 2003 00:23:28 -0000 1.17 +++ engine/Makefile.am 22 Feb 2003 10:19:24 -0000 @@ -40,13 +40,13 @@ printutils.c \ readconnect.c \ reading.c \ - surround.c \ score.c \ semeai.c \ sgfdecide.c \ sgffile.c \ shapes.c \ showbord.c \ + surround.c \ utils.c \ value_moves.c \ worm.c Index: engine/board.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/board.c,v retrieving revision 1.65 diff -u -r1.65 board.c --- engine/board.c 12 Jan 2003 03:49:21 -0000 1.65 +++ engine/board.c 22 Feb 2003 10:19:31 -0000 @@ -1935,6 +1935,19 @@ } +/* Determine whether vertex is a corner. */ +int +is_corner_vertex(int pos) +{ + ASSERT_ON_BOARD1(pos); + if ((!ON_BOARD(WEST(pos)) || !ON_BOARD(EAST(pos))) + && (!ON_BOARD(SOUTH(pos)) || !ON_BOARD(NORTH(pos)))) + return 1; + + return 0; +} + + /* Count the number of liberties of the string at pos. pos must not be * empty. @@ -2120,7 +2133,7 @@ if (LIBERTY(EAST(pos))) fast_liberties++; } - else if(ally2 < 0) { /* One ally */ + else if (ally2 < 0) { /* One ally */ if (LIBERTY(SOUTH(pos)) && !NON_SOUTH_NEIGHBOR_OF_STRING(SOUTH(pos), ally1, color)) fast_liberties++; @@ -2271,7 +2284,8 @@ } -int fastlib(int pos, int color, int ignore_captures) +int +fastlib(int pos, int color, int ignore_captures) { int liberties1 = fastlib_old(pos, color, ignore_captures); int liberties2 = fastlib_new(pos, color, ignore_captures); Index: engine/dragon.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/dragon.c,v retrieving revision 1.107 diff -u -r1.107 dragon.c --- engine/dragon.c 19 Feb 2003 19:21:35 -0000 1.107 +++ engine/dragon.c 22 Feb 2003 10:19:36 -0000 @@ -56,7 +56,6 @@ static void add_adjacent_dragon(int a, int b); static int dragon_invincible(int pos); static int dragon_looks_inessential(int origin); -static void mark_dragon(int pos, char mx[BOARDMAX], char mark); static void identify_thrashing_dragons(void); static void analyze_false_eye_territory(void); static int connected_to_eye(int pos, int str, int color, int eye_color, @@ -249,7 +248,7 @@ && find_eye_dragons(black_eye[str].origin, black_eye, BLACK, &dr, 1) == 1) { - gg_assert(board[dr] == BLACK); + ASSERT1(board[dr] == BLACK, dr); TRACE("eye at %1m found for dragon at %1m--augmenting genus\n", str, dr); if (eye_move_urgency(&black_eye[str].value) @@ -264,7 +263,7 @@ && find_eye_dragons(white_eye[str].origin, white_eye, WHITE, &dr, 1) == 1) { - gg_assert(board[dr] == WHITE); + ASSERT1(board[dr] == WHITE, dr); TRACE("eye at %1m found for dragon at %1m--augmenting genus\n", str, dr); if (eye_move_urgency(&white_eye[str].value) @@ -949,8 +948,8 @@ static void add_adjacent_dragons(int a, int b) { - gg_assert(a >= 0 - && a < number_of_dragons && b >= 0 && b < number_of_dragons); + gg_assert(a >= 0 && a < number_of_dragons + && b >= 0 && b < number_of_dragons); if (a == b) return; add_adjacent_dragon(a, b); @@ -962,8 +961,8 @@ add_adjacent_dragon(int a, int b) { int i; - gg_assert(a >= 0 - && a < number_of_dragons && b >= 0 && b < number_of_dragons); + gg_assert(a >= 0 && a < number_of_dragons + && b >= 0 && b < number_of_dragons); /* If the array of adjacent dragons already is full, ignore * additional neighbors. */ @@ -998,7 +997,7 @@ int strong_eyes = 0; int mx[BOARDMAX]; - gg_assert(IS_STONE(board[dr])); + ASSERT1(IS_STONE(board[dr]), dr); /* First look for invincible strings in the dragon. */ for (pos = BOARDMIN; pos < BOARDMAX; pos++) { @@ -1112,17 +1111,6 @@ } -/* Mark the stones of a dragon. */ -static void -mark_dragon(int pos, char mx[BOARDMAX], char mark) -{ - int w; - for (w = first_worm_in_dragon(dragon[pos].origin); w != NO_MOVE; - w = next_worm_in_dragon(w)) - mark_string(w, mx, mark); -} - - /* If the opponent's last move is a dead dragon, this is called a * *thrashing dragon*. We must be careful because the opponent may be * trying to trick us, so even though GNU Go thinks the stone is dead, @@ -1173,7 +1161,7 @@ DEBUG(DEBUG_DRAGONS, "neighbor at distance %d of thrashing dragon found at %1m\n", dist + 1, DRAGON(d).origin); - mark_dragon(DRAGON(d).origin, thrashing_stone, (char)(dist + 1)); + mark_dragon(DRAGON(d).origin, thrashing_stone, dist + 1); } } } @@ -1594,7 +1582,7 @@ if (eye[pos].color == BLACK_BORDER) color = BLACK; else { - gg_assert(eye[pos].color == WHITE_BORDER); + ASSERT1(eye[pos].color == WHITE_BORDER, pos); color = WHITE; } @@ -1641,9 +1629,9 @@ if (d1 == d2) return; - gg_assert(board[d1] == board[d2]); + ASSERT1(board[d1] == board[d2], d1); gg_assert(dragon2_initialized == 0); - gg_assert(IS_STONE(board[d1])); + ASSERT1(IS_STONE(board[d1]), d1); /* We want to have the origin pointing to the largest string of * the dragon. If this is not unique, we take the "upper @@ -2124,7 +2112,7 @@ weakness_value[2] = gg_interpolate(&genus2weakness, true_genus); DEBUG(DEBUG_DRAGONS, - " moyo value %f -> %f, escape %f -> %f, eyes %f -> %f,\n", + " moyo value %f -> %f, escape %f -> %f, eyes %f -> %f\n", moyo_value, weakness_value[0], escape_route, weakness_value[1], true_genus, weakness_value[2]); @@ -2257,6 +2245,17 @@ } +/* Mark the stones of a dragon. */ +void +mark_dragon(int pos, char mx[BOARDMAX], char mark) +{ + int w; + for (w = first_worm_in_dragon(dragon[pos].origin); w != NO_MOVE; + w = next_worm_in_dragon(w)) + mark_string(w, mx, mark); +} + + /* The following two functions allow to traverse all worms in a dragon: * for (ii = first_worm_in_dragon(pos); ii != NO_MOVE; * ii = next_worm_in_dragon(ii);) @@ -2273,7 +2272,7 @@ int next_worm_in_dragon(int w) { - gg_assert(worm[w].origin == w); + ASSERT1(worm[w].origin == w, w); return next_worm_list[w]; } Index: engine/filllib.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/filllib.c,v retrieving revision 1.27 diff -u -r1.27 filllib.c --- engine/filllib.c 2 Jan 2003 00:23:28 -0000 1.27 +++ engine/filllib.c 22 Feb 2003 10:19:37 -0000 @@ -375,7 +375,7 @@ * opponent. Save it for later use. */ acode = attack(move, &apos); - gg_assert(acode != 0 && apos > NO_MOVE); + gg_assert(acode != 0 && apos != NO_MOVE); /* Find liberties. */ liberties = findlib(move, MAXLIBS, libs); Index: engine/genmove.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/genmove.c,v retrieving revision 1.66 diff -u -r1.66 genmove.c --- engine/genmove.c 15 Feb 2003 14:32:54 -0000 1.66 +++ engine/genmove.c 22 Feb 2003 10:19:39 -0000 @@ -122,6 +122,7 @@ make_worms(); time_report(0, " make worms", NO_MOVE, 1.0); } + if (how_much == EXAMINE_WORMS) { verbose = save_verbose; gg_assert(test_gray_border() < 0); @@ -231,7 +232,7 @@ #if ORACLE if (metamachine) { retval = metamachine_genmove(i, j, color); - gg_assert (stackp == 0); + gg_assert(stackp == 0); if (*i != -1) return 1; } Index: engine/gnugo.h =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/gnugo.h,v retrieving revision 1.90 diff -u -r1.90 gnugo.h --- engine/gnugo.h 15 Feb 2003 14:32:54 -0000 1.90 +++ engine/gnugo.h 22 Feb 2003 10:19:40 -0000 @@ -314,8 +314,6 @@ /* Keep this as 2D until we change the entire API. */ extern float potential_moves[MAX_BOARD][MAX_BOARD]; -extern volatile int time_to_die; /* set by signal handlers */ - extern int limit_search; /* limit move search to a portion of the board */ extern int oracle_exists; /* oracle is available for consultation */ extern int metamachine; /* use metamachine_genmove */ Index: engine/influence.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/influence.c,v retrieving revision 1.75 diff -u -r1.75 influence.c --- engine/influence.c 15 Feb 2003 14:32:54 -0000 1.75 +++ engine/influence.c 22 Feb 2003 10:19:44 -0000 @@ -150,7 +150,7 @@ float b; float inv_attenuation; float inv_diagonal_damping; - float (*permeability_array); + float *permeability_array; /* Clear the queue. Entry 0 is implicitly (m, n). */ int queue_start = 0; Index: engine/liberty.h =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v retrieving revision 1.159 diff -u -r1.159 liberty.h --- engine/liberty.h 19 Feb 2003 19:21:35 -0000 1.159 +++ engine/liberty.h 22 Feb 2003 10:19:47 -0000 @@ -167,8 +167,9 @@ extern int position_number; -/* Detect vertex on edge. */ +/* Detect vertex on edge or corner. */ int is_edge_vertex(int pos); +int is_corner_vertex(int pos); /* Count and/or find liberties at (pos). */ @@ -402,6 +403,7 @@ float moyo_value, float escape_route); int is_same_dragon(int d1, int d2); int are_neighbor_dragons(int d1, int d2); +void mark_dragon(int pos, char mx[BOARDMAX], char mark); int first_worm_in_dragon(int w); int next_worm_in_dragon(int w); int lively_dragon_exists(int color); Index: engine/move_reasons.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/move_reasons.c,v retrieving revision 1.109 diff -u -r1.109 move_reasons.c --- engine/move_reasons.c 28 Jan 2003 12:12:19 -0000 1.109 +++ engine/move_reasons.c 22 Feb 2003 10:19:50 -0000 @@ -814,7 +814,7 @@ ASSERT_ON_BOARD1(w1); ASSERT_ON_BOARD1(w2); - gg_assert(worm[w1].color == worm[w2].color); + ASSERT1(worm[w1].color == worm[w2].color, w1); if (worm[w1].origin == worm[w2].origin) return; @@ -834,7 +834,7 @@ ASSERT_ON_BOARD1(w1); ASSERT_ON_BOARD1(w2); - gg_assert(worm[w1].color == worm[w2].color); + ASSERT1(worm[w1].color == worm[w2].color, w1); if (worm[w1].origin == worm[w2].origin) return; connection = find_connection(worm[w1].origin, worm[w2].origin); @@ -1541,7 +1541,7 @@ float new_strength; int ii; - gg_assert(IS_STONE(board[affected])); + ASSERT1(IS_STONE(board[affected]), affected); if (new_status == 0) new_strength = 0.0; @@ -1577,12 +1577,8 @@ * confirm_safety routines spot an attack with ko and thinks the * move is unsafe. */ - if (move_reasons[r].type == OWL_DEFEND_MOVE) { - int ii; - for (ii = first_worm_in_dragon(what); ii != NO_MOVE; - ii = next_worm_in_dragon(ii)) - mark_string(ii, saved, 1); - } + if (move_reasons[r].type == OWL_DEFEND_MOVE) + mark_dragon(what, saved, 1); } } Index: engine/optics.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/optics.c,v retrieving revision 1.69 diff -u -r1.69 optics.c --- engine/optics.c 6 Feb 2003 13:34:59 -0000 1.69 +++ engine/optics.c 22 Feb 2003 10:19:54 -0000 @@ -69,7 +69,7 @@ struct eye_data eye[BOARDMAX], struct eyevalue *value, int *pessimistic_min); static void reset_map(int size); -static void first_map(int* map_value); +static void first_map(int *map_value); static int next_map(int *q, int map[MAXEYE]); static void print_eye(struct eye_data eye[BOARDMAX], struct half_eye_data heye[BOARDMAX], int pos); @@ -121,7 +121,6 @@ struct eye_data w_eye[BOARDMAX], int owl_call) { - int i, j; int k; int pos; int lively[BOARDMAX]; @@ -149,68 +148,69 @@ * each eye shape. */ - for (i = 0; i < board_size; i++) - for (j = 0; j < board_size; j++) { - pos = POS(i, j); - if (board[pos] == EMPTY || !lively[pos]) { - if (black_domain[pos] == 0 && white_domain[pos] == 0) { - if (w_eye) - w_eye[pos].color = GRAY; - if (b_eye) - b_eye[pos].color = GRAY; + for (pos = BOARDMIN; pos < BOARDMAX; pos++) { + if (!ON_BOARD(pos)) + continue; + + if (board[pos] == EMPTY || !lively[pos]) { + if (black_domain[pos] == 0 && white_domain[pos] == 0) { + if (w_eye) + w_eye[pos].color = GRAY; + if (b_eye) + b_eye[pos].color = GRAY; + } + else if (black_domain[pos] == 1 && white_domain[pos] == 0 && b_eye) { + b_eye[pos].color = BLACK_BORDER; + for (k = 0; k < 4; k++) { + int apos = pos + delta[k]; + if (ON_BOARD(apos) && white_domain[apos] && !black_domain[apos]) { + b_eye[pos].marginal = 1; + break; + } } - else if (black_domain[pos] == 1 && white_domain[pos] == 0 && b_eye) { - b_eye[pos].color = BLACK_BORDER; + } + else if (black_domain[pos] == 0 && white_domain[pos] == 1 && w_eye) { + w_eye[pos].color = WHITE_BORDER; + for (k = 0; k < 4; k++) { + int apos = pos + delta[k]; + if (ON_BOARD(apos) && black_domain[apos] && !white_domain[apos]) { + w_eye[pos].marginal = 1; + break; + } + } + } + else if (black_domain[pos] == 1 && white_domain[pos] == 1) { + if (b_eye) { for (k = 0; k < 4; k++) { int apos = pos + delta[k]; - if (ON_BOARD(apos) && white_domain[apos] && !black_domain[apos]) { + if (ON_BOARD(apos) && black_domain[apos] + && !white_domain[apos]) { b_eye[pos].marginal = 1; + b_eye[pos].color = BLACK_BORDER; break; } } + if (k == 4) + b_eye[pos].color = GRAY; } - else if (black_domain[pos] == 0 && white_domain[pos] == 1 && w_eye) { - w_eye[pos].color = WHITE_BORDER; + + if (w_eye) { for (k = 0; k < 4; k++) { int apos = pos + delta[k]; - if (ON_BOARD(apos) && black_domain[apos] && !white_domain[apos]) { + if (ON_BOARD(apos) && white_domain[apos] + && !black_domain[apos]) { w_eye[pos].marginal = 1; + w_eye[pos].color = WHITE_BORDER; break; } } - } - else if (black_domain[pos] == 1 && white_domain[pos] == 1) { - if (b_eye) { - for (k = 0; k < 4; k++) { - int apos = pos + delta[k]; - if (ON_BOARD(apos) && black_domain[apos] - && !white_domain[apos]) { - b_eye[pos].marginal = 1; - b_eye[pos].color = BLACK_BORDER; - break; - } - } - if (k == 4) - b_eye[pos].color = GRAY; - } - - if (w_eye) { - for (k = 0; k < 4; k++) { - int apos = pos + delta[k]; - if (ON_BOARD(apos) && white_domain[apos] - && !black_domain[apos]) { - w_eye[pos].marginal = 1; - w_eye[pos].color = WHITE_BORDER; - break; - } - } - if (k == 4) - w_eye[pos].color = GRAY; - } + if (k == 4) + w_eye[pos].color = GRAY; } } } - + } + /* * If called from make_dragons, search connection database for cutting * points, which may modify the eyespace in order to avoid amalgamation and @@ -614,8 +614,8 @@ /* Find the dragon or dragons surrounding an eye space. Up to - max_dragons dragons adjacent to the eye space are added to - the dragon array, and the number of dragons found is returned. + * max_dragons dragons adjacent to the eye space are added to + * the dragon array, and the number of dragons found is returned. */ int @@ -663,6 +663,7 @@ int pos) { int m, n; + int pos2; int mini, maxi; int minj, maxj; int origin = eye[pos].origin; @@ -670,35 +671,36 @@ gprintf("Eyespace at %1m: color=%C, esize=%d, msize=%d\n", pos, eye[pos].color, eye[pos].esize, eye[pos].msize); - for (m = 0; m < board_size; m++) - for (n = 0; n < board_size; n++) { - int pos2 = POS(m, n); - if (eye[pos2].origin != pos) - continue; - - if (eye[pos2].marginal && IS_STONE(board[pos2])) - gprintf("%1m (X!)\n", pos2); - else if (is_halfeye(heye, pos2) && IS_STONE(board[pos2])) { - if (heye[pos2].value == 3.0) - gprintf("%1m (XH)\n", pos2); - else - gprintf("%1m (XH) (topological eye value = %f)\n", pos2, - heye[pos2].value); - } - else if (!eye[pos2].marginal && IS_STONE(board[pos2])) - gprintf("%1m (X)\n", pos2); - else if (eye[pos2].marginal && board[pos2] == EMPTY) - gprintf("%1m (!)\n", pos2); - else if (is_halfeye(heye, pos2) && board[pos2] == EMPTY) { - if (heye[pos2].value == 3.0) - gprintf("%1m (H)\n", pos2); - else - gprintf("%1m (H) (topological eye value = %f)\n", pos2, - heye[pos2].value); - } + for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { + if (!ON_BOARD(pos2)) + continue; + + if (eye[pos2].origin != pos) + continue; + + if (eye[pos2].marginal && IS_STONE(board[pos2])) + gprintf("%1m (X!)\n", pos2); + else if (is_halfeye(heye, pos2) && IS_STONE(board[pos2])) { + if (heye[pos2].value == 3.0) + gprintf("%1m (XH)\n", pos2); else - gprintf("%1m\n", pos2); + gprintf("%1m (XH) (topological eye value = %f)\n", pos2, + heye[pos2].value); } + else if (!eye[pos2].marginal && IS_STONE(board[pos2])) + gprintf("%1m (X)\n", pos2); + else if (eye[pos2].marginal && board[pos2] == EMPTY) + gprintf("%1m (!)\n", pos2); + else if (is_halfeye(heye, pos2) && board[pos2] == EMPTY) { + if (heye[pos2].value == 3.0) + gprintf("%1m (H)\n", pos2); + else + gprintf("%1m (H) (topological eye value = %f)\n", pos2, + heye[pos2].value); + } + else + gprintf("%1m\n", pos2); + } gprintf("\n"); /* Determine the size of the eye. */ @@ -809,7 +811,7 @@ struct eye_data eye[BOARDMAX], struct half_eye_data heye[BOARDMAX]) { - int m, n; + int pos2; int margins = 0; int halfeyes = 0; int margins_adjacent_to_margin = 0; @@ -820,21 +822,21 @@ */ int interior_stones = 0; - for (m = 0; m < board_size; m++) - for (n = 0; n < board_size; n++) { - int pos2 = POS(m, n); - if (eye[pos2].origin != pos) - continue; - if (eye[pos2].marginal || is_halfeye(heye, pos2)) { - margins++; - if (eye[pos2].marginal && eye[pos2].marginal_neighbors > 0) - margins_adjacent_to_margin++; - if (is_halfeye(heye, pos2)) - halfeyes++; - } - else if (IS_STONE(board[pos2])) - interior_stones++; + for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { + if (!ON_BOARD(pos2)) + continue; + if (eye[pos2].origin != pos) + continue; + if (eye[pos2].marginal || is_halfeye(heye, pos2)) { + margins++; + if (eye[pos2].marginal && eye[pos2].marginal_neighbors > 0) + margins_adjacent_to_margin++; + if (is_halfeye(heye, pos2)) + halfeyes++; } + else if (IS_STONE(board[pos2])) + interior_stones++; + } /* This is a measure based on the simplified assumption that both * players only cares about playing the marginal eye spaces. It is @@ -905,7 +907,6 @@ int best_attack_point = NO_MOVE; int best_defense_point = NO_MOVE; float score = 0.0; - int pos2; for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { if (ON_BOARD(pos2) && eye[pos2].origin == pos) { @@ -1095,7 +1096,7 @@ struct half_eye_data heye[BOARDMAX], struct vital_points *vp) { - int m, n; + int pos2; int eye_color; int eye_size = 0; int num_marginals = 0; @@ -1123,48 +1124,49 @@ return 0; /* Create list of eye vertices */ - for (m = 0; m < board_size; m++) - for (n = 0; n < board_size; n++) { - int pos2 = POS(m, n); - if (eye[pos2].origin == pos) { - vpos[eye_size] = pos2; - marginal[eye_size] = eye[pos2].marginal; + for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { + if (!ON_BOARD(pos2)) + continue; + if (eye[pos2].origin == pos) { + vpos[eye_size] = pos2; + marginal[eye_size] = eye[pos2].marginal; + if (marginal[eye_size]) + num_marginals++; + neighbors[eye_size] = eye[pos2].neighbors; + if (0) { if (marginal[eye_size]) - num_marginals++; - neighbors[eye_size] = eye[pos2].neighbors; - if (0) { - if (marginal[eye_size]) - TRACE("(%1m)", vpos[eye_size]); - else - TRACE(" %1m ", vpos[eye_size]); - TRACE("\n"); - } - + TRACE("(%1m)", vpos[eye_size]); + else + TRACE(" %1m ", vpos[eye_size]); + TRACE("\n"); + } + + if (is_corner_vertex(pos2)) + edge[eye_size] = 2; + else if (is_edge_vertex(pos2)) + edge[eye_size] = 1; + else edge[eye_size] = 0; - if (m == 0 || m == board_size-1) - edge[eye_size]++; - if (n == 0 || n == board_size-1) - edge[eye_size]++; - - if (is_halfeye(heye, pos2)) { - neighbors[eye_size]++; /* Increase neighbors of half eye. */ - eye_size++; - /* Use a virtual marginal vertex for mapping purposes. We set it - * to be at NO_MOVE so it won't accidentally count as a - * neighbor for another vertex. Note that the half eye precedes - * the virtual marginal vertex in the list. - */ - vpos[eye_size] = NO_MOVE; - marginal[eye_size] = 1; - num_marginals++; - edge[eye_size] = 0; - neighbors[eye_size] = 1; - } - + + if (is_halfeye(heye, pos2)) { + neighbors[eye_size]++; /* Increase neighbors of half eye. */ eye_size++; + /* Use a virtual marginal vertex for mapping purposes. We set it + * to be at NO_MOVE so it won't accidentally count as a + * neighbor for another vertex. Note that the half eye precedes + * the virtual marginal vertex in the list. + */ + vpos[eye_size] = NO_MOVE; + marginal[eye_size] = 1; + num_marginals++; + edge[eye_size] = 0; + neighbors[eye_size] = 1; } + + eye_size++; } - + } + /* We attempt to construct a map from the graph to the eyespace * preserving the adjacency structure. If this can be done, we've * identified the eyeshape. @@ -1566,6 +1568,52 @@ return heye[pos].type == FALSE_EYE; } + +/* Find topological half eyes and false eyes by analyzing the + * diagonal intersections, as described in the Texinfo + * documentation (Eyes/Eye Topology). + */ +void +find_half_and_false_eyes(int color, struct eye_data eye[BOARDMAX], + struct half_eye_data heye[BOARDMAX], + char find_mask[BOARDMAX]) +{ + int eye_color = (color == WHITE ? WHITE_BORDER : BLACK_BORDER); + int pos; + float sum; + + for (pos = BOARDMIN; pos < BOARDMAX; pos++) { + /* skip eyespaces which owl doesn't want to be searched */ + if (!ON_BOARD(pos) || (find_mask && find_mask[eye[pos].origin] <= 1)) + continue; + + /* skip every vertex which can't be a false or half eye */ + if (eye[pos].color != eye_color + || eye[pos].marginal + || eye[pos].neighbors > 1) + continue; + + sum = topological_eye(pos, color, eye, heye); + if (sum >= 4.0) { + /* false eye */ + heye[pos].type = FALSE_EYE; + if (eye[pos].esize == 1 + || is_legal(pos, OTHER_COLOR(color)) + || board[pos] == OTHER_COLOR(color)) + add_false_eye(pos, eye, heye); + } + else if (sum > 2.0) { + /* half eye */ + heye[pos].type = HALF_EYE; + ASSERT1(heye[pos].num_attacks > 0, pos); + ASSERT_ON_BOARD1(heye[pos].attack_point[0]); + ASSERT1(heye[pos].num_defends > 0, pos); + ASSERT_ON_BOARD1(heye[pos].defense_point[0]); + } + } +} + + /* See Texinfo documentation (Eyes:Eye Topology). Returns: * - 2 or less if (pos) is a proper eye for (color); * - between 2 and 3 if the eye can be made false only by ko @@ -2199,51 +2247,6 @@ } } verbose = save_verbose; -} - - -/* Find topological half eyes and false eyes by analyzing the - * diagonal intersections, as described in the Texinfo - * documentation (Eyes/Eye Topology). - */ -void -find_half_and_false_eyes(int color, struct eye_data eye[BOARDMAX], - struct half_eye_data heye[BOARDMAX], - char find_mask[BOARDMAX]) -{ - int eye_color = (color == WHITE ? WHITE_BORDER : BLACK_BORDER); - int pos; - float sum; - - for (pos = BOARDMIN; pos < BOARDMAX; pos++) { - /* skip eyespaces which owl doesn't want to be searched */ - if (!ON_BOARD(pos) || (find_mask && find_mask[eye[pos].origin] <= 1)) - continue; - - /* skip every vertex which can't be a false or half eye */ - if (eye[pos].color != eye_color - || eye[pos].marginal - || eye[pos].neighbors > 1) - continue; - - sum = topological_eye(pos, color, eye, heye); - if (sum >= 4.0) { - /* false eye */ - heye[pos].type = FALSE_EYE; - if (eye[pos].esize == 1 - || is_legal(pos, OTHER_COLOR(color)) - || board[pos] == OTHER_COLOR(color)) - add_false_eye(pos, eye, heye); - } - else if (sum > 2.0) { - /* half eye */ - heye[pos].type = HALF_EYE; - ASSERT1(heye[pos].num_attacks > 0, pos); - ASSERT_ON_BOARD1(heye[pos].attack_point[0]); - ASSERT1(heye[pos].num_defends > 0, pos); - ASSERT_ON_BOARD1(heye[pos].defense_point[0]); - } - } } Index: engine/oracle.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/oracle.c,v retrieving revision 1.10 diff -u -r1.10 oracle.c --- engine/oracle.c 2 Jan 2003 00:23:28 -0000 1.10 +++ engine/oracle.c 22 Feb 2003 10:19:56 -0000 @@ -57,7 +57,7 @@ #define TELL_ORACLE(x, args...) do { \ if (debug & DEBUG_ORACLE_STREAM) fprintf(stderr, x, ##args); \ if (fprintf(to_gnugo_stream, x, ##args) < 0) \ - error ("can't write command in to_gnugo_stream"); \ + error("can't write command in to_gnugo_stream"); \ fflush(to_gnugo_stream); \ } while (0) @@ -224,7 +224,7 @@ va_start(ap, fmt); if (debug & DEBUG_ORACLE_STREAM) fprintf(stderr, fmt, ap); if (fprintf(to_gnugo_stream, fmt, ap) < 0) - error ("can't write command in to_gnugo_stream"); + error("can't write command in to_gnugo_stream"); fflush(to_gnugo_stream); va_end(ap); } Index: engine/owl.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/owl.c,v retrieving revision 1.144 diff -u -r1.144 owl.c --- engine/owl.c 20 Feb 2003 11:55:21 -0000 1.144 +++ engine/owl.c 22 Feb 2003 10:20:06 -0000 @@ -241,8 +241,8 @@ /* Semeai worms are worms whose capture wins the semeai. */ #define MAX_SEMEAI_WORMS 20 -int s_worms = 0; -int semeai_worms[MAX_SEMEAI_WORMS]; +static int s_worms = 0; +static int semeai_worms[MAX_SEMEAI_WORMS]; /* Called when (apos) and (bpos) point to adjacent dragons * of the opposite color, both with matcher_status DEAD or @@ -312,7 +312,7 @@ sgf_dumptree = save_sgf_dumptree; } - gg_assert(board[apos] == OTHER_COLOR(board[bpos])); + ASSERT1(board[apos] == OTHER_COLOR(board[bpos]), apos); count_variations = 1; TRACE("owl_analyze_semeai: %1m vs. %1m\n", apos, bpos); if (owl) { @@ -407,8 +407,8 @@ global_owl_node_counter++; local_owl_node_counter++; - gg_assert(board[apos] == owla->color); - gg_assert(board[bpos] == owlb->color); + ASSERT1(board[apos] == owla->color, apos); + ASSERT1(board[bpos] == owlb->color, bpos); if (stackp <= owl_branch_depth && (hashflags & HASH_SEMEAI) && !pass && owl_phase) { @@ -468,7 +468,7 @@ moves[k].name = NULL; moves[k].same_dragon = 2; } - gg_assert(other == board[bpos]); + ASSERT1(other == board[bpos], bpos); memset(mw, 0, sizeof(mw)); /* Look for a tactical attack. We seek a semeai worm of owlb @@ -555,7 +555,8 @@ /* FIXME: This is kind of quick and dirty. */ if (probable_eyes_a.b > matches_found) probable_eyes_a.b -= matches_found; - else probable_eyes_a.b = 0; + else + probable_eyes_a.b = 0; } owl_determine_life(owlb, owla, komaster, 1, vital_offensive_moves, @@ -569,7 +570,8 @@ /* FIXME: This is kind of quick and dirty. */ if (probable_eyes_b.b > matches_found) probable_eyes_b.b -= matches_found; - else probable_eyes_b.b = 0; + else + probable_eyes_b.b = 0; } /* Certain cases can be handled immediately. */ @@ -1000,7 +1002,7 @@ int color = owla->color; int save_verbose = verbose; - gg_assert(board[move] == EMPTY); + ASSERT1(board[move] == EMPTY, move); verbose = 0; if (safe_move(move, color)) { for (pos = BOARDMIN; pos < BOARDMAX; pos++) { @@ -2327,7 +2329,7 @@ * This function calls owl_determine_life() to get an eye estimate, * and matchpat() for vital attack moves, and decides according to * various policies (depth-dependant) whether the dragon should thus - * be considered alife. + * be considered alive. */ static int owl_estimate_life(struct local_owl_data *owl, @@ -4170,7 +4172,7 @@ if (debug & DEBUG_OWL_PERFORMANCE) start = gg_cputime(); - gg_assert(board[target2] == color); + ASSERT1(board[target2] == color, target2); TRACE("owl_connection_defends %1m %1m %1m\n", move, target1, target2); if (worm[target1].unconditional_status == DEAD) @@ -4431,20 +4433,6 @@ } -/* Returns true if and only if `pos' is a corner (1-1) point. - */ -static int -corner_point(int pos) -{ - ASSERT_ON_BOARD1(pos); - - return pos == POS(0, 0) - || pos == POS(0, board_size - 1) - || pos == POS(board_size - 1, 0) - || pos == POS(board_size - 1, board_size - 1); -} - - /* Try to improve the move to attack a lunch. Essentially we try to * avoid unsafe moves when there are less risky ways to attack. * @@ -4467,7 +4455,7 @@ int adj[MAXCHAIN]; if (safe_move(attack_point, color)) { - if (countstones(lunch) == 1 && corner_point(attack_point) + if (countstones(lunch) == 1 && is_corner_vertex(attack_point) && chainlinks2(lunch, adj, 1) == 0) { for (k = 0; k < 4; k++) { int apos = attack_point + delta[k]; @@ -4668,7 +4656,6 @@ owl_substantial(int str) { int k; - int m, n; int libs[MAX_SUBSTANTIAL_LIBS + 1]; int liberties = findlib(str, MAX_SUBSTANTIAL_LIBS+1, libs); int reading_nodes_when_called = get_reading_node_counter(); @@ -4698,10 +4685,8 @@ if (liberties > MAX_SUBSTANTIAL_LIBS) return 0; - - for (m = 0; m < board_size; m++) - for (n = 0; n < board_size; n++) - owl->goal[POS(m, n)] = 0; + + memset(owl->goal, 0, sizeof(owl->goal)); /* Mark the neighbors of the string. If one is found which is alive, return * true. */ { @@ -4712,10 +4697,7 @@ for (k = 0; k < adj; k++) { if (dragon[adjs[k]].status == ALIVE) return 1; - for (m = 0; m < board_size; m++) - for (n = 0; n < board_size; n++) - if (is_same_dragon(POS(m, n), adjs[k])) - owl->goal[POS(m, n)] = 1; + mark_dragon(adjs[k], owl->goal, 1); } } Index: engine/readconnect.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/readconnect.c,v retrieving revision 1.44 diff -u -r1.44 readconnect.c --- engine/readconnect.c 4 Feb 2003 15:22:03 -0000 1.44 +++ engine/readconnect.c 22 Feb 2003 10:20:12 -0000 @@ -80,10 +80,10 @@ static void order_connection_moves(int *moves, int str1, int str2, int color_to_move, const char *funcname); -int nodes_connect = 0; -int max_nodes_connect = 2000; -int max_connect_depth = 64; -int max_connect_depth2 = 20; /* Used by the alternate algorithm. */ +static int nodes_connect = 0; +static int max_nodes_connect = 2000; +static int max_connect_depth = 64; +static int max_connect_depth2 = 20; /* Used by the alternate algorithm. */ /* Used by alternate connections. */ static char connection_shadow[BOARDMAX]; @@ -1341,7 +1341,7 @@ } Moves[0] = 0; - moves_to_prevent_connection_in_three_moves (Moves, str1, str2); + moves_to_prevent_connection_in_three_moves(Moves, str1, str2); if (Moves[0] > 0) res = 0; order_connection_moves(Moves, str1, str2, OTHER_COLOR(board[str1]), @@ -1565,8 +1565,8 @@ * because the function that prevents connection in one * move is called at and nodes. */ - moves_to_connect_in_two_moves (Moves, str1, str2); - moves_to_connect_in_two_moves (Moves, str2, str3); + moves_to_connect_in_two_moves(Moves, str1, str2); + moves_to_connect_in_two_moves(Moves, str2, str3); /* If there are some forced moves to prevent the capture * of one of the two strings, then we only look at @@ -1608,7 +1608,7 @@ nodes_connect = 0; *move = PASS_MOVE; - moves_to_prevent_connection_in_three_moves (Moves, str1, str3); + moves_to_prevent_connection_in_three_moves(Moves, str1, str3); if (Moves[0] > 0) res = 0; order_connection_moves(Moves, str1, str2, OTHER_COLOR(board[str1]), Index: engine/reading.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/reading.c,v retrieving revision 1.104 diff -u -r1.104 reading.c --- engine/reading.c 19 Feb 2003 00:45:27 -0000 1.104 +++ engine/reading.c 22 Feb 2003 10:20:22 -0000 @@ -1253,11 +1253,10 @@ color = board[str]; other = OTHER_COLOR(color); - gg_assert(IS_STONE(board[str])); - gg_assert(countlib(str) == 2); + ASSERT1(IS_STONE(board[str]), str); + ASSERT1(countlib(str) == 2, str); liberties = findlib(str, 2, libs); - ASSERT1(liberties == 2, str); if (fast_defense(str, liberties, libs, &xpos)) RETURN_RESULT(WIN, xpos, move, "fast defense"); @@ -1488,11 +1487,10 @@ color = board[str]; other = OTHER_COLOR(color); - gg_assert(IS_STONE(board[str])); - gg_assert(countlib(str) == 3); + ASSERT1(IS_STONE(board[str]), str); + ASSERT1(countlib(str) == 3, str); liberties = findlib(str, 3, libs); - ASSERT1(liberties == 3, str); if (fast_defense(str, liberties, libs, &xpos)) RETURN_RESULT(WIN, xpos, move, "fast defense"); @@ -1765,11 +1763,10 @@ color = board[str]; other = OTHER_COLOR(color); - gg_assert(IS_STONE(board[str])); - gg_assert(countlib(str) == 4); + ASSERT1(IS_STONE(board[str]), str); + ASSERT1(countlib(str) == 4, str); liberties = findlib(str, 4, libs); - ASSERT1(liberties == 4, str); if (fast_defense(str, liberties, libs, &xpos)) RETURN_RESULT(WIN, xpos, move, "fast defense"); @@ -2228,6 +2225,51 @@ } } +/* + * set_up_snapback_moves() is called with (str) a string having a + * single liberty at (lib). + * + * This adds moves which may defend a string in atari by capturing a + * neighbor in a snapback. One example is this position: + * + * OOOOO + * OXXXO + * OX.OX + * OXOXX + * OX*.. + * ----- + * + * This code also finds the move * to defend the lone O stone with ko + * in this position: + * + * |XXXXX + * |XOOOX + * |OX.OO + * |.*... + * +----- + * + */ + +static void +set_up_snapback_moves(int str, int lib, struct reading_moves *moves) +{ + int color = board[str]; + int other = OTHER_COLOR(color); + int libs2[2]; + + ASSERT1(countlib(str) == 1, str); + + /* This can only work if our string is a single stone and the + * opponent is short of liberties. + */ + if (stackp <= backfill_depth + && countstones(str) == 1 + && approxlib(lib, other, 2, libs2) == 1 + && !is_self_atari(libs2[0], color)) + ADD_CANDIDATE_MOVE(libs2[0], 0, *moves); +} + + /* In positions like * @@ -3396,7 +3438,7 @@ reading_node_counter++; moves.num = 0; - gg_assert(IS_STONE(board[str])); + ASSERT1(IS_STONE(board[str]), str); if (stackp > depth) RETURN_RESULT(0, 0, move, "stackp > depth"); @@ -3614,7 +3656,7 @@ SETUP_TRACE_INFO("attack4", str); - gg_assert(IS_STONE(board[str])); + ASSERT1(IS_STONE(board[str]), str); reading_node_counter++; moves.num = 0; @@ -3854,7 +3896,7 @@ int bpos; int k; - gg_assert(countlib(str) == 2); + ASSERT1(countlib(str) == 2, str); for (k = 0; k < 2; k++) { apos = libs[k]; @@ -3913,7 +3955,7 @@ int elibs; int k, s, t; - gg_assert(countlib(str) == 2); + ASSERT1(countlib(str) == 2, str); /* To avoid making this too general, we require that both * liberties are self ataris for X. @@ -5272,51 +5314,6 @@ } } -/* - * set_up_snapback_moves() is called with (str) a string having a - * single liberty at (lib). - * - * This adds moves which may defend a string in atari by capturing a - * neighbor in a snapback. One example is this position: - * - * OOOOO - * OXXXO - * OX.OX - * OXOXX - * OX*.. - * ----- - * - * This code also finds the move * to defend the lone O stone with ko - * in this position: - * - * |XXXXX - * |XOOOX - * |OX.OO - * |.*... - * +----- - * - */ - -static void -set_up_snapback_moves(int str, int lib, struct reading_moves *moves) -{ - int color = board[str]; - int other = OTHER_COLOR(color); - int libs2[2]; - - ASSERT1(countlib(str) == 1, str); - - /* This can only work if our string is a single stone and the - * opponent is short of liberties. - */ - if (stackp <= backfill_depth - && countstones(str) == 1 - && approxlib(lib, other, 2, libs2) == 1 - && !is_self_atari(libs2[0], color)) - ADD_CANDIDATE_MOVE(libs2[0], 0, *moves); -} - - /* ================================================================ */ @@ -5614,7 +5611,7 @@ reading_node_counter++; moves.num = 0; - gg_assert(IS_STONE(board[str])); + ASSERT1(IS_STONE(board[str]), str); ASSERT1(countlib(str) == 1, str); /* lib will be the liberty of the string. */ Index: engine/surround.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/surround.c,v retrieving revision 1.8 diff -u -r1.8 surround.c --- engine/surround.c 12 Jan 2003 18:37:56 -0000 1.8 +++ engine/surround.c 22 Feb 2003 10:20:23 -0000 @@ -107,21 +107,15 @@ char mn[BOARDMAX]; /* neighbor dragons */ int sd[BOARDMAX]; /* distances to the goal */ + if (DRAGON2(pos).hostile_neighbors == 0) + return(0); + memset(mf, 0, sizeof(mf)); memset(mn, 0, sizeof(mn)); memset(sd, 0, sizeof(sd)); - /* mark dragon */ + mark_dragon(pos, mf, 1); - for (dpos = BOARDMIN; dpos < BOARDMAX; dpos++) - if (ON_BOARD(dpos) - && worm[dpos].origin == dpos - && is_same_dragon(dpos, pos)) - mark_string(dpos, mf, 1); - - if (DRAGON2(pos).hostile_neighbors == 0) - return(0); - /* mark hostile neighbors */ for (k = 0; k < DRAGON2(pos).neighbors; k++) { @@ -130,11 +124,7 @@ if (board[nd] != color) { if (0) gprintf("neighbor: %1m\n", nd); - for (dpos = BOARDMIN; dpos < BOARDMAX; dpos++) - if (ON_BOARD(dpos) - && worm[dpos].origin == dpos - && is_same_dragon(dpos, nd)) - mark_string(dpos, mn, 1); + mark_dragon(nd, mn, 1); } } @@ -193,7 +183,7 @@ break; } } - } while(found_some); + } while (found_some); /* prepare corner array */ @@ -217,10 +207,10 @@ gg_sort(corner, corners, sizeof(int), compare_angles); - /* if apos is non NULL, mark it. */ + /* if apos is not NO_MOVE, mark it. */ - if (apos) { - gg_assert(ON_BOARD(apos)); + if (apos != NO_MOVE) { + ASSERT_ON_BOARD1(apos); mn[apos] = 1; } @@ -276,7 +266,7 @@ best_slope = slope; } } - gg_assert(ON_BOARD(best_found)); + ASSERT_ON_BOARD1(best_found); left_corner[left_corners] = best_found; } @@ -308,7 +298,7 @@ } } } - gg_assert(ON_BOARD(best_found)); + ASSERT_ON_BOARD1(best_found); right_corner[right_corners] = best_found; } @@ -324,9 +314,11 @@ for (n = J(left_corner[0]); n <= J(right_corner[0]); n++) mn[POS(top_row, n)] = 1; + for (n = J(left_corner[left_corners-1]); n <= J(right_corner[right_corners-1]); n++) mn[POS(bottom_row, n)] = 1; + for (m = top_row+1; m < bottom_row; m++) { int left_boundary = -1, right_boundary = -1; for (k = 1; k < left_corners; k++) { @@ -346,6 +338,7 @@ break; } } + for (k = 1; k < right_corners; k++) { if (I(right_corner[k]) > m) { float ti = I(right_corner[k-1]); @@ -362,6 +355,7 @@ break; } } + for (n = left_boundary; n <= right_boundary; n++) mn[POS(m, n)] = 1; } @@ -478,55 +472,37 @@ /* revise the status if an ikken tobi jumps out. */ if (surrounded) { - for (dpos = BOARDMIN; dpos < BOARDMAX && surrounded; dpos++) - if (ON_BOARD(dpos) && mf[dpos]) { - if ((ON_BOARD(NORTH(dpos)) - && board[NORTH(dpos)] == EMPTY - && ON_BOARD(NORTH(NORTH(dpos))) - && board[NORTH(NORTH(dpos))] == color - && mn[NORTH(NORTH(dpos))] != 1 - && ON_BOARD(EAST(NORTH(dpos))) - && board[EAST(NORTH(dpos))] != other - && ON_BOARD(WEST(NORTH(dpos))) - && board[WEST(NORTH(dpos))] != other) - || (ON_BOARD(SOUTH(dpos)) - && board[SOUTH(dpos)] == EMPTY - && ON_BOARD(SOUTH(SOUTH(dpos))) - && board[SOUTH(SOUTH(dpos))] == color - && mn[SOUTH(SOUTH(dpos))] != 1 - && ON_BOARD(EAST(SOUTH(dpos))) - && board[EAST(SOUTH(dpos))] != other - && ON_BOARD(WEST(SOUTH(dpos))) - && board[WEST(SOUTH(dpos))] != other) - || (ON_BOARD(EAST(dpos)) - && board[EAST(dpos)] == EMPTY - && ON_BOARD(EAST(EAST(dpos))) - && board[EAST(EAST(dpos))] == color - && mn[EAST(EAST(dpos))] != 1 - && ON_BOARD(NORTH(EAST(dpos))) - && board[NORTH(EAST(dpos))] != other - && ON_BOARD(SOUTH(EAST(dpos))) - && board[SOUTH(EAST(dpos))] != other) - || (ON_BOARD(WEST(dpos)) - && board[WEST(dpos)] == EMPTY - && ON_BOARD(WEST(WEST(dpos))) - && board[WEST(WEST(dpos))] == color - && mn[WEST(WEST(dpos))] != 1 - && ON_BOARD(NORTH(WEST(dpos))) - && board[NORTH(WEST(dpos))] != other - && ON_BOARD(SOUTH(WEST(dpos))) - && board[SOUTH(WEST(dpos))] != other)) + for (dpos = BOARDMIN; dpos < BOARDMAX && surrounded; dpos++) { + if (!ON_BOARD(dpos) || !mf[dpos]) + continue; + + for (k = 0; k < 4; k++) { + int up = delta[k]; + int right = delta[(k + 1) % 4]; + if (board[dpos + up] == EMPTY + && board[dpos + 2*up] == color + && mn[dpos + 2*up] != 1 + && ON_BOARD(dpos + up + right) + && board[dpos + up + right] != other + && ON_BOARD(dpos + up - right) + && board[dpos + up - right] != other) { surrounded = 0; + break; + } } + } } + if (showboard == 1 || (showboard == 2 && surrounded)) { show_surround_map(mf, mn); } + if (!apos && surrounded && surround_pointer < MAX_SURROUND) { memcpy(surroundings[surround_pointer].surround_map, mn, sizeof(mn)); surroundings[surround_pointer].dragon_number = dragon[pos].id; surround_pointer++; } + if (surround_size) { int pos; @@ -535,6 +511,7 @@ if (ON_BOARD(pos) && mn[pos] == 1) (*surround_size)++; } + return surrounded; } @@ -616,7 +593,6 @@ else return 0; } - } Index: engine/utils.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/utils.c,v retrieving revision 1.65 diff -u -r1.65 utils.c --- engine/utils.c 2 Jan 2003 19:41:19 -0000 1.65 +++ engine/utils.c 22 Feb 2003 10:20:27 -0000 @@ -982,9 +982,7 @@ verbose = current_verbose; *return_value += 2.0 * dragon[bpos].effective_size; if (safe_stones) - for (ii = first_worm_in_dragon(bpos); ii != NO_MOVE; - ii = next_worm_in_dragon(ii)) - mark_string(ii, safe_stones, 0); + mark_dragon(bpos, safe_stones, 0); } else if (acode == LOSS) { verbose = save_verbose; @@ -1887,7 +1885,7 @@ /* Internal timers for assessing time spent on various tasks. */ #define NUMBER_OF_TIMERS 4 -double timers[NUMBER_OF_TIMERS]; +static double timers[NUMBER_OF_TIMERS]; /* Start a timer. */ void Index: engine/worm.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/worm.c,v retrieving revision 1.51 diff -u -r1.51 worm.c --- engine/worm.c 2 Jan 2003 00:23:29 -0000 1.51 +++ engine/worm.c 22 Feb 2003 10:20:30 -0000 @@ -113,7 +113,7 @@ int lib1, lib2, lib3, lib4; ping_cave(pos, &lib1, &lib2, &lib3, &lib4); - gg_assert(worm[pos].liberties == lib1); + ASSERT1(worm[pos].liberties == lib1, pos); worm[pos].liberties2 = lib2; worm[pos].liberties3 = lib3; worm[pos].liberties4 = lib4; @@ -636,7 +636,7 @@ break; } if (!already_counted) { - gg_assert(nworms[pos] < 2*(board_size-1)); + ASSERT1(nworms[pos] < 2*(board_size-1), pos); worms[pos][nworms[pos]] = worms[pos2][k]; nworms[pos]++; } @@ -1178,8 +1178,8 @@ int points[MAX_TACTICAL_POINTS], int codes[MAX_TACTICAL_POINTS]) { - gg_assert(ON_BOARD(str)); - gg_assert(str == worm[str].origin); + ASSERT_ON_BOARD1(str); + ASSERT1(str == worm[str].origin, str); movelist_change_point(move, code, MAX_TACTICAL_POINTS, points, codes); propagate_worm2(str); Index: interface/main.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/main.c,v retrieving revision 1.65 diff -u -r1.65 main.c --- interface/main.c 15 Feb 2003 14:32:54 -0000 1.65 +++ interface/main.c 22 Feb 2003 10:20:33 -0000 @@ -28,6 +28,7 @@ #include #ifdef HAVE_UNISTD_H +/* For isatty(). */ #include #else #include @@ -266,8 +267,6 @@ {NULL, 0, NULL, 0} }; -float memory = (float) DEFAULT_MEMORY; /* Megabytes used for hash table. */ - int main(int argc, char *argv[]) @@ -297,6 +296,8 @@ FILE *gtp_input_FILE, *output_check; int orientation = 0; + float memory = (float) DEFAULT_MEMORY; /* Megabytes used for hash table. */ + /* If seed is zero, GNU Go will play a different game each time. If * it is set using -r, GNU Go will play the same game each time. * (Change seed to get a different game). @@ -1061,12 +1062,14 @@ } if (!string_to_location(board_size, decide_this, &ai, &aj)) { - fprintf(stderr, "usage: --decide-connection [first string]/[second string]\n"); + fprintf(stderr, + "usage: --decide-connection [first string]/[second string]\n"); return EXIT_FAILURE; } if (!string_to_location(board_size, decide_that, &bi, &bj)) { - fprintf(stderr, "usage: --decide-connection [first string]/[second string]\n"); + fprintf(stderr, + "usage: --decide-connection [first string]/[second string]\n"); return EXIT_FAILURE; } Index: interface/play_ascii.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_ascii.c,v retrieving revision 1.34 diff -u -r1.34 play_ascii.c --- interface/play_ascii.c 18 Jan 2003 03:05:31 -0000 1.34 +++ interface/play_ascii.c 22 Feb 2003 10:20:35 -0000 @@ -1020,7 +1020,7 @@ return; /* EOF or some error */ for (i = 0; i < 12; i++) - line[i] = (isupper ((int) line[i]) ? tolower ((int) line[i]) : line[i]); + line[i] = tolower((int) line[i]); if (!strncmp(line, "done", 4)) done = 1; else if (!strncmp(line, "quit", 4)) @@ -1158,7 +1158,7 @@ if (!fgets(line, 80, stdin)) return; /* EOF or some error */ for (i = 0; i < 80; i++) - line[i] = (isupper ((int) line[i]) ? tolower ((int) line[i]) : line[i]); + line[i] = tolower((int) line[i]); if (!strncmp(line, "undo", 4)) { if (!handi) @@ -1175,8 +1175,8 @@ } else if (!strncmp(line, "done", 4)) { if (handi == 1) /* Don't bother with checks later */ - printf ("\nHandicap cannot be one stone. Either add " - "some more, or delete the only stone.\n"); + printf("\nHandicap cannot be one stone. Either add " + "some more, or delete the only stone.\n"); else break; } Index: patterns/dfa.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/patterns/dfa.c,v retrieving revision 1.29 diff -u -r1.29 dfa.c --- patterns/dfa.c 11 Feb 2003 11:56:05 -0000 1.29 +++ patterns/dfa.c 22 Feb 2003 10:20:39 -0000 @@ -588,8 +588,8 @@ * Create a linear dfa from a string and an attributes value * and resize the dfa if needed. * - * For eg. - * create_dfa (pdfa, "Oo?.", 2001) + * For example: + * create_dfa(pdfa, "Oo?.", 2001) * gives: * * 1 0,1 0,1,2 0 Index: patterns/mkeyes.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/patterns/mkeyes.c,v retrieving revision 1.14 diff -u -r1.14 mkeyes.c --- patterns/mkeyes.c 2 Jan 2003 00:23:29 -0000 1.14 +++ patterns/mkeyes.c 22 Feb 2003 10:20:40 -0000 @@ -40,8 +40,6 @@ #include "eyes.h" -int fatal_errors = 0; - int main(void) { @@ -70,6 +68,7 @@ int num_attacks = 0; int num_defenses = 0; int debug = 0; + int fatal_errors = 0; printf("/* This file is automatically generated by mkeyes. Do not\n"); printf(" * edit it directly. Instead, edit the eye shape database.\n"); @@ -91,7 +90,7 @@ } /* remove trailing whitespace */ - for (last--; last >= 0 && isspace(line[last]); last--) { + for (last--; last >= 0 && isspace((int) line[last]); last--) { line[last] = '\n'; line[last+1] = '\0'; } Index: patterns/mkpat.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/patterns/mkpat.c,v retrieving revision 1.114 diff -u -r1.114 mkpat.c --- patterns/mkpat.c 11 Feb 2003 11:56:05 -0000 1.114 +++ patterns/mkpat.c 22 Feb 2003 10:20:47 -0000 @@ -120,9 +120,9 @@ /* valid characters that can appear in a pattern * position in string is att value to store */ -const char VALID_PATTERN_CHARS[] = ".XOxo,a!*?QY"; -const char VALID_EDGE_CHARS[] = "+-|"; -const char VALID_CONSTRAINT_LABELS[] = "abcdefghijklmnpqrstuvwyzABCDEFGHIJKLMNPRSTUVWZ"; +static const char VALID_PATTERN_CHARS[] = ".XOxo,a!*?QY"; +static const char VALID_EDGE_CHARS[] = "+-|"; +static const char VALID_CONSTRAINT_LABELS[] = "abcdefghijklmnpqrstuvwyzABCDEFGHIJKLMNPRSTUVWZ"; /* the offsets into the list are the ATT_* defined in patterns.h @@ -139,44 +139,44 @@ * Modify them using `goal_elements ...' and `callback_data ..' * commands in a database. By default, we don't drop any elements. */ -int nongoal[8] = {0, 0, 0, 0, 0, 0, 0, 0}; -int callback_unneeded[8] = {0, 0, 0, 0, 0, 0, 0, 0}; +static int nongoal[8] = {0, 0, 0, 0, 0, 0, 0, 0}; +static int callback_unneeded[8] = {0, 0, 0, 0, 0, 0, 0, 0}; /* stuff used in reading/parsing pattern rows */ -int maxi, maxj; /* (i,j) offsets of largest element */ -int mini, minj; /* offset of top-left element +static int maxi, maxj; /* (i,j) offsets of largest element */ +static int mini, minj; /* offset of top-left element (0,0) unless there are edge constraints */ -int movei, movej; -unsigned int where; /* NORTH_EDGE | WEST_EDGE, etc */ -int el; /* next element number in current pattern */ -struct patval_b elements[MAX_BOARD*MAX_BOARD]; /* elements of current pattern */ -int num_stars; +static int movei, movej; +static unsigned int where; /* NORTH_EDGE | WEST_EDGE, etc */ +static int el; /* next element number in current pattern */ +static struct patval_b elements[MAX_BOARD*MAX_BOARD]; /* elements of current pattern */ +static int num_stars; -int ci = -1, cj = -1; /* position of origin (first piece element) +static int ci = -1, cj = -1; /* position of origin (first piece element) relative to top-left */ -int patno; /* current pattern */ -int discard_pattern = 0; /* Set to nonzero to discard a pattern (if e.g. +static int patno; /* current pattern */ +static int discard_pattern = 0; /* Set to nonzero to discard a pattern (if e.g. * it is too large or duplicated). */ -int pats_with_constraints = 0; /* just out of interest */ -int label_coords[256][2]; /* Coordinates for labeled stones in the - autohelper patterns. */ -int current_c_i; /* Counter for the line number of a +static int pats_with_constraints = 0; /* just out of interest */ +static int label_coords[256][2]; /* Coordinates for labeled stones in the + autohelper patterns. */ +static int current_c_i; /* Counter for the line number of a constraint diagram. */ -char constraint[MAXCONSTRAINT]; /* Store constraint lines. */ -char action[MAXCONSTRAINT]; /* Store action lines. */ +static char constraint[MAXCONSTRAINT]; /* Store constraint lines. */ +static char action[MAXCONSTRAINT]; /* Store action lines. */ static char diagram[MAX_BOARD+2][MAX_BOARD+3]; /* store pattern diagram*/ static char constraint_diagram[MAX_BOARD+2][MAX_BOARD+3]; /* store pattern constraint diagram */ /* stuff to maintain info about patterns while reading */ -char *prefix; -struct pattern pattern[MAXPATNO]; /* accumulate the patterns into here */ -char pattern_names[MAXPATNO][80]; /* with optional names here, */ -char helper_fn_names[MAXPATNO][80]; /* helper fn names here */ -char autohelper_code[MAXPATNO*300]; /* code for automatically generated */ +static char *prefix; +static struct pattern pattern[MAXPATNO]; /* accumulate the patterns into here */ +static char pattern_names[MAXPATNO][80]; /* with optional names here, */ +static char helper_fn_names[MAXPATNO][80]; /* helper fn names here */ +static char autohelper_code[MAXPATNO*300]; /* code for automatically generated */ /* helper functions here */ -char *code_pos; /* current position in code buffer */ +static char *code_pos; /* current position in code buffer */ struct autohelper_func { const char *name; int params; @@ -192,8 +192,8 @@ /* * current_* are useful for debugging broken patterns. */ -const char *current_file = 0; -int current_line_number = 0; +static const char *current_file = NULL; +static int current_line_number = 0; /* ================================================================ */ /* */ @@ -402,27 +402,27 @@ #include \"patterns.h\"\n\n\ " -int fatal_errors = 0; +static int fatal_errors = 0; /* options */ -int verbose = 0; /* -v */ -int database_type = 0; /* -p (default), -c, -f, -C, -D or -T */ -int anchor = 0; /* Whether both O and/or X may be anchors. - * -b for both. -X for only X. - */ +int verbose = 0; /* -v */ +static int database_type = 0; /* -p (default), -c, -f, -C, -D or -T */ +static int anchor = 0; /* Whether both O and/or X may be anchors. + * -b for both. -X for only X. + */ -int choose_best_anchor = 0; /* -m */ +static int choose_best_anchor = 0; /* -m */ /* FIXME: `fixed anchor' option doesn't work properly yet. * Probably the first thing to implement is to add * checks for anchor validity. */ -int fixed_anchor = 0; /* -a */ -int pre_rotate = 0; /* -p */ +static int fixed_anchor = 0; /* -a */ +static int pre_rotate = 0; /* -p */ -dfa_t dfa; -dfa_patterns dfa_pats; +static dfa_t dfa; +static dfa_patterns dfa_pats; -int transformation_hint = 0; +static int transformation_hint = 0; /************************** * @@ -1029,6 +1029,7 @@ char class[80]; char entry[80]; char *p = line; + char *p2; int n; float v = 0.0; @@ -1101,47 +1102,44 @@ } } - { - char *p; - for (p = class; *p; p++) { - switch (*p) { - case 's': pattern[patno].class |= CLASS_s; break; - case 'O': pattern[patno].class |= CLASS_O; break; - case 'o': pattern[patno].class |= CLASS_o; break; - case 'X': pattern[patno].class |= CLASS_X; break; - case 'x': pattern[patno].class |= CLASS_x; break; - case 'D': pattern[patno].class |= CLASS_D; break; - case 'C': pattern[patno].class |= CLASS_C; break; - case 'c': pattern[patno].class |= CLASS_c; break; - case 'n': pattern[patno].class |= CLASS_n; break; - case 'B': pattern[patno].class |= CLASS_B; break; - case 'A': pattern[patno].class |= CLASS_A; break; - case 'b': pattern[patno].class |= CLASS_b; break; - case 'e': pattern[patno].class |= CLASS_e; break; - case 'E': pattern[patno].class |= CLASS_E; break; - case 'a': pattern[patno].class |= CLASS_a; break; - case 'd': pattern[patno].class |= CLASS_d; break; - case 'I': pattern[patno].class |= CLASS_I; break; - case 'J': pattern[patno].class |= CLASS_J; break; - case 'j': pattern[patno].class |= CLASS_j; break; - case 't': pattern[patno].class |= CLASS_t; break; - case 'T': pattern[patno].class |= CLASS_T; break; - case 'U': pattern[patno].class |= CLASS_U; break; - case 'W': pattern[patno].class |= CLASS_W; break; - case 'F': pattern[patno].class |= CLASS_F; break; - case 'N': pattern[patno].class |= CLASS_N; break; - case 'Y': pattern[patno].class |= CLASS_Y; break; - case '-': break; - default: - if (!isgraph((int) *p)) - break; - fprintf(stderr, - "%s(%d) : error : Unknown classification letter %c. (pattern %s).\n", - current_file, current_line_number, *p, - pattern_names[patno]); - fatal_errors++; + for (p2 = class; *p2; p2++) { + switch (*p2) { + case 's': pattern[patno].class |= CLASS_s; break; + case 'O': pattern[patno].class |= CLASS_O; break; + case 'o': pattern[patno].class |= CLASS_o; break; + case 'X': pattern[patno].class |= CLASS_X; break; + case 'x': pattern[patno].class |= CLASS_x; break; + case 'D': pattern[patno].class |= CLASS_D; break; + case 'C': pattern[patno].class |= CLASS_C; break; + case 'c': pattern[patno].class |= CLASS_c; break; + case 'n': pattern[patno].class |= CLASS_n; break; + case 'B': pattern[patno].class |= CLASS_B; break; + case 'A': pattern[patno].class |= CLASS_A; break; + case 'b': pattern[patno].class |= CLASS_b; break; + case 'e': pattern[patno].class |= CLASS_e; break; + case 'E': pattern[patno].class |= CLASS_E; break; + case 'a': pattern[patno].class |= CLASS_a; break; + case 'd': pattern[patno].class |= CLASS_d; break; + case 'I': pattern[patno].class |= CLASS_I; break; + case 'J': pattern[patno].class |= CLASS_J; break; + case 'j': pattern[patno].class |= CLASS_j; break; + case 't': pattern[patno].class |= CLASS_t; break; + case 'T': pattern[patno].class |= CLASS_T; break; + case 'U': pattern[patno].class |= CLASS_U; break; + case 'W': pattern[patno].class |= CLASS_W; break; + case 'F': pattern[patno].class |= CLASS_F; break; + case 'N': pattern[patno].class |= CLASS_N; break; + case 'Y': pattern[patno].class |= CLASS_Y; break; + case '-': break; + default: + if (!isgraph((int) *p2)) break; - } + fprintf(stderr, + "%s(%d) : error : Unknown classification letter %c. (pattern %s).\n", + current_file, current_line_number, *p2, + pattern_names[patno]); + fatal_errors++; + break; } } } @@ -1255,7 +1253,7 @@ { int i; char varnames[MAXPARAMS][8]; - char pattern[MAXLINE]; + char pattern_id[MAXLINE]; for (i = 0; i < number_of_params; i++) { if (labels[i] == (int) '*') @@ -1325,24 +1323,24 @@ /* A very special case. We add the address of the current pattern * before the actual parameters. So far, used only by `value'. */ - sprintf(pattern, "(%s + %d)", prefix, patno); + sprintf(pattern_id, "(%s + %d)", prefix, patno); switch (number_of_params) { case 0: code_pos += sprintf(code_pos, autohelper_functions[funcno].code, - pattern); + pattern_id); break; case 1: code_pos += sprintf(code_pos, autohelper_functions[funcno].code, - pattern, varnames[0]); + pattern_id, varnames[0]); break; case 2: code_pos += sprintf(code_pos, autohelper_functions[funcno].code, - pattern, varnames[0], varnames[1]); + pattern_id, varnames[0], varnames[1]); break; case 3: code_pos += sprintf(code_pos, autohelper_functions[funcno].code, - pattern, varnames[0], varnames[1], varnames[2]); + pattern_id, varnames[0], varnames[1], varnames[2]); break; default: fprintf(stderr, "%s(%d) : error : unknown number of parameters (pattern %s)", @@ -2250,9 +2248,9 @@ * quickly as possible (based on num_stones field value). The latter * can still be improved if a need arises. */ -static int corner_best_element(struct corner_element *el, int n, - struct corner_variation_b *variations, - int color) +static int +corner_best_element(struct corner_element *el, int n, + struct corner_variation_b *variations, int color) { int k; int i; @@ -2940,7 +2938,7 @@ /* Remove trailing white space from `line' */ { int i = strlen(line) - 2; /* Start removing backwards just before newline */ - while (i >= 0 && isspace(line[i])) + while (i >= 0 && isspace((int) line[i])) i--; line[i+1] = '\n'; line[i+2] = '\0'; Index: patterns/patterns.db =================================================================== RCS file: /cvsroot/gnugo/gnugo/patterns/patterns.db,v retrieving revision 1.101 diff -u -r1.101 patterns.db --- patterns/patterns.db 3 Feb 2003 13:12:50 -0000 1.101 +++ patterns/patterns.db 22 Feb 2003 10:20:56 -0000 @@ -1360,8 +1360,8 @@ :8,C -hbEg? -ca*df +ObEO? +ca*dO ..... ----- @@ -1380,8 +1380,8 @@ :8,C -eXXg? -ea*df +eXXO? +ea*dO .b... ----- @@ -1783,13 +1783,13 @@ :8,-,shape(5) -?X*b -?XOD -..ac +?X*O +?XOB +..aO .... ---- -; !attack(D) && oplay_attack(*,a,a) +; !attack(B) && oplay_attack(*,a,a) Pattern EC28 @@ -1803,7 +1803,7 @@ :8,- caXO? -cXdXO +cXOXO ob.*. ----- Index: patterns/patterns2.db =================================================================== RCS file: /cvsroot/gnugo/gnugo/patterns/patterns2.db,v retrieving revision 1.54 diff -u -r1.54 patterns2.db --- patterns/patterns2.db 3 Feb 2003 13:12:50 -0000 1.54 +++ patterns/patterns2.db 22 Feb 2003 10:20:58 -0000 @@ -3063,7 +3063,6 @@ ba* ?OX - ;((!o_somewhere(b) && oterri(b)) ; || (!o_somewhere(c) && oterri(c))) ;&& safe_xmove(*) && !xplay_attack(*,a,*) Index: sgf/sgfnode.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/sgf/sgfnode.c,v retrieving revision 1.19 diff -u -r1.19 sgfnode.c --- sgf/sgfnode.c 2 Jan 2003 00:23:30 -0000 1.19 +++ sgf/sgfnode.c 22 Feb 2003 10:21:07 -0000 @@ -70,7 +70,7 @@ if (!pt) { fprintf(stderr, "xalloc: Out of memory!\n"); - exit(2); + exit(EXIT_FAILURE); } memset(pt, 0, (unsigned long) size); @@ -84,7 +84,7 @@ if (!ptnew) { fprintf(stderr, "xrealloc: Out of memory!\n"); - exit(2); + exit(EXIT_FAILURE); } return ptnew; } Index: utils/gg_utils.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/utils/gg_utils.c,v retrieving revision 1.29 diff -u -r1.29 gg_utils.c --- utils/gg_utils.c 2 Jan 2003 00:23:30 -0000 1.29 +++ utils/gg_utils.c 22 Feb 2003 10:21:08 -0000 @@ -246,8 +246,8 @@ * if available, otherwise substituting a workaround for portability. */ -int -gg_gettimeofday2(struct timeval *tv, void *p) +static int +gg_gettimeofday2(struct timeval *tv) { #ifdef HAVE_GETTIMEOFDAY return gettimeofday(tv, NULL); @@ -264,7 +264,7 @@ gg_gettimeofday(void) { struct timeval tv; - gg_gettimeofday2(&tv, NULL); + gg_gettimeofday2(&tv); return tv.tv_sec + 1.e-6*tv.tv_usec; } Index: utils/gg_utils.h =================================================================== RCS file: /cvsroot/gnugo/gnugo/utils/gg_utils.h,v retrieving revision 1.14 diff -u -r1.14 gg_utils.h --- utils/gg_utils.h 2 Jan 2003 00:23:30 -0000 1.14 +++ utils/gg_utils.h 22 Feb 2003 10:21:08 -0000 @@ -59,7 +59,6 @@ va_list args); void gg_snprintf(char *dest, unsigned long len, const char *fmt, ...); -int gg_gettimeofday2(struct timeval *tv, void *p); double gg_gettimeofday(void); double gg_cputime(void);