gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] Metamachine patch


From: bump
Subject: [gnugo-devel] Metamachine patch
Date: Sun, 5 May 2002 09:13:37 -0700

This patch improves the performance of metamachine in blunder.tst
and reading.tst. I have not performed the full regressions on it.

When moves are rejected in genmove, because (for example) they
do not pass confirm_safety, they should be removed from the
list of top moves. This happens after print_top_moves has
run so it will not change the move list reported by
genmove unless we do some further rewriting. However it
does affect the list of moves reported by gtp_top_moves and
that helps a lot with metamachine.

It also fixes a couple of bugs in metamachine.

- top moves list maintained when moves are rejected
- bugfixes in metamachine


Index: engine/genmove.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/genmove.c,v
retrieving revision 1.40
diff -u -r1.40 genmove.c
--- engine/genmove.c    18 Apr 2002 21:00:26 -0000      1.40
+++ engine/genmove.c    5 May 2002 16:01:39 -0000
@@ -476,6 +476,7 @@
       && fill_liberty(move, color)) {
     val = 1.0;
     TRACE("Filling a liberty at %1m\n", *move);
+    record_top_move(*move, val);
     move_considered(*move, val);
     time_report(1, "fill liberty", NO_MOVE, 1.0);
   }
@@ -496,6 +497,7 @@
     ASSERT1(is_legal(*move, color), *move);
     val = 1.0;
     TRACE("Aftermath move at %1m\n", *move);
+    record_top_move(*move, val);
     move_considered(*move, val);
     time_report(1, "aftermath_genmove", NO_MOVE, 1.0);
   }
Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.98
diff -u -r1.98 liberty.h
--- engine/liberty.h    3 May 2002 17:57:58 -0000       1.98
+++ engine/liberty.h    5 May 2002 16:03:08 -0000
@@ -391,6 +391,8 @@
 void add_shape_value(int pos, float value);
 void add_followup_value(int pos, float value);
 void add_reverse_followup_value(int pos, float value);
+void record_top_move(int move, float val);
+void remove_top_move(int move);
 
 /* Parameters to add_either_move and add_all_move */
 #define ATTACK_STRING  1
Index: engine/value_moves.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/value_moves.c,v
retrieving revision 1.35
diff -u -r1.35 value_moves.c
--- engine/value_moves.c        3 May 2002 17:57:58 -0000       1.35
+++ engine/value_moves.c        5 May 2002 16:04:03 -0000
@@ -2454,24 +2454,16 @@
   int pos;
   float tval;
   
-  for (k = 0; k < 10; k++)
+  for (k = 0; k < 10; k++) {
+    best_moves[k] = NO_MOVE;
     best_move_values[k] = 0.0;
-
+  }
   for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
     if (!ON_BOARD(pos) || move[pos].final_value <= 0.0)
       continue;
       
     tval = move[pos].final_value;
-
-    for (k = 9; k >= 0; k--)
-      if (tval > best_move_values[k]) {
-       if (k < 9) {
-         best_move_values[k+1] = best_move_values[k];
-         best_moves[k+1] = best_moves[k];
-       }
-       best_move_values[k] = tval;
-       best_moves[k] = pos;
-      }
+    record_top_move(pos, tval);
   }
   
   if (verbose > 0 || (debug & DEBUG_TOP_MOVES)) {
@@ -2481,6 +2473,41 @@
   }
 }
 
+/* Add a move to the list of top moves (if it is among the top ten) */
+
+  void
+record_top_move(int move, float val)
+{
+  int k;
+  for (k = 9; k >= 0; k--)
+    if (val > best_move_values[k]) {
+      if (k < 9) {
+       best_move_values[k+1] = best_move_values[k];
+       best_moves[k+1] = best_moves[k];
+      }
+      best_move_values[k] = val;
+      best_moves[k] = move;
+    }
+}
+
+/* remove a rejected move from the list of top moves */
+
+void
+remove_top_move(int move)
+{
+  int k;
+  for (k = 0; k < 10; k++) {
+    if (best_moves[k] == move) {
+      int l;
+      for (l = k; l < 10; l++) {
+       best_moves[l] = best_moves[l+1];
+       best_move_values[l] = best_move_values[l+1];
+      }
+      best_moves[9] = NO_MOVE;
+      best_move_values[9] = 0.0;
+    }
+  }
+}
 
 /* This function is called if the biggest move on board was an illegal
  * ko capture.
@@ -2722,6 +2749,7 @@
        }
        else {
          TRACE("Move at %1m would be suicide.\n", pos);
+         remove_top_move(pos);
          move[pos].value = 0.0;
          move[pos].final_value = 0.0;
        }
@@ -2751,6 +2779,7 @@
       redistribute_points();
       time_report(2, "  reevaluate_ko_threats", NO_MOVE, 1.0);
       ko_values_have_been_added = 1;
+      remove_top_move(best_move);
       move[best_move].value = 0.0;
       move[best_move].final_value = 0.0;
       print_top_moves();
@@ -2764,6 +2793,7 @@
             && !value_moves_confirm_safety(best_move, color,
                                            allowed_blunder_size)) {
       TRACE("Move at %1m would be a blunder.\n", best_move);
+      remove_top_move(best_move);
       move[best_move].value = 0.0;
       move[best_move].final_value = 0.0;
       good_move_found = 0;
Index: interface/gtp_examples/metamachine.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/gtp_examples/metamachine.c,v
retrieving revision 1.2
diff -u -r1.2 metamachine.c
--- interface/gtp_examples/metamachine.c        4 Mar 2002 06:49:08 -0000       
1.2
+++ interface/gtp_examples/metamachine.c        5 May 2002 16:05:02 -0000
@@ -104,8 +104,8 @@
     char *p;
     int n;
 
-    if (!fgets(client_line, GTP_BUFSIZE, stdin) 
-       || strstr(client_line, "quit")) {
+    if (!fgets(client_line, GTP_BUFSIZE, stdin)
+       || (strstr(client_line, "quit") == client_line)) {
       tell_gnugo("quit\n", "a");
        return 1;
     }
@@ -181,6 +181,9 @@
                  move_i[k], move_j[k], move_value[k]);
       }
       moves_considered = k;
+      if (debug)
+       fprintf(stderr, "moves considered: %d\n",
+               moves_considered);
       for (k = 0; k < 2 && k < moves_considered; k++) {
        float upper, lower;
        int n;
@@ -214,7 +217,7 @@
        if (id == -1)
          gprintf(stdout, "= PASS\n\n");
        else
-         gprintf(stdout, "=%d PASS\n\n");
+         gprintf(stdout, "=%d PASS\n\n", id);
        fflush(stdout);
       }
       else if (moves_considered == 1 ||




reply via email to

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