gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnugo-devel] final patch, first version


From: Paul Pogonyshev
Subject: [gnugo-devel] final patch, first version
Date: Sat, 7 Sep 2002 17:03:29 +0300

this patch includes and replaces two patches: sgf_3_7.3 (gmp mode) and
sgf_3_8.1 (play_solo and play_test).

this patch does the following:
  - every mode now outputs using trees.
  - deletes obsolete functions from sgffile.c (except for
    sgffile_printboard() which is commented with #if/#endif).
  - deletes obsolete fields from Gameinfo structure.
  - renames all functions in sgffile.c to start with sgffile_
    (sgftree_printboard -> sgffile_printboard, begin_sgftreedump ->
    sgffile_begindump, end_sgftreedump -> sgffile_enddump).
  - deletes all calls to obsolete functions which still remained.
  - removes sgf_output parameter from all decide_ functions (we have a
    global variable outfilename now).

load and print mode "just works". if needed, output of PL and IL tags
can be added later (as in old implementation, that is why i kept old
sgffile_printboard() commented and didn't delete it).

gmp mode should work properly with handicaps now (no changes, but
there's no more sgfffile_open_file() and sgffile_close_file()).

Index: engine/sgffile.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/sgffile.c,v
retrieving revision 1.18
diff -u -r1.18 sgffile.c
--- engine/sgffile.c    4 Sep 2002 07:23:46 -0000       1.18
+++ engine/sgffile.c    7 Sep 2002 13:50:08 -0000
@@ -39,260 +39,6 @@
 #include "liberty.h"
 #include "sgftree.h"
 
-/* The SGF file while a game is played. */
-static FILE *sgfout = NULL;
-
-static int sgffile_flush_file(void);
-
-
-/* ================================================================ */
-
-
-/*
- * Handling of the SGF file itself (open, close, etc).
- * FIXME: remove this part once it isn't used anymore
- */
-
-
-/*
- * Open the sgf file for output.  The filename "-" means stdout.
- */
-
-int 
-sgffile_open_file(const char *sgf_filename)
-{
-  /* If the file already was open, close it and assume we want to
-   * start writing from scratch.
-   */
-  if (sgfout)
-    sgffile_close_file();
-  
-  if (strcmp(sgf_filename, "-") == 0)
-    sgfout = stdout;
-  else
-    sgfout = fopen(sgf_filename, "w");
-  
-  if (!sgfout)
-    return 0;
-  else
-    return 1;
-}
-
-
-/*
- * Flush buffered output to the sgf file.
- */
-
-static int 
-sgffile_flush_file()
-{
-  if (!sgfout) 
-    return 0;
-  
-  fflush(sgfout);
-  return 1;
-}
-
-
-/*
- * Close the sgf file for output.
- */
-
-int 
-sgffile_close_file()
-{
-  if (!sgfout)
-    return 0;
-
-  /* enable if we ever return to creating of sgf files on the fly */
-#if 0
-  fprintf(sgfout, ")\n"); 
-#endif
-
-  /* Don't close sgfout if it happens to be stdout. */
-  if (sgfout != stdout)
-    fclose(sgfout);
-  sgfout = NULL;
-  
-  return 1;
-}
-
-
-/* ---------------------------------------------------------------- */
-
-
-/*
- * Basic output functions.
- */
-
-
-/*
- * Write a line to the sgf file.
- */
-
-int 
-sgffile_write_line(const char * line, ...)
-{
-  va_list ap;
-
-  if (!sgfout)
-    return 0;
-
-  va_start(ap, line);
-  vfprintf(sgfout, line, ap);
-  va_end(ap);
-
-  return sgffile_flush_file();
-}
-
-
-/*
- * Write a comment to the SGF file.
- */
-
-void
-sgffile_write_comment(const char *comment)
-{
-  if (sgfout)
-    fprintf(sgfout, "C[%s]", comment);
-}
-
-
-/*
- * Add a stone to the SGF file.
- */
-
-void
-sgffile_put_stone(int i, int j, int color)
-{
-  if (sgfout)
-    fprintf(sgfout, "A%c[%c%c]", color==WHITE ? 'W' : 'B',
-           'a' + j, 'a' + i);
-}
-
-
-/*
- * Add a circle mark to the SGF file
- */
-
-void
-sgffile_write_circle_mark(int i, int j)
-{
-  if (sgfout)
-    fprintf(sgfout, "CR[%c%c]", 'a' + j, 'a' + i);
-}
-
-
-/* 
- * Write header information to the sgf file.
- */
-
-int 
-sgffile_write_gameinfo(Gameinfo *ginfo, const char *gametype)
-{
-  char outbuf[200];
-
-  if (!sgfout) 
-    return 0;
-
-  fprintf(sgfout, "(;GM[1]FF[4]");
-  fprintf(sgfout, "RU[%s]", "Japanese");
-  fprintf(sgfout, "SZ[%d]", board_size);
-  fprintf(sgfout, "\n");
-  
-  sprintf(outbuf, "GNU Go %s (level %d) %s", VERSION, level, gametype);
-  fprintf(sgfout, "PW[%s]PB[%s]", 
-         (ginfo->computer_player == WHITE 
-          || ginfo->computer_player == GRAY) ? outbuf : "Unknown",
-         (ginfo->computer_player == BLACK 
-          || ginfo->computer_player == GRAY) ? outbuf : "Unknown");
-  fprintf(sgfout, "HA[%d]", ginfo->handicap);
-  fprintf(sgfout, "KM[%.1f]", komi);
-  fprintf(sgfout, "GN[GNU Go %s %s ", VERSION, gametype);
-  fprintf(sgfout, "Random Seed %d", random_seed);
-  fprintf(sgfout, "] ");
-  fprintf(sgfout, "\n");
-  
-  return sgffile_flush_file();
-}
-
-
-/* ---------------------------------------------------------------- */
-
-
-/*
- * The functions below here accesses internal gnugo data structures.
- */
-
-
-/*
- * A move has been made; Write out the move and the potential moves
- * that were also considered.
- */
-
-void 
-sgffile_move_made(int i, int j, int color, int value)
-{
-  int m, n;
-  int done_label = 0;
-  
-  if (!sgfout)
-    return;
-
-  for (m = 0; m < board_size; ++m) {
-    for (n = 0; n < board_size; ++n) {
-      if (potential_moves[m][n] > 0.0) {
-       if (!done_label) {
-         fprintf(sgfout, "\nLB");
-         done_label = 1;
-       }
-       if (potential_moves[m][n] < 1.0)
-         fprintf(sgfout, "[%c%c:<1]", 'a'+n, 'a'+m);
-       else
-         fprintf(sgfout, "[%c%c:%d]", 'a'+n, 'a'+m,
-                 (int) potential_moves[m][n]);
-      }
-    }
-  }
-
-  if (value)
-    fprintf(sgfout, "\nC[Value of move: %d]", value);
-
-  /* If it is a pass move */
-  if (is_pass(POS(i, j))) {
-    if (board_size > 19)
-      fprintf(sgfout, "\n;%c[]\n", color == WHITE ? 'W' : 'B');
-    else
-      fprintf(sgfout, "\n;%c[tt]\n", color == WHITE ? 'W' : 'B');
-  }
-  else
-    fprintf(sgfout, "\n;%c[%c%c]\n", color == WHITE ? 'W' : 'B',
-           'a' + j, 'a' + i);
-
-  fflush(sgfout);  /* in case cgoban terminates us without notice */
-}  
-
-
-/*
- * Mark dead and critical dragons in the sgf file.
- */
-
-void 
-sgffile_dragon_status(int i, int j, int status)
-{
-  if (sgfout) {
-    switch (status) {
-      case DEAD:
-       fprintf(sgfout, "LB[%c%c:X]\n", 'a'+j, 'a'+i);
-       break;
-      case CRITICAL:
-       fprintf(sgfout, "LB[%c%c:!]\n", 'a'+j, 'a'+i);
-       break;
-    }
-  }
-}
-
-/* ---------------------------------------------------------------- */
 
 /*
  * Add debug information to a node if user requested it from command
@@ -308,7 +54,7 @@
   if (outfilename[0]) {
     for (m = 0; m < board_size; ++m)
       for (n = 0; n < board_size; ++n) {
-        if (BOARD(m,n) && (output_flags & OUTPUT_MARKDRAGONS))
+        if (BOARD(m, n) && (output_flags & OUTPUT_MARKDRAGONS))
           switch (dragon[POS(m, n)].crude_status) {
             case DEAD:
              sgfLabel(node, "X", m, n);
@@ -351,6 +97,7 @@
  * The parameter next, tells whose turn it is to move.
  */
 
+#if 0
 void
 sgffile_printboard(int next) 
 {
@@ -414,7 +161,7 @@
   }
   fprintf(sgfout, "\n");
 }
-
+#endif
 
 /* ================================================================ 
  * Dumping of information about a position into an sgftree.
@@ -423,16 +170,16 @@
 
 
 /*
- * begin_sgftreedump begins storing all moves considered by
+ * sgffile_begindump begins storing all moves considered by
  * trymove and tryko in an sgf tree in memory.
  *
  * The caller only has to provide an own SGFTree pointer if he wants
  * to do something more with the tree than writing it to file as done
- * by end_sgftreedump().
+ * by sgffile_enddump().
  */
 
 void
-begin_sgftreedump(SGFTree *tree)
+sgffile_begindump(SGFTree *tree)
 {
   SGFNode *node;
   static SGFTree local_tree;
@@ -446,28 +193,28 @@
   sgftree_clear(sgf_dumptree);
   node = sgftreeCreateHeaderNode(sgf_dumptree, board_size, 0.0);
   sgftreeSetLastNode(sgf_dumptree, node);
-  sgftree_printboard(sgf_dumptree);
+  sgffile_printboard(sgf_dumptree);
 }
 
 
 /*
- * end_sgftreedump ends the dump and writes the sgf tree to file.
+ * sgffile_enddump ends the dump and writes the sgf tree to file.
  */
 
 void 
-end_sgftreedump(const char *filename)
+sgffile_enddump()
 {
-  writesgf(sgf_dumptree->root, filename);
+  sgffile_output(sgf_dumptree->root);
   sgf_dumptree = NULL;
 }
 
 
 /*
- * sgftree_printboard adds the current board position to the tree.
+ * sgffile_printboard adds the current board position to the tree.
  */
 
 void
-sgftree_printboard(SGFTree *tree)
+sgffile_printboard(SGFTree *tree)
 {
   int i, j;
   SGFNode *node;
@@ -500,15 +247,11 @@
 {
   int i, j;
 
-  for (i = 0; i < board_size; i++) {
-    for (j = 0; j < board_size; j++) {
-      if (BOARD(i, j) == BLACK) {
-       sgffile_put_stone(i, j, BLACK);
-       if (node)
-         sgfAddStone(node, BLACK, i, j);
-      }
-    }
-  }
+  if (node)
+    for (i = 0; i < board_size; i++)
+      for (j = 0; j < board_size; j++)
+        if (BOARD(i, j) == BLACK)
+          sgfAddStone(node, BLACK, i, j);
 }
 
 
Index: engine/sgfdecide.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/sgfdecide.c,v
retrieving revision 1.37
diff -u -r1.37 sgfdecide.c
--- engine/sgfdecide.c  6 Aug 2002 19:04:11 -0000       1.37
+++ engine/sgfdecide.c  7 Sep 2002 13:50:09 -0000
@@ -39,7 +39,7 @@
  */
 
 void
-decide_string(int pos, const char *sgf_output)
+decide_string(int pos)
 {
   int aa, dd;
   int acode, dcode;
@@ -50,8 +50,7 @@
     return ;
   }
 
-  if (sgf_output)
-    begin_sgftreedump(&tree);
+  sgffile_begindump(&tree);
 
   /* Prepare pattern matcher and reading code. */
   reset_engine();
@@ -105,10 +104,8 @@
     }
   }
 
-  if (sgf_output) {
-    end_sgftreedump(sgf_output);
-    count_variations = 0;
-  }
+  sgffile_enddump();
+  count_variations = 0;
 }
 
 
@@ -119,7 +116,7 @@
  */
 
 void
-decide_connection(int apos, int bpos, const char *sgf_output)
+decide_connection(int apos, int bpos)
 {
   int move;
   int result;
@@ -138,8 +135,7 @@
     return;
   }
 
-  if (sgf_output)
-    begin_sgftreedump(&tree);
+  sgffile_begindump(&tree);
 
   /* Prepare pattern matcher and reading code. */
   reset_engine();
@@ -184,10 +180,8 @@
     gprintf("%1m and %1m cannot be disconnected (%d variations)\n", 
            apos, bpos, count_variations);
   
-  if (sgf_output) {
-    end_sgftreedump(sgf_output);
-    count_variations = 0;
-  }
+  sgffile_enddump();
+  count_variations = 0;
 }
 
 
@@ -198,7 +192,7 @@
  */
 
 void
-decide_dragon(int pos, const char *sgf_output)
+decide_dragon(int pos)
 {
   int move = NO_MOVE;
   int acode, dcode;
@@ -221,8 +215,7 @@
    */
   reading_cache_clear();
   
-  if (sgf_output)
-    begin_sgftreedump(&tree);
+  sgffile_begindump(&tree);
 
   count_variations = 1;
   acode = owl_attack(pos, &move, &result_certain);
@@ -277,10 +270,8 @@
   else
     gprintf(" result uncertain\n");
   
-  if (sgf_output) {
-    end_sgftreedump(sgf_output);
-    count_variations = 0;
-  }
+  sgffile_enddump();
+  count_variations = 0;
 }
 
 
@@ -308,7 +299,7 @@
  */
 
 void
-decide_semeai(int apos, int bpos, const char *sgf_output)
+decide_semeai(int apos, int bpos)
 {
   SGFTree tree;
   int resulta, resultb, move;
@@ -330,8 +321,8 @@
    * from the cache. Thus we clear the cache here. */
   reading_cache_clear();
   
-  if (sgf_output)
-    begin_sgftreedump(&tree);
+  sgffile_begindump(&tree);
+
   owl_analyze_semeai(apos, bpos, &resulta, &resultb, &move, 1);
   gprintf("After %s at %1m, %1m is %s, %1m is %s (%d nodes)\n",
          color == BLACK ? "black" : "white",
@@ -347,15 +338,13 @@
          bpos, safety_to_string(resultb),
          count_variations);
 
-  if (sgf_output) {
-    end_sgftreedump(sgf_output);
-    count_variations = 0;
-  }
+  sgffile_enddump();
+  count_variations = 0;
 }
 
 
 void
-decide_tactical_semeai(int apos, int bpos, const char *sgf_output)
+decide_tactical_semeai(int apos, int bpos)
 {
   SGFTree tree;
   int resulta, resultb, move;
@@ -377,8 +366,8 @@
    * from the cache. Thus we clear the cache here. */
   reading_cache_clear();
   
-  if (sgf_output)
-    begin_sgftreedump(&tree);
+  sgffile_begindump(&tree);
+
   owl_analyze_semeai(apos, bpos, &resulta, &resultb, &move, 0);
   gprintf("After %s at %1m, %1m is %s, %1m is %s (%d nodes)\n",
          color == BLACK ? "black" : "white",
@@ -394,10 +383,8 @@
          bpos, safety_to_string(resultb),
          count_variations);
 
-  if (sgf_output) {
-    end_sgftreedump(sgf_output);
-    count_variations = 0;
-  }
+  sgffile_enddump();
+  count_variations = 0;
 }
 
 
@@ -407,7 +394,7 @@
  */
 
 void
-decide_position(int color, const char *sgf_output)
+decide_position(int color)
 {
   int pos;
   int move = NO_MOVE;
@@ -424,8 +411,7 @@
    * from the cache. Thus we clear the cache here. */
   reading_cache_clear();
 
-  if (sgf_output)
-    begin_sgftreedump(&tree);
+  sgffile_begindump(&tree);
 
   count_variations = 1;
 
@@ -490,10 +476,8 @@
       gprintf("status of %1m revised to ALIVE\n", pos);
   }
   
-  if (sgf_output) {
-    end_sgftreedump(sgf_output);
-    count_variations = 0;
-  }
+  sgffile_enddump();
+  count_variations = 0;
 }
 
 
@@ -502,7 +486,7 @@
  */
 
 void
-decide_eye(int pos, const char *sgf_output)
+decide_eye(int pos)
 {
   int color;
   struct eyevalue value;
@@ -530,8 +514,7 @@
     reset_life_node_counter();
 
   /* Enable sgf output. */
-  if (sgf_output)
-    begin_sgftreedump(&tree);
+  sgffile_begindump(&tree);
   count_variations = 1;
   
   if (black_eye[pos].color == BLACK_BORDER) {
@@ -563,10 +546,8 @@
           get_life_node_counter());
 
   /* Finish sgf output. */
-  if (sgf_output) {
-    end_sgftreedump(sgf_output);
-    count_variations = 0;
-  }
+  sgffile_enddump();
+  count_variations = 0;
 }
 
 
@@ -576,7 +557,7 @@
  */
 
 void
-decide_combination(int color, const char *sgf_output)
+decide_combination(int color)
 {
   int attack_move;
   int defense_move;
@@ -587,8 +568,7 @@
 
   silent_examine_position(color, EXAMINE_ALL);
 
-  if (sgf_output)
-    begin_sgftreedump(&tree);
+  sgffile_begindump(&tree);
   count_variations = 1;
 
   if (atari_atari(color, &attack_move, &defense_move, verbose))
@@ -597,10 +577,8 @@
   else
     gprintf("No Combination attack for %C\n", color);
   
-  if (sgf_output) {
-    end_sgftreedump(sgf_output);
-    count_variations = 0;
-  }
+  sgffile_enddump();
+  count_variations = 0;
 }
 
 
Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.110
diff -u -r1.110 liberty.h
--- engine/liberty.h    2 Sep 2002 14:19:22 -0000       1.110
+++ engine/liberty.h    7 Sep 2002 13:50:15 -0000
@@ -582,16 +582,14 @@
 
 
 /* debugging support */
+void goaldump(char goal[BOARDMAX]);
 void move_considered(int move, float value);
 
 
 /* SGF routines for debugging purposes in sgffile.c */
-int sgffile_write_line(const char *line, ...);
-void sgffile_dragon_status(int i, int j, int status);
-void goaldump(char goal[BOARDMAX]);
-void sgftree_printboard(struct SGFTree_t *tree);
-void begin_sgftreedump(struct SGFTree_t *tree);
-void end_sgftreedump(const char *filename);
+void sgffile_printboard(struct SGFTree_t *tree);
+void sgffile_begindump(struct SGFTree_t *tree);
+void sgffile_enddump();
 
 
 
Index: engine/interface.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/interface.c,v
retrieving revision 1.26
diff -u -r1.26 interface.c
--- engine/interface.c  2 Sep 2002 06:40:40 -0000       1.26
+++ engine/interface.c  7 Sep 2002 13:50:17 -0000
@@ -388,9 +388,6 @@
 
   /* Info relevant to the computer player. */
   ginfo->computer_player = WHITE; /* Make an assumption. */
-
-  ginfo->outfilename[0] = '\0';
-  ginfo->outfile = NULL;
 }
 
 
@@ -463,8 +460,6 @@
   gnugo_play_move(i, j, color);
   sgftreeAddPlay(&ginfo->game_record, 0, color, i, j);
 
-  sgffile_move_made(i, j, color, 0);
-
   ginfo->to_move = OTHER_COLOR(color);
 }
 
@@ -552,7 +547,6 @@
         */
        rotate(i, j, &i, &j, board_size, orientation);
        gnugo_add_stone(i, j, BLACK);
-       sgffile_put_stone(i, j, BLACK);
        addstone = 1;
        break;
              
@@ -560,7 +554,6 @@
        get_moveXY(prop, &i, &j, board_size);
        rotate(i, j, &i, &j, board_size, orientation);
        gnugo_add_stone(i, j, WHITE);
-       sgffile_put_stone(i, j, WHITE);
        addstone = 1;
        break;
              
@@ -608,7 +601,6 @@
        if ((ON_BOARD2(i, j) && board[POS(i, j)] == EMPTY)
            || (i == -1 && j == -1)) {
          gnugo_play_move(i, j, next);
-         sgffile_move_made(i, j, next, 0);
          next = OTHER_COLOR(next);
        }
        else {
Index: engine/gnugo.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/gnugo.h,v
retrieving revision 1.62
diff -u -r1.62 gnugo.h
--- engine/gnugo.h      3 Sep 2002 00:28:12 -0000       1.62
+++ engine/gnugo.h      7 Sep 2002 13:50:19 -0000
@@ -164,10 +164,6 @@
   SGFTree   game_record;       /* Game record in sgf format. */
 
   int       computer_player;   /* BLACK, WHITE, or EMPTY (used as BOTH) */
-
-  /* FIXME: remove these fields once all sgf output goes through trees */
-  char     outfilename[128];
-  FILE      *outfile;
 } Gameinfo;
 
 void gameinfo_clear(Gameinfo *ginfo, int boardsize, float komi);
@@ -480,27 +476,19 @@
 void sgffile_debuginfo(SGFNode *node, int value);
 void sgffile_output(SGFNode *root);
 
-void sgffile_move_made(int i, int j, int color, int value);
-void sgffile_put_stone(int i, int j, int color);
-
-int sgffile_open_file(const char *);
-int sgffile_close_file(void);
-int sgffile_write_gameinfo(Gameinfo *gameinfo, const char *);
-void sgffile_write_comment(const char *comment);
-void sgffile_write_circle_mark(int i, int j);
-void sgffile_printboard(int next);
+void sgffile_printboard(struct SGFTree_t *tree);
 void sgffile_recordboard(SGFNode *node);
 
 /* sgfdecide.c */
-void decide_string(int pos, const char *sgf_output);
-void decide_connection(int apos, int bpos, const char *sgf_output);
-void decide_dragon(int pos, const char *sgf_output);
+void decide_string(int pos);
+void decide_connection(int apos, int bpos);
+void decide_dragon(int pos);
 void decide_dragon_data(int pos);
-void decide_semeai(int apos, int bpos, const char *sgf_output);
-void decide_tactical_semeai(int apos, int bpos, const char *sgf_output);
-void decide_position(int color, const char *sgf_output);
-void decide_eye(int pos, const char *sgf_output);
-void decide_combination(int color, const char *sgf_output);
+void decide_semeai(int apos, int bpos);
+void decide_tactical_semeai(int apos, int bpos);
+void decide_position(int color);
+void decide_eye(int pos);
+void decide_combination(int color);
 
 
 #endif  /* _GNUGO_H_ */
Index: interface/play_test.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_test.c,v
retrieving revision 1.10
diff -u -r1.10 play_test.c
--- interface/play_test.c       4 Sep 2002 07:23:46 -0000       1.10
+++ interface/play_test.c       7 Sep 2002 13:50:19 -0000
@@ -39,65 +39,56 @@
 /* --------------------------------------------------------------*/
 
 void
-play_replay(SGFNode *sgf_head, int color_to_replay)
+play_replay(Gameinfo *gameinfo, int color_to_replay)
 {
-  Gameinfo  gameinfo;
   int tmpi;
   float tmpf;
   char *tmpc = NULL;
 
-  SGFNode *node;
+  SGFTree tree = gameinfo->game_record;
+  SGFNode *node = tree.root;
 
   /* Get the board size. */
-  if (!sgfGetIntProperty(sgf_head, "SZ", &tmpi)) {
+  if (!sgfGetIntProperty(node, "SZ", &tmpi)) {
     fprintf(stderr, "Couldn't find the size (SZ) attribute!\n");
     exit(EXIT_FAILURE);
   }
-  gameinfo_clear(&gameinfo, tmpi, 5.5);
-   
-  /* Get the number of handicap stones. */
-  if (sgfGetIntProperty(sgf_head, "HA", &tmpi)) {
-    /* Handicap stones should appear as AW,AB properties in the sgf file. */
-    gameinfo.handicap = tmpi;
-  }
+
+  gnugo_clear_board(tmpi);
 
   /* Get the komi. */
-  if (sgfGetFloatProperty(sgf_head, "KM", &tmpf))
+  if (sgfGetFloatProperty(node, "KM", &tmpf))
     komi = tmpf;
 
   if (!quiet) {
-    if (sgfGetCharProperty(sgf_head, "RU", &tmpc))
+    if (sgfGetCharProperty(node, "RU", &tmpc))
       printf("Ruleset:      %s\n", tmpc);
-    if (sgfGetCharProperty(sgf_head, "GN", &tmpc))
+    if (sgfGetCharProperty(node, "GN", &tmpc))
       printf("Game Name:    %s\n", tmpc);
-    if (sgfGetCharProperty(sgf_head, "DT", &tmpc))
+    if (sgfGetCharProperty(node, "DT", &tmpc))
       printf("Game Date:    %s\n", tmpc);
-    if (sgfGetCharProperty(sgf_head, "GC", &tmpc))
+    if (sgfGetCharProperty(node, "GC", &tmpc))
       printf("Game Comment: %s\n", tmpc);
-    if (sgfGetCharProperty(sgf_head, "US", &tmpc))
+    if (sgfGetCharProperty(node, "US", &tmpc))
       printf("Game User:    %s\n", tmpc);
-    if (sgfGetCharProperty(sgf_head, "PB", &tmpc))
+    if (sgfGetCharProperty(node, "PB", &tmpc))
       printf("Black Player: %s\n", tmpc);
-    if (sgfGetCharProperty(sgf_head, "PW", &tmpc))
+    if (sgfGetCharProperty(node, "PW", &tmpc))
       printf("White Player: %s\n", tmpc);
 
-    gameinfo_print(&gameinfo);
+    gameinfo_print(gameinfo);
   }
 
-  sgffile_write_gameinfo(&gameinfo, "replay game");         
-   
   /*
    * Now actually run through the file.  This is the interesting part.
    * We need to traverse the SGF tree, and every time we encounter a node
    * we need to check what move GNU Go would make, and see if it is OK. 
    */
-  node = sgf_head;
   while (node) {
     replay_node(node, color_to_replay);
+    sgffile_output(tree.root);
     node = node->child;
   }
-
-   sgffile_close_file();
 }
 
 
@@ -117,6 +108,8 @@
   int m, n; /* Move from file. */
   int i, j; /* Move generated by GNU Go. */
 
+  char buf[127];
+
   /* Handle any AB / AW properties, and note presence
    * of move properties.
    */
@@ -127,15 +120,11 @@
       /* add black */
       gnugo_add_stone(get_moveX(sgf_prop, boardsize),
                      get_moveY(sgf_prop, boardsize), BLACK);
-      sgffile_put_stone(get_moveX(sgf_prop, boardsize),
-                       get_moveY(sgf_prop, boardsize), BLACK);
       break;
     case SGFAW:
       /* add white */
       gnugo_add_stone(get_moveX(sgf_prop, boardsize),
                      get_moveY(sgf_prop, boardsize), WHITE);
-      sgffile_put_stone(get_moveX(sgf_prop, boardsize),
-                       get_moveY(sgf_prop, boardsize), WHITE);
       break;
     case SGFB:
     case SGFW:
@@ -168,21 +157,24 @@
       printf("\n");
     }
     if (i != m || j != n) {
-      char buf[127];
-      gg_snprintf(buf, 127, "GNU Go plays %s(%.2f) - Game move %s(%.2f)",
+      gg_snprintf(buf, 127, "GNU Go plays %s (%.2f) - Game move %s (%.2f)",
                  location_to_string(POS(i, j)),
                  gnugo_is_pass(i, j) ? 0 : potential_moves[i][j],
                  location_to_string(POS(m, n)),
                  gnugo_is_pass(m, n)
                  && potential_moves[m][n] < 0.0 ? 0 : potential_moves[m][n]);
-      sgffile_write_comment(buf);
-      sgffile_write_circle_mark(i, j);
+      sgfCircle(node, i, j);
     }
+    else
+      gg_snprintf(buf, 127, "GNU Go plays the same move %s (%.2f)",
+                 location_to_string(POS(i, j)),
+                 gnugo_is_pass(i, j) ? 0 : potential_moves[i][j]);
+    sgfAddComment(node, buf);
+    sgffile_debuginfo(node, 0);
   }
 
   /* Finally, do play the move from the file. */
   gnugo_play_move(m, n, color);
-  sgffile_move_made(m, n, color, 0);
 }
 
 
Index: interface/play_solo.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_solo.c,v
retrieving revision 1.15
diff -u -r1.15 play_solo.c
--- interface/play_solo.c       4 Sep 2002 07:23:46 -0000       1.15
+++ interface/play_solo.c       7 Sep 2002 13:50:20 -0000
@@ -34,6 +34,8 @@
 #include "random.h"
 #include "gg_utils.h"
 
+SGFTree sgftree;
+SGFNode *curnode;
 
 void
 play_solo(Gameinfo *gameinfo, int moves)
@@ -56,7 +58,11 @@
   int n = 6 + 2*gg_rand()%5;
   int i, j;
 
-  sgffile_write_gameinfo(gameinfo, "solo");
+  gnugo_set_komi(5.5);
+
+  sgftree_clear(&sgftree);
+  curnode = sgftreeCreateHeaderNode(&sgftree, gnugo_get_boardsize(), 
gnugo_get_komi());
+  sgf_write_header(sgftree.root, 1, random_seed, 5.5, level, chinese_rules);
  
   /* Generate some random moves. */
   if (boardsize > 6) {
@@ -65,8 +71,11 @@
        i = (gg_rand() % 4) + (gg_rand() % (boardsize - 4));
        j = (gg_rand() % 4) + (gg_rand() % (boardsize - 4));
       } while (!gnugo_is_legal(i, j, gameinfo->to_move));
-      
-      gameinfo_play_move(gameinfo, i, j, gameinfo->to_move);
+
+      gnugo_play_move(i, j, gameinfo->to_move);
+      curnode = sgfAddPlay(curnode, gameinfo->to_move, i, j);
+      sgfAddComment(curnode, "random move");
+      gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
     } while (--n > 0);
   }
   
@@ -75,7 +84,12 @@
   while (passes < 2 && --moves >= 0 && !time_to_die) {
     reset_owl_node_counter();
     move_val = gnugo_genmove(&i, &j, gameinfo->to_move);
-    gameinfo_play_move(gameinfo, i, j, gameinfo->to_move);
+
+    gnugo_play_move(i, j, gameinfo->to_move);
+    sgffile_debuginfo(curnode, move_val);
+    curnode = sgfAddPlay(curnode, gameinfo->to_move, i, j);
+    sgffile_output(sgftree.root);
+    gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
 
     if (move_val < 0) {
       ++passes;
@@ -100,6 +114,10 @@
   /* Two passes and it's over. (EMPTY == BOTH) */
   gnugo_who_wins(EMPTY, stdout);
 
+  score = gnugo_estimate_score(&lower_bound, &upper_bound);
+  sgfWriteResult(sgftree.root, score, 1);
+  sgffile_output(sgftree.root);
+
 #if 0
   if (t2 == t1)
     printf("%.3f moves played\n", (double) (save_moves-moves));
@@ -136,31 +154,23 @@
   int i, j;
   int next;
   int r;
+  int move_val;
   
   next = gameinfo->to_move;
-  gameinfo->computer_player = next;
-  sgffile_write_gameinfo(gameinfo, "load and analyze");
+  sgftree = gameinfo->game_record;
 
-  if (benchmark) {
-    for (r = 0; r < benchmark; ++r) {
-      genmove(&i, &j, next);
-      next = OTHER_COLOR(next);
-    }
-  }
-  else {
-    genmove(&i, &j, next);
-    
-    if (is_pass(POS(i, j))) {
-      gprintf("%s move: PASS!\n", next == WHITE ? "white (O)" : "black (X)");
-      sgffile_move_made(i, j, next, 0);
-    }
-    else {
-      gprintf("%s move %m\n", next == WHITE ? "white (O)" : "black (X)",
-             i, j);
-      gnugo_play_move(i, j, next);
-      sgffile_move_made(i, j, next, 0);
-    }
-  }
+  move_val = gnugo_genmove(&i, &j, next);
+
+  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);
+  curnode = sgftreeNodeCheck(&sgftree, 0);
+  curnode = sgfAddPlay(curnode, next, i, j);
+  sgfAddComment(curnode, "load and analyze mode");
+  sgffile_debuginfo(curnode, move_val);
+  sgffile_output(sgftree.root);
 }
 
 
@@ -192,11 +202,10 @@
   sgftree_clear(&score_tree);
   node = sgftreeCreateHeaderNode(&score_tree, board_size, komi);
   sgftreeSetLastNode(&score_tree, node);
-  sgftree_printboard(&score_tree);
+  sgffile_printboard(&score_tree);
   
-  sgffile_write_gameinfo(gameinfo, "load and score");
   next = gameinfo->to_move;
-  sgffile_printboard(next);
+  node = node->child;
   doing_scoring = 1;
   reset_engine();
   
@@ -215,13 +224,13 @@
                next == WHITE ? "white (O)" : "black (X)");
       }
       play_move(POS(i, j), next);
-      sgffile_move_made(i, j, next, move_val);
-      sgftreeAddPlay(&score_tree, NULL, next, i, j);
+      sgffile_debuginfo(node, move_val);
+      node = sgfAddPlay(node, next, i, j);
+      sgffile_output(score_tree.root);
       next = OTHER_COLOR(next);
     } while (movenum <= until && pass < 2);
 
     if (pass >= 2) {
-      node = score_tree.lastnode;
       /* Calculate the score */
       if (!strcmp(scoringmode, "aftermath"))
        score = aftermath_compute_score(next, komi, &score_tree);
@@ -242,7 +251,6 @@
       }
       fputs(text, stdout);
       sgfAddComment(node, text);
-      sgffile_write_comment(text);
       if (sgfGetCharProperty(tree->root, "RE", &tempc)) {
        if (sscanf(tempc, "%1c%f", &dummy, &result) == 2) {
          fprintf(stdout, "Result from file: %1.1f\n", result);
@@ -265,26 +273,23 @@
        }
       }
       sgfWriteResult(score_tree.root, score, 1);
+      sgffile_output(score_tree.root);
     }
   }
   doing_scoring = 0;
 
 
-  if (!strcmp(scoringmode, "aftermath")) {
-    if (gameinfo->outfilename)
-      writesgf(score_tree.root, gameinfo->outfilename);
-    return;
+  if (strcmp(scoringmode, "aftermath")) {
+    /* Before we call estimate_score() we must make sure that the dragon
+     * status is computed. Therefore the call to examine_position().
+     */
+    examine_position(next, EXAMINE_ALL);
+    score = estimate_score(NULL, NULL);
+
+    fprintf(stdout, "\n%s seems to win by %1.1f points\n",
+      score < 0 ? "B" : "W",
+      score < 0 ? -score : score);
   }
-
-  /* Before we call estimate_score() we must make sure that the dragon
-   * status is computed. Therefore the call to examine_position().
-   */
-  examine_position(next, EXAMINE_ALL);
-  score = estimate_score(NULL, NULL);
-
-  fprintf(stdout, "\n%s seems to win by %1.1f points\n",
-         score < 0 ? "B" : "W",
-         score < 0 ? -score : score);
 }
 
 
Index: interface/play_gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v
retrieving revision 1.86
diff -u -r1.86 play_gtp.c
--- interface/play_gtp.c        2 Sep 2002 14:19:22 -0000       1.86
+++ interface/play_gtp.c        7 Sep 2002 13:50:25 -0000
@@ -2792,7 +2792,7 @@
 gtp_start_sgftrace(char *s)
 {
   UNUSED(s);
-  begin_sgftreedump(&gtp_sgftree);
+  sgffile_begindump(&gtp_sgftree);
   count_variations = 1;
   return gtp_success("");
 }
@@ -2820,7 +2820,7 @@
   if (nread < 1)
     return gtp_failure("missing filename");
 
-  end_sgftreedump(filename);
+  sgffile_enddump();
   count_variations = 0;
   return gtp_success("");
 }
Index: interface/play_gmp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gmp.c,v
retrieving revision 1.9
diff -u -r1.9 play_gmp.c
--- interface/play_gmp.c        7 Mar 2002 05:35:28 -0000       1.9
+++ interface/play_gmp.c        7 Sep 2002 13:50:25 -0000
@@ -118,7 +118,7 @@
   }
 
   gameinfo->computer_player = mycolor;
-  sgffile_write_gameinfo(gameinfo, "gmp");
+  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);
 
@@ -132,7 +132,8 @@
 
       if (message == gmp_err) {
        fprintf(stderr, "GNU Go: Sorry, error from gmp client\n");
-       sgffile_close_file();
+        sgfAddComment(curnode, "got error from gmp client");
+        sgffile_output(sgftree.root);
        return;
       }
 
@@ -146,8 +147,8 @@
                    j - k);
            break;
          }
-         sgffile_write_comment("undo");
-         curnode = curnode->parent;
+         sgfAddComment(curnode, "undone");
+          curnode = curnode->parent;
          to_move = OTHER_COLOR(to_move);
        }
        continue;
@@ -157,7 +158,7 @@
        ++passes;
         curnode = sgfAddPlay(curnode, to_move, -1, -1);
        gnugo_play_move(-1, -1, yourcolor);
-       sgffile_move_made(-1, -1, to_move, moveval);
+       sgffile_output(sgftree.root);
       }
       else {
        /* not pass */
@@ -165,7 +166,7 @@
         curnode = sgfAddPlay(curnode, to_move, i, j);
        TRACE("\nyour move: %m\n\n", i, j);
        gnugo_play_move(i, j, yourcolor);
-       sgffile_move_made(i, j, to_move, moveval);
+       sgffile_output(sgftree.root);
       }
 
     }
@@ -173,22 +174,23 @@
       /* Generate my next move. */
       moveval = gnugo_genmove(&i, &j, mycolor);
       gnugo_play_move(i, j, mycolor);
+      sgffile_debuginfo(curnode, moveval);
       
       if (moveval < 0) {
        /* pass */
         curnode = sgfAddPlay(curnode, to_move, -1, -1);
        gmp_sendPass(ge);
-       sgffile_move_made(-1, -1, to_move, moveval);
        ++passes;
       }
       else {
        /* not pass */
         curnode = sgfAddPlay(curnode, to_move, i, j);
        gmp_sendMove(ge, j, i);
-       sgffile_move_made(i, j, to_move, moveval);
        passes = 0;
        TRACE("\nmy move: %m\n\n", i, j);
       }
+      sgffile_debuginfo(curnode, 0);
+      sgffile_output(sgftree.root);
     }
     
     to_move = OTHER_COLOR(to_move);
@@ -203,7 +205,6 @@
   
   if (!quiet)
     fprintf(stderr, "Game over - waiting for client to shut us down\n");
-  sgffile_close_file();
   who_wins(mycolor, stderr);
   
   
@@ -213,6 +214,7 @@
   score = gnugo_estimate_score(&lower_bound, &upper_bound);
 
   sgfWriteResult(sgftree.root, score, 1);
+  sgffile_output(sgftree.root);
   
   while (!time_to_die) {
     message = gmp_check(ge, 1, &j, &i, &error);
Index: interface/play_ascii.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_ascii.c,v
retrieving revision 1.23
diff -u -r1.23 play_ascii.c
--- interface/play_ascii.c      3 Sep 2002 00:28:12 -0000       1.23
+++ interface/play_ascii.c      7 Sep 2002 13:50:27 -0000
@@ -617,6 +617,7 @@
          sgftreeWriteResult(&sgftree,
                             gameinfo->to_move == WHITE ? -1000.0 : 1000.0,
                             1);
+         sgffile_output(sgftree.root);
        case END:
        case EXIT:
        case QUIT:
@@ -940,7 +941,7 @@
        if (tmpstring) {
          /* discard newline */
          tmpstring[strlen(tmpstring)-1] = 0;
-         init_sgf(gameinfo,sgftree.root);
+          init_sgf(gameinfo,sgftree.root);
          writesgf(sgftree.root, tmpstring);
        }
        else
@@ -963,6 +964,8 @@
        state = 0;
       }
     }
+    sgftreeWriteResult(&sgftree, estimate_score(NULL, NULL), 1);
+    sgffile_output(sgftree.root);
     passes = 0;
     showdead = 0;
     /* Play a different game next time. */
Index: interface/main.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/main.c,v
retrieving revision 1.45
diff -u -r1.45 main.c
--- interface/main.c    3 Sep 2002 00:28:12 -0000       1.45
+++ interface/main.c    7 Sep 2002 13:50:31 -0000
@@ -385,10 +385,6 @@
       case 'o':
        outfile = gg_optarg;
        strcpy(outfilename, gg_optarg);
-
-        /* FIXME: remove this line once all sgf output goes through trees */
-       strcpy(gameinfo.outfilename, gg_optarg);
-
        break;
 
       case 'O':
@@ -881,9 +877,8 @@
     gameinfo_play_sgftree_rot(&gameinfo, sgftree.root,
                              untilstring, orientation);
   }
-
+  else
   /* Initialize and empty sgf tree if there was no infile. */
-  if (!sgftree.root)
     sgftreeCreateHeaderNode(&sgftree, board_size, komi);
 
   /* Set the game_record to be identical to the loaded one or the
@@ -906,7 +901,12 @@
     else
       playmode = (isatty(0)) ? MODE_ASCII : MODE_GMP;
   }
-  
+
+/* FIXME: add some check of whether outfile can be opened for writing
+ *        here. don't bother with mode checking - it can be used with
+ *       any mode */
+
+#if 0  
   if (outfile) {
     if (playmode != MODE_DECIDE_STRING
        && playmode != MODE_DECIDE_CONNECTION
@@ -920,8 +920,9 @@
       if (!sgffile_open_file(outfile)) {
        fprintf(stderr, "Error: could not open '%s'\n", gg_optarg);
        exit(EXIT_FAILURE);
-      }
+      };
   }
+#endif
   
   switch (playmode) {
   case MODE_GMP:     
@@ -933,18 +934,18 @@
     break;
     
   case MODE_REPLAY:    
-    if (!sgftree.root) {
+    if (!infilename) {
       fprintf(stderr, "You must use -l infile with replay mode.\n");
       exit(EXIT_FAILURE);
     }
-    play_replay(sgftree.root, replay_color);
+    play_replay(&gameinfo, replay_color);
     break;
     
   case MODE_LOAD_AND_ANALYZE:
     if (mandated_color != EMPTY)
       gameinfo.to_move = mandated_color;
     
-    if (!sgftree.root) {
+    if (!infilename) {
       fprintf(stderr, "You must use -l infile with load and analyze mode.\n");
       exit(EXIT_FAILURE);
     }
@@ -952,7 +953,7 @@
     break;
     
   case MODE_LOAD_AND_SCORE:
-    if (!sgftree.root) {
+    if (!infilename) {
       fprintf(stderr, "gnugo: --score must be used with -l\n");
       exit(EXIT_FAILURE);
     }
@@ -960,14 +961,15 @@
     break;
     
   case MODE_LOAD_AND_PRINT:
-    if (!sgftree.root) {
+    if (!infilename) {
       fprintf(stderr, "gnugo: --printsgf must be used with -l\n");
       exit(EXIT_FAILURE);
     }
     else {
-      sgffile_open_file(printsgffile);
-      sgffile_write_gameinfo(&gameinfo, "load and print"); 
-      sgffile_printboard(gameinfo.to_move);
+      sgftree.root->child = NULL;
+      sgftreeSetLastNode(&sgftree, sgftree.root);
+      sgffile_printboard(&sgftree);
+      sgffile_output(sgftree.root);
     }
     break;
     
@@ -986,7 +988,7 @@
       }
 
       rotate(m, n, &m, &n, board_size, orientation);
-      decide_string(POS(m, n), outfile);
+      decide_string(POS(m, n));
     }
     break;
   
@@ -1011,7 +1013,7 @@
 
       rotate(ai, aj, &ai, &aj, board_size, orientation);
       rotate(bi, bj, &bi, &bj, board_size, orientation);
-      decide_connection(POS(ai, aj), POS(bi, bj), outfile);
+      decide_connection(POS(ai, aj), POS(bi, bj));
     }
   break;
   
@@ -1030,7 +1032,7 @@
       }
 
       rotate(m, n, &m, &n, board_size, orientation);
-      decide_dragon(POS(m, n), outfile);
+      decide_dragon(POS(m, n));
     }
     break;
   
@@ -1076,7 +1078,7 @@
 
       rotate(ai, aj, &ai, &aj, board_size, orientation);
       rotate(bi, bj, &bi, &bj, board_size, orientation);
-      decide_semeai(POS(ai, aj), POS(bi, bj), outfile);
+      decide_semeai(POS(ai, aj), POS(bi, bj));
     }
     break;
     
@@ -1104,7 +1106,7 @@
 
       rotate(ai, aj, &ai, &aj, board_size, orientation);
       rotate(bi, bj, &bi, &bj, board_size, orientation);
-      decide_tactical_semeai(POS(ai, aj), POS(bi, bj), outfile);
+      decide_tactical_semeai(POS(ai, aj), POS(bi, bj));
     }
     break;
     
@@ -1119,7 +1121,7 @@
       color = gameinfo.to_move;
       if (mandated_color != EMPTY)
        color = mandated_color;
-      decide_position(color, outfile);
+      decide_position(color);
     }
     break;
     
@@ -1138,7 +1140,7 @@
       }
       
       rotate(m, n, &m, &n, board_size, orientation);
-      decide_eye(POS(m, n), outfile);
+      decide_eye(POS(m, n));
     }
     break;
   
@@ -1152,7 +1154,7 @@
       color = gameinfo.to_move;
       if (mandated_color != EMPTY)
        color = mandated_color;
-      decide_combination(color, outfile);
+      decide_combination(color);
     }
     break;
     
@@ -1186,8 +1188,6 @@
     break;
   }
   
-  sgffile_close_file();
-  
   if (profile_patterns)
     report_pattern_profiling();
 
@@ -1299,7 +1299,7 @@
    --score estimate        estimate score at loaded position\n\
    --score finish          generate moves to finish game, then score\n\
    --score aftermath       generate moves to finish, use best algorithm\n\
-   --score aftermath --capture-all-dead --chinese rules   Tromp-Taylor score\n\
+   --score aftermath --capture-all-dead --chinese-rules   Tromp-Taylor score\n\
 \n\
 Cache size (higher=more memory usage, faster unless swapping occurs):\n\
    -M, --cache-size <megabytes>  RAM cache for hashing (default %4.1f Mb)\n\
@@ -1365,7 +1365,7 @@
    -O, --output-flags <flags>    optional output (use with -o)\n\
                     d: mark dead and critical dragons\n\
                     v: show values of considered moves\n\
-                    specify either no flags (default), 'd', 'v' or 'dv'\n\
+                    specify either 'd', 'v' or 'dv' (nothing by default)\n\
    --showtime                    print timing diagnostic\n\
    --replay <color>              replay game. Use with -o.\n\
    --showscore                   print estimated score\n\
Index: interface/interface.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/interface.h,v
retrieving revision 1.9
diff -u -r1.9 interface.h
--- interface/interface.h       7 Mar 2002 05:35:28 -0000       1.9
+++ interface/interface.h       7 Sep 2002 13:50:31 -0000
@@ -37,7 +37,7 @@
 void play_gtp(FILE *gtp_input, int gtp_initial_orientation);
 void play_gmp(Gameinfo *gameinfo);
 void play_solo(Gameinfo *gameinfo, int benchmark);
-void play_replay(SGFNode *sgf_head, int color_to_test);
+void play_replay(Gameinfo *gameinfo, int color_to_test);
 
 void load_and_analyze_sgf_file(Gameinfo *gameinfo, int benchmark);
 void load_and_score_sgf_file(SGFTree *tree, Gameinfo *gameinfo,





reply via email to

[Prev in Thread] Current Thread [Next in Thread]