Index: engine/clock.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/clock.c,v retrieving revision 1.12 diff -u -r1.12 clock.c --- engine/clock.c 4 Mar 2002 06:49:08 -0000 1.12 +++ engine/clock.c 16 Sep 2002 08:32:51 -0000 @@ -36,8 +36,8 @@ #include "gnugo.h" -#include -#include +#include "liberty.h" +#include "gg_utils.h" #include "clock.h" /* parameters */ Index: engine/hash.h =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/hash.h,v retrieving revision 1.7 diff -u -r1.7 hash.h --- engine/hash.h 25 Mar 2002 04:47:27 -0000 1.7 +++ engine/hash.h 16 Sep 2002 08:32:51 -0000 @@ -20,7 +20,7 @@ \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include -#include +#include "gnugo.h" /* * This file, together with engine/hash.c implements hashing of go positions Index: engine/interface.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/interface.c,v retrieving revision 1.29 diff -u -r1.29 interface.c --- engine/interface.c 12 Sep 2002 20:21:10 -0000 1.29 +++ engine/interface.c 16 Sep 2002 08:32:51 -0000 @@ -28,7 +28,7 @@ #include "liberty.h" #include "clock.h" -#include +#include "gg_utils.h" /* * Initialize the gnugo engine. This needs to be called Index: engine/sgffile.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/engine/sgffile.c,v retrieving revision 1.21 diff -u -r1.21 sgffile.c --- engine/sgffile.c 10 Sep 2002 20:09:52 -0000 1.21 +++ engine/sgffile.c 16 Sep 2002 08:32:51 -0000 @@ -38,7 +38,7 @@ #include "liberty.h" #include "sgftree.h" - +#include "gg_utils.h" /* * Add debug information to a node if user requested it from command @@ -113,7 +113,6 @@ void sgffile_begindump(SGFTree *tree) { - SGFNode *node; static SGFTree local_tree; gg_assert(sgf_dumptree == NULL); Index: interface/main.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/main.c,v retrieving revision 1.51 diff -u -r1.51 main.c --- interface/main.c 16 Sep 2002 07:27:49 -0000 1.51 +++ interface/main.c 16 Sep 2002 08:32:51 -0000 @@ -21,7 +21,6 @@ #include "gnugo.h" -#include #include #include #include @@ -44,13 +43,12 @@ # endif #endif -#include +#include "liberty.h" #include "gg-getopt.h" -#include +#include "gg_utils.h" #include "interface.h" -#include "gmp.h" #include "sgftree.h" #include "random.h" @@ -258,7 +256,7 @@ Gameinfo gameinfo; SGFTree sgftree; - int i, umove; + int i; int mandated_color = EMPTY; enum mode playmode = MODE_UNKNOWN; int replay_color = EMPTY; @@ -332,9 +330,6 @@ sgftree_clear(&sgftree); gameinfo_clear(&gameinfo, board_size, komi); - /* Set some standard options. */ - umove = BLACK; - /* Now weed through all of the command line options. */ while ((i = gg_getopt_long(argc, argv, "-ab:B:d:D:EF:gh::H:K:l:L:M:m:o:O:p:r:fsStTvw", @@ -1147,16 +1142,16 @@ case MODE_ASCII_EMACS: if (mandated_color != EMPTY) - umove = mandated_color; - gameinfo.computer_player = OTHER_COLOR(umove); + gameinfo.computer_player = OTHER_COLOR(mandated_color); + play_ascii_emacs(&sgftree, &gameinfo, infilename, untilstring); break; case MODE_ASCII: default: if (mandated_color != EMPTY) - umove = mandated_color; - gameinfo.computer_player = OTHER_COLOR(umove); + gameinfo.computer_player = OTHER_COLOR(mandated_color); + play_ascii(&sgftree, &gameinfo, infilename, untilstring); break; } @@ -1164,7 +1159,7 @@ if (profile_patterns) report_pattern_profiling(); - clock_report_autolevel(NULL, OTHER_COLOR(umove)); + clock_report_autolevel(NULL, gameinfo.computer_player); return 0; } /* end main */ Index: interface/play_ascii.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_ascii.c,v retrieving revision 1.27 diff -u -r1.27 play_ascii.c --- interface/play_ascii.c 14 Sep 2002 19:06:19 -0000 1.27 +++ interface/play_ascii.c 16 Sep 2002 08:32:51 -0000 @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "liberty.h" @@ -46,7 +45,7 @@ static int opt_showboard = 1; static int showdead = 0; static int emacs = 0; -SGFTree sgftree; +static SGFTree sgftree; static int last_move_i; /* The position of the last move */ static int last_move_j; /* -""- */ @@ -790,7 +789,7 @@ case CMD_BACK: if (gnugo_undo_move(1)) { sgftreeAddComment(&sgftree, "undone"); - sgftreeBack(&sgftree); + sgftreeBack(&sgftree); gameinfo->to_move = OTHER_COLOR(gameinfo->to_move); } else @@ -799,19 +798,19 @@ case CMD_FORWARD: if (sgftreeForward(&sgftree)) gameinfo->to_move = gnugo_play_sgfnode(sgftree.lastnode, - gameinfo->to_move); + gameinfo->to_move); else printf("\nEnd of game tree.\n"); break; case CMD_LAST: while (sgftreeForward(&sgftree)) gameinfo->to_move = gnugo_play_sgfnode(sgftree.lastnode, - gameinfo->to_move); + gameinfo->to_move); break; case COMMENT: printf("\nEnter comment. Press ENTER when ready.\n"); fgets(line, 80, stdin); - sgftreeAddComment(&sgftree, line); + sgftreeAddComment(&sgftree, line); break; case SCORE: showscore = !showscore; @@ -865,7 +864,7 @@ /* discard newline */ tmpstring[strlen(tmpstring)-1] = 0; /* make sure we are saving proper handicap */ - init_sgf(gameinfo); + init_sgf(gameinfo); writesgf(sgftree.root, tmpstring); printf("You may resume the game"); printf(" with -l %s --mode ascii\n", tmpstring); @@ -916,11 +915,11 @@ printf("You may optionally save the game as an SGF file.\n"); state = 0; while (state == 0) { - printf("\n\ -Type \"save \" to save,\n\ - \"count\" to recount,\n\ - \"quit\" to quit\n\ - or \"game\" to play again\n"); + printf("\n"); + printf("Type \"save \" to save,\n"); + printf(" \"count\" to recount,\n"); + printf(" \"quit\" to quit\n"); + printf(" or \"game\" to play again\n"); line_ptr = line; if (!fgets(line, 80, stdin)) break; @@ -991,8 +990,8 @@ ascii_showboard(); while (!done) { printf("Dead stones are marked with small letters (x,o).\n"); - printf("\nIf you don't agree, enter the location of a group\n\ -to toggle its state or \"done\".\n"); + printf("\nIf you don't agree, enter the location of a group\n"); + printf("to toggle its state or \"done\".\n"); if (!fgets(line, 12, stdin)) return; /* EOF or some error */ @@ -1023,11 +1022,13 @@ printf("dead group, or type \"done\"\n"); } else if (!strncmp(line, "undo", 4)) { - printf("UNDO not allowed anymore. The status of the stones now toggles after entering the location of it.\n"); + printf("UNDO not allowed anymore. The status of the stones now\n"); + printf("toggles after entering the location of it.\n"); ascii_showboard(); } else { - if (!string_to_location(board_size, line, &i, &j) || BOARD(i, j) == EMPTY) + if (!string_to_location(board_size, line, &i, &j) + || BOARD(i, j) == EMPTY) printf("\ninvalid!\n"); else { int status = dragon_status(POS(i, j)); @@ -1046,10 +1047,12 @@ { int i, j, x, y; if (line) - if (!string_to_location(board_size, line, &i, &j) || BOARD(i, j) == EMPTY) { + if (!string_to_location(board_size, line, &i, &j) + || BOARD(i, j) == EMPTY) { printf("\ninvalid point!\n"); return; } + if (gnugo_attack(i, j, &x, &y)) mprintf("\nSuccessfull attack of %m at %m\n", i, j, x, y); else @@ -1062,7 +1065,8 @@ { int i, j, x, y; if (line) - if (!string_to_location(board_size, line, &i, &j) || BOARD(i, j) == EMPTY) { + if (!string_to_location(board_size, line, &i, &j) + || BOARD(i, j) == EMPTY) { printf("\ninvalid point!\n"); return; } @@ -1081,16 +1085,16 @@ static void ascii_goto(Gameinfo *gameinfo, char *line) { - char *movenumber = line; + const char *movenumber = line; if (!line) return; + if (!strncmp(line, "last", 4)) movenumber = "9999"; - else { - if (!strncmp(line, "first", 4)) - movenumber = "1"; - } + else if (!strncmp(line, "first", 4)) + movenumber = "1"; + printf("goto %s\n", movenumber); gameinfo_play_sgftree(gameinfo, &sgftree, movenumber); } Index: interface/play_gmp.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_gmp.c,v retrieving revision 1.13 diff -u -r1.13 play_gmp.c --- interface/play_gmp.c 14 Sep 2002 19:06:19 -0000 1.13 +++ interface/play_gmp.c 16 Sep 2002 08:32:51 -0000 @@ -63,7 +63,8 @@ if (chinese_rules) gmp_startGame(ge, -1, -1, 5.5, -1, -1); else - gmp_startGame(ge, -1, -1, 5.5, 0, -1); + gmp_startGame(ge, -1, -1, 5.5, 0, -1); + do { message = gmp_check(ge, 1, NULL, NULL, &error); } while (message == gmp_nothing || message == gmp_reset); @@ -113,7 +114,8 @@ } gameinfo->computer_player = mycolor; - sgf_write_header(sgftree.root, 1, random_seed, gnugo_get_komi(), level, chinese_rules); + sgf_write_header(sgftree.root, 1, random_seed, gnugo_get_komi(), + level, chinese_rules); gameinfo->handicap = gnugo_sethand(gameinfo->handicap, sgftree.root); sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap); @@ -143,7 +145,7 @@ break; } sgftreeAddComment(&sgftree, "undone"); - sgftreeBack(&sgftree); + sgftreeBack(&sgftree); to_move = OTHER_COLOR(to_move); } continue; Index: interface/play_gtp.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v retrieving revision 1.90 diff -u -r1.90 play_gtp.c --- interface/play_gtp.c 16 Sep 2002 07:27:49 -0000 1.90 +++ interface/play_gtp.c 16 Sep 2002 08:32:52 -0000 @@ -1345,7 +1345,7 @@ silent_examine_position(BOARD(i, j), EXAMINE_DRAGONS_WITHOUT_OWL); /* to get the variations into the sgf file, clear the reading cache */ if (sgf_dumptree) - reading_cache_clear(); + reading_cache_clear(); owl_analyze_semeai(dragona, dragonb, &resulta, &resultb, &move, 1); gtp_start_response(GTP_SUCCESS); Index: interface/play_solo.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/interface/play_solo.c,v retrieving revision 1.18 diff -u -r1.18 play_solo.c --- interface/play_solo.c 14 Sep 2002 19:06:19 -0000 1.18 +++ interface/play_solo.c 16 Sep 2002 08:32:52 -0000 @@ -138,10 +138,6 @@ /* ================================================================ */ -/* FIXME: This should be in a separate source file. - */ - - /* * Load SGF file and run genmove(). */ @@ -162,11 +158,9 @@ if (is_pass(POS(i, j))) gprintf("%s move: PASS!\n", next == WHITE ? "white (O)" : "black (X)"); else - gprintf("%s move %m\n", next == WHITE ? "white (O)" : "black (X)", - i, j); + gprintf("%s move %m\n", next == WHITE ? "white (O)" : "black (X)", i, j); gnugo_play_move(i, j, next); - sgftreeNodeCheck(&sgftree, 0); sgftreeAddPlay(&sgftree, next, i, j); sgftreeAddComment(&sgftree, "load and analyze mode"); sgffile_add_debuginfo(sgftree.lastnode, move_val); Index: patterns/.cvsignore =================================================================== RCS file: /cvsroot/gnugo/gnugo/patterns/.cvsignore,v retrieving revision 1.3 diff -u -r1.3 .cvsignore --- patterns/.cvsignore 27 Feb 2002 16:29:44 -0000 1.3 +++ patterns/.cvsignore 16 Sep 2002 08:32:52 -0000 @@ -26,3 +26,4 @@ owl_defendpat.c read_attack.c read_defend.c +handipat.c \ No newline at end of file Index: sgf/sgfnode.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/sgf/sgfnode.c,v retrieving revision 1.16 diff -u -r1.16 sgfnode.c --- sgf/sgfnode.c 4 Sep 2002 07:23:46 -0000 1.16 +++ sgf/sgfnode.c 16 Sep 2002 08:32:52 -0000 @@ -790,6 +790,7 @@ { if (lookahead == -1 || !isupper(lookahead)) parse_error("Expected an upper case letter.", 0); + while (lookahead != -1 && isalpha(lookahead)) { if (isupper(lookahead) && size > 1) { *buffer++ = lookahead; @@ -829,6 +830,7 @@ lookahead = sgf_getch(); } match(']'); + /* Remove trailing whitespace */ --p; while (p > buffer && isspace((int) *p)) @@ -1386,7 +1388,8 @@ } void -sgf_write_header(SGFNode *root, int overwrite, int seed, float komi, int level, int rules) +sgf_write_header(SGFNode *root, int overwrite, int seed, float komi, + int level, int rules) { time_t curtime = time(NULL); struct tm *loctime = localtime(&curtime); @@ -1430,9 +1433,12 @@ unparse_game(outfile, root, 1); fclose(outfile); - /* remove "printed" marks so that the tree can be written multiple - times */ + + /* Remove "printed" marks so that the tree can be written multiple + * times. + */ restore_node(root); + return 1; } @@ -1469,4 +1475,3 @@ * c-basic-offset: 2 * End: */ - Index: sgf/sgftree.c =================================================================== RCS file: /cvsroot/gnugo/gnugo/sgf/sgftree.c,v retrieving revision 1.11 diff -u -r1.11 sgftree.c --- sgf/sgftree.c 12 Sep 2002 20:21:11 -0000 1.11 +++ sgf/sgftree.c 16 Sep 2002 08:32:52 -0000 @@ -47,7 +47,8 @@ /* Go back one node in the tree. If lastnode is NULL, go to the last - node (the one in main variant which has no children) */ + * node (the one in main variant which has no children). + */ int sgftreeBack(SGFTree *tree) @@ -60,12 +61,14 @@ } else while (sgftreeForward(tree)); + return 1; } /* Go forward one node in the tree. If lastnode is NULL, go to the - tree root */ + * tree root. + */ int sgftreeForward(SGFTree *tree) @@ -78,6 +81,7 @@ } else tree->lastnode = tree->root; + return 1; } @@ -87,27 +91,25 @@ /* ================================================================ */ /* - * Returns the node to modify. When node==NULL then lastnode is used, - * except if lastnode is NULL, then the current end of game is used. + * Returns the node to modify. Use lastnode if available, otherwise + * follow the main variation to the current end of the game. */ -/* FIXME: do we need node parameter here? it is never used. */ - SGFNode * -sgftreeNodeCheck(SGFTree *tree, SGFNode *node) +sgftreeNodeCheck(SGFTree *tree) { - assert(tree->root); + SGFNode *node = NULL; + assert(tree->root); + + if (tree->lastnode) + node = tree->lastnode; + else { + node = tree->root; + while (node->child) + node = node->child; + } - if (!node) { - if (tree->lastnode) - node = tree->lastnode; - else { - node = tree->root; - while (node->child) - node = node->child; - } - } - return node; + return node; } @@ -119,7 +121,7 @@ void sgftreeAddStone(SGFTree *tree, int color, int movex, int movey) { - SGFNode *node = sgftreeNodeCheck(tree, NULL); + SGFNode *node = sgftreeNodeCheck(tree); sgfAddStone(node, color, movex, movey); } @@ -131,7 +133,7 @@ void sgftreeAddPlay(SGFTree *tree, int color, int movex, int movey) { - SGFNode *node = sgftreeNodeCheck(tree, NULL); + SGFNode *node = sgftreeNodeCheck(tree); tree->lastnode = sgfAddPlay(node, color, movex, movey); } @@ -144,7 +146,7 @@ void sgftreeAddPlayLast(SGFTree *tree, int color, int movex, int movey) { - SGFNode *node = sgftreeNodeCheck(tree, NULL); + SGFNode *node = sgftreeNodeCheck(tree); tree->lastnode = sgfAddPlayLast(node, color, movex, movey); } @@ -171,7 +173,7 @@ SGFNode *node; assert(tree && tree->root); - node = sgftreeNodeCheck(tree, NULL); + node = sgftreeNodeCheck(tree); sgfAddComment(node, comment); } @@ -186,7 +188,7 @@ SGFNode *node; assert(tree->root); - node = sgftreeNodeCheck(tree, NULL); + node = sgftreeNodeCheck(tree); sgfBoardText(node, i, j, text); } @@ -201,7 +203,7 @@ SGFNode *node; assert(tree->root); - node = sgftreeNodeCheck(tree, NULL); + node = sgftreeNodeCheck(tree); sgfBoardChar(node, i, j, c); } @@ -213,7 +215,7 @@ void sgftreeBoardNumber(SGFTree *tree, int i, int j, int number) { - SGFNode *node = sgftreeNodeCheck(tree, NULL); + SGFNode *node = sgftreeNodeCheck(tree); sgfBoardNumber(node, i, j, number); } @@ -225,7 +227,7 @@ void sgftreeTriangle(SGFTree *tree, int i, int j) { - SGFNode *node = sgftreeNodeCheck(tree, NULL); + SGFNode *node = sgftreeNodeCheck(tree); sgfTriangle(node, i, j); } @@ -237,7 +239,7 @@ void sgftreeCircle(SGFTree *tree, int i, int j) { - SGFNode *node = sgftreeNodeCheck(tree, NULL); + SGFNode *node = sgftreeNodeCheck(tree); sgfCircle(node, i, j); } @@ -249,7 +251,7 @@ void sgftreeSquare(SGFTree *tree, int i, int j) { - SGFNode *node = sgftreeNodeCheck(tree, NULL); + SGFNode *node = sgftreeNodeCheck(tree); sgfSquare(node, i, j); } @@ -261,7 +263,7 @@ void sgftreeMark(SGFTree *tree, int i, int j) { - SGFNode *node = sgftreeNodeCheck(tree, NULL); + SGFNode *node = sgftreeNodeCheck(tree); sgfMark(node, i, j); } @@ -273,7 +275,7 @@ void sgftreeStartVariant(SGFTree *tree) { - SGFNode *node = sgftreeNodeCheck(tree, NULL); + SGFNode *node = sgftreeNodeCheck(tree); tree->lastnode = sgfStartVariant(node); } @@ -285,7 +287,7 @@ void sgftreeStartVariantFirst(SGFTree *tree) { - SGFNode *node = sgftreeNodeCheck(tree, NULL); + SGFNode *node = sgftreeNodeCheck(tree); tree->lastnode = sgfStartVariantFirst(node); } Index: sgf/sgftree.h =================================================================== RCS file: /cvsroot/gnugo/gnugo/sgf/sgftree.h,v retrieving revision 1.12 diff -u -r1.12 sgftree.h --- sgf/sgftree.h 12 Sep 2002 20:21:11 -0000 1.12 +++ sgf/sgftree.h 16 Sep 2002 08:32:52 -0000 @@ -132,7 +132,7 @@ void sgftree_clear(SGFTree *tree); -int sgftree_readfile(SGFTree *tree, const char *infilename); +int sgftree_readfile(SGFTree *tree, const char *infilename); int sgftreeBack(SGFTree *tree); int sgftreeForward(SGFTree *tree); @@ -141,7 +141,7 @@ void sgftreeAddPlayLast(SGFTree *tree, int color, int movex, int movey); void sgftreeAddStone(SGFTree *tree, int color, int movex, int movey); void sgftreeWriteResult(SGFTree *tree, float score, int overwrite); -SGFNode *sgftreeNodeCheck(SGFTree *tree, SGFNode *node); +SGFNode *sgftreeNodeCheck(SGFTree *tree); void sgftreeCircle(SGFTree *tree, int i, int j); void sgftreeSquare(SGFTree *tree, int i, int j);