gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] arend_3_3.4: further reading.c cleanup


From: Arend Bayer
Subject: [gnugo-devel] arend_3_3.4: further reading.c cleanup
Date: Sun, 19 May 2002 15:57:27 +0200 (CEST)

 - further reading.c cleanup

* more naming consistency
* unused caching code removed from attack?, defend?
* more macros to make code more readable
* change attack2->simple_ladder_attack only at stackp > depth + 10

Gunnar wrote:
> > Would it be consensus to remove the cache lookups from
> > attack1234/defend1234?
> I see no reason to keep them. Just make sure that the traces in the
> READ_RETURN macros continue to work
Yup, I added a CHECK_RESULT macro that replaces the following code, found
zillions of times in reading.c:

        if (acode == 0) {
          SGFTRACE(xpos, WIN, "defense effective - A");
          READ_RETURN(read_result, move, xpos, WIN);
        }
        /* if the move works with ko we save it, then look for something
         * better.
         */
        UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);

(and also a RETURN_RESULT macro which does SGFTRACE + READ_RETURN
without the cache part).

This make the code more readable in my opinion, and should also come in
handy if we would want to do things like alpha-beta-cut.

There were two changes in arend_3_3.3 that I hadn't intended to go in yet
(and were not mentioned in the e-mail). One was apparently spotted by Dan
as it is now mentioned in ChangeLog, that is using simple_ladder_attack
instead of attack2 if we are 5 plies beyond depth. The other is to give
up in simple_ladder_attack if we are 20 plies beyond depth and we are komaster
-- there is no sense in trying to play a ladder across the whole board
if it depends on a ko, as opponent will have too many ko threats.

This wasn't tested extensively, and I've for now changed 5 to 10 to be a
little more conservative. OTOH, I do think it's necessary; I have a case
here where it reduces simple_ladder_attack reading nodes from 300,000
to some 6000 (which had caused an extremely slow move on NNGS at level 4).

Arend


Index: engine/cache.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/cache.h,v
retrieving revision 1.17
diff -u -r1.17 cache.h
--- engine/cache.h      7 Apr 2002 12:40:25 -0000       1.17
+++ engine/cache.h      19 May 2002 13:07:10 -0000
@@ -350,22 +350,15 @@
 /* ================================================================ */
 /* Routine numbers. */

-#define FIND_DEFENSE    0
-#define DEFEND1         1
-#define DEFEND2         2
-#define DEFEND3         3
-#define DEFEND4         4
-
-#define ATTACK          5
-#define ATTACK2         6
-#define ATTACK3         7
-
-#define OWL_ATTACK      8
-#define OWL_DEFEND      9
-#define SEMEAI         10
+#define OWL_ATTACK      0
+#define OWL_DEFEND      1
+#define SEMEAI          2

-#define CONNECT        11
-#define DISCONNECT     12
+#define FIND_DEFENSE    3
+#define ATTACK          4
+
+#define CONNECT         5
+#define DISCONNECT      6

 #define MAX_ROUTINE     DISCONNECT
 #define NUM_ROUTINES    (MAX_ROUTINE + 1)
@@ -398,9 +391,9 @@


 #define UPDATE_SAVED_KO_RESULT(savecode, save, code, move) \
-  if (code != 0 && (WIN - code) > savecode) { \
+  if (code != 0 && REVERSE_RESULT(code) > savecode) { \
     save = move; \
-    savecode = WIN - code; \
+    savecode = REVERSE_RESULT(code); \
   } \

 /* Same as above, except this should be used when there's no
Index: engine/gnugo.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/gnugo.h,v
retrieving revision 1.55
diff -u -r1.55 gnugo.h
--- engine/gnugo.h      11 May 2002 00:10:08 -0000      1.55
+++ engine/gnugo.h      19 May 2002 13:07:13 -0000
@@ -230,13 +230,7 @@
  */

 #define HASH_FIND_DEFENSE 0x0001  /* NOTE : can specify -d0x... */
-#define HASH_DEFEND1      0x0002
-#define HASH_DEFEND2      0x0004
-#define HASH_DEFEND3      0x0008
-#define HASH_DEFEND4      0x0010
 #define HASH_ATTACK       0x0020
-#define HASH_ATTACK2      0x0040
-#define HASH_ATTACK3      0x0080
 #define HASH_OWL_ATTACK   0x0100
 #define HASH_OWL_DEFEND   0x0200
 #define HASH_SEMEAI       0x0400
Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.100
diff -u -r1.100 liberty.h
--- engine/liberty.h    16 May 2002 19:14:41 -0000      1.100
+++ engine/liberty.h    19 May 2002 13:07:17 -0000
@@ -111,6 +111,7 @@

 #define BOARD(i, j)   board[POS(i, j)]

+#define REVERSE_RESULT(result)         (WIN - result)

 /* This struct holds the internal board state.
  */
Index: engine/owl.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/owl.c,v
retrieving revision 1.87
diff -u -r1.87 owl.c
--- engine/owl.c        17 May 2002 19:34:45 -0000      1.87
+++ engine/owl.c        19 May 2002 13:07:36 -0000
@@ -52,9 +52,6 @@
 #define MAX_LUNCHES 10
 #define MAX_WORMS 10          /* maximum number of worms in a dragon to be 
cataloged */

-/* If set, pattern constraint are only checked if the pattern might produce
- * a candidate move.
- */

 #include <stdio.h>
 #include <stdlib.h>
@@ -145,16 +142,16 @@
 static struct owl_cache persistent_owl_cache[MAX_OWL_CACHE_SIZE];
 static int persistent_owl_cache_size = 0;

-#define OWL_THREATEN_ATTACK    0
-#define OWL_THREATEN_DEFENSE   1
-#define OWL_DOES_DEFEND        2
-#define OWL_DOES_ATTACK        3
-#define OWL_CONNECTION_DEFENDS 4
-#define OWL_SUBSTANTIAL        5
-#define OWL_CONFIRM_SAFETY     6
 /* The following two are defined in cache.h */
-/* #define OWL_ATTACK    8 */
-/* #define OWL_DEFEND    9 */
+/* #define OWL_ATTACK    0 */
+/* #define OWL_DEFEND    1 */
+#define OWL_THREATEN_ATTACK    2
+#define OWL_THREATEN_DEFENSE   3
+#define OWL_DOES_DEFEND        4
+#define OWL_DOES_ATTACK        5
+#define OWL_CONNECTION_DEFENDS 6
+#define OWL_SUBSTANTIAL        7
+#define OWL_CONFIRM_SAFETY     8

 static int verify_stored_board(char board[BOARDMAX]);
 static int search_persistent_owl_cache(int routine, int apos,
Index: engine/printutils.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/printutils.c,v
retrieving revision 1.22
diff -u -r1.22 printutils.c
--- engine/printutils.c 31 Mar 2002 18:48:08 -0000      1.22
+++ engine/printutils.c 19 May 2002 13:07:38 -0000
@@ -402,20 +402,8 @@
 {
   if (routine == FIND_DEFENSE)
     return "FIND_DEFENSE";
-  else if (routine == DEFEND1)
-    return "DEFEND1";
-  else if (routine == DEFEND2)
-    return "DEFEND2";
-  else if (routine == DEFEND3)
-    return "DEFEND3";
-  else if (routine == DEFEND4)
-    return "DEFEND4";
   else if (routine == ATTACK)
     return "ATTACK";
-  else if (routine == ATTACK2)
-    return "ATTACK2";
-  else if (routine == ATTACK3)
-    return "ATTACK3";
   else if (routine == OWL_ATTACK)
     return "OWL_ATTACK";
   else if (routine == OWL_DEFEND)
Index: engine/reading.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/reading.c,v
retrieving revision 1.63
diff -u -r1.63 reading.c
--- engine/reading.c    17 May 2002 19:01:21 -0000      1.63
+++ engine/reading.c    19 May 2002 13:08:01 -0000
@@ -79,6 +79,45 @@
   } while (0)


+/* This macro checks whether the reported result is a loss, so we have won
+ * and can exit, or else if it is the best result so far.
+ * Note that SGFTRACE must have been setup.
+ */
+#define CHECK_RESULT(savecode, savemove, code, move_pos, move_ptr, \
+                    trace_message) \
+  do {\
+    if (code == 0) {\
+      if (move_ptr) \
+       *(move_ptr) = (move_pos); \
+      SGFTRACE(move_pos, WIN, trace_message); \
+      return WIN; \
+    } \
+    else if (REVERSE_RESULT(code) > savecode) {\
+      savemove = move_pos; \
+      savecode = REVERSE_RESULT(code); \
+    } \
+  } while (0)
+
+/* Reverse of CHECK_RESULT, for results passed from a helper function. */
+#define CHECK_RESULT_UNREVERSED(savecode, savemove, code, move_pos, move_ptr, \
+                               trace_message) \
+       CHECK_RESULT(savecode, savemove, REVERSE_RESULT(code), move_pos, \
+                    move_ptr, trace_message)
+
+
+#define RETURN_RESULT(savecode, savemove, move_ptr, trace_message) \
+  do {\
+    if (savecode) {\
+      if (move_ptr)\
+       *(move_ptr) = (savemove); \
+      SGFTRACE(savemove, savecode, trace_message); \
+    }\
+    else \
+      SGFTRACE(0, 0, NULL); \
+    return savecode; \
+  } while (0)
+
+
 /*
  * The functions in reading.c are used to read whether groups
  * can be captured or not. See the Texinfo documentation
@@ -104,12 +143,12 @@
                           int komaster, int kom_pos);
 static int special_rescue4(int str, int libs[3], int *move,
                           int komaster, int kom_pos);
-static void special_rescue5(int str, int libs[3], int moves[MAX_MOVES],
-                           int scores[MAX_MOVES], int *num_moves);
-static void special_rescue6(int str, int libs[3], int moves[MAX_MOVES],
-                           int scores[MAX_MOVES], int *num_moves);
-static void edge_clamp(int str, int moves[MAX_MOVES],
-                      int scores[MAX_MOVES], int *num_moves);
+static void special_rescue5_moves(int str, int libs[3], int moves[MAX_MOVES],
+                                 int scores[MAX_MOVES], int *num_moves);
+static void special_rescue6_moves(int str, int libs[3], int moves[MAX_MOVES],
+                                 int scores[MAX_MOVES], int *num_moves);
+static void edge_clamp_moves(int str, int moves[MAX_MOVES],
+                            int scores[MAX_MOVES], int *num_moves);
 static int do_attack(int str, int *move, int komaster, int kom_pos);
 static int attack1(int str, int *move, int komaster, int kom_pos);
 static int attack2(int str, int *move, int komaster, int kom_pos);
@@ -466,7 +505,7 @@
        popgo();
       }
     }
-    return 3 - ((defended0 > defended1) ? defended1 : defended0);
+    return REVERSE_RESULT(gg_min(defended0, defended1));
   }

 }
@@ -1083,8 +1122,6 @@
   int savecode = 0;
   int liberties;
   int k;
-  int found_read_result;
-  Read_result *read_result = NULL;

   SETUP_TRACE_INFO("defend1", str);
   reading_node_counter++;
@@ -1093,21 +1130,6 @@
   ASSERT1(countlib(str) == 1, str);
   RTRACE("try to escape atari on %1m.\n", str);

-  if ((stackp <= depth) && (hashflags & HASH_DEFEND1)) {
-
-    found_read_result = get_read_result(DEFEND1, komaster, kom_pos,
-                                       &str, &read_result);
-    if (found_read_result) {
-      TRACE_CACHED_RESULT(*read_result);
-      if (rr_get_result(*read_result) != 0)
-       *move = rr_get_move(*read_result);
-
-      SGFTRACE(rr_get_move(*read_result),
-              rr_get_result(*read_result), "cached");
-      return rr_get_result(*read_result);
-    }
-  }
-
   /* lib will be the liberty of the string. */
   liberties = findlib(str, 1, &lib);
   ASSERT1(liberties == 1, str);
@@ -1135,14 +1157,8 @@
       if (!ko_move) {
        int acode = do_attack(str, NULL, new_komaster, new_kom_pos);
        popgo();
-       if (acode == 0) {
-         SGFTRACE(xpos, WIN, "defense effective - A");
-         READ_RETURN(read_result, move, xpos, WIN);
-       }
-       /* if the move works with ko we save it, then look for something
-        * better.
-        */
-       UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
+       CHECK_RESULT(savecode, savemove, acode, xpos, move,
+                    "defense effective - A");
       }
       else {
        if (do_attack(str, NULL, new_komaster, new_kom_pos) != WIN) {
@@ -1171,25 +1187,14 @@
        if ((liberties == 1 || !is_self_atari(apos, other))
            && trymove(apos, color, "attack1-C", str, komaster, kom_pos)) {
          int acode = do_attack(str, NULL, komaster, kom_pos);
-         if (acode == 0) {
-           popgo();
-           SGFTRACE(apos, WIN, "backfilling");
-           READ_RETURN(read_result, move, apos, WIN);
-         }
-         UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, apos);
          popgo();
+         CHECK_RESULT(savecode, savemove, acode, apos, move, "backfilling");
        }
       }
     }
   }

-  if (savecode != 0) {
-    SGFTRACE(savemove, savecode, "saved move");
-    READ_RETURN(read_result, move, savemove, savecode);
-  }
-
-  SGFTRACE(0, 0, NULL);
-  READ_RETURN0(read_result);
+  RETURN_RESULT(savecode, savemove, move, "saved move");
 }


@@ -1223,8 +1228,6 @@
   int k;
   int r;
   int s;
-  int found_read_result;
-  Read_result *read_result = NULL;

   SETUP_TRACE_INFO("defend2", str);
   reading_node_counter++;
@@ -1238,21 +1241,6 @@
   gg_assert(IS_STONE(board[str]));
   gg_assert(countlib(str) == 2);

-  if ((stackp <= depth) && (hashflags & HASH_DEFEND2)) {
-
-    found_read_result = get_read_result(DEFEND2, komaster, kom_pos,
-                                       &str, &read_result);
-    if (found_read_result) {
-      TRACE_CACHED_RESULT(*read_result);
-      if (rr_get_result(*read_result) != 0)
-       *move = rr_get_move(*read_result);
-
-      SGFTRACE(rr_get_move(*read_result),
-              rr_get_result(*read_result), "cached");
-      return rr_get_result(*read_result);
-    }
-  }
-
   liberties = findlib(str, 2, libs);
   ASSERT1(liberties == 2, str);

@@ -1271,7 +1259,7 @@
   break_chain_moves(str, moves, scores, &num_moves);
   break_chain2_efficient_moves(str, moves, scores, &num_moves);
   propose_edge_moves(str, libs, liberties, moves, scores, &num_moves, color);
-  edge_clamp(str, moves, scores, &num_moves);
+  edge_clamp_moves(str, moves, scores, &num_moves);

   order_moves(str, num_moves, moves, scores, color, read_function_name);

@@ -1288,14 +1276,8 @@
       if (!ko_move) {
        int acode = do_attack(str, NULL, new_komaster, new_kom_pos);
        popgo();
-       if (acode == 0) {
-         SGFTRACE(xpos, WIN, "defense effective - A");
-         READ_RETURN(read_result, move, xpos, WIN);
-       }
-       /* if the move works with ko we save it, then look for something
-        * better.
-        */
-       UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
+       CHECK_RESULT(savecode, savemove, acode, xpos, move,
+                    "defense effective - A");
       }
       else {
        if (do_attack(str, NULL, new_komaster, new_kom_pos) != WIN) {
@@ -1333,11 +1315,8 @@
          }

          popgo();
-         if (acode == 0) {
-           SGFTRACE(xpos, WIN, "backfill effective");
-           READ_RETURN(read_result, move, xpos, WIN);
-         }
-         UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
+         CHECK_RESULT(savecode, savemove, acode, xpos, move,
+                      "backfill effective");
        }
       }
     }
@@ -1357,11 +1336,8 @@
          int acode = do_attack(str, NULL, komaster, kom_pos);
          moves[s] = xpos;
          popgo();
-         if (acode == 0) {
-           SGFTRACE(xpos, WIN, "backfill effective");
-           READ_RETURN(read_result, move, xpos, WIN);
-         }
-         UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
+         CHECK_RESULT(savecode, savemove, acode, xpos, move,
+                      "backfill effective");
        }
       }
     }
@@ -1371,31 +1347,22 @@
     for (k = 0; k < liberties; k++) {
       int dcode = special_rescue(str, libs[k], &xpos, komaster, kom_pos,
                                 moves, num_moves);
-      if (dcode == WIN) {
-       SGFTRACE(xpos, WIN, "special rescue");
-       READ_RETURN(read_result, move, xpos, WIN);
-      }
-      UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos);
+      CHECK_RESULT_UNREVERSED(savecode, savemove, dcode, xpos, move,
+                             "special rescue");
     }
   }

   if (stackp <= backfill_depth) {
     int dcode = special_rescue2(str, libs, &xpos, komaster, kom_pos,
                                moves, num_moves);
-    if (dcode == WIN) {
-      SGFTRACE(xpos, WIN, "special rescue2");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, dcode, xpos, move,
+                           "special rescue2");
   }

   if (level >= 10 && stackp <= superstring_depth) {
     int dcode = superstring_breakchain(str, &xpos, komaster, kom_pos, 4);
-    if (dcode == WIN) {
-      SGFTRACE(xpos, WIN, "superstring_breakchain");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, dcode, xpos, move,
+                           "superstring_breakchain");
   }

   /* If nothing else works, we try playing a liberty of the
@@ -1428,11 +1395,8 @@
          moves[s] = apos;
        }
        popgo();
-       if (acode == 0) {
-         SGFTRACE(apos, WIN, "superstring liberty");
-         READ_RETURN(read_result, move, apos, WIN);
-       }
-       UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, apos);
+       CHECK_RESULT(savecode, savemove, acode, apos, move,
+                    "superstring liberty");
       }
     }

@@ -1448,11 +1412,8 @@

       dcode = special_rescue(str, apos, &xpos, komaster, kom_pos,
                             moves, num_moves);
-      if (dcode == WIN) {
-       SGFTRACE(xpos, WIN, "special rescue");
-       READ_RETURN(read_result, move, xpos, WIN);
-      }
-      UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos);
+      CHECK_RESULT_UNREVERSED(savecode, savemove, dcode, xpos, move,
+                             "special rescue");
     }
   }

@@ -1462,15 +1423,12 @@
    */

   bc = break_chain2(str, &xpos, komaster, kom_pos);
-  if (bc == WIN) {
-    SGFTRACE(xpos, bc, "break chain2");
-    READ_RETURN(read_result, move, xpos, bc);
-  }
-  UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, bc, xpos);
+  CHECK_RESULT_UNREVERSED(savecode, savemove, bc, xpos, move,
+                         "break chain2");

   if (stackp <= backfill_depth) {
     int saved_num_moves = num_moves;
-    special_rescue5(str, libs, moves, scores, &num_moves);
+    special_rescue5_moves(str, libs, moves, scores, &num_moves);

     /* Only order and test the new set of moves. */
     order_moves(str, num_moves-saved_num_moves,
@@ -1491,14 +1449,8 @@
        if (!ko_move) {
          int acode = do_attack(str, NULL, new_komaster, new_kom_pos);
          popgo();
-         if (acode == 0) {
-           SGFTRACE(xpos, WIN, "defense effective - A");
-           READ_RETURN(read_result, move, xpos, WIN);
-         }
-         /* if the move works with ko we save it, then look for something
-          * better.
-          */
-         UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
+         CHECK_RESULT(savecode, savemove, acode, xpos, move,
+                      "defense effective - A");
        }
        else {
          if (do_attack(str, NULL, new_komaster, new_kom_pos) != WIN) {
@@ -1513,21 +1465,15 @@

   if (stackp <= backfill2_depth) {
     bc = break_chain3(str, &xpos, komaster, kom_pos);
-    if (bc == WIN) {
-      SGFTRACE(xpos, bc, "break chain3");
-      READ_RETURN(read_result, move, xpos, bc);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, bc, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, bc, xpos, move,
+                           "break chain3");
   }

-  if (savecode != 0) {
-    SGFTRACE(savemove, savecode, "saved move");
-    READ_RETURN(read_result, move, savemove, savecode);
-  }
+  if (savecode != 0)
+    RETURN_RESULT(savecode, savemove, move, "saved move");

   RTRACE("failed to find rescuing move.\n");
-  SGFTRACE(0, 0, NULL);
-  READ_RETURN0(read_result);
+  RETURN_RESULT(savecode, savemove, move, NULL);
 }


@@ -1550,8 +1496,6 @@
   int savecode = 0;
   int bc;
   int k;
-  int found_read_result;
-  Read_result *read_result = NULL;

   SETUP_TRACE_INFO("defend3", str);
   reading_node_counter++;
@@ -1563,20 +1507,6 @@
   gg_assert(IS_STONE(board[str]));
   gg_assert(countlib(str) == 3);

-  if ((stackp <= depth) && (hashflags & HASH_DEFEND3)) {
-    found_read_result = get_read_result(DEFEND3, komaster, kom_pos,
-                                       &str, &read_result);
-    if (found_read_result) {
-      TRACE_CACHED_RESULT(*read_result);
-      if (rr_get_result(*read_result) != 0)
-       *move = rr_get_move(*read_result);
-
-      SGFTRACE(rr_get_move(*read_result),
-              rr_get_result(*read_result), "cached");
-      return rr_get_result(*read_result);
-    }
-  }
-
   liberties = findlib(str, 3, libs);
   ASSERT1(liberties == 3, str);

@@ -1595,7 +1525,7 @@
   break_chain_moves(str, moves, scores, &num_moves);
   break_chain2_efficient_moves(str, moves, scores, &num_moves);
   propose_edge_moves(str, libs, liberties, moves, scores, &num_moves, color);
-  edge_clamp(str, moves, scores, &num_moves);
+  edge_clamp_moves(str, moves, scores, &num_moves);

   order_moves(str, num_moves, moves, scores, color, read_function_name);

@@ -1615,14 +1545,8 @@
       if (!ko_move) {
        int acode = do_attack(str, NULL, new_komaster, new_kom_pos);
        popgo();
-       if (acode == 0) {
-         SGFTRACE(xpos, WIN, "defense effective - A");
-         READ_RETURN(read_result, move, xpos, WIN);
-       }
-       /* if the move works with ko we save it, then look for something
-        * better.
-        */
-       UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
+       CHECK_RESULT(savecode, savemove, acode, xpos, move,
+                    "defense effective - A");
       }
       else {
        if (do_attack(str, NULL, new_komaster, new_kom_pos) != WIN) {
@@ -1665,11 +1589,8 @@
              acode = do_attack(str, NULL, komaster, kom_pos);

            popgo();
-           if (acode == 0) {
-             SGFTRACE(xpos, WIN, "backfill effective");
-             READ_RETURN(read_result, move, xpos, WIN);
-           }
-           UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
+           CHECK_RESULT(savecode, savemove, acode, xpos, move,
+                        "backfill effective");
          }
        }
       }
@@ -1689,11 +1610,8 @@
                && trymove(xpos, color, "defend2-G", str, komaster, kom_pos)) {
              int acode = do_attack(str, NULL, komaster, kom_pos);
              popgo();
-             if (acode == 0) {
-               SGFTRACE(xpos, WIN, "backfill effective");
-               READ_RETURN(read_result, move, xpos, WIN);
-             }
-             UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
+             CHECK_RESULT(savecode, savemove, acode, xpos, move
+                          "backfill effective");
            }
          }
        }
@@ -1707,39 +1625,27 @@
     for (k = 0; k < liberties; k++) {
       int dcode = special_rescue(str, libs[k], &xpos, komaster, kom_pos,
                                 moves, num_moves);
-      if (dcode == WIN) {
-       SGFTRACE(xpos, WIN, "special rescue");
-       READ_RETURN(read_result, move, xpos, WIN);
-      }
-      UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos);
+      CHECK_RESULT_UNREVERSED(savecode, savemove, dcode, xpos, move,
+                             "special rescue");
     }
   }

   if (stackp <= backfill_depth) {
     int dcode = special_rescue3(str, libs, &xpos, komaster, kom_pos);
-    if (dcode == WIN) {
-      SGFTRACE(xpos, WIN, "special rescue3");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, dcode, xpos, move,
+                           "special rescue3");
   }

   if (stackp <= backfill_depth) {
     int dcode = special_rescue4(str, libs, &xpos, komaster, kom_pos);
-    if (dcode == WIN) {
-      SGFTRACE(xpos, WIN, "special rescue4");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, dcode, xpos, move,
+                           "special rescue4");
   }

   if (level >= 10 && stackp <= backfill2_depth) {
     int dcode = superstring_breakchain(str, &xpos, komaster, kom_pos, 4);
-    if (dcode == WIN) {
-      SGFTRACE(xpos, WIN, "superstring_breakchain");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, dcode, xpos, move,
+                           "superstring_breakchain");
   }

   /* If nothing else works, we try playing a liberty of the
@@ -1764,11 +1670,8 @@
          acode = do_attack(str, NULL, komaster, kom_pos);

        popgo();
-       if (acode == 0) {
-         SGFTRACE(apos, WIN, "superstring liberty");
-         READ_RETURN(read_result, move, apos, WIN);
-       }
-       UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, apos);
+       CHECK_RESULT(savecode, savemove, acode, apos, move,
+                    "superstring liberty");
       }
     }

@@ -1784,11 +1687,8 @@

       dcode = special_rescue(str, apos, &xpos, komaster, kom_pos,
                             moves, num_moves);
-      if (dcode == WIN) {
-       SGFTRACE(xpos, WIN, "special rescue");
-       READ_RETURN(read_result, move, xpos, WIN);
-      }
-      UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos);
+      CHECK_RESULT_UNREVERSED(savecode, savemove, dcode, xpos, move,
+                             "special rescue");
     }
   }

@@ -1798,17 +1698,14 @@
    */
   if (stackp <= backfill2_depth) {
     bc = break_chain2(str, &xpos, komaster, kom_pos);
-    if (bc == WIN) {
-      SGFTRACE(xpos, bc, "break chain2");
-      READ_RETURN(read_result, move, xpos, bc);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, bc, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, bc, xpos, move,
+                           "break chain2");
   }

   if (stackp <= backfill_depth) {
     int saved_num_moves = num_moves;
-    special_rescue5(str, libs, moves, scores, &num_moves);
-    special_rescue6(str, libs, moves, scores, &num_moves);
+    special_rescue5_moves(str, libs, moves, scores, &num_moves);
+    special_rescue6_moves(str, libs, moves, scores, &num_moves);

     /* Only order and test the new set of moves. */
     order_moves(str, num_moves-saved_num_moves,
@@ -1829,14 +1726,8 @@
        if (!ko_move) {
          int acode = do_attack(str, NULL, new_komaster, new_kom_pos);
          popgo();
-         if (acode == 0) {
-           SGFTRACE(xpos, WIN, "defense effective - A");
-           READ_RETURN(read_result, move, xpos, WIN);
-         }
-         /* if the move works with ko we save it, then look for something
-          * better.
-          */
-         UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
+         CHECK_RESULT(savecode, savemove, acode, xpos, move,
+                      "defense effective - A");
        }
        else {
          if (do_attack(str, NULL, new_komaster, new_kom_pos) != WIN) {
@@ -1851,21 +1742,15 @@

   if (stackp <= backfill2_depth) {
     bc = break_chain3(str, &xpos, komaster, kom_pos);
-    if (bc == WIN) {
-      SGFTRACE(xpos, bc, "break chain3");
-      READ_RETURN(read_result, move, xpos, bc);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, bc, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, bc, xpos, move,
+                           "break chain3");
   }

-  if (savecode != 0) {
-    SGFTRACE(savemove, savecode, "saved move");
-    READ_RETURN(read_result, move, savemove, savecode);
-  }
+  if (savecode != 0)
+    RETURN_RESULT(savecode, savemove, move, "saved move");

   RTRACE("failed to find rescuing move.\n");
-  SGFTRACE(0, 0, NULL);
-  READ_RETURN0(read_result);
+  RETURN_RESULT(0, 0, move, NULL);
 }


@@ -1888,8 +1773,6 @@
   int savemove = 0;
   int savecode = 0;
   int k;
-  int found_read_result;
-  Read_result *read_result = NULL;

   SETUP_TRACE_INFO("defend4", str);
   reading_node_counter++;
@@ -1901,20 +1784,6 @@
   gg_assert(IS_STONE(board[str]));
   gg_assert(countlib(str) == 4);

-  if ((stackp <= depth) && (hashflags & HASH_DEFEND4)) {
-    found_read_result = get_read_result(DEFEND4, komaster, kom_pos,
-                                       &str, &read_result);
-    if (found_read_result) {
-      TRACE_CACHED_RESULT(*read_result);
-      if (rr_get_result(*read_result) != 0)
-       *move = rr_get_move(*read_result);
-
-      SGFTRACE(rr_get_move(*read_result),
-              rr_get_result(*read_result), "cached");
-      return rr_get_result(*read_result);
-    }
-  }
-
   liberties = findlib(str, 4, libs);
   ASSERT1(liberties == 4, str);

@@ -1949,14 +1818,8 @@
       if (!ko_move) {
        int acode = do_attack(str, NULL, new_komaster, new_kom_pos);
        popgo();
-       if (acode == 0) {
-         SGFTRACE(xpos, WIN, "defense effective - A");
-         READ_RETURN(read_result, move, xpos, WIN);
-       }
-       /* if the move works with ko we save it, then look for something
-        * better.
-        */
-       UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
+       CHECK_RESULT(savecode, savemove, acode, xpos, move,
+                    "defense effective - A");
       }
       else {
        if (do_attack(str, NULL, new_komaster, new_kom_pos) != WIN) {
@@ -1970,21 +1833,15 @@

   if (stackp <= backfill_depth) {
     int bc = break_chain2(str, &xpos, komaster, kom_pos);
-    if (bc == WIN) {
-      SGFTRACE(xpos, WIN, "break chain2");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, bc, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, bc, xpos, move,
+                           "break chain2");
   }

-  if (savecode != 0) {
-    SGFTRACE(savemove, savecode, "saved move");
-    READ_RETURN(read_result, move, savemove, savecode);
-  }
+  if (savecode != 0)
+    RETURN_RESULT(savecode, savemove, move, "saved move");

   RTRACE("failed to find rescuing move.\n");
-  SGFTRACE(0, 0, NULL);
-  READ_RETURN0(read_result);
+  RETURN_RESULT(0, 0, move, NULL);
 }


@@ -2037,13 +1894,12 @@

       if (trymove(lib + d, color, "special_rescue", str, komaster, kom_pos)) {
        int acode = do_attack(str, NULL, komaster, kom_pos);
+       popgo();
        if (acode == 0) {
-         popgo();
          *move = lib + d;
          return WIN;
        }
        UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, lib + d);
-       popgo();
       }
     }
   }
@@ -2105,7 +1961,7 @@
        }
        break_chain_moves(newstr, moves, scores, &num_moves);
        break_chain2_efficient_moves(newstr, moves, scores, &num_moves);
-       edge_clamp(newstr, moves, scores, &num_moves);
+       edge_clamp_moves(newstr, moves, scores, &num_moves);
       }
     }
   }
@@ -2337,8 +2193,8 @@
  * returns moves which are potentially useful in these positions.
  */
 static void
-special_rescue5(int str, int libs[3], int moves[MAX_MOVES],
-               int scores[MAX_MOVES], int *num_moves)
+special_rescue5_moves(int str, int libs[3], int moves[MAX_MOVES],
+                     int scores[MAX_MOVES], int *num_moves)
 {
   int color = board[str];
   int other = OTHER_COLOR(color);
@@ -2411,8 +2267,8 @@
  *
  */
 static void
-special_rescue6(int str, int libs[3], int moves[MAX_MOVES],
-               int scores[MAX_MOVES], int *num_moves)
+special_rescue6_moves(int str, int libs[3], int moves[MAX_MOVES],
+                     int scores[MAX_MOVES], int *num_moves)
 {
   int color = board[str];
   int other = OTHER_COLOR(color);
@@ -2499,8 +2355,8 @@
  */

 static void
-edge_clamp(int str, int moves[MAX_MOVES], int scores[MAX_MOVES],
-          int *num_moves)
+edge_clamp_moves(int str, int moves[MAX_MOVES], int scores[MAX_MOVES],
+                int *num_moves)
 {
   int color = board[str];
   int other = OTHER_COLOR(color);
@@ -3157,7 +3013,7 @@
   if (libs == 1)
     result = attack1(str, &xpos, komaster, kom_pos);
   else if (libs == 2) {
-    if (stackp > depth + 5)
+    if (stackp > depth + 10)
       result = simple_ladder_attack(str, &xpos, komaster, kom_pos);
     else
       result = attack2(str, &xpos, komaster, kom_pos);
@@ -3368,8 +3224,6 @@
   int scores[MAX_MOVES];
   int num_moves = 0;
   int adjacent_liberties = 0;
-  int found_read_result;
-  Read_result *read_result = NULL;

   SETUP_TRACE_INFO("attack2", str);
   reading_node_counter++;
@@ -3380,21 +3234,6 @@

   RTRACE("checking attack on %1m with 2 liberties\n", str);

-  if ((stackp <= depth) && (hashflags & HASH_ATTACK2)) {
-
-    found_read_result = get_read_result(ATTACK2, komaster, kom_pos,
-                                       &str, &read_result);
-    if (found_read_result) {
-      TRACE_CACHED_RESULT(*read_result);
-      if (rr_get_result(*read_result) != 0)
-       *move = rr_get_move(*read_result);
-
-      SGFTRACE(rr_get_move(*read_result),
-              rr_get_result(*read_result), "cached");
-      return rr_get_result(*read_result);
-    }
-  }
-
   /* The attack may fail if a boundary string is in atari and cannot
    * be defended.  First we must try defending such a string.
    *
@@ -3408,8 +3247,7 @@
      * be a working ladder, so continue if that is the case.
      */
     if (stackp > depth && countstones(adjs[r]) > 1) {
-      SGFTRACE(0, 0, "boundary in atari");
-      READ_RETURN0(read_result);
+      RETURN_RESULT(0, 0, move, "boundary in atari");
     }

     /* Pick up moves breaking the second order chain. */
@@ -3501,13 +3339,12 @@
        dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos);
        if (dcode != WIN
            && do_attack(str, NULL, new_komaster, new_kom_pos)) {
-         if (dcode == 0) {
-           popgo();
-           SGFTRACE(apos, WIN, "attack effective");
-           READ_RETURN(read_result, move, apos, WIN);
-         }
-         UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, apos);
+         popgo();
+         CHECK_RESULT(savecode, savemove, dcode, apos, move,
+                      "attack effective");
        }
+       else
+         popgo();
       }
       else {
        if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN
@@ -3515,44 +3352,31 @@
          savemove = apos;
          savecode = KO_B;
        }
+        popgo();
       }
-      popgo();
     }
   }

   /* The simple ataris didn't work. Try something more fancy. */
   acode = find_cap2(str, libs[0], libs[1], &xpos, komaster, kom_pos);
-  if (acode == WIN) {
-    SGFTRACE(xpos, WIN, "find cap2");
-    READ_RETURN(read_result, move, xpos, WIN);
-  }
-  UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, acode, xpos);
+  CHECK_RESULT_UNREVERSED(savecode, savemove, acode, xpos, move, "find cap2");

   if (stackp <= backfill_depth) {
     acode = special_attack2(str, libs, &xpos, komaster, kom_pos);
-    if (acode == WIN) {
-      SGFTRACE(xpos, WIN, "special attack2");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, acode, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, acode, xpos, move,
+                           "special attack2");
   }

   if (stackp <= backfill_depth) {
     acode = special_attack3(str, libs, &xpos, komaster, kom_pos);
-    if (acode == WIN) {
-      SGFTRACE(xpos, WIN, "special attack3");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, acode, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, acode, xpos, move,
+                           "special attack3");
   }

   if (stackp <= backfill_depth) {
     acode = special_attack4(str, libs, &xpos, komaster, kom_pos);
-    if (acode == WIN) {
-      SGFTRACE(xpos, WIN, "special attack4");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, acode, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, acode, xpos, move,
+                           "special attack4");
   }

   /* If it is not possible to make a direct atari, we try filling
@@ -3584,14 +3408,12 @@
              if (trymove(xpos, other, "attack2-D", str, komaster, kom_pos)) {
                dcode = do_find_defense(str, NULL, komaster, kom_pos);
                if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) {
-                 if (dcode == 0) {
-                   popgo();
-                   SGFTRACE(xpos, WIN, "attack effective");
-                   READ_RETURN(read_result, move, xpos, WIN);
-                 }
-                 UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, xpos);
+                 popgo();
+                 CHECK_RESULT(savecode, savemove, dcode, xpos, move,
+                              "attack effective");
                }
-               popgo();
+               else
+                 popgo();
              }
            }
            else
@@ -3601,14 +3423,12 @@
            dcode = do_find_defense(str, NULL, komaster, kom_pos);
            if (dcode != WIN
                && do_attack(str, NULL, komaster, kom_pos)) {
-             if (dcode == 0) {
-               popgo();
-               SGFTRACE(apos, WIN, "attack effective");
-               READ_RETURN(read_result, move, apos, WIN);
-             }
-             UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, apos);
+             popgo();
+             CHECK_RESULT(savecode, savemove, dcode, apos, move,
+                          "attack effective");
            }
-           popgo();
+           else
+             popgo();
          }
        }
       }
@@ -3617,12 +3437,11 @@

   if (savecode == 0) {
     RTRACE("ALIVE!!\n");
-    SGFTRACE(0, 0, NULL);
-    READ_RETURN0(read_result);
+    RETURN_RESULT(0, 0, move, NULL);
   }

-  SGFTRACE(savemove, savecode, "saved move");
-  READ_RETURN(read_result, move, savemove, savecode);
+
+  RETURN_RESULT(savecode, savemove, move, "saved move");
 }


@@ -3657,32 +3476,14 @@
   int num_moves = 0;
   int savemove = 0;
   int savecode = 0;
-  int found_read_result;
-  Read_result *read_result = NULL;

   SETUP_TRACE_INFO("attack3", str);
   reading_node_counter++;

   gg_assert(IS_STONE(board[str]));

-  if ((stackp <= depth) && (hashflags & HASH_ATTACK3)) {
-    found_read_result = get_read_result(ATTACK3, komaster, kom_pos,
-                                       &str, &read_result);
-    if (found_read_result) {
-      TRACE_CACHED_RESULT(*read_result);
-      if (rr_get_result(*read_result) != 0)
-       *move = rr_get_move(*read_result);
-
-      SGFTRACE(rr_get_move(*read_result),
-              rr_get_result(*read_result), "cached");
-      return rr_get_result(*read_result);
-    }
-  }
-
-  if (stackp > depth) {
-    SGFTRACE(0, 0, "stackp > depth");
-    READ_RETURN0(read_result);
-  }
+  if (stackp > depth)
+    RETURN_RESULT(0, 0, move, "stackp > depth");

   adj = chainlinks2(str, adjs, 1);
   for (r = 0; r < adj; r++) {
@@ -3753,13 +3554,12 @@
       if (!ko_move) {
        dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos);
        if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) {
-         if (dcode == 0) {
-           popgo();
-           SGFTRACE(xpos, WIN, "attack effective");
-           READ_RETURN(read_result, move, xpos, WIN);
-         }
-         UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, xpos);
+         popgo();
+         CHECK_RESULT(savecode, savemove, dcode, xpos, move,
+                      "attack effective");
        }
+       else
+         popgo();
       }
       else {
        if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN
@@ -3767,28 +3567,22 @@
          savemove = xpos;
          savecode = KO_B;
        }
+       popgo();
       }
-      popgo();
     }
   }

   /* The simple ataris didn't work. Try something more fancy. */
   if (stackp <= backfill_depth) {
     int acode = find_cap3(str, &xpos, komaster, kom_pos);
-    if (acode == WIN) {
-      SGFTRACE(xpos, WIN, "find cap3");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, acode, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, acode, xpos, move,
+                           "find cap3");
   }

   if (stackp <= fourlib_depth) {
     int acode = draw_back(str, &xpos, komaster, kom_pos);
-    if (acode == WIN) {
-      SGFTRACE(xpos, WIN, "draw back");
-      READ_RETURN(read_result, move, xpos, WIN);
-    }
-    UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, acode, xpos);
+    CHECK_RESULT_UNREVERSED(savecode, savemove, acode, xpos, move,
+                           "draw back");
   }

   /* Try to defend chain links with two liberties. */
@@ -3826,13 +3620,12 @@
          dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos);
          if (dcode != WIN
              && do_attack(str, NULL, new_komaster, new_kom_pos)) {
-           if (dcode == 0) {
-             popgo();
-             SGFTRACE(xpos, WIN, "attack effective");
-             READ_RETURN(read_result, move, xpos, WIN);
-           }
-           UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, xpos);
+           popgo();
+           CHECK_RESULT(savecode, savemove, dcode, xpos, move,
+                        "attack effective");
          }
+         else
+           popgo();
        }
        else {
          if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN
@@ -3840,8 +3633,8 @@
            savemove = xpos;
            savecode = KO_B;
          }
+         popgo();
        }
-       popgo();
       }
     }
   }
@@ -3869,14 +3662,12 @@
              if (trymove(xpos, other, "attack3-F", str, komaster, kom_pos)) {
                dcode = do_find_defense(str, NULL, komaster, kom_pos);
                if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) {
-                 if (dcode == 0) {
-                   popgo();
-                   SGFTRACE(xpos, WIN, "attack effective");
-                   READ_RETURN(read_result, move, xpos, WIN);
-                 }
-                 UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, xpos);
+                 popgo();
+                 CHECK_RESULT(savecode, savemove, dcode, xpos, move,
+                              "attack effective");
                }
-               popgo();
+               else
+                 popgo();
              }
            }
            else
@@ -3885,27 +3676,19 @@
          else {
            dcode = do_find_defense(str, NULL, komaster, kom_pos);
            if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) {
-             if (dcode == 0) {
-               popgo();
-               SGFTRACE(apos, WIN, "attack effective");
-               READ_RETURN(read_result, move, apos, WIN);
-             }
-             UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, apos);
+             popgo();
+             CHECK_RESULT(savecode, savemove, dcode, apos, move,
+                          "attack effective");
            }
-           popgo();
+           else
+             popgo();
          }
        }
       }
     }
   }

-  if (savecode != 0) {
-    SGFTRACE(savemove, savecode, "saved move");
-    READ_RETURN(read_result, move, savemove, savecode);
-  }
-
-  SGFTRACE(0, 0, NULL);
-  READ_RETURN0(read_result);
+  RETURN_RESULT(savecode, savemove, move, "saved move");
 }


@@ -3928,7 +3711,6 @@
   int moves[MAX_MOVES];
   int scores[MAX_MOVES];
   int num_moves = 0;
-  Read_result *read_result = NULL;
   int savemove = 0;
   int savecode = 0;

@@ -4006,13 +3788,12 @@
       if (!ko_move) {
        dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos);
        if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) {
-         if (dcode == 0) {
-           popgo();
-           SGFTRACE(xpos, WIN, "attack effective");
-           READ_RETURN(read_result, move, xpos, WIN);
-         }
-         UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, xpos);
+         popgo();
+         CHECK_RESULT(savecode, savemove, dcode, xpos, move,
+                      "attack effective");
        }
+       else
+         popgo();
       }
       else {
        if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN
@@ -4020,19 +3801,12 @@
          savemove = xpos;
          savecode = KO_B;
        }
+       popgo();
       }
-      popgo();
     }
   }

-  if (savecode != 0) {
-    SGFTRACE(savemove, savecode, "saved move");
-    *move = savemove;
-    return savecode;
-  }
-
-  SGFTRACE(0, 0, NULL);
-  return 0;
+  RETURN_RESULT(savecode, savemove, move, "saved move");
 }


@@ -6617,15 +6391,7 @@
     }
   }

-  if (savecode == 0) {
-    SGFTRACE(0, 0, NULL);
-    return 0;
-  }
-
-  SGFTRACE(savemove, savecode, "saved move");
-  if (move)
-    *move = savemove;
-  return savecode;
+  RETURN_RESULT(savecode, savemove, move, "saved move");
 }


@@ -6678,18 +6444,9 @@
        acode = simple_ladder_attack(str, NULL, new_komaster, new_kom_pos);
       popgo();

-      if (!ko_move) {
-       if (acode == 0) {
-         SGFTRACE(xpos, WIN, "defense effective");
-         if (move)
-           *move = xpos;
-         return WIN;
-       }
-       /* if the move works with ko we save it, then look for something
-        * better.
-        */
-       UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
-      }
+      if (!ko_move)
+       CHECK_RESULT(savecode, savemove, acode, xpos, move,
+                    "defense effective");
       else {
        if (acode != WIN) {
          savemove = xpos;
@@ -6699,15 +6456,7 @@
     }
   }

-  if (savecode != 0) {
-    SGFTRACE(savemove, savecode, "saved move");
-    if (move)
-      *move = savemove;
-    return savecode;
-  }
-
-  SGFTRACE(0, 0, NULL);
-  return 0;
+  RETURN_RESULT(savecode, savemove, move, "saved move");
 }






reply via email to

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