gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] trymove pass


From: Gunnar Farnebäck
Subject: [gnugo-devel] trymove pass
Date: Wed, 17 Nov 2004 06:13:52 +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)

From time to time when I'm doing experiments I find it annoying that
it's not possible to trymove a pass. This patch adds that
functionality.

(It should be used with care though since it wastes a stack position
and might interfere with horizon effects avoidance code.)

- allow PASS_MOVE in trymove() and tryko()
- do_trymove() and popgo() revised

/Gunnar

Index: engine/board.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/board.c,v
retrieving revision 1.103
diff -u -r1.103 board.c
--- engine/board.c      13 Nov 2004 04:46:43 -0000      1.103
+++ engine/board.c      17 Nov 2004 05:00:32 -0000
@@ -596,30 +596,32 @@
 static int 
 do_trymove(int pos, int color, int ignore_ko)
 {
-  /* 1. The move must be inside the board and the color must be BLACK
-   * or WHITE.
-   */
-  ASSERT_ON_BOARD1(pos);
+  /* 1. The color must be BLACK or WHITE. */
   gg_assert(color == BLACK || color == WHITE);
  
-  /* Update the reading tree shadow. */
-  shadow[pos] = 1;
-
-  /* 2. The location must be empty. */
-  if (board[pos] != EMPTY)
-    return 0;
+  if (pos != PASS_MOVE) {
+    /* 2. Unless pass, the move must be inside the board. */
+    ASSERT_ON_BOARD1(pos);
+    
+    /* Update the reading tree shadow. */
+    shadow[pos] = 1;
 
-  /* 3. The location must not be the ko point, unless ignore_ko == 1. */
-  if (!ignore_ko && pos == board_ko_pos) {
-    if (board[WEST(pos)] == OTHER_COLOR(color)
-       || board[EAST(pos)] == OTHER_COLOR(color)) {
+    /* 3. The location must be empty. */
+    if (board[pos] != EMPTY)
       return 0;
+    
+    /* 4. The location must not be the ko point, unless ignore_ko == 1. */
+    if (!ignore_ko && pos == board_ko_pos) {
+      if (board[WEST(pos)] == OTHER_COLOR(color)
+         || board[EAST(pos)] == OTHER_COLOR(color)) {
+       return 0;
+      }
     }
-  }
 
-  /* 4. Test for suicide. */
-  if (is_suicide(pos, color))
-    return 0;
+    /* 5. Test for suicide. */
+    if (is_suicide(pos, color))
+      return 0;
+  }
   
   /* Check for stack overflow. */
   if (stackp >= MAXSTACK-2) {
@@ -666,17 +668,18 @@
   PUSH_VALUE(board_ko_pos);
   memcpy(&board_hash_stack[stackp], &board_hash, sizeof(board_hash));
 
-  if (board_ko_pos != NO_MOVE) {
+  if (board_ko_pos != NO_MOVE)
     hashdata_invert_ko(&board_hash, board_ko_pos);
-  }
+
   board_ko_pos = NO_MOVE;
   
-  PUSH_VALUE(black_captured);
-  PUSH_VALUE(white_captured);
-
-  ++stackp;
+  stackp++;
 
-  do_play_move(pos, color);
+  if (pos != PASS_MOVE) {
+    PUSH_VALUE(black_captured);
+    PUSH_VALUE(white_captured);
+    do_play_move(pos, color);
+  }
 
   return 1;
 }
@@ -697,14 +700,20 @@
 
   if (sgf_dumptree) {
     char buf[100];
+    int is_tryko = 0;
+    char *sgf_comment;
+    
+    if (sgfGetCharProperty(sgf_dumptree->lastnode, "C", &sgf_comment)
+       && strncmp(sgf_comment, "tryko:", 6) == 0)
+      is_tryko = 1;
+    
     gg_snprintf(buf, 100, "(next variation: %d)", count_variations);
     sgftreeAddComment(sgf_dumptree, buf);
     sgf_dumptree->lastnode = sgf_dumptree->lastnode->parent;
-    /* After tryko() we need to undo two pass nodes too. Since we have
-     * no other way to identify ko moves, we skip all pass nodes.
-     */
-    while (is_pass_node(sgf_dumptree->lastnode, board_size))
-      sgf_dumptree->lastnode = sgf_dumptree->lastnode->parent;
+
+    /* After tryko() we need to undo two pass nodes too. */
+    if (is_tryko)
+      sgf_dumptree->lastnode = sgf_dumptree->lastnode->parent->parent;
   }
 }
 
Index: interface/play_gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v
retrieving revision 1.157
diff -u -r1.157 play_gtp.c
--- interface/play_gtp.c        16 Nov 2004 19:41:59 -0000      1.157
+++ interface/play_gtp.c        17 Nov 2004 05:00:36 -0000
@@ -1160,7 +1160,7 @@
 {
   int i, j;
   int color;
-  if (!gtp_decode_move(s, &color, &i, &j) || POS(i, j) == PASS_MOVE)
+  if (!gtp_decode_move(s, &color, &i, &j))
     return gtp_failure("invalid color or coordinate");
 
   if (!trymove(POS(i, j), color, "gtp_trymove", NO_MOVE))




reply via email to

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