gnugo-devel
[Top][All Lists]
Advanced

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

Re: [gnugo-devel] Patch: semeai.c and filllib.c now 1-dimensional


From: Gunnar Farneback
Subject: Re: [gnugo-devel] Patch: semeai.c and filllib.c now 1-dimensional
Date: Tue, 16 Oct 2001 23:20:37 +0200
User-agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/20.7 (sparc-sun-solaris2.7) (with unibyte mode)

Inge wrote:
> Here is a patch that makes filllib.c and semeai.c 1-dimensional.
> 
> Summary:
>  - filllib.c and semeai.c made 1-dimensional.
> 
> All clear?  :-)

We've done a bit of double work here so this patch conflicts horribly
with my last patch. A merge, sort of, looks like below, relative to
current CVS.

> Only in gnugo-3.1.10p1iw1/engine: filllib.c.save
> Only in gnugo-3.1.10p1iw1/engine: filllib.c~
> Binary files gnugo-3.1.10p1/engine/filllib.o and 
> gnugo-3.1.10p1iw1/engine/filllib.o differ
> Binary files gnugo-3.1.10p1/engine/fuseki.o and 
> gnugo-3.1.10p1iw1/engine/fuseki.o differ

Regardless of the existence of a .cvsignore file, you're very welcome
to cut out garbage from your patches. They don't break just by
deleting superfluous lines, you know.

/Gunnar

Index: engine/filllib.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/filllib.c,v
retrieving revision 1.11
diff -u -r1.11 filllib.c
--- engine/filllib.c    2001/10/16 19:53:01     1.11
+++ engine/filllib.c    2001/10/16 21:06:12
@@ -48,7 +48,7 @@
 }
 
 
-/* Determine whether (m, n) effectively is a black or white point.
+/* Determine whether (pos) effectively is a black or white point.
  * The test for inessentiality is to avoid filling the liberties
  * around a killing nakade string.
  */
@@ -96,7 +96,7 @@
  * that several backfilling moves are ultimately necessary.
  *
  * If a move for color is found, return 1, otherwise return 0.
- * The move is returned in (*i, *j).
+ * The move is returned in (*move).
  */
 
 int 
@@ -134,16 +134,15 @@
       
       if (dragon[pos].matcher_status != DEAD) {
        for (k = 0; k < 12; k++) {
-         int di = deltai[k%8];
-         int dj = deltaj[k%8];
+         int d = delta[k%8];
+
          if (k >= 8) {
-           if (BOARD(m+di, n+dj) != EMPTY)
+           if (board[pos + d] != EMPTY)
              continue;
-           di *= 2;
-           dj *= 2;
+           d *= 2;
          }
-         if (BOARD(m+di, n+dj) == EMPTY)
-           potential_color[POS(m+di, n+dj)] |= board[pos];
+         if (board[pos + d] == EMPTY)
+           potential_color[pos + d] |= board[pos];
        }
       }
     }
@@ -165,15 +164,14 @@
        continue;
 
       /* Quick rejection based on preliminary test above. */
-      if (potential_color[POS(m, n)] != GRAY)
+      if (potential_color[pos] != GRAY)
        continue;
 
       /* Loop over the neighbors. */
       for (k = 0; k < 4; k++) {
-       int dm = deltai[k];
-       int dn = deltaj[k];
-       if (ON_BOARD(POS(m+dm, n+dn)))
-         analyze_neighbor(POS(m+dm, n+dn), &found_black, &found_white);
+       int d = delta[k];
+       if (ON_BOARD(pos + d))
+         analyze_neighbor(pos + d, &found_black, &found_white);
       }
       
       /* Do we have neighbors of both colors? */
@@ -190,7 +188,7 @@
        * 6. Move would violate confirm_safety.
        */
 
-      DEBUG(DEBUG_FILLLIB, "Filllib: Considering move at %m.\n", m, n);
+      DEBUG(DEBUG_FILLLIB, "Filllib: Considering move at %1m.\n", pos);
       
       /* Legal and tactically safe, play it if it passes
        * confirm_safety test, i.e. that it isn't a blunder which
@@ -235,7 +233,7 @@
        DEBUG(DEBUG_FILLLIB,
              "Filllib: Legal but not safe, looking for backfilling move.\n");
 
-       if (find_backfilling_move(POS(m, n), color, move)) {
+       if (find_backfilling_move(pos, color, move)) {
          DEBUG(DEBUG_FILLLIB, "Filllib: Backfilling move at %1m.\n", *move);
          /* In certain positions it may happen that an illegal move
           * is found. This probably only can happen if we try to play
@@ -281,11 +279,10 @@
         */
        DEBUG(DEBUG_FILLLIB, "Filllib: Illegal, looking for back-capture.\n");
        for (k = 0; k < 4; k++) {
-         int dm = deltai[k];
-         int dn = deltaj[k];
-         if (BOARD(m+dm, n+dn) == other
-             && worm[POS(m+dm, n+dn)].attack_codes[0] == WIN) {
-           *move = worm[POS(m+dm, n+dn)].attack_points[0];
+         int d = delta[k];
+         if (board[pos + d] == other
+             && worm[pos + d].attack_codes[0] == WIN) {
+           *move = worm[pos + d].attack_points[0];
            DEBUG(DEBUG_FILLLIB, "Filllib: Found at %1m.\n", *move);
            return 1;
          }
@@ -294,12 +291,11 @@
        DEBUG(DEBUG_FILLLIB,
              "Filllib: Nothing found, looking for ko back-capture.\n");
        for (k = 0; k < 4; k++) {
-         int dm = deltai[k];
-         int dn = deltaj[k];
-         if (BOARD(m+dm, n+dn) == other
-             && worm[POS(m+dm, n+dn)].attack_codes[0] != 0
-             && is_legal(worm[POS(m+dm, n+dn)].attack_points[0], color)) {
-           *move = worm[POS(m+dm, n+dn)].attack_points[0];
+         int d = delta[k];
+         if (board[pos + d] == other
+             && worm[pos + d].attack_codes[0] != 0
+             && is_legal(worm[pos + d].attack_points[0], color)) {
+           *move = worm[pos + d].attack_points[0];
            DEBUG(DEBUG_FILLLIB, "Filllib: Found at %1m.\n", *move);
            return 1;
          }
@@ -308,13 +304,12 @@
        DEBUG(DEBUG_FILLLIB,
              "Filllib: Nothing found, looking for threat to back-capture.\n");
        for (k = 0; k < 4; k++) {
-         int dm = deltai[k];
-         int dn = deltaj[k];
-         if (BOARD(m+dm, n+dn) == other
-             && worm[POS(m+dm, n+dn)].attack_codes[0] != 0) {
+         int d = delta[k];
+         if (board[pos + d] == other
+             && worm[pos + d].attack_codes[0] != 0) {
            /* Just pick some other liberty. */
            int libs[2];
-           if (findlib(POS(m+dm, n+dn), 2, libs) > 1) {
+           if (findlib(pos + d, 2, libs) > 1) {
              if (is_legal(libs[0], color))
                *move = libs[0];
              else if (is_legal(libs[1], color))
@@ -336,15 +331,15 @@
 /* The strategy for finding a backfilling move is to first identify
  * moves that
  *
- * 1. defends the position obtained after playing (m,n).
- * 2. captures a stone adjacent to our neighbors to (m,n), before
- *    (m,n) is played.
+ * 1. defends the position obtained after playing (move).
+ * 2. captures a stone adjacent to our neighbors to (move), before
+ *    (move) is played.
  *
- * Then we check which of these are legal before (m,n) is played. If
+ * Then we check which of these are legal before (move) is played. If
  * there is at least one, we take one of these arbitrarily as a
  * backfilling move.
  *
- * Now it may happen that (m,n) still isn't a safe move. In that case
+ * Now it may happen that (move) still isn't a safe move. In that case
  * we recurse to find a new backfilling move. To do things really
  * correctly we should also give the opponent the opportunity to keep
  * up the balance of the position by letting him do a backfilling move
@@ -369,7 +364,7 @@
   int acode;
   int saved_move = NO_MOVE;
   
-  /* Play (m,n) and identify all liberties and adjacent strings. */
+  /* Play (move) and identify all liberties and adjacent strings. */
   if (!trymove(move, color, "find_backfilling_move", move, EMPTY, NO_MOVE))
     return 0; /* This shouldn't happen, I believe. */
 
@@ -385,7 +380,7 @@
   /* Find neighbors. */
   neighbors = chainlinks(move, adjs);
 
-  /* Remove (m,n) again. */
+  /* Remove (move) again. */
   popgo();
   
   /* It's most fun to capture stones. Start by trying to take some
@@ -473,7 +468,7 @@
 }
 
 
-/* Confirm that (m, n) is a safe move for color. In addition to
+/* Confirm that (move) is a safe move for color. In addition to
  * calling the global confirm_safety(), this function also calls the
  * owl code to verify the strategical viability of the move.
  */
Index: engine/semeai.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/semeai.c,v
retrieving revision 1.15
diff -u -r1.15 semeai.c
--- engine/semeai.c     2001/10/16 19:53:01     1.15
+++ engine/semeai.c     2001/10/16 21:06:16
@@ -86,7 +86,7 @@
   }
 }
 
-/* liberty_of_dragon(pos, dr) returns true if the vertex at (pos) is a
+/* liberty_of_dragon(pos, origin) returns true if the vertex at (pos) is a
  * liberty of the dragon with origin at (origin).
  */
 
@@ -171,12 +171,14 @@
 #endif
       if (dragon[your_dragon].owl_status == DEAD) {
        for (m = 0; m < board_size; m++)
-         for (n = 0; n < board_size; n++)
-           if (board[POS(m, n)] == board[your_dragon]
-               && is_same_dragon(POS(m, n), your_dragon)) {
-             dragon[POS(m, n)].owl_status = CRITICAL;
-             dragon[POS(m, n)].matcher_status = CRITICAL;
+         for (n = 0; n < board_size; n++) {
+           int pos = POS(m, n);
+           if (board[pos] == board[your_dragon]
+               && is_same_dragon(pos, your_dragon)) {
+             dragon[pos].owl_status = CRITICAL;
+             dragon[pos].matcher_status = CRITICAL;
            }
+         }
        DEBUG(DEBUG_SEMEAI,
              "changed owl_status and matcher_status of %1m to CRITICAL\n",
              your_dragon);
@@ -222,12 +224,14 @@
            my_dragon, dragon[your_dragon].owl_attack_point);
       if (dragon[my_dragon].owl_status == DEAD) {
        for (m = 0; m < board_size; m++)
-         for (n = 0; n < board_size; n++)
-           if (board[POS(m, n)] == board[my_dragon]
-               && is_same_dragon(POS(m, n), my_dragon)) {
-             dragon[POS(m, n)].owl_status = CRITICAL;
-             dragon[POS(m, n)].matcher_status = CRITICAL;
+         for (n = 0; n < board_size; n++) {
+           int pos = POS(m, n);
+           if (board[pos] == board[my_dragon]
+               && is_same_dragon(pos, my_dragon)) {
+             dragon[pos].owl_status = CRITICAL;
+             dragon[pos].matcher_status = CRITICAL;
            }
+         }
        DEBUG(DEBUG_SEMEAI,
              "changed owl_status and matcher_status of %1m to CRITICAL\n",
              my_dragon);
@@ -276,20 +280,21 @@
    */
   for (m = 0; m < board_size; m++)
     for (n = 0; n < board_size; n++) {
-      if (worm[POS(m, n)].origin == POS(m, n)
-         && worm[POS(m, n)].attack_codes[0] == WIN)
-       if (dragon[POS(m, n)].origin == my_dragon
-           || dragon[POS(m, n)].origin == your_dragon) {
+      int pos = POS(m, n);
+      if (worm[pos].origin == pos
+         && worm[pos].attack_codes[0] == WIN)
+       if (dragon[pos].origin == my_dragon
+           || dragon[pos].origin == your_dragon) {
          int adj;
          int adjs[MAXCHAIN];
          int r;
          
-         adj = chainlinks(POS(m, n), adjs);
+         adj = chainlinks(pos, adjs);
          for (r = 0; r < adj; r++) {
            int cpos = adjs[r];
            if (dragon[cpos].origin == my_dragon
                || dragon[cpos].origin == your_dragon)
-             if (owl_substantial(POS(m, n))) {
+             if (owl_substantial(pos)) {
                DEBUG(DEBUG_SEMEAI, "...tactical situation detected, 
exiting\n");
                return;
              }
@@ -300,11 +305,13 @@
   
   /* Mark the dragons as involved in semeai */
   for (i = 0; i < board_size; i++)
-    for (j = 0; j < board_size; j++)
-      if (is_same_dragon(POS(i, j), my_dragon)
-         || is_same_dragon(POS(i, j), your_dragon))
-       DRAGON2(POS(i, j)).semeai = 1;
-
+    for (j = 0; j < board_size; j++) {
+      int pos = POS(i, j);
+      if (is_same_dragon(pos, my_dragon)
+         || is_same_dragon(pos, your_dragon))
+       DRAGON2(pos).semeai = 1;
+    }
+  
   /* First we try to determine the number of liberties of each
    * dragon, and the number of common liberties. We subtract
    * 1 minus the number of worms of the dragon from the liberty
@@ -315,17 +322,18 @@
    */
   for (i = 0; i < board_size; i++)
     for (j = 0; j < board_size; j++) {
-      if (board[POS(i, j)]
-         && worm[POS(i, j)].origin == POS(i, j)) {
-       if (is_same_dragon(POS(i, j), my_dragon))
+      int pos = POS(i, j);
+      if (board[pos]
+         && worm[pos].origin == pos) {
+       if (is_same_dragon(pos, my_dragon))
          mylibs--;
-       if (is_same_dragon(POS(i, j), your_dragon))
+       if (is_same_dragon(pos, your_dragon))
          yourlibs--;
       }
-      else if (board[POS(i, j)] == EMPTY) {
-       if (liberty_of_dragon(POS(i, j), your_dragon)) {
+      else if (board[pos] == EMPTY) {
+       if (liberty_of_dragon(pos, your_dragon)) {
          yourlibs ++;
-         if (liberty_of_dragon(POS(i, j), my_dragon)) {
+         if (liberty_of_dragon(pos, my_dragon)) {
            commonlibs++;
            mylibs++;
            commonlibi = i;
@@ -336,7 +344,7 @@
            yourlibj = j;
          }
        }
-       else if (liberty_of_dragon(POS(i, j), my_dragon))
+       else if (liberty_of_dragon(pos, my_dragon))
          mylibs++;
       }
     }
@@ -602,21 +610,23 @@
     }
     else {
       for (i = 0; i < board_size-1; i++)
-       for (j = 0; j < board_size-1; j++)
-         if (liberty_of_dragon(POS(i, j), your_dragon) 
-             && !liberty_of_dragon(POS(i, j), my_dragon)
-             && safe_move(POS(i, j), color)) {
+       for (j = 0; j < board_size-1; j++) {
+         int pos = POS(i, j);
+         if (liberty_of_dragon(pos, your_dragon) 
+             && !liberty_of_dragon(pos, my_dragon)
+             && safe_move(pos, color)) {
            /* add move reasons for EVERY outside liberty where we can
              * play safely. A move to win a semeai might not be a
              * safe move if it is inside the opponent's eyespace. 
              * However we hope that the reading code can analyze the
              * semeai in cases where every safe liberty has been filled.
             */
-           add_appropriate_semeai_moves(POS(i, j), my_dragon, your_dragon,
+           add_appropriate_semeai_moves(pos, my_dragon, your_dragon,
                                         my_status, your_status,
                                         margin_of_safety);
            found_one = 1;
          }
+       }
       if (!found_one) {
        /* No outside liberties --- look for common liberties.
         * Filling a common liberty is usually bad but if our 
@@ -626,12 +636,14 @@
         * be a safe move.
         */
        for (i = 0; i < board_size-1; i++)
-         for (j = 0; j < board_size-1; j++)
-           if (liberty_of_dragon(POS(i, j), your_dragon)
-               && safe_move(POS(i, j), color))
-             add_appropriate_semeai_moves(POS(i, j), my_dragon, your_dragon,
+         for (j = 0; j < board_size-1; j++) {
+           int pos = POS(i, j);
+           if (liberty_of_dragon(pos, your_dragon)
+               && safe_move(pos, color))
+             add_appropriate_semeai_moves(pos, my_dragon, your_dragon,
                                           my_status, your_status,
                                           margin_of_safety);
+         }
       }
     }
   }
@@ -724,7 +736,7 @@
 }
 
 /* Helper function for small_semeai. Tries to resolve the
- * semeai between (i,j) and (m,n), possibly revising points
+ * semeai between (str1) and (str2), possibly revising points
  * of attack and defense.
  */
 



reply via email to

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