gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] arend_3_7.4: revised pattern handling: class B, add_attack


From: Arend Bayer
Subject: [gnugo-devel] arend_3_7.4: revised pattern handling: class B, add_attack_either_move
Date: Mon, 26 Aug 2002 18:06:31 +0200 (CEST)

Less power to Patterns!

As we have at the moment appr. 3000 hand-written patterns, it is probably
a good idea to add more automatic checks, which should ease maintaining the
patterns.

This patch does this with two unrelated, but similar changes:
Instead of automatically triggering add_attack_either_move, the patterns
now call test_attack_either_move. This adds an attack EITHER_MOVE reason if
* the opponent could defend both strings in the current position, but
* he cannot defend both strings after the move.
Anything else confuses the move valuation.

The other change is a "back-merge" from the experimental_connections code.
A "B" pattern only triggers a cut move reason if it does indeed work.
Note that this means that the constraints of these patterns might become
superfluos. I haven't done this; it might even be advisable to keep them
because the constraints are probably faster evaluated than the call
to the connection module.

The performance impact of this patch is negligeable. It gets three
PASSes, no FAILs on the regressions (tactics:5, nngs2:100, century2002:35).

Arend

- Apply "B" cutting patterns in shapes.db only when they really work
- Let patterns suggest attack_either_move instead of mandating it

Index: engine/shapes.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/shapes.c,v
retrieving revision 1.34
diff -u -r1.34 shapes.c
--- engine/shapes.c     11 Aug 2002 12:13:02 -0000      1.34
+++ engine/shapes.c     25 Aug 2002 19:53:53 -0000
@@ -274,26 +274,8 @@
     pattern->autohelper(pattern, ll, move, color, 1);
   }

-  /* Pattern class B, cut all combinations of opponent dragons. */
-  if ((class & CLASS_B) && !experimental_connections) {
-    for (k = 0; k < your_ndragons; k++)
-      for (l = k+1; l < your_ndragons; l++) {
-       add_cut_move(move, your_dragons[k], your_dragons[l]);
-       TRACE("...cuts dragons %1m, %1m\n", your_dragons[k], your_dragons[l]);
-      }
-  }
-
-  /* Pattern class C, connect all combinations of our dragons. */
-  if ((class & CLASS_C) && !experimental_connections) {
-    for (k = 0; k < my_ndragons; k++)
-      for (l = k+1; l < my_ndragons; l++) {
-       add_connection_move(move, my_dragons[k], my_dragons[l]);
-       TRACE("...connects dragons %1m, %1m\n", my_dragons[k], my_dragons[l]);
-      }
-  }
-
   /* Pattern class B, try to cut all combinations of opponent strings. */
-  if ((class & CLASS_B) && experimental_connections) {
+  if (class & CLASS_B) {
     for (k = 0; k < your_nstrings; k++)
       for (l = k+1; l < your_nstrings; l++) {
        if (string_connect(your_strings[k], your_strings[l], NULL)
@@ -303,6 +285,15 @@
          TRACE("...cuts strings %1m, %1m\n",
                your_strings[k], your_strings[l]);
        }
+      }
+  }
+
+  /* Pattern class C, connect all combinations of our dragons. */
+  if ((class & CLASS_C) && !experimental_connections) {
+    for (k = 0; k < my_ndragons; k++)
+      for (l = k+1; l < my_ndragons; l++) {
+       add_connection_move(move, my_dragons[k], my_dragons[l]);
+       TRACE("...connects dragons %1m, %1m\n", my_dragons[k], my_dragons[l]);
       }
   }

Index: patterns/helpers.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/helpers.c,v
retrieving revision 1.35
diff -u -r1.35 helpers.c
--- patterns/helpers.c  7 Apr 2002 14:48:33 -0000       1.35
+++ patterns/helpers.c  25 Aug 2002 19:53:55 -0000
@@ -739,6 +739,42 @@
         && DRAGON2(pos).safety != INVINCIBLE;
 }

+
+void
+test_attack_either_move(int move, int color, int worma, int wormb)
+{
+  ASSERT_ON_BOARD1(move);
+  ASSERT1(board[move] == EMPTY, move);
+  ASSERT1(board[worma] == OTHER_COLOR(color)
+          && board[wormb] == OTHER_COLOR(color), move);
+
+  if (!defend_both(worma, wormb)) {
+    if (0)
+      gprintf("%1m: Rej. attack_either_move for %1m & %1m (can't defend both 
anyway)\n",
+             move, worma, wormb);
+    return;
+  }
+  if (trymove(move, color, "suggest_attack_either_move", worma,
+            EMPTY, NO_MOVE)) {
+    if (board[worma] == OTHER_COLOR(color)
+       && board[wormb] == OTHER_COLOR(color)) {
+      if (!defend_both(worma, wormb))
+        add_either_move(move, ATTACK_STRING, worma, ATTACK_STRING, wormb);
+      else {
+       if (0)
+         gprintf("%1m: Rej. attack_either_move for %1m & %1m (doesn't work)\n",
+                 move, worma, wormb);
+      }
+    }
+    else
+      if (0)
+       gprintf("%1m: Rej. attack_either_move for %1m & %1m (captured 
directly)\n",
+               move, worma, wormb);
+    popgo();
+  }
+}
+
+
 /*
  * LOCAL Variables:
  * tab-width: 8
Index: patterns/mkpat.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/mkpat.c,v
retrieving revision 1.79
diff -u -r1.79 mkpat.c
--- patterns/mkpat.c    18 Aug 2002 21:41:02 -0000      1.79
+++ patterns/mkpat.c    25 Aug 2002 19:54:05 -0000
@@ -268,8 +268,8 @@
   {"antisuji",                 1, 0.0, "add_antisuji_move(%s)"},
   {"add_connect_move",         2, 0.0, "add_connection_move(move,%s,%s)"},
   {"add_cut_move",             2, 0.0, "add_cut_move(move,%s,%s)"},
-  {"add_attack_either_move",   2, 0.0,
-               "add_either_move(move,ATTACK_STRING,%s,ATTACK_STRING,%s)"},
+  {"test_attack_either_move",2, 0.0,
+               "test_attack_either_move(move,color,%s,%s)"},
   {"add_defend_both_move",     2, 0.0,
                "add_all_move(move,DEFEND_STRING,%s,DEFEND_STRING,%s)"},
   {"same_dragon",              2, 0.01, "is_same_dragon(%s,%s)"},
Index: patterns/patterns.db
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/patterns.db,v
retrieving revision 1.79
diff -u -r1.79 patterns.db
--- patterns/patterns.db        5 Aug 2002 23:42:15 -0000       1.79
+++ patterns/patterns.db        25 Aug 2002 19:54:22 -0000
@@ -9541,7 +9541,7 @@

 ;lib(A)==2 && lib(B)==2 && lib(c)>1 && lib(d)>1

->add_attack_either_move(A,B);
+>test_attack_either_move(A,B);


 Pattern ED38
@@ -9560,7 +9560,7 @@

 ;oplay_attack(*,b,C) && oplay_attack(a,b,D)

->add_attack_either_move(C,D);
+>test_attack_either_move(C,D);


 Pattern ED39
@@ -10708,7 +10708,7 @@

 ;lib(E)==2 && !oplay_attack(*,c) && !oplay_defend_both(*,a,b,E,D)

->add_attack_either_move(D,E);
+>test_attack_either_move(D,E);


 Pattern CD41
Index: patterns/patterns.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/patterns.h,v
retrieving revision 1.35
diff -u -r1.35 patterns.h
--- patterns/patterns.h 18 Aug 2002 21:41:02 -0000      1.35
+++ patterns/patterns.h 25 Aug 2002 19:54:24 -0000
@@ -312,6 +312,7 @@
 int connect_and_cut_helper2(int Apos, int bpos, int cpos, int color);
 int edge_double_sente_helper(int move, int apos, int bpos, int cpos);
 int dragon_weak(int pos);
+void test_attack_either_move(int move, int color, int worma, int wormb);
 void set_value_helper(struct pattern *patt, int value);

 /* FIXME: Can this be set up inside of the mkpat.c function helper list? */
Index: patterns/patterns2.db
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/patterns2.db,v
retrieving revision 1.42
diff -u -r1.42 patterns2.db
--- patterns/patterns2.db       11 Aug 2002 12:13:02 -0000      1.42
+++ patterns/patterns2.db       25 Aug 2002 19:54:29 -0000
@@ -2951,9 +2951,7 @@
 *A
 BO

-;!oplay_defend_both(*,A,B)
-
->add_attack_either_move(A,B);
+>test_attack_either_move(A,B)


 Pattern DD2
@@ -3002,7 +3000,7 @@
 ;oplay_attack(*,D) && oplay_attack_either(*,a,D,E)
 ;&& !oplay_defend_both(*,b,c,D,E)

->add_attack_either_move(D,E);
+>test_attack_either_move(D,E)


 Pattern DD4
@@ -3054,9 +3052,7 @@
 A*B
 ?o?

-;!oplay_defend_both(*,A,B)
-
->add_attack_either_move(A,B);
+>test_attack_either_move(A,B)


 Pattern DD7
@@ -3072,9 +3068,9 @@

 ;lib(d)<4 && (xlib(*)>1 || lib(d)<3)
 ;&& oplay_defend(*,A) && oplay_defend(*,B)
-;&& !oplay_defend_both(*,A,B) && !oplay_attack(*,c)
+;&& !oplay_attack(*,c)

->add_attack_either_move(A,B);
+>test_attack_either_move(A,B)


 Pattern DD8
@@ -3146,7 +3142,7 @@

 ; !attack(A) && !attack(B) && oplay_attack(*,A) && oplay_attack(*,B)

->add_attack_either_move(A,B)
+>test_attack_either_move(A,B)


 Pattern DD12
@@ -3169,7 +3165,7 @@
 ;lib(A)==3 && !oplay_attack(*,E) && oplay_attack(*,d,A)
 ;&& !oplay_defend_both(*,c,d,A,B)

->add_attack_either_move(A,B)
+>test_attack_either_move(A,B)


 Pattern DD13





reply via email to

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