gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] complete conversion of break-in reading to new cache


From: Arend Bayer
Subject: [gnugo-devel] complete conversion of break-in reading to new cache
Date: Tue, 27 Jan 2004 19:49:00 +0100 (CET)


This fixes the problem noted by Inge, and also converts recursive_block()
to use the new cache. (Previously I had only converted recursive_break().)

Almost no change in node counts (small reduction).

Arend


Index: engine/cache.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/cache.h,v
retrieving revision 1.42
diff -u -p -r1.42 cache.h
--- engine/cache.h      24 Jan 2004 23:44:38 -0000      1.42
+++ engine/cache.h      25 Jan 2004 13:34:04 -0000
@@ -370,6 +370,14 @@ int get_read_result2(enum routine_id rou
     return (value); \
   } while (0)

+#define READ_RETURN_HASH_NG(komaster, kom_pos, routine, str, remaining_depth, 
hash, point, move, value) \
+  do { \
+    tt_update(&ttable, komaster, kom_pos, routine, str, remaining_depth, hash,\
+              value, 0, move);\
+    if ((value) != 0 && (point) != 0) *(point) = (move); \
+    return (value); \
+  } while (0)
+
 #define READ_RETURN2_NG(komaster, kom_pos, routine, str, remaining_depth, 
point, move, value1, value2) \
   do { \
     tt_update(&ttable, komaster, kom_pos, routine, str, remaining_depth, NULL,\
Index: engine/readconnect.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/readconnect.c,v
retrieving revision 1.66
diff -u -p -r1.66 readconnect.c
--- engine/readconnect.c        24 Jan 2004 23:21:13 -0000      1.66
+++ engine/readconnect.c        25 Jan 2004 13:34:06 -0000
@@ -2806,8 +2806,8 @@ recursive_break(int str, const char goal
        if (acode == 0) {
          SGFTRACE(xpos, WIN, "break effective");
 #if USE_HASHTABLE_NG
-         READ_RETURN_NG(komaster, kom_pos, BREAK_IN, str, depth - stackp,
-                        move, xpos, WIN);
+         READ_RETURN_HASH_NG(komaster, kom_pos, BREAK_IN, str, depth - stackp,
+                             goal_hash, move, xpos, WIN);
 #else
          READ_RETURN(read_result, move, xpos, WIN);
 #endif
@@ -2831,8 +2831,8 @@ recursive_break(int str, const char goal
   if (tried_moves == 0 && distance < 1.0) {
     SGFTRACE(NO_MOVE, WIN, "no move, probably connected");
 #if USE_HASHTABLE_NG
-    READ_RETURN_NG(komaster, kom_pos, BREAK_IN, str, depth -stackp,
-                  move, xpos, WIN);
+    READ_RETURN_HASH_NG(komaster, kom_pos, BREAK_IN, str, depth - stackp,
+                       goal_hash, move, xpos, WIN);
 #else
     READ_RETURN(read_result, move, NO_MOVE, WIN);
 #endif
@@ -2841,8 +2841,8 @@ recursive_break(int str, const char goal
   if (savecode != 0) {
     SGFTRACE(savemove, savecode, "saved move");
 #if USE_HASHTABLE_NG
-    READ_RETURN_NG(komaster, kom_pos, BREAK_IN, str, depth -stackp,
-                  move, xpos, savecode);
+    READ_RETURN_HASH_NG(komaster, kom_pos, BREAK_IN, str, depth - stackp,
+                       goal_hash, move, xpos, savecode);
 #else
     READ_RETURN(read_result, move, savemove, savecode);
 #endif
@@ -2850,8 +2850,8 @@ recursive_break(int str, const char goal

   SGFTRACE(0, 0, NULL);
 #if USE_HASHTABLE_NG
-  READ_RETURN_NG(komaster, kom_pos, BREAK_IN, str, depth -stackp,
-                move, xpos, 0);
+  READ_RETURN_HASH_NG(komaster, kom_pos, BREAK_IN, str, depth - stackp,
+                     goal_hash, move, xpos, 0);
 #else
   READ_RETURN(read_result, move, NO_MOVE, 0);
 #endif
@@ -2873,9 +2873,13 @@ recursive_block(int str, const char goal
   int xpos;
   int savemove = NO_MOVE;
   int savecode = 0;
-  int found_read_result;
   int tried_moves = 0;
+#if USE_HASHTABLE_NG
+  int retval;
+#else
+  int found_read_result;
   Read_result *read_result = NULL;
+#endif
   SETUP_TRACE_INFO("recursive_block", str);

   nodes_connect++;
@@ -2906,6 +2910,17 @@ recursive_block(int str, const char goal
     return WIN;
   }

+#if USE_HASHTABLE_NG
+  if ((stackp <= depth)
+      && (hashflags & HASH_BLOCK_OFF)
+      && (tt_get(&ttable, komaster, kom_pos, BLOCK_OFF, str,
+                 depth - stackp, goal_hash, &retval, NULL, &xpos) == 2)) {
+    SGFTRACE(xpos, retval, "cached");
+    if (move)
+      *move = xpos;
+    return retval;
+  }
+#else
   if ((stackp <= depth) && (hashflags & HASH_BLOCK_OFF)) {
     found_read_result
       = get_read_result_hash_modified(BLOCK_OFF, komaster, kom_pos,
@@ -2921,10 +2936,17 @@ recursive_block(int str, const char goal
       return rr_get_result(*read_result);
     }
   }
+#endif

   if (ladder_capture(str, &xpos) == WIN) {
     SGFTRACE(xpos, WIN, "string capturable");
+#if USE_HASHTABLE_NG
+    READ_RETURN_HASH_NG(komaster, kom_pos, BLOCK_OFF, str, depth - stackp,
+                       goal_hash, move, xpos, WIN);
+#else
     READ_RETURN(read_result, move, xpos, WIN);
+#endif
+
   }

   num_moves = find_break_moves(str, goal, other, moves, &distance);
@@ -2947,7 +2969,12 @@ recursive_block(int str, const char goal
        popgo();
        if (dcode == 0) {
          SGFTRACE(xpos, WIN, "block effective");
+#if USE_HASHTABLE_NG
+         READ_RETURN_HASH_NG(komaster, kom_pos, BLOCK_OFF, str,
+                             depth - stackp, goal_hash, move, xpos, WIN);
+#else
          READ_RETURN(read_result, move, xpos, WIN);
+#endif
        }
        /* if the move works with ko we save it, then look for something
         * better.
@@ -2971,16 +2998,31 @@ recursive_block(int str, const char goal
          || !recursive_break(str, goal, NULL, komaster, kom_pos, 1,
                              goal_hash))) {
     SGFTRACE(NO_MOVE, WIN, "no move, probably disconnected");
+#if USE_HASHTABLE_NG
+    READ_RETURN_HASH_NG(komaster, kom_pos, BLOCK_OFF, str,
+                       depth - stackp, goal_hash, move, NO_MOVE, WIN);
+#else
     READ_RETURN(read_result, move, NO_MOVE, WIN);
+#endif
   }

   if (savecode != 0) {
     SGFTRACE(savemove, savecode, "saved move");
+#if USE_HASHTABLE_NG
+    READ_RETURN_HASH_NG(komaster, kom_pos, BLOCK_OFF, str,
+                       depth - stackp, goal_hash, move, savemove, savecode);
+#else
     READ_RETURN(read_result, move, savemove, savecode);
+#endif
   }

   SGFTRACE(0, 0, NULL);
+#if USE_HASHTABLE_NG
+  READ_RETURN_HASH_NG(komaster, kom_pos, BLOCK_OFF, str,
+                     depth - stackp, goal_hash, move, NO_MOVE, 0);
+#else
   READ_RETURN(read_result, move, NO_MOVE, 0);
+#endif
 }






reply via email to

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