gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] optics patch


From: Gunnar Farneback
Subject: [gnugo-devel] optics patch
Date: Wed, 19 Dec 2001 17:49:28 +0100
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)

This patch removes linear_eye_space(). As expected is has no effects
at all on the regressions.

- linear_eye_space() removed

/Gunnar

Index: engine/optics.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/optics.c,v
retrieving revision 1.33
diff -u -r1.33 optics.c
--- engine/optics.c     15 Dec 2001 14:35:26 -0000      1.33
+++ engine/optics.c     19 Dec 2001 16:45:27 -0000
@@ -73,8 +73,6 @@
 static void guess_eye_space(int pos, int effective_eyesize, int margins,
                            struct eye_data eye[BOARDMAX],
                            int *max, int *min, int *pessimistic_min);
-static int linear_eye_space(int pos, int *vital_point, int *max, int *min,
-                           struct eye_data eye[BOARDMAX]);
 static void first_map(int q, int map[MAXEYE]);
 static int next_map(int *q, int map[MAXEYE], int esize);
 static void print_eye(struct eye_data eye[BOARDMAX],
@@ -770,14 +768,6 @@
     }
   }
 
-  /* If not found we examine whether we have a linear eye space. */
-  if (linear_eye_space(pos, attack_point, max, min, eye)) {
-    *defense_point = *attack_point; /* Duplicate attack point to defense 
point. */
-    if (debug & DEBUG_EYES)
-      gprintf("Linear eye shape at %1m\n", pos);
-    return;
-  }
-
   /* Ideally any eye space that hasn't been matched yet should be two
    * secure eyes. Until the database becomes more complete we have
    * some additional heuristics to guess the values of unknown
@@ -881,44 +871,6 @@
          *max, *min, *pessimistic_min);
   }
   
-  /* If not found we examine whether we have a linear eye space. */
-  else if (linear_eye_space(pos, attack_point, max, min, eye)) {
-    /* Duplicate attack point to defense point. */
-    if (defense_point)
-      *defense_point = *attack_point;
-    if (debug & DEBUG_EYES)
-      gprintf("Linear eye shape at %1m\n", pos);
-    *pessimistic_min = *min - margins;
-    if (*pessimistic_min == 2)
-      *pessimistic_min = 1;
-    if (*pessimistic_min < 0)
-      *pessimistic_min = 0;
-
-    DEBUG(DEBUG_EYES, "  linear_eye - max=%d, min=%d, pessimistic_min=%d\n",
-         *max, *min, *pessimistic_min);
-
-    /* Change this to 1 to get notification when linear_eye() would
-     * give a different result than guess_eye_space(), for eyespaces
-     * without a matching graph.
-     */
-    if (0) {
-      int max2, min2, pessimistic_min2;
-      guess_eye_space(pos, effective_eyesize, margins, eye, &max2, &min2,
-                     &pessimistic_min2);
-      if (*max != *min
-         || *max != max2
-         || *min != min2) {
-       gprintf("  linear_eye - max=%d, min=%d, pessimistic_min=%d\n",
-               *max, *min, *pessimistic_min);
-       gprintf("  guess_eye - max=%d, min=%d, pessimistic_min=%d\n",
-               max2, min2, pessimistic_min2);
-       print_eye(eye, heye, pos);
-       gprintf("Linear eye space failure.\n");
-       showboard(0);
-      }
-    }
-  }
-
   /* Ideally any eye space that hasn't been matched yet should be two
    * secure eyes. Until the database becomes more complete we have
    * some additional heuristics to guess the values of unknown
@@ -1008,6 +960,7 @@
   }
 }
 
+
 static void
 guess_eye_space(int pos, int effective_eyesize, int margins,
                struct eye_data eye[BOARDMAX],
@@ -1040,363 +993,6 @@
   }
 }
 
-/*
- * A linear eyespace is one in which each vertex has 2 neighbors, 
- * except for two vertices on the end. Only the end vertices can
- * be marginal.
- *
- * This function returns true if the eyespace is linear, and if so, 
- * returns in the variables @code{*max} and @code{*min} the number of
- * eyes it yields if the defender plays first and if the attacker
- * plays first. If these are different, then (*attacki, *attackj)
- * is the vital point of attack.
- */
-static int
-linear_eye_space(int pos, int *vital_point, int *max, int *min,
-                struct eye_data eye[BOARDMAX])
-{
-  int posa;
-  int end1 = NO_MOVE;
-  int end2 = NO_MOVE;
-  int centers = 0;
-  int center = NO_MOVE;
-  int middle = NO_MOVE;
-  int is_line = 1;
-  int msize = eye[pos].msize;
-  int esize = eye[pos].esize;
-
-  for (posa = BOARDMIN; posa < BOARDMAX; posa++) {
-    if (ON_BOARD(posa)) {
-      if (eye[posa].origin == pos) {
-       if (eye[posa].neighbors > 2) {
-         if (center == NO_MOVE)
-           center = posa;
-         centers++;
-         is_line = 0;
-       }
-       if (eye[posa].neighbors == 2) {
-         middle = posa;
-         if (eye[posa].marginal)
-           is_line = 0;
-       }
-       if (eye[posa].neighbors == 1) {
-         if (end1 == NO_MOVE)
-           end1 = posa;
-         else if (end2 == NO_MOVE) {
-           end2 = posa;
-         }
-       }
-      }
-    }
-  }
-  if (!is_line)
-    return 0;
-
-  /* If we got this far, we have a linear eye space.
-   * end1 and end2 are the endpoints. middle is a
-   * vertex which is not one of these though its 
-   * location is not specified beyond that.
-   */
-
-  /* 1. Check eye spaces with no marginal vertices. */
-  if (msize == 0) {
-    if (esize == 1 || esize == 2) {
-      *max = 1;
-      *min = 1;
-      return 1;
-    }
-    if (esize == 3) {
-      gg_assert(middle != NO_MOVE);
-      if (board[middle] == EMPTY) {
-       *max = 2;
-       *min = 1;
-       *vital_point = middle;
-       return 1;
-      }
-      else {
-       *max = 1;
-       *min = 1;
-       return 1;
-      }
-    }
-    if (esize == 4) {
-      int farmiddle;
-      if (ON_BOARD(SOUTH(middle))
-         && eye[SOUTH(middle)].origin == pos
-         && eye[SOUTH(middle)].neighbors == 2)
-       farmiddle = SOUTH(middle);
-      else if (ON_BOARD(NORTH(middle))
-              && eye[NORTH(middle)].origin == pos
-              && eye[NORTH(middle)].neighbors == 2)
-       farmiddle = NORTH(middle);
-      else if (ON_BOARD(EAST(middle))
-              && eye[EAST(middle)].origin == pos
-              && eye[EAST(middle)].neighbors == 2)
-       farmiddle = EAST(middle);
-      else if (ON_BOARD(WEST(middle))
-              && eye[WEST(middle)].origin == pos
-              && eye[WEST(middle)].neighbors == 2)
-       farmiddle = WEST(middle);
-      else {
-       farmiddle = NO_MOVE; /* to prevent compiler warning */
-       abort();
-      }
-      
-      if (board[middle] == EMPTY) {
-       
-       if (board[farmiddle] == EMPTY) {
-         *max = 2;
-         *min = 2;
-         return 1;
-       }
-       else {
-         *max = 2;
-         *min = 1;
-         *vital_point = middle;
-         return 1;
-       }
-      }
-      else
-       if (board[farmiddle] == EMPTY) {
-         *max = 2;
-         *min = 1;
-         *vital_point = farmiddle;
-         return 1;
-       }
-       else {
-         *max = 1;
-         *min = 1;
-         return 1;
-       }
-    }
-    if (esize > 4) {
-      *max = 2;
-      *min = 2;
-      return 1;
-    }
-  }
-  /* 2. Check eye spaces with one marginal vertex. */
-  if (msize == 1) {
-    if (esize == 1) {
-      *max = 0;
-      *min = 0;
-      return 1;
-    }
-    if (esize == 2) {
-      *max = 1;
-      *min = 0;
-      if (eye[end1].marginal) {
-       *vital_point = end1;
-      }
-      else
-       *vital_point = end2;
-      
-      /* We need to make an exception for cases like this:
-       * XXOOO
-       * .OX.O
-       * -----
-       */
-      if (IS_STONE(board[*vital_point])) {
-       *max = 0;
-       *vital_point = NO_MOVE;
-      }
-      return 1;
-    }
-
-    if (esize == 3) {
-      if (board[middle] == EMPTY) {
-       *max = 1;
-       *min = 1;
-       
-       /* Exceptional cases. (optics.tst:312) */
-       if ((eye[end1].marginal
-            && IS_STONE(board[end1])
-            && board[end2] == EMPTY)
-           || (eye[end2].marginal
-               && IS_STONE(board[end2])
-               && board[end1] == EMPTY)) {
-         *max = 1;
-         *min = 0;
-         *vital_point = middle;
-         return 1;
-       }
-      }
-      else {
-       *max = 1;
-       *min = 0;
-       if (eye[end1].marginal) {
-         if (board[end1] == EMPTY) {
-           *vital_point = end1;
-         }
-         else {
-           if (IS_STONE(board[end2]))
-             *min = 1; /* three tactically dead stones in a row. */
-           else
-             *max = 0;
-         }
-       }
-       else {
-         if (board[end2] == EMPTY)
-           *vital_point = end2;
-         else {
-           if (IS_STONE(board[end1]))
-             *min = 1; /* three tactically dead stones in a row. */
-           else
-             *max = 0;
-         }
-       }
-       return 1;
-      }
-    }
-
-    if (esize == 4) {
-      if (board[middle] == EMPTY) {
-       *max = 1;
-       *min = 1;
-       return 1;
-      }
-      else {
-       int farmiddle;
-
-       if (ON_BOARD(SOUTH(middle))
-           && eye[SOUTH(middle)].origin == pos
-           && eye[SOUTH(middle)].neighbors == 2)
-         farmiddle = SOUTH(middle);
-       else if (ON_BOARD(NORTH(middle))
-                && eye[NORTH(middle)].origin == pos
-                && eye[NORTH(middle)].neighbors == 2)
-         farmiddle = NORTH(middle);
-       else if (ON_BOARD(EAST(middle))
-                && eye[EAST(middle)].origin == pos
-                && eye[EAST(middle)].neighbors == 2)
-         farmiddle = EAST(middle);
-       else if (ON_BOARD(WEST(middle))
-                && eye[WEST(middle)].origin == pos
-                && eye[WEST(middle)].neighbors == 2)
-         farmiddle = WEST(middle);
-
-       /* Now farmiddle is the second middle vertex */
-
-       else {
-         farmiddle = NO_MOVE; /* to prevent compiler warning */
-         abort();
-       }
-       if (board[farmiddle] == EMPTY) {
-         *max = 1;
-         *min = 1;
-         return 1;
-       }
-       else {
-         if (eye[end1].marginal) {
-           if (board[end1] == EMPTY) {
-             *max = 1;
-             *min = 0;
-             *vital_point = end1;
-             return 1;
-           }
-           else {
-             /* Since end1, middle and farmiddle are occupied,
-              * if they are captured, an eye results.
-              */
-             int apos;
-             if (attack(end1, &apos)) {
-               if (find_defense(end1, NULL)) {
-                 *max = 1;
-                 *min = 0;
-                 *vital_point = end2;
-                 return 1;
-               }
-               else {
-                 *max = 1;
-                 *min = 1;
-                 return 1;
-               }
-             }
-           }
-         }
-       }
-      }
-    }
-    
-    if (esize == 5) {
-      *max = 2;
-      *min = 1;
-      if (eye[end1].marginal) {
-       if (board[end1] == EMPTY) {
-         *vital_point = end1;
-         return 1;
-       }
-       else {
-         *max = 1;
-         *min = 1;
-         return 1;
-       }
-      }
-      else
-       if (board[end2] == EMPTY) {
-         *vital_point = end2;
-         return 1;
-       }
-       else {
-         *max = 1;
-         *min = 1;
-         return 1;
-       }
-    }
-    if (esize == 6) {
-      *max = 2;
-      *min = 2;
-      return 1;
-    }
-  }
-  
-  if (msize == 2) {
-    if (esize < 4) {
-      *max = 0;
-      *min = 0;
-      return 1;
-    }
-    if (esize == 4) {
-      if (board[end1] == EMPTY
-         && board[end2] == EMPTY) {
-       *max = 1;
-       *min = 0;
-       *vital_point = end1;
-       return 1;
-      }
-      else {
-       *max = 0;
-       *min = 0;
-       return 1;
-      }
-    }
-    if (esize == 5 || esize == 6) {
-      *max = 1;
-      *min = 1;
-      return 1;
-    }
-    if (esize == 7) {
-      if (board[end1] == EMPTY
-         && board[end2] == EMPTY) {
-       *max = 2;
-       *min = 1;
-       *vital_point = end1;
-      }
-      else {
-       *max = 2;
-       *min = 1;
-       return 1;
-      }
-    }
-    if (esize > 7) {
-      *max = 2;
-      *min = 2;
-      return 1;
-    }
-  }
-
-  return 0;
-}
 
 /* recognize_eye(pos, *attack_point, *defense_point, *max, *min, eye_data, 
  * half_eye_data, add_moves, color), where pos is the origin of an eyespace,



reply via email to

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