Ticket #32: gunnar_7_8.1

File gunnar_7_8.1, 8.7 KB (added by gunnar, 6 years ago)
Line 
1Index: interface/interface.h
2===================================================================
3RCS file: /cvsroot/gnugo/gnugo/interface/interface.h,v
4retrieving revision 1.18
5diff -u -r1.18 interface.h
6--- interface/interface.h       12 Jun 2005 09:34:14 -0000      1.18
7+++ interface/interface.h       9 Oct 2005 20:41:21 -0000
8@@ -37,7 +37,7 @@
9              int gtp_initial_orientation);
10 void play_gmp(Gameinfo *gameinfo, int simplified);
11 void play_solo(Gameinfo *gameinfo, int benchmark);
12-void play_replay(Gameinfo *gameinfo, int color_to_test);
13+void play_replay(SGFTree *tree, int color_to_test);
14 
15 void load_and_analyze_sgf_file(Gameinfo *gameinfo);
16 void load_and_score_sgf_file(SGFTree *tree, Gameinfo *gameinfo,
17Index: interface/main.c
18===================================================================
19RCS file: /cvsroot/gnugo/gnugo/interface/main.c,v
20retrieving revision 1.119
21diff -u -r1.119 main.c
22--- interface/main.c    7 Oct 2005 23:22:31 -0000       1.119
23+++ interface/main.c    9 Oct 2005 20:41:21 -0000
24@@ -1024,7 +1024,7 @@
25       fprintf(stderr, "You must use -l infile with replay mode.\n");
26       exit(EXIT_FAILURE);
27     }
28-    play_replay(&gameinfo, replay_color);
29+    play_replay(&sgftree, replay_color);
30     break;
31     
32   case MODE_LOAD_AND_ANALYZE:
33Index: interface/play_test.c
34===================================================================
35RCS file: /cvsroot/gnugo/gnugo/interface/play_test.c,v
36retrieving revision 1.22
37diff -u -r1.22 play_test.c
38--- interface/play_test.c       5 Oct 2005 16:32:12 -0000       1.22
39+++ interface/play_test.c       9 Oct 2005 20:41:21 -0000
40@@ -32,10 +32,8 @@
41 #include "gg_utils.h"
42 #include "liberty.h"
43 
44-static void replay_node(SGFNode *node, int color_to_test);
45-
46-static float replay_score;
47-static float total_score;
48+static void replay_node(SGFNode *node, int color_to_test, float *replay_score,
49+                       float *total_score);
50 
51 
52 /* --------------------------------------------------------------*/
53@@ -43,28 +41,25 @@
54 /* --------------------------------------------------------------*/
55 
56 void
57-play_replay(Gameinfo *gameinfo, int color_to_replay)
58+play_replay(SGFTree *tree, int color_to_replay)
59 {
60-  int tmpi;
61-  float tmpf;
62   char *tmpc = NULL;
63+  float replay_score = 0.0;
64+  float total_score = 0.0;
65 
66-  SGFTree tree = gameinfo->game_record;
67-  SGFNode *node = tree.root;
68-
69-  /* Get the board size. */
70-  if (!sgfGetIntProperty(node, "SZ", &tmpi)) {
71-    fprintf(stderr, "Couldn't find the size (SZ) attribute!\n");
72-    exit(EXIT_FAILURE);
73-  }
74-
75-  gnugo_clear_board(tmpi);
76-
77-  /* Get the komi. */
78-  if (sgfGetFloatProperty(node, "KM", &tmpf))
79-    komi = tmpf;
80+  SGFNode *node = tree->root;
81 
82+  /* Board size and komi are already set up correctly since the game
83+   * has already been loaded before this function is called. Now we
84+   * only have to clear the board before starting over.
85+   */
86+  clear_board();
87+
88   if (!quiet) {
89+    printf("Board Size:   %d\n", board_size);
90+    if (sgfGetCharProperty(node, "HA", &tmpc))
91+      printf("Handicap:     %s\n", tmpc);
92+    printf("Komi:         %.1f\n", komi);
93     if (sgfGetCharProperty(node, "RU", &tmpc))
94       printf("Ruleset:      %s\n", tmpc);
95     if (sgfGetCharProperty(node, "GN", &tmpc))
96@@ -79,11 +74,8 @@
97       printf("Black Player: %s\n", tmpc);
98     if (sgfGetCharProperty(node, "PW", &tmpc))
99       printf("White Player: %s\n", tmpc);
100-
101-    gameinfo_print(gameinfo);
102-
103-    replay_score = 0.0;
104-    total_score = 0.0;
105+    if (sgfGetCharProperty(node, "RE", &tmpc))
106+      printf("Result:       %s\n", tmpc);
107   }
108 
109   /*
110@@ -92,42 +84,43 @@
111    * we need to check what move GNU Go would make, and see if it is OK.
112    */
113   while (node) {
114-    replay_node(node, color_to_replay);
115-    sgffile_output(&tree);
116+    replay_node(node, color_to_replay, &replay_score, &total_score);
117+    sgffile_output(tree);
118     node = node->child;
119   }
120 
121-  if (!quiet) {
122-    printf("\nGlobal score: %.2f / %.2f", replay_score, total_score);
123-  }
124+  if (!quiet)
125+    printf("Global score: %.2f / %.2f", replay_score, total_score);
126 
127   if (showtime) {
128-      gprintf("\nSLOWEST MOVE: %d at %1m ", slowest_movenum, slowest_move);
129-      fprintf(stderr, "(%.2f seconds)\n", slowest_time);
130-      fprintf(stderr, "\nAVERAGE TIME: %.2f seconds per move\n",
131-             total_time / movenum);
132-      fprintf(stderr, "\nTOTAL TIME: %.2f seconds\n",
133-             total_time);
134+    gprintf("SLOWEST MOVE: %d at %1m ", slowest_movenum, slowest_move);
135+    fprintf(stderr, "(%.2f seconds)\n", slowest_time);
136+    fprintf(stderr, "AVERAGE TIME: %.2f seconds per move\n",
137+           total_time / movenum);
138+    fprintf(stderr, "TOTAL TIME: %.2f seconds\n",
139+           total_time);
140   }
141 }
142 
143 
144+#define BUFSIZE 128
145 
146 /*
147  * Handle this node.
148  */
149 
150 static void
151-replay_node(SGFNode *node, int color_to_replay)
152+replay_node(SGFNode *node, int color_to_replay, float *replay_score,
153+           float *total_score)
154 {
155   SGFProperty *sgf_prop;  /* iterate over properties of the node */
156   SGFProperty *move_prop = NULL; /* remember if we see a move property */
157   int color; /* color of move to be made at this node. */
158   
159-  int m, n; /* Move from file. */
160-  int i, j; /* Move generated by GNU Go. */
161+  int old_move; /* The move played in the file. */
162+  int new_move; /* The move generated by GNU Go. */
163 
164-  char buf[127];
165+  char buf[BUFSIZE];
166 
167   /* Handle any AB / AW properties, and note presence
168    * of move properties.
169@@ -158,63 +151,67 @@
170   if (!move_prop)
171     return;
172 
173-  m = get_moveX(move_prop, board_size);
174-  n = get_moveY(move_prop, board_size);
175+  old_move = POS(get_moveX(move_prop, board_size),
176+                get_moveY(move_prop, board_size));
177   color = (move_prop->name == SGFW) ? WHITE : BLACK;
178 
179   if (color == color_to_replay || color_to_replay == GRAY) {
180+    float new_move_value = 0.0;
181+    float old_move_value = 0.0;
182
183     /* Get a move from the engine for color. */
184     int resign;
185-    gnugo_genmove(&i, &j, color, &resign);
186+    new_move = genmove(color, NULL, &resign);
187+   
188+    /* Pick up the relevant values from the potential_moves[] array. */
189+    if (new_move != PASS_MOVE)
190+      new_move_value = potential_moves[new_move];
191+    if (old_move != PASS_MOVE)
192+      old_move_value = potential_moves[old_move];
193+   
194     /* Now report on how well the computer generated the move. */
195-    if (i != m || j != n || !quiet) {
196+    if (new_move != old_move || !quiet) {
197       mprintf("Move %d (%C): ", movenum + 1, color);
198     
199       if (resign)
200        printf("GNU Go resigns ");
201       else {
202-       mprintf("GNU Go plays %m ", i, j);
203-       if (!is_pass(POS(i, j)))
204-         printf("(%.2f) ", potential_moves[POS(i, j)]);
205+       mprintf("GNU Go plays %1m ", new_move);
206+       if (new_move != PASS_MOVE)
207+         printf("(%.2f) ", new_move_value);
208       }
209-      mprintf("- Game move %m ", m, n);
210-      if (!is_pass(POS(m, n)) && potential_moves[POS(m, n)] > 0.0)
211-       printf("(%.2f) ", potential_moves[POS(m, n)]);
212+     
213+      mprintf("- Game move %1m ", old_move);
214+      if (new_move != PASS_MOVE && old_move_value > 0.0)
215+       printf("(%.2f) ", old_move_value);
216       printf("\n");
217 
218-      if (!quiet) {
219-       replay_score += (potential_moves[POS(i, j)] - potential_moves[POS(m, n)]);
220-       total_score += potential_moves[POS(i, j)];
221-      }
222+      *replay_score += new_move_value - old_move_value;
223+      *total_score += new_move_value;
224     }
225-    if (i != m || j != n) {
226+   
227+    if (new_move != old_move) {
228       if (resign)
229-       gg_snprintf(buf, 127, "GNU Go resigns - Game move %s (%.2f)",
230-                   location_to_string(POS(m, n)),
231-                   is_pass(POS(m, n))
232-                   && potential_moves[POS(m, n)] < 0.0 ?
233-                       0 : potential_moves[POS(m, n)]);
234+       gg_snprintf(buf, BUFSIZE, "GNU Go resigns - Game move %s (%.2f)",
235+                   location_to_string(old_move), old_move_value);
236       else {     
237-       gg_snprintf(buf, 127, "GNU Go plays %s (%.2f) - Game move %s (%.2f)",
238-                   location_to_string(POS(i, j)),
239-                   is_pass(POS(i, j)) ? 0 : potential_moves[POS(i, j)],
240-                   location_to_string(POS(m, n)),
241-                   is_pass(POS(m, n))
242-                   && potential_moves[POS(m, n)] < 0.0 ?
243-                       0 : potential_moves[POS(m, n)]);
244-       sgfCircle(node, i, j);
245+       gg_snprintf(buf, BUFSIZE,
246+                   "GNU Go plays %s (%.2f) - Game move %s (%.2f)",
247+                   location_to_string(new_move), new_move_value,
248+                   location_to_string(old_move), old_move_value);
249+       sgfCircle(node, I(new_move), J(new_move));
250       }
251     }
252     else
253-      gg_snprintf(buf, 127, "GNU Go plays the same move %s (%.2f)",
254-                 location_to_string(POS(i, j)),
255-                 is_pass(POS(i, j)) ? 0 : potential_moves[POS(i, j)]);
256+      gg_snprintf(buf, BUFSIZE, "GNU Go plays the same move %s (%.2f)",
257+                 location_to_string(new_move), new_move_value);
258+   
259     sgfAddComment(node, buf);
260     sgffile_add_debuginfo(node, 0.0);
261   }
262 
263   /* Finally, do play the move from the file. */
264-  gnugo_play_move(m, n, color);
265+  play_move(old_move, color);
266 }
267 
268