gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] does_attack() made ko aware


From: Gunnar Farnebäck
Subject: [gnugo-devel] does_attack() made ko aware
Date: Thu, 18 Nov 2004 03:22:23 +0100
User-agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/21.3 (sparc-sun-solaris2.9) MULE/5.0 (SAKAKI)

This patch makes does_attack() ko aware, i.e. it returns the result
code for the specified attack move. As before it requires that the
target is not already captured, or more specifically that the result
code is improved compared to a tenuki.

The regression results are:

trevorc:1580    FAIL A5 [C8]
auto_handtalk:3 PASS 2 T15 [2 T15]
Total nodes: 1661173976 3061629 13215077 (+0.012% +0.042% +0.013%)

The failure is accidental. The difference is that after the patch the
owl attack of C4 (with ko) at B4 is correctly found.

The pass is a real improvement. There are still relevant variations
which are not tried but the simplest line is now correctly read.

The patch also adds does_attack and does_defend GTP commands.

- does_attack() made ko aware
- new GTP commands does_attack and does_defend

/Gunnar

Index: doc/gtp-commands.texi
===================================================================
RCS file: /cvsroot/gnugo/gnugo/doc/gtp-commands.texi,v
retrieving revision 1.25
diff -u -r1.25 gtp-commands.texi
--- doc/gtp-commands.texi       17 Nov 2004 20:12:42 -0000      1.25
+++ doc/gtp-commands.texi       18 Nov 2004 02:20:39 -0000
@@ -481,6 +481,30 @@
 
 @end example
 
address@hidden does_attack
address@hidden does_attack
+
address@hidden
+
+ Function:  Examine whether a specific move attacks a string tactically.
+ Arguments: vertex (move), vertex (dragon)
+ Fails:     invalid vertex, empty vertex
+ Returns:   attack code
+
address@hidden example
+
address@hidden does_defend
address@hidden does_defend
+
address@hidden
+
+ Function:  Examine whether a specific move defends a string tactically.
+ Arguments: vertex (move), vertex (dragon)
+ Fails:     invalid vertex, empty vertex
+ Returns:   attack code
+
address@hidden example
+
 @cindex ladder_attack
 @item ladder_attack
 
Index: engine/utils.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/utils.c,v
retrieving revision 1.100
diff -u -r1.100 utils.c
--- engine/utils.c      13 Nov 2004 04:46:45 -0000      1.100
+++ engine/utils.c      18 Nov 2004 02:20:44 -0000
@@ -84,9 +84,11 @@
 
 
 /*
- * does_attack(move, str) returns true if the move at (move)
- * attacks (str). This means that it captures the string, and that
- * (str) is not already dead.
+ * does_attack(move, str) returns the result code for an attack on the
+ * string 'str' by the move 'move'. However, if the move does not
+ * improve the attack result compared to tenuki, 0 is returned. In
+ * particular if the string is already captured, does_attack() always
+ * returns 0.
  */
 
 int
@@ -112,12 +114,18 @@
   }
   
   if (trymove(move, other, "does_attack-A", str)) {
-    if (!board[str] || !find_defense(str, NULL)) {
+    if (!board[str])
       result = WIN;
+    else
+      result = REVERSE_RESULT(find_defense(str, NULL));
+    if (result != 0) {
       increase_depth_values();
       if (spos != NO_MOVE && trymove(spos, color, "does_attack-B", str)) {
-       if (board[str] && !attack(str, NULL))
-         result = 0;
+       if (board[str]) {
+         int new_result = attack(str, NULL);
+         if (new_result < result)
+           result = new_result;
+       }
        popgo();
       }
       decrease_depth_values();
@@ -125,6 +133,9 @@
     popgo();
   }
 
+  if (result < acode)
+    result = 0;
+  
   return result;
 }
 
@@ -133,6 +144,8 @@
  * does_defend(move, str) returns true if the move at (move)
  * defends (str). This means that it defends the string, and that
  * (str) can be captured if no defense is made.
+ *
+ * FIXME: Make does_defend() ko aware like does_attack().
  */
 
 int
Index: interface/play_gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v
retrieving revision 1.158
diff -u -r1.158 play_gtp.c
--- interface/play_gtp.c        17 Nov 2004 20:12:42 -0000      1.158
+++ interface/play_gtp.c        18 Nov 2004 02:20:46 -0000
@@ -89,6 +89,8 @@
 DECLARE(gtp_defend);
 DECLARE(gtp_defend_both);
 DECLARE(gtp_disconnect);
+DECLARE(gtp_does_attack);
+DECLARE(gtp_does_defend);
 DECLARE(gtp_does_surround);
 DECLARE(gtp_dragon_data);
 DECLARE(gtp_dragon_status);
@@ -226,6 +228,8 @@
   {"defend",                         gtp_defend},
   {"defend_both",            gtp_defend_both},
   {"disconnect",                     gtp_disconnect},
+  {"does_attack",             gtp_does_attack},
+  {"does_defend",             gtp_does_defend},
   {"does_surround",           gtp_does_surround},
   {"dragon_data",             gtp_dragon_data},
   {"dragon_status",                  gtp_dragon_status},
@@ -1325,6 +1329,88 @@
 }  
 
 
+/* Function:  Examine whether a specific move attacks a string tactically.
+ * Arguments: vertex (move), vertex (dragon)
+ * Fails:     invalid vertex, empty vertex
+ * Returns:   attack code
+ */
+static int
+gtp_does_attack(char *s)
+{
+  int i, j;
+  int ti, tj;
+  int attack_code;
+  int n;
+
+  n = gtp_decode_coord(s, &ti, &tj);
+  if (n == 0)
+    return gtp_failure("invalid coordinate");
+
+  if (BOARD(ti, tj) != EMPTY)
+    return gtp_failure("move vertex must be empty");
+
+  n = gtp_decode_coord(s + n, &i, &j);
+  if (n == 0)
+    return gtp_failure("invalid coordinate");
+
+  if (BOARD(i, j) == EMPTY)
+    return gtp_failure("string vertex must not be empty");
+
+  if (stackp == 0)
+    silent_examine_position(EXAMINE_WORMS);
+  
+  /* to get the variations into the sgf file, clear the reading cache */
+  if (sgf_dumptree)
+    reading_cache_clear();
+  
+  attack_code = does_attack(POS(ti, tj), POS(i, j));
+  gtp_start_response(GTP_SUCCESS);
+  gtp_print_code(attack_code);
+  return gtp_finish_response();
+}  
+
+
+/* Function:  Examine whether a specific move defends a string tactically.
+ * Arguments: vertex (move), vertex (dragon)
+ * Fails:     invalid vertex, empty vertex
+ * Returns:   attack code
+ */
+static int
+gtp_does_defend(char *s)
+{
+  int i, j;
+  int ti, tj;
+  int defense_code;
+  int n;
+
+  n = gtp_decode_coord(s, &ti, &tj);
+  if (n == 0)
+    return gtp_failure("invalid coordinate");
+
+  if (BOARD(ti, tj) != EMPTY)
+    return gtp_failure("move vertex must be empty");
+
+  n = gtp_decode_coord(s + n, &i, &j);
+  if (n == 0)
+    return gtp_failure("invalid coordinate");
+
+  if (BOARD(i, j) == EMPTY)
+    return gtp_failure("string vertex must not be empty");
+
+  if (stackp == 0)
+    silent_examine_position(EXAMINE_WORMS);
+  
+  /* to get the variations into the sgf file, clear the reading cache */
+  if (sgf_dumptree)
+    reading_cache_clear();
+  
+  defense_code = does_defend(POS(ti, tj), POS(i, j));
+  gtp_start_response(GTP_SUCCESS);
+  gtp_print_code(defense_code);
+  return gtp_finish_response();
+}  
+
+
 /* Function:  Try to attack a string strictly in a ladder.
  * Arguments: vertex
  * Fails:     invalid vertex, empty vertex




reply via email to

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