gnugo-devel
[Top][All Lists]
Advanced

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

Re: [gnugo-devel] reading connections


From: Gunnar Farneback
Subject: Re: [gnugo-devel] reading connections
Date: Sat, 06 Oct 2001 22:01:02 +0200
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)

Tristan wrote:
> So maybe, we could have tests like this for the gtp :
> 
> 1 connect D8 D6
> #? [1 (F8|E8)]
> 2 disconnect D8 D6
> #? [1 E9]
> 
> calling functions that sends back the connection status and the
> associated moves ?

Yes. I had thought this would be the recursive_connect() and
recursive_disconnect() functions, but I now see that those only can
return status, not the effective move.

Not letting that stop me I changed these functions to have these
declarations:

int recursive_connect(int str1, int str2, int *move);
int recursive_disconnect(int str1, int str2, int *move);

Instead of passing around a connect_depth parameter, I have changed
the code to use the global variable stackp, which tells how many
trymove() calls are currently in effect. This is the normal way to
measure call depth in the GNU Go reading functions.

This patch makes the above mentioned changes and also implements the
gtp commands connect and disconnect. They certainly don't work
currently, but this should give a framework for testing the code. The
patch is in the CVS.

/Gunnar

Index: ChangeLog
===================================================================
RCS file: /cvsroot/gnugo/gnugo/ChangeLog,v
retrieving revision 1.37
diff -u -r1.37 ChangeLog
--- ChangeLog   2001/10/06 19:16:00     1.37
+++ ChangeLog   2001/10/06 19:58:33
@@ -2,6 +2,7 @@
 -- ChangeLog
 -------------------------------------------------------------------------
 
+- new gtp functions connect and disconnect
 - naive_ladder() made global
 - warnings eliminated from readconnect.c
 - most functions in readconnect.c made static
Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.26
diff -u -r1.26 liberty.h
--- engine/liberty.h    2001/10/06 19:16:00     1.26
+++ engine/liberty.h    2001/10/06 19:58:36
@@ -253,8 +253,8 @@
 void reading_hotspots(float values[MAX_BOARD][MAX_BOARD]);
 
 /* readconnect.c */
-int recursive_connect(int str1, int str2, int connect_depth);
-int recursive_disconnect(int str1, int str2, int connect_depth);
+int recursive_connect(int str1, int str2, int *move);
+int recursive_disconnect(int str1, int str2, int *move);
 
 
 int liberty_of_string(int pos, int str);
@@ -298,8 +298,6 @@
 void find_cuts(void);
 void find_connections(void);
 void modify_eye_spaces(void);
-int recursive_connect (int str1, int str2, int connect_depth);
-int recursive_disconnect (int str1, int str2, int connect_depth);
 
 /* functions to add (or remove) move reasons */
 void clear_move_reasons(void);
Index: engine/readconnect.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/readconnect.c,v
retrieving revision 1.2
diff -u -r1.2 readconnect.c
--- engine/readconnect.c        2001/10/06 19:16:00     1.2
+++ engine/readconnect.c        2001/10/06 19:58:37
@@ -321,7 +321,7 @@
 
 /* returns 1 if str1 and str2 can be connected */
 
-int recursive_connect (int str1, int str2, int connect_depth) {
+int recursive_connect (int str1, int str2, int *move) {
   int i, res = 0, Moves[MAX_MOVES], ForcedMoves[MAX_MOVES];
   
   if ( (board[str1] == EMPTY) || (board[str2] == EMPTY) )
@@ -330,7 +330,7 @@
     return 1;
   if (nodes_connect > max_nodes_connect)
     return 0;
-  if (connect_depth == max_connect_depth)
+  if (stackp == max_connect_depth)
     return 0;
 
   nodes_connect++;
@@ -356,7 +356,7 @@
 
   for (i = 1; ((i < Moves[0] + 1) && (res == 0)); i++) {
     if (trymove(Moves[i], board[str1], NULL, 0, EMPTY, 0)) {
-      if (!recursive_disconnect(str1, str2, connect_depth+1))
+      if (!recursive_disconnect(str1, str2, move))
        res = 1;
       popgo();
     }
@@ -366,7 +366,7 @@
   
 /* returns 1 if str1 and str2 can be disconnected */
 
-int recursive_disconnect (int str1, int str2, int connect_depth) {
+int recursive_disconnect (int str1, int str2, int *move) {
   int i, res = 1, Moves[MAX_MOVES];
   
   if ((board[str1] == EMPTY) || (board[str2] == EMPTY))
@@ -381,7 +381,7 @@
     return 0;
   if (nodes_connect > max_nodes_connect)
     return 1;
-  if (connect_depth == max_connect_depth)
+  if (stackp == max_connect_depth)
     return 1;
   
   nodes_connect++;
@@ -398,7 +398,7 @@
   if (res == 0)
     for (i = 1; ((i < Moves[0] + 1) && (res == 0)); i++)
       if (trymove(Moves[i], OTHER_COLOR(board[str1]), NULL, 0, EMPTY, 0)) {
-       if (!recursive_connect(str1, str2, connect_depth + 1))
+       if (!recursive_connect(str1, str2, move))
          res=1;
        popgo();
       }
Index: interface/play_gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v
retrieving revision 1.20
diff -u -r1.20 play_gtp.c
--- interface/play_gtp.c        2001/10/04 18:38:53     1.20
+++ interface/play_gtp.c        2001/10/06 19:58:39
@@ -68,11 +68,13 @@
 DECLARE(gtp_all_legal);
 DECLARE(gtp_attack);
 DECLARE(gtp_combination_attack);
+DECLARE(gtp_connect);
 DECLARE(gtp_countlib);
 DECLARE(gtp_debug_influence);
 DECLARE(gtp_debug_move_influence);
 DECLARE(gtp_decrease_depths);
 DECLARE(gtp_defend);
+DECLARE(gtp_disconnect);
 DECLARE(gtp_dragon_data);
 DECLARE(gtp_dragon_status);
 DECLARE(gtp_dragon_stones);
@@ -137,11 +139,13 @@
   {"boardsize",                      gtp_set_boardsize},
   {"color",                          gtp_what_color},
   {"combination_attack",      gtp_combination_attack},
+  {"connect",                gtp_connect},
   {"countlib",                       gtp_countlib},
   {"debug_influence",         gtp_debug_influence},
   {"debug_move_influence",    gtp_debug_move_influence},
   {"decrease_depths",                gtp_decrease_depths},
   {"defend",                         gtp_defend},
+  {"disconnect",                     gtp_disconnect},
   {"dragon_data",             gtp_dragon_data},
   {"dragon_status",                  gtp_dragon_status},
   {"dragon_stones",           gtp_dragon_stones},
@@ -836,6 +840,84 @@
   }
   if (!result_certain && report_uncertainty)
     gtp_printf(" uncertain");
+  return gtp_finish_response();
+}  
+
+
+/***********************
+ * Connection reading. *
+ ***********************/
+
+/* Function:  Try to connect two strings.
+ * Arguments: vertex, vertex
+ * Fails:     invalid vertex, empty vertex, vertices of different colors
+ * Returns:   connect result followed by connect point if successful.
+ */
+static int
+gtp_connect(char *s, int id)
+{
+  int ai, aj;
+  int bi, bj;
+  int connect_move = PASS_MOVE;
+  int result;
+  int n;
+  
+  n = gtp_decode_coord(s, &ai, &aj);
+  if (n == 0)
+    return gtp_failure(id, "invalid coordinate");
+
+  if (!gtp_decode_coord(s + n, &bi, &bj))
+    return gtp_failure(id, "invalid coordinate");
+
+  if (BOARD(ai, aj) == EMPTY || BOARD(bi, bj) == EMPTY)
+    return gtp_failure(id, "vertex must not be empty");
+
+  if (BOARD(ai, aj) != BOARD(bi, bj))
+    return gtp_failure(id, "vertices must have same color");
+
+  result = recursive_connect(POS(ai, aj), POS(bi, bj), &connect_move);
+  gtp_printid(id, GTP_SUCCESS);
+  gtp_printf("%d", result);
+  if (result != 0)
+    gtp_mprintf(" %m", I(connect_move), J(connect_move));
+
+  return gtp_finish_response();
+}  
+
+
+/* Function:  Try to disconnect two strings.
+ * Arguments: vertex, vertex
+ * Fails:     invalid vertex, empty vertex, vertices of different colors
+ * Returns:   disconnect result followed by disconnect point if successful.
+ */
+static int
+gtp_disconnect(char *s, int id)
+{
+  int ai, aj;
+  int bi, bj;
+  int disconnect_move = PASS_MOVE;
+  int result;
+  int n;
+  
+  n = gtp_decode_coord(s, &ai, &aj);
+  if (n == 0)
+    return gtp_failure(id, "invalid coordinate");
+
+  if (!gtp_decode_coord(s + n, &bi, &bj))
+    return gtp_failure(id, "invalid coordinate");
+
+  if (BOARD(ai, aj) == EMPTY || BOARD(bi, bj) == EMPTY)
+    return gtp_failure(id, "vertex must not be empty");
+
+  if (BOARD(ai, aj) != BOARD(bi, bj))
+    return gtp_failure(id, "vertices must have same color");
+
+  result = recursive_disconnect(POS(ai, aj), POS(bi, bj), &disconnect_move);
+  gtp_printid(id, GTP_SUCCESS);
+  gtp_printf("%d", result);
+  if (result != 0)
+    gtp_mprintf(" %m", I(disconnect_move), J(disconnect_move));
+
   return gtp_finish_response();
 }  
 



reply via email to

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