gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] lunch patch


From: Gunnar Farneback
Subject: [gnugo-devel] lunch patch
Date: Wed, 26 Mar 2003 21:49:16 +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 modifies the handling of lunches. More specifically it
removes the lunch invalidating patterns in conn.db and instead adds
some general code to handle lunches.

- modify_eye_spaces(), remove_lunch(), and not_lunch_helper() removed
- new function estimate_lunch_eye_value() broken out of sniff_lunch()
- obvious_false_eye() moved from owl.c to optics.c
- lunch invalidating patterns removed from conn.db together with
  corresponding code in connections.c

Regression delta:
trevor:310      PASS A8 [A8]
nngs3:400       FAIL Q15 [N13]
nngs3:980       PASS T14 [!G10]
gunnar:19       PASS L4 [L4]

/Gunnar

Index: engine/dragon.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/dragon.c,v
retrieving revision 1.108
diff -u -r1.108 dragon.c
--- engine/dragon.c     22 Feb 2003 10:54:23 -0000      1.108
+++ engine/dragon.c     26 Mar 2003 17:04:34 -0000
@@ -192,11 +192,6 @@
   find_half_and_false_eyes(BLACK, black_eye, half_eye, NULL);
   find_half_and_false_eyes(WHITE, white_eye, half_eye, NULL);
 
-  /* Pattern based modification of the eye shapes computed by
-   * make_domains and halfeye analysis.
-   */
-  modify_eye_spaces();
-  
   /* Compute the number of eyes, half eyes, etc. in an eye space. */
   for (str = BOARDMIN; str < BOARDMAX; str++) {
     if (!ON_BOARD(str))
Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.161
diff -u -r1.161 liberty.h
--- engine/liberty.h    22 Feb 2003 10:54:24 -0000      1.161
+++ engine/liberty.h    26 Mar 2003 17:04:40 -0000
@@ -377,6 +377,8 @@
 int stones_on_board(int color);
 
 int obvious_false_eye(int pos, int color);
+void estimate_lunch_eye_value(int lunch, int *min, int *probable, int *max,
+                             int appreciate_one_two_lunches);
 int owl_topological_eye(int pos, int color);
 int vital_chain(int pos);
 int confirm_safety(int move, int color, int *defense_point,
@@ -418,7 +420,6 @@
 void transform2(int i, int j, int *ti, int *tj, int trans);
 void find_cuts(void);
 void find_connections(void);
-void modify_eye_spaces(void);
 
 /* movelist.c */
 int movelist_move_known(int move, int max_points, int points[], int codes[]);
@@ -436,7 +437,6 @@
 /* functions to add (or remove) move reasons */
 void clear_move_reasons(void);
 void add_lunch(int eater, int food);
-void remove_lunch(int eater, int food);
 void add_attack_move(int pos, int ww, int code);
 void add_defense_move(int pos, int ww, int code);
 void add_attack_threat_move(int pos, int ww, int code);
Index: engine/move_reasons.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/move_reasons.c,v
retrieving revision 1.110
diff -u -r1.110 move_reasons.c
--- engine/move_reasons.c       22 Feb 2003 10:54:24 -0000      1.110
+++ engine/move_reasons.c       26 Mar 2003 17:04:43 -0000
@@ -350,33 +350,6 @@
   return;
 }
 
-/*
- * Remove a lunch from the list of lunches.  A lunch is in this context a pair
- * of eater (a dragon) and food (a worm).  
- */
-void
-remove_lunch(int eater, int food)
-{
-  int k;
-  int dragon1 = dragon[eater].origin;
-  int worm1   = worm[food].origin;
-  ASSERT_ON_BOARD1(eater);
-  ASSERT_ON_BOARD1(food);
-  
-  for (k = 0; k < next_lunch; k++)
-    if ((lunch_dragon[k] == dragon1) && (lunch_worm[k] == worm1))
-      break;
-  
-  if (k == next_lunch)
-    return; /* Not found */
-  
-  /* Remove entry k. */
-  lunch_dragon[k] = lunch_dragon[next_lunch - 1];
-  lunch_worm[k] = lunch_worm[next_lunch - 1];
-  next_lunch--;
-}
-
-
 /* ---------------------------------------------------------------- */
 
 
Index: engine/optics.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/optics.c,v
retrieving revision 1.70
diff -u -r1.70 optics.c
--- engine/optics.c     22 Feb 2003 10:54:24 -0000      1.70
+++ engine/optics.c     26 Mar 2003 17:04:47 -0000
@@ -1962,6 +1962,36 @@
 }
 
 
+/* Conservative relative of topological_eye(). Essentially the same
+ * algorithm is used, but only tactically safe opponent strings on
+ * diagonals are considered. This may underestimate the false/half eye
+ * status, but it should never be overestimated.
+ */
+int
+obvious_false_eye(int pos, int color)
+{
+  int i = I(pos);
+  int j = J(pos);
+  int k;
+  int diagonal_sum = 0;
+  for (k = 4; k < 8; k++) {
+    int di = deltai[k];
+    int dj = deltaj[k];
+    
+    if (!ON_BOARD2(i+di, j) && !ON_BOARD2(i, j+dj))
+      diagonal_sum--;
+    
+    if (!ON_BOARD2(i+di, j+dj))
+      diagonal_sum++;
+    else if (BOARD(i+di, j+dj) == OTHER_COLOR(color)
+            && !attack(POS(i+di, j+dj), NULL))
+      diagonal_sum += 2;
+  }
+  
+  return diagonal_sum >= 4;
+}
+
+
 void
 set_eyevalue(struct eyevalue *e, int a, int b, int c, int d)
 {
Index: engine/owl.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/owl.c,v
retrieving revision 1.149
diff -u -r1.149 owl.c
--- engine/owl.c        12 Mar 2003 21:57:37 -0000      1.149
+++ engine/owl.c        26 Mar 2003 17:04:58 -0000
@@ -4805,7 +4806,6 @@
            struct local_owl_data *owl)
 {
   int other = OTHER_COLOR(board[lunch]);
-  int size;
   int libs[MAXLIBS];
   int liberties;
   int r;
@@ -4836,19 +4836,29 @@
       }
     }
   }
-  
-  size = countstones(lunch);
+
+  estimate_lunch_eye_value(lunch, min, probable, max, 1);
+
+  if (*probable < 2)
+    eat_lunch_escape_bonus(lunch, min, probable, max, owl);
+}
+
+void
+estimate_lunch_eye_value(int lunch, int *min, int *probable, int *max,
+                        int appreciate_one_two_lunches)
+{
+  int other = OTHER_COLOR(board[lunch]);
+  int size = countstones(lunch);
+
   if (size > 6) {
     *min = 2;
     *probable = 2;
     *max = 2;
-    return;
   }
   else if (size > 4) {
     *min = 1;
     *probable = 2;
     *max = 2;
-    return;
   }
   else if (size > 2) {
     *min = 0;
@@ -4861,7 +4871,8 @@
     /* A lunch on a 1-2 point tends always to be worth contesting. */
     if ((obvious_false_eye(stones[0], other)
        || obvious_false_eye(stones[1], other))
-       && !(one_two_point(stones[0]) || one_two_point(stones[1]))) {
+       && (!appreciate_one_two_lunches
+           || !(one_two_point(stones[0]) || one_two_point(stones[1])))) {
       *min = 0;
       *probable = 0;
       *max = 0;
@@ -4884,11 +4895,8 @@
       *max = 0;
     }
   }
-
-  eat_lunch_escape_bonus(lunch, min, probable, max, owl);
 }
 
-
 /* Gives a bonus for a lunch capture which joins a (or some) friendly
  * string(s) to the goal dragon and improves the escape potential at
  * the same time. This is indicated in some situations where the owl
@@ -4947,36 +4955,6 @@
 }
 
  
-/* Conservative relative of topological_eye. Essentially the same
- * algorithm is used, but only tactically safe opponent strings on
- * diagonals are considered. This may underestimate the false/half eye
- * status, but it should never be overestimated.
- */
-int
-obvious_false_eye(int pos, int color)
-{
-  int i = I(pos);
-  int j = J(pos);
-  int k;
-  int diagonal_sum = 0;
-  for (k = 4; k < 8; k++) {
-    int di = deltai[k];
-    int dj = deltaj[k];
-    
-    if (!ON_BOARD2(i+di, j) && !ON_BOARD2(i, j+dj))
-      diagonal_sum--;
-    
-    if (!ON_BOARD2(i+di, j+dj))
-      diagonal_sum++;
-    else if (BOARD(i+di, j+dj) == OTHER_COLOR(color)
-            && !attack(POS(i+di, j+dj), NULL))
-      diagonal_sum += 2;
-  }
-  
-  return diagonal_sum >= 4;
-}
-
-
 /* Retrieve topological eye values stored in the half_eye[] array of
  * the current owl data.
  *
Index: engine/value_moves.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/value_moves.c,v
retrieving revision 1.83
diff -u -r1.83 value_moves.c
--- engine/value_moves.c        17 Mar 2003 21:57:26 -0000      1.83
+++ engine/value_moves.c        26 Mar 2003 17:05:15 -0000
@@ -2043,6 +2043,17 @@
            || worm[aa].inessential)
          break;
 
+       /* If the lunch has no potential to create eyes, no points. */
+       {
+         int min;
+         int probable;
+         int max;
+
+         estimate_lunch_eye_value(aa, &min, &probable, &max, 0);
+         if (max == 0)
+           break;
+       }
+       
        /* Can't use k in this loop too. */
        for (l = 0; l < next_lunch; l++)
          if (lunch_worm[l] == aa) {
Index: patterns/conn.db
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/conn.db,v
retrieving revision 1.35
diff -u -r1.35 conn.db
--- patterns/conn.db    3 Feb 2003 13:12:50 -0000       1.35
+++ patterns/conn.db    26 Mar 2003 17:05:34 -0000
@@ -42,7 +42,6 @@
 #
 #  B - Indicate cutting points and inhibit connections.
 #  C - Amalgamate worms into dragons.
-#  I - Invalidate lunches, late matching.
 #
 # Additionally there are a few acceptance modifiers. 
 #
@@ -1724,68 +1723,6 @@
 ac
 
 ;attack(a) && attack(b) && !xcut(c) && !xcut(d)
-
-
-#############################
-#
-# lunch invalidating patterns
-#
-#############################
-
-callback_data X
-
-
-Pattern Lunch1
-# O stone on edge is not lunch!
-
-XO|            not lunch!
-O.|
-oo|
-?o|
-
-:8,sI
-
-ba|
-O.|
-oo|
-?o|
-
->not_lunch(a,b);
-
-
-Pattern Lunch2
-# O stone on edge is not lunch!
-
-XO|            not lunch!
-OX|
-o.|
-
-:8,sI
-
-ba|
-cX|
-od|
-
-;!attack(c) && !safe_xmove(d)
->not_lunch(a,b);
-
-
-Pattern Lunch3
-# O stone on edge is not lunch!
-
-XO|            not lunch!
-O.|
-oo|
---+
-
-:8,sI
-
-ba|
-O.|
-oo|
---+
-
->not_lunch(a,b);
 
 
 # END OF FILE
Index: patterns/connections.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/connections.c,v
retrieving revision 1.34
diff -u -r1.34 connections.c
--- patterns/connections.c      26 Feb 2003 22:22:24 -0000      1.34
+++ patterns/connections.c      26 Mar 2003 17:05:35 -0000
@@ -120,7 +120,7 @@
       return;
   }
 
-  if ((pattern->class & (CLASS_B | CLASS_I))
+  if ((pattern->class & CLASS_B)
       && !(pattern->class & CLASS_s)) {
     /* Require that the X stones in the pattern are tactically safe. */
     for (k = 0; k < pattern->patlen; ++k) { /* match each point */
@@ -145,9 +145,6 @@
   else if (pattern->class & CLASS_C)
     DEBUG(DEBUG_DRAGONS, "Connecting pattern %s+%d found at %1m\n",
          pattern->name, ll, anchor);
-  else if (pattern->class & CLASS_I)
-    DEBUG(DEBUG_DRAGONS, "Lunch invalidating pattern %s+%d found at %1m\n",
-         pattern->name, ll, anchor);
 
   /* does the pattern have an action? */
   if (pattern->autohelper_flag & HAVE_ACTION) {
@@ -242,16 +239,7 @@
 conn_callback(int anchor, int color, struct pattern *pattern, int ll,
              void *data)
 {
-  if (!(pattern->class & (CLASS_B | CLASS_I)))
-    cut_connect_callback(anchor, color, pattern, ll, data);
-}
-  
-/* Only consider e patterns. */
-static void
-modify_eye_callback(int anchor, int color, struct pattern *pattern,
-                    int ll, void *data)
-{
-  if (pattern->class & CLASS_I)
+  if (!(pattern->class & CLASS_B))
     cut_connect_callback(anchor, color, pattern, ll, data);
 }
   
@@ -269,12 +257,6 @@
 find_connections(void)
 {
   matchpat(conn_callback, ANCHOR_COLOR, &conn_db, NULL, NULL);
-}
-
-void
-modify_eye_spaces(void)
-{
-  matchpat(modify_eye_callback, ANCHOR_COLOR, &conn_db, NULL, NULL);
 }
 
 
Index: patterns/helpers.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/helpers.c,v
retrieving revision 1.49
diff -u -r1.49 helpers.c
--- patterns/helpers.c  17 Mar 2003 21:57:27 -0000      1.49
+++ patterns/helpers.c  26 Mar 2003 17:05:40 -0000
@@ -233,35 +233,6 @@
 }
 
 
-/*
- *
- * Prevent misreporting of a as lunch for b.
- * To be used in autohelper action line. E.g.
- *
- *  XO|          ba|
- *  O*|          O*|
- *  oo|          oo|
- *  ?o|          ?o|
- *  
- *  >not_lunch(a,b);
- */
-
-int
-not_lunch_helper(int apos, int bpos)
-{
-  if (worm[apos].size > 2)
-    return 0;
-
-  /* Tell the move generation code about the change in status. */
-  remove_lunch(bpos, apos);
-  
-  if (DRAGON2(bpos).lunch == apos)
-    DRAGON2(bpos).lunch = NO_MOVE;
-
-  return 0;
-}
-  
-
 /* This is intended for use in autohelpers. */
 
 /* Check whether the string at (str) can attack any surrounding
Index: patterns/mkpat.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/mkpat.c,v
retrieving revision 1.116
diff -u -r1.116 mkpat.c
--- patterns/mkpat.c    17 Mar 2003 21:57:27 -0000      1.116
+++ patterns/mkpat.c    26 Mar 2003 17:05:47 -0000
@@ -297,7 +297,6 @@
   {"seki_helper",              1, 0, 0.0, "seki_helper(%s)"},
   {"threaten_to_save",         1, 0, 0.0, "threaten_to_save_helper(move,%s)"},
   {"threaten_to_capture",      1, 0, 0.0, 
"threaten_to_capture_helper(move,%s)"},
-  {"not_lunch",                        2, 0, 0.0, "not_lunch_helper(%s, %s)"},
   {"eye",                      1, 0, 0.01, "is_eye_space(%s)"},
   {"proper_eye",               1, 0, 0.01, "is_proper_eye_space(%s)"},
   {"marginal_eye",             1, 0, 0.01, "is_marginal_eye_space(%s)"},
Index: patterns/patterns.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/patterns.h,v
retrieving revision 1.53
diff -u -r1.53 patterns.h
--- patterns/patterns.h 17 Mar 2003 21:57:27 -0000      1.53
+++ patterns/patterns.h 26 Mar 2003 17:05:57 -0000
@@ -283,9 +283,8 @@
 DECLARE(throw_in_atari_helper);
 DECLARE(ugly_cutstone_helper);
 DECLARE(cutstone2_helper);
 
 /* autohelper fns */
-int not_lunch_helper(int apos, int bpos);
 int seki_helper(int str);
 void threaten_to_save_helper(int move, int str);
 void threaten_to_capture_helper(int move, int str);




reply via email to

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