Index: engine/board.h =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/board.h,v retrieving revision 1.25 diff -u -r1.25 board.h --- engine/board.h 14 Sep 2005 18:33:20 -0000 1.25 +++ engine/board.h 7 Oct 2005 23:19:11 -0000 @@ -386,7 +386,7 @@ const char *location_to_string(int pos); void location_to_buffer(int pos, char *buf); -int string_to_location(int boardsize, const char *str, int *m, int *n); +int string_to_location(int boardsize, const char *str); int is_hoshi_point(int m, int n); void draw_letter_coordinates(FILE *outfile); Index: engine/dragon.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/dragon.c,v retrieving revision 1.148 diff -u -r1.148 dragon.c --- engine/dragon.c 12 Jun 2005 09:34:13 -0000 1.148 +++ engine/dragon.c 7 Oct 2005 23:19:11 -0000 @@ -2406,11 +2406,9 @@ void ascii_report_dragon(char *string) { - int m, n, pos; + int pos = string_to_location(board_size, string); - string_to_location(board_size, string, &m, &n); - pos = POS(m, n); - if (!ON_BOARD1(pos)) + if (!ON_BOARD(pos)) fprintf(stderr, "unknown position %s\n", string); else report_dragon(stderr, pos); Index: engine/gnugo.h =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/gnugo.h,v retrieving revision 1.121 diff -u -r1.121 gnugo.h --- engine/gnugo.h 5 Oct 2005 16:32:12 -0000 1.121 +++ engine/gnugo.h 7 Oct 2005 23:19:11 -0000 @@ -270,7 +270,7 @@ /* influence.c */ -void debug_influence_move(int i, int j); +void debug_influence_move(int move); #define TRACE (!(verbose)) ? (void)0 : (void)gprintf Index: engine/influence.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/influence.c,v retrieving revision 1.110 diff -u -r1.110 influence.c --- engine/influence.c 12 Jun 2005 09:34:14 -0000 1.110 +++ engine/influence.c 7 Oct 2005 23:19:12 -0000 @@ -2216,9 +2216,9 @@ * move at (i, j). */ void -debug_influence_move(int i, int j) +debug_influence_move(int move) { - debug_influence = POS(i, j); + debug_influence = move; } Index: engine/liberty.h =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v retrieving revision 1.239 diff -u -r1.239 liberty.h --- engine/liberty.h 28 Sep 2005 21:52:04 -0000 1.239 +++ engine/liberty.h 7 Oct 2005 23:19:12 -0000 @@ -50,7 +50,7 @@ void transformation_init(void); -void report_worm(int m, int n); +void report_worm(int pos); void ascii_report_worm(char *string); void report_dragon(FILE *outfile, int pos); void ascii_report_dragon(char *string); Index: engine/oracle.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/oracle.c,v retrieving revision 1.16 diff -u -r1.16 oracle.c --- engine/oracle.c 12 Jun 2005 09:34:14 -0000 1.16 +++ engine/oracle.c 7 Oct 2005 23:19:13 -0000 @@ -397,8 +397,7 @@ token = strtok(NULL, delimiters); if (!token) break; - string_to_location(board_size, token, &i, &j); - moves[k] = POS(i, j); + moves[k] = string_to_location(board_size, token); token = strtok(NULL, delimiters); if (!token) break; Index: engine/printutils.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/printutils.c,v retrieving revision 1.52 diff -u -r1.52 printutils.c --- engine/printutils.c 12 Jun 2005 09:34:14 -0000 1.52 +++ engine/printutils.c 7 Oct 2005 23:19:13 -0000 @@ -353,35 +353,35 @@ /* - * Get the (m, n) coordinates in the standard GNU Go coordinate system - * from the string STR. This means that m is the nth row from the top - * and n is the column. Both coordinates are between 0 and boardsize-1, - * inclusive. - * - * Return 1 if ok, otherwise return 0; + * Convert the string str to a 1D coordinate. Return NO_MOVE if invalid + * string. */ int -string_to_location(int boardsize, const char *str, int *m, int *n) +string_to_location(int boardsize, const char *str) { + int m, n; + if (*str == '\0') - return 0; + return NO_MOVE; if (!isalpha((int) *str)) - return 0; - *n = tolower((int) *str) - 'a'; + return NO_MOVE; + + n = tolower((int) *str) - 'a'; if (tolower((int) *str) >= 'i') - --*n; - if (*n < 0 || *n > boardsize - 1) - return 0; + --n; + if (n < 0 || n > boardsize - 1) + return NO_MOVE; - if (!isdigit((int) *(str+1))) - return 0; - *m = boardsize - atoi(str + 1); - if (*m < 0 || *m > boardsize - 1) - return 0; + if (!isdigit((int) *(str + 1))) + return NO_MOVE; + + m = boardsize - atoi(str + 1); + if (m < 0 || m > boardsize - 1) + return NO_MOVE; - return 1; + return POS(m, n); } Index: engine/worm.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/worm.c,v retrieving revision 1.66 diff -u -r1.66 worm.c --- engine/worm.c 12 Jun 2005 09:34:14 -0000 1.66 +++ engine/worm.c 7 Oct 2005 23:19:13 -0000 @@ -1748,16 +1748,14 @@ void ascii_report_worm(char *string) { - int m, n; - string_to_location(board_size, string, &m, &n); - report_worm(m, n); + int pos = string_to_location(board_size, string); + report_worm(pos); } void -report_worm(int m, int n) +report_worm(int pos) { - int pos = POS(m, n); int i; if (board[pos] == EMPTY) { Index: interface/main.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/main.c,v retrieving revision 1.118 diff -u -r1.118 main.c --- interface/main.c 6 Oct 2005 18:50:55 -0000 1.118 +++ interface/main.c 7 Oct 2005 23:19:14 -0000 @@ -797,13 +797,12 @@ case OPT_LIMIT_SEARCH: { - int m, n; - - if (!string_to_location(board_size, gg_optarg, &m, &n)) { + int pos = string_to_location(board_size, gg_optarg); + if (pos == NO_MOVE) { fprintf(stderr, "gnugo: use --limit-search \n"); return EXIT_FAILURE; } - set_search_diamond(POS(m, n)); + set_search_diamond(pos); } break; @@ -972,9 +971,8 @@ /* Notice that we need to know the board size before we can do this. */ if (debuginfluence_move[0]) { - int m, n; - string_to_location(board_size, debuginfluence_move, &m, &n); - debug_influence_move(m, n); + int pos = string_to_location(board_size, debuginfluence_move); + debug_influence_move(pos); } /* Figure out a default mode if there was no explicit one. */ @@ -1080,131 +1078,140 @@ case MODE_DECIDE_STRING: { - int m, n; + int str; if (!infilename) { fprintf(stderr, "gnugo: --decide-string must be used with -l\n"); return EXIT_FAILURE; } - - if (!string_to_location(board_size, decide_this, &m, &n)) { + + str = string_to_location(board_size, decide_this); + if (str == NO_MOVE) { fprintf(stderr, "gnugo: --decide-string: strange coordinate \n"); return EXIT_FAILURE; } - decide_string(POS(m, n)); + decide_string(str); } break; case MODE_DECIDE_CONNECTION: { - int ai, aj, bi, bj; + int str1, str2; if (!infilename) { fprintf(stderr, "gnugo: --decide-connection must be used with -l\n"); return EXIT_FAILURE; } - - if (!string_to_location(board_size, decide_this, &ai, &aj)) { + + str1 = string_to_location(board_size, decide_this); + if (str1 == NO_MOVE) { fprintf(stderr, "usage: --decide-connection [first string]/[second string]\n"); return EXIT_FAILURE; } - - if (!string_to_location(board_size, decide_that, &bi, &bj)) { + + str2 = string_to_location(board_size, decide_that); + if (str2 == NO_MOVE) { fprintf(stderr, "usage: --decide-connection [first string]/[second string]\n"); return EXIT_FAILURE; } - decide_connection(POS(ai, aj), POS(bi, bj)); + decide_connection(str1, str2); } break; case MODE_DECIDE_OWL: { - int m, n; + int pos; if (!infilename) { fprintf(stderr, "gnugo: --decide-dragon must be used with -l\n"); return EXIT_FAILURE; } - - if (!string_to_location(board_size, decide_this, &m, &n)) { + + pos = string_to_location(board_size, decide_this); + if (pos == NO_MOVE) { fprintf(stderr, "gnugo: --decide-dragon: strange coordinate \n"); return EXIT_FAILURE; } - decide_owl(POS(m, n)); + decide_owl(pos); } break; case MODE_DECIDE_DRAGON_DATA: { - int m, n; + int pos; if (!infilename) { fprintf(stderr, "gnugo: --decide-dragon-data must be used with -l\n"); return EXIT_FAILURE; } - - if (!string_to_location(board_size, decide_this, &m, &n)) { + + pos = string_to_location(board_size, decide_this); + if (pos == NO_MOVE) { fprintf(stderr, "gnugo: --decide-dragon-data: strange coordinate \n"); return EXIT_FAILURE; } - decide_dragon_data(POS(m, n)); + decide_dragon_data(pos); } break; case MODE_DECIDE_SEMEAI: { - int ai, aj, bi, bj; + int pos1, pos2; if (!infilename) { fprintf(stderr, "gnugo: --decide-semeai must be used with -l\n"); return EXIT_FAILURE; } - - if (!string_to_location(board_size, decide_this, &ai, &aj)) { + + pos1 = string_to_location(board_size, decide_this); + if (pos1 == NO_MOVE) { fprintf(stderr, "usage: --decide-semeai [first dragon]/[second dragon]\n"); return EXIT_FAILURE; } - - if (!string_to_location(board_size, decide_that, &bi, &bj)) { + + pos2 = string_to_location(board_size, decide_that); + if (pos2 == NO_MOVE) { fprintf(stderr, "usage: --decide-semeai [first dragon]/[second dragon]\n"); return EXIT_FAILURE; } - decide_semeai(POS(ai, aj), POS(bi, bj)); + decide_semeai(pos1, pos2); } break; case MODE_DECIDE_TACTICAL_SEMEAI: { - int ai, aj, bi, bj; + int pos1, pos2; if (!infilename) { fprintf(stderr, "gnugo: --decide-tactical-semeai must be used with -l\n"); return EXIT_FAILURE; } - - if (!string_to_location(board_size, decide_this, &ai, &aj)) { + + pos1 = string_to_location(board_size, decide_this); + if (pos1 == NO_MOVE) { fprintf(stderr, "usage: --decide-tactical-semeai [first dragon]/[second dragon]\n"); return EXIT_FAILURE; } - - if (!string_to_location(board_size, decide_that, &bi, &bj)) { + + pos2 = string_to_location(board_size, decide_that); + if (pos2 == NO_MOVE) { fprintf(stderr, "usage: --decide-tactical-semeai [first dragon]/[second dragon]\n"); return EXIT_FAILURE; } - decide_tactical_semeai(POS(ai, aj), POS(bi, bj)); + decide_tactical_semeai(pos1, pos2); } break; @@ -1221,19 +1228,20 @@ case MODE_DECIDE_EYE: { - int m, n; + int pos; if (!infilename) { fprintf(stderr, "gnugo: --decide-eye must be used with -l\n"); return EXIT_FAILURE; } - - if (!string_to_location(board_size, decide_this, &m, &n)) { + + pos = string_to_location(board_size, decide_this); + if (pos == NO_MOVE) { fprintf(stderr, "gnugo: --decide-eye: strange coordinate \n"); return EXIT_FAILURE; } - decide_eye(POS(m, n)); + decide_eye(pos); } break; @@ -1253,15 +1261,15 @@ case MODE_DECIDE_SURROUNDED: { - int m, n; + int pos = string_to_location(board_size, decide_this); - if (!string_to_location(board_size, decide_this, &m, &n)) { + if (pos == NO_MOVE) { fprintf(stderr, "usage: --decide-surrounded [pos]\n"); return EXIT_FAILURE; } - decide_surrounded(POS(m, n)); + decide_surrounded(pos); break; } Index: interface/play_ascii.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_ascii.c,v retrieving revision 1.60 diff -u -r1.60 play_ascii.c --- interface/play_ascii.c 7 Oct 2005 21:36:57 -0000 1.60 +++ interface/play_ascii.c 7 Oct 2005 23:19:14 -0000 @@ -505,24 +505,24 @@ static int do_move(Gameinfo *gameinfo, char *command, int *passes, int force) { - int i, j; + int move = string_to_location(board_size, command); - if (!string_to_location(board_size, command, &i, &j)) { + if (move == NO_MOVE) { printf("\nInvalid move: %s\n", command); return 0; } - if (!is_legal(POS(i, j), gameinfo->to_move)) { + if (!is_legal(move, gameinfo->to_move)) { printf("\nIllegal move: %s", command); return 0; } *passes = 0; - TRACE("\nyour move: %m\n\n", i, j); + TRACE("\nyour move: %1m\n\n", move); init_sgf(gameinfo); - gnugo_play_move(i, j, gameinfo->to_move); + gnugo_play_move(I(move), J(move), gameinfo->to_move); sgffile_add_debuginfo(sgftree.lastnode, 0.0); - sgftreeAddPlay(&sgftree, gameinfo->to_move, i, j); + sgftreeAddPlay(&sgftree, gameinfo->to_move, I(move), J(move)); sgffile_output(&sgftree); if (opt_showboard) { @@ -1095,7 +1095,7 @@ { char line[12]; int done = 0; - int i, j; + int i; int xyzzy = 1; printf("\nGame over. Let's count!.\n"); @@ -1140,13 +1140,13 @@ ascii_showboard(); } else { - if (!string_to_location(board_size, line, &i, &j) - || BOARD(i, j) == EMPTY) + int pos = string_to_location(board_size, line); + if (pos == NO_MOVE || board[pos] == EMPTY) printf("\ninvalid!\n"); else { - int status = dragon_status(POS(i, j)); + int status = dragon_status(pos); status = (status == DEAD) ? ALIVE : DEAD; - change_dragon_status(POS(i, j), status); + change_dragon_status(pos, status); ascii_showboard(); } } @@ -1158,44 +1158,44 @@ static void showcapture(char *line) { - int i, j; + int str; int move; gg_assert(line); - if (!string_to_location(board_size, line, &i, &j) - || BOARD(i, j) == EMPTY) { + str = string_to_location(board_size, line); + if (str == NO_MOVE || board[str] == EMPTY) { printf("\ninvalid point!\n"); return; } - if (attack(POS(i, j), &move)) - mprintf("\nSuccessful attack of %m at %1m\n", i, j, move); + if (attack(str, &move)) + mprintf("\nSuccessful attack of %1m at %1m\n", str, move); else - mprintf("\n%m cannot be attacked\n", i, j); + mprintf("\n%1m cannot be attacked\n", str); } static void showdefense(char *line) { - int i, j; + int str; int move; gg_assert(line); - if (!string_to_location(board_size, line, &i, &j) - || BOARD(i, j) == EMPTY) { + str = string_to_location(board_size, line); + if (str == NO_MOVE || board[str] == EMPTY) { printf("\ninvalid point!\n"); return; } - if (attack(POS(i, j), NULL)) { - if (find_defense(POS(i, j), &move)) - mprintf("\nSuccessful defense of %m at %1m\n", i, j, move); + if (attack(str, NULL)) { + if (find_defense(str, &move)) + mprintf("\nSuccessful defense of %1m at %1m\n", str, move); else - mprintf("\n%m cannot be defended\n", i, j); + mprintf("\n%1m cannot be defended\n", str); } else - mprintf("\nThere is no need to defend %m\n", i, j); + mprintf("\nThere is no need to defend %1m\n", str); } @@ -1224,7 +1224,6 @@ int i; char line[80]; int stones[MAX_BOARD*MAX_BOARD]; - int x, y, pos; if (sscanf(handicap, "%d", &handi) == 1) { /* Gnu Go is to place handicap */ @@ -1274,17 +1273,19 @@ else break; } - else if (string_to_location(board_size, line, &x, &y)) { - pos = POS(x, y); - if (board[pos] != EMPTY) - printf("\nThere's already a stone there.\n"); - else { - add_stone(pos, BLACK); - stones[handi++] = pos; + else { + int pos = string_to_location(board_size, line); + if (pos != NO_MOVE) { + if (board[pos] != EMPTY) + printf("\nThere's already a stone there.\n"); + else { + add_stone(pos, BLACK); + stones[handi++] = pos; + } } + else + printf("\nInvalid command: %s", line); } - else - printf("\nInvalid command: %s", line); } } gameinfo->handicap = handi;