gnugo-devel
[Top][All Lists]
Advanced

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

Re: [gnugo-devel] Patch: new cache


From: Arend Bayer
Subject: Re: [gnugo-devel] Patch: new cache
Date: Tue, 5 Aug 2003 19:16:39 +0200 (CEST)

On Tue, 5 Aug 2003 address@hidden wrote:

>
> > Just changing the 4 above to 7 is of course not a solution, as this
> > will certainly get overlooked in case someone changed the komaster
> > scheme once again.
>
> Maybe it help to put a comment pointing out this constraint where the
> komaster scheme is defined.

And a comment pointing back from hash.c to the komaster schemes, yes.
But I always feel that the need for such cross-commenting points out
bad design.

I wrote:
> What I suggest to do is the following (I saw this in the gcc sources):
>
> We should create a new file defs.h. This should collect a load of
> stuff that is currently scattered over the code in the following form:

I assume this is more easily discussed with a patch. This does not yet
convert the komaster status to an enum, only because I don't want
to clash with gunnar_5_1.3. But this will work exactly as the
NUM_CACHE_ROUTINES already used in the patch.


Arend

- move declarations needed for libboard from liberty.h to new file board.h
- ..._to_string function converted to use machinery from defs.h
- new file defs.h to define enum's for status, safety, ... and
  corresponding arrays of names


Index: engine/Makefile.am
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/Makefile.am,v
retrieving revision 1.20
diff -u -p -r1.20 Makefile.am
--- engine/Makefile.am  2 Jun 2003 23:49:47 -0000       1.20
+++ engine/Makefile.am  5 Aug 2003 17:09:22 -0000
@@ -10,7 +10,7 @@ INCLUDES = \
        -I$(top_srcdir)/utils

 noinst_HEADERS = cache.h gnugo.h hash.h clock.h readconnect.h \
-                 influence.h liberty.h move_reasons.h
+                 influence.h liberty.h move_reasons.h board.h defs.h

 # preconfigured settings for various configurations
 noinst_LIBRARIES = libengine.a libboard.a
Index: engine/Makefile.in
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/Makefile.in,v
retrieving revision 1.46
diff -u -p -r1.46 Makefile.in
--- engine/Makefile.in  2 Aug 2003 14:17:52 -0000       1.46
+++ engine/Makefile.in  5 Aug 2003 17:09:22 -0000
@@ -89,7 +89,7 @@ INCLUDES = \


 noinst_HEADERS = cache.h gnugo.h hash.h clock.h readconnect.h \
-                 influence.h liberty.h move_reasons.h
+                 influence.h liberty.h move_reasons.h board.h defs.h


 # preconfigured settings for various configurations
Index: engine/board.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/board.c,v
retrieving revision 1.82
diff -u -p -r1.82 board.c
--- engine/board.c      4 Aug 2003 23:49:18 -0000       1.82
+++ engine/board.c      5 Aug 2003 17:09:25 -0000
@@ -35,7 +35,7 @@
 #include <stdlib.h>
 #include <stdarg.h>

-#include "liberty.h"
+#include "board.h"
 #include "hash.h"
 #include "sgftree.h"
 #include "gg_utils.h"
Index: engine/board.h
===================================================================
RCS file: engine/board.h
diff -N engine/board.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ engine/board.h      5 Aug 2003 17:09:26 -0000
@@ -0,0 +1,336 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
+ * This is GNU Go, a Go program. Contact address@hidden, or see       *
+ * http://www.gnu.org/software/gnugo/ for more information.          *
+ *                                                                   *
+ * Copyright 1999, 2000, 2001, 2002 and 2003                         *
+ * by the Free Software Foundation.                                  *
+ *                                                                   *
+ * This program is free software; you can redistribute it and/or     *
+ * modify it under the terms of the GNU General Public License as    *
+ * published by the Free Software Foundation - version 2             *
+ *                                                                   *
+ * This program is distributed in the hope that it will be useful,   *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     *
+ * GNU General Public License in file COPYING for more details.      *
+ *                                                                   *
+ * You should have received a copy of the GNU General Public         *
+ * License along with this program; if not, write to the Free        *
+ * Software Foundation, Inc., 59 Temple Place - Suite 330,           *
+ * Boston, MA 02111, USA.                                            *
+\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+#ifndef _BOARD_H_
+#define _BOARD_H_
+
+/* We need the defition of Hash_data here. */
+#include "hash.h"
+
+
+/* Define if you want the new transposition table. */
+#define USE_HASHTABLE_NG
+
+/* local versions of absolute value, min and max */
+
+#define gg_abs(x) ((x) < 0 ? -(x) : (x))
+#define gg_min(a, b) ((a)<(b) ? (a) : (b))
+#define gg_max(a, b) ((a)<(b) ? (b) : (a))
+
+/* Avoid compiler warnings with unused parameters */
+#define UNUSED(x)  (void)x
+
+
+/* A string with n stones can have at most 2(n+1) liberties. From this
+ * follows that an upper bound on the number of liberties of a string
+ * on a board of size N^2 is 2/3 (N^2+1).
+ */
+#define MAXLIBS   (2*(MAX_BOARD*MAX_BOARD + 1)/3)
+/* This is a smaller, practical number of liberties that we care to keep track 
of. */
+#define MAX_LIBERTIES 20
+
+
+/* This is an upper bound of the number of strings that can exist on
+ * the board simultaneously.
+ * FIXME: This is not sufficiently large;  above stackp==0, the incremental
+ *   board code doesn't necessarily re-use all indices.  This is a problem
+ *   only in very pathological cases, and is extremely unlikely to occur in
+ *   practice.
+ */
+#define MAX_STRINGS (2 * MAX_BOARD * MAX_BOARD / 3)
+
+/* Per gf: Unconditional_life() can get very close to filling the
+ * entire board under certain circumstances. This was discussed in
+ * the list around August 21, 2001, in a thread with the subject
+ * "gnugo bug logs".
+ */
+#define MAXSTACK  MAX_BOARD * MAX_BOARD
+#define MAXCHAIN  160
+
+
+/* ================================================================ *
+ *                         One-dimensional board                    *
+ * ================================================================ */
+
+/* Note that POS(-1, -1) == 0
+ * DELTA() is defined so that POS(i+di, j+dj) = POS(i, j) + DELTA(di, dj).
+ */
+#define BOARDSIZE     ((MAX_BOARD + 2) * (MAX_BOARD + 1) + 1)
+#define BOARDMIN      (MAX_BOARD + 2)
+#define BOARDMAX      (MAX_BOARD + 1) * (MAX_BOARD + 1)
+#define POS(i, j)     ((MAX_BOARD + 2) + (i) * (MAX_BOARD + 1) + (j))
+#define DELTA(di, dj) ((di) * (MAX_BOARD + 1) + (dj))
+#define I(pos)        ((pos) / (MAX_BOARD + 1) - 1)
+#define J(pos)        ((pos) % (MAX_BOARD + 1) - 1)
+#define PASS_MOVE     0
+#define NO_MOVE       PASS_MOVE
+#define NS            (MAX_BOARD + 1)
+#define WE            1
+#define SOUTH(pos)    ((pos) + NS)
+#define WEST(pos)     ((pos) - 1)
+#define NORTH(pos)    ((pos) - NS)
+#define EAST(pos)     ((pos) + 1)
+#define SW(pos)       ((pos) + NS - 1)
+#define NW(pos)       ((pos) - NS - 1)
+#define NE(pos)       ((pos) - NS + 1)
+#define SE(pos)       ((pos) + NS + 1)
+#define SS(pos)       ((pos) + 2 * NS)
+#define WW(pos)       ((pos) - 2)
+#define NN(pos)       ((pos) - 2 * NS)
+#define EE(pos)       ((pos) + 2)
+
+#define BOARD(i, j)   board[POS(i, j)]
+
+/* Transformation stuff. */
+#define MAX_OFFSET                     (2*MAX_BOARD - 1) * (2*MAX_BOARD - 1)
+#define OFFSET(dx, dy)\
+  ((dy + MAX_BOARD - 1) * (2*MAX_BOARD - 1) + (dx + MAX_BOARD - 1))
+#define OFFSET_DELTA(dx, dy)           (OFFSET(dx, dy) - OFFSET(0, 0))
+#define CENTER_OFFSET(offset)          (offset - OFFSET(0, 0))
+#define TRANSFORM(offset, trans)       (transformation[offset][trans])
+#define AFFINE_TRANSFORM(offset, trans, delta)\
+  (transformation[offset][trans] + delta)
+#define TRANSFORM2(x, y, tx, ty, trans)\
+  do {\
+    *tx = transformation2[trans][0][0] * (x) + transformation2[trans][0][1] * 
(y);\
+    *ty = transformation2[trans][1][0] * (x) + transformation2[trans][1][1] * 
(y);\
+  } while (0)
+
+
+/* ================================================================ */
+/*                         global variables                         */
+/* ================================================================ */
+
+/* The board and the other parameters deciding the current position. */
+extern int          board_size;             /* board size (usually 19) */
+extern Intersection board[BOARDSIZE];       /* go board */
+extern int          board_ko_pos;
+extern int          black_captured;   /* num. of black stones captured */
+extern int          white_captured;
+
+extern Intersection initial_board[BOARDSIZE];
+extern int          initial_board_ko_pos;
+extern int          initial_white_captured;
+extern int          initial_black_captured;
+extern int          move_history_color[MAX_MOVE_HISTORY];
+extern int          move_history_pos[MAX_MOVE_HISTORY];
+extern int          move_history_pointer;
+
+extern float        komi;
+extern int          movenum;      /* movenumber - used for debug output */
+
+extern Intersection shadow[BOARDMAX];      /* reading tree shadow */
+
+
+extern int chinese_rules;
+
+extern int stackp;                /* stack pointer */
+extern int count_variations;      /* count (decidestring) */
+extern SGFTree *sgf_dumptree;
+
+extern Hash_data    hashdata;
+extern Hashvalue_ng hashval_ng;
+
+extern int          transformation[MAX_OFFSET][8];
+extern const int    transformation2[8][2][2];
+
+
+
+
+/* This struct holds the internal board state.
+ */
+struct board_state {
+  int board_size;
+
+  Intersection board[BOARDSIZE];
+  int board_ko_pos;
+  int black_captured;
+  int white_captured;
+
+  Intersection initial_board[BOARDSIZE];
+  int initial_board_ko_pos;
+  int initial_white_captured;
+  int initial_black_captured;
+  int move_history_color[MAX_MOVE_HISTORY];
+  int move_history_pos[MAX_MOVE_HISTORY];
+  int move_history_pointer;
+
+  float komi;
+  int move_number;
+};
+
+
+/* board utility functions */
+int find_origin(int str);
+int chainlinks(int str, int adj[MAXCHAIN]);
+int chainlinks2(int str, int adj[MAXCHAIN], int lib);
+int chainlinks3(int str, int adj[MAXCHAIN], int lib);
+int extended_chainlinks(int str, int adj[MAXCHAIN], int both_colors);
+
+
+/* This is increased by one anytime a move is (permanently) played or
+ * the board is cleared.
+ */
+extern int position_number;
+
+
+/* Detect vertex on edge or corner. */
+int is_edge_vertex(int pos);
+int is_corner_vertex(int pos);
+int edge_distance(int pos);
+
+
+/* Count and/or find liberties at (pos). */
+int countlib(int str);
+int findlib(int str, int maxlib, int *libs);
+int fastlib(int pos, int color, int ignore_captures);
+int approxlib(int pos, int color, int maxlib, int *libs);
+int accuratelib(int pos, int color, int maxlib, int *libs);
+int count_common_libs(int str1, int str2);
+int find_common_libs(int str1, int str2, int maxlib, int *libs);
+int have_common_lib(int str1, int str2, int *lib);
+
+
+/* Check for self atari. */
+int is_self_atari(int pos, int color);
+
+/* Count the number of stones in a string. */
+int countstones(int str);
+int findstones(int str, int maxstones, int *stones);
+
+/* Exported from incremental_board.c so that reading.c can use it. */
+void incremental_order_moves(int move, int color, int string,
+                            int *number_edges, int *number_same_string,
+                            int *number_own, int *number_opponent,
+                            int *captured_stones, int *threatened_stones,
+                            int *saved_stones, int *number_open);
+
+/* Board caches initialization functions. */
+void clear_approxlib_cache(void);
+void clear_accuratelib_cache(void);
+
+
+void dump_stack(void);
+
+int square_dist(int pos1, int pos2);
+
+/* Is this point inside the board? */
+#if 0
+#define ON_BOARD2(i, j) ((i)>=0 && (j)>=0 && (i)<board_size && (j)<board_size)
+#else
+/*
+ * For the case when expr can only be slightly negative,
+ *    if (expr < 0 || expr > something)
+ * is equivalent to
+ *    if ((unsigned) expr > something)
+ *
+ * (I think gcc knows this trick, but it does no harm to
+ *  encode it explicitly since it saves typing !)
+ */
+#define ON_BOARD2(i, j) ((unsigned) (i) < (unsigned) board_size &&\
+                        (unsigned) (j) < (unsigned) board_size)
+#endif
+
+#define ASSERT_ON_BOARD2(i, j) ASSERT2(ON_BOARD2((i), (j)), (i), (j))
+
+#define ON_BOARD1(pos) (((unsigned) (pos) < BOARDSIZE) && board[pos] != GRAY)
+#define ON_BOARD(pos) (board[pos] != GRAY)
+#define ASSERT_ON_BOARD1(pos) ASSERT1(ON_BOARD1(pos), (pos))
+
+/* Coordinates for the eight directions, ordered
+ * south, west, north, east, southwest, northwest, northeast, southeast.
+ * Defined in utils.c.
+ */
+extern int deltai[8]; /* = { 1,  0, -1,  0,  1, -1, -1, 1}; */
+extern int deltaj[8]; /* = { 0, -1,  0,  1, -1, -1,  1, 1}; */
+extern int delta[8];  /* = { NS, -1, -NS, 1, NS-1, -NS-1, -NS+1, NS+1}; */
+
+void store_board(struct board_state *state);
+void restore_board(struct board_state *state);
+
+/* board.c */
+int liberty_of_string(int pos, int str);
+int second_order_liberty_of_string(int pos, int str);
+int neighbor_of_string(int pos, int str);
+int has_neighbor(int pos, int color);
+int same_string(int str1, int str2);
+int adjacent_strings(int str1, int str2);
+int is_ko(int pos, int color, int *ko_pos);
+int is_ko_point(int pos);
+int komaster_trymove(int pos, int color,
+                    const char *message, int str,
+                    int komaster, int kom_pos,
+                    int *new_komaster, int *new_kom_pos,
+                    int *is_conditional_ko, int consider_conditional_ko);
+int does_capture_something(int pos, int color);
+void mark_string(int str, char mx[BOARDMAX], char mark);
+int move_in_stack(int pos, int cutoff);
+void get_move_from_stack(int k, int *move, int *color);
+int stones_on_board(int color);
+
+/* SGF routines for debugging purposes in sgffile.c */
+void sgffile_begindump(struct SGFTree_t *tree);
+void sgffile_enddump(const char *filename);
+
+
+/* Hashing and Caching statistics. */
+struct stats_data {
+  int nodes;                     /* Number of visited nodes while reading */
+  int position_entered;          /* Number of Positions entered. */
+  int position_hits;             /* Number of hits of Positions. */
+  int read_result_entered;       /* Number of Read_results entered. */
+  int read_result_hits;          /* Number of hits of Read_results. */
+  int hash_collisions;           /* Number of hash collisions. */
+};
+
+extern struct stats_data stats;
+
+/* ================================================================ */
+/*                         assertions                               */
+/* ================================================================ */
+
+/* Our own abort() which prints board state on the way out.
+ * (pos) is a "relevant" board position for info.
+ */
+void abortgo(const char *file, int line, const char *msg, int pos);
+
+#ifdef GG_TURN_OFF_ASSERTS
+#define ASSERT2(x, i, j)
+#define ASSERT1(x, pos)
+#else
+/* avoid dangling else */
+/* FIXME: Should probably re-write these using do {...} while (0) idiom. */
+#define ASSERT2(x, i, j) if (x) ; else abortgo(__FILE__, __LINE__, #x, POS(i, 
j))
+#define ASSERT1(x, pos) if (x) ; else abortgo(__FILE__, __LINE__, #x, pos)
+#endif
+
+#define gg_assert(x) ASSERT1(x, NO_MOVE);
+
+#endif  /* _BOARD_H_ */
+
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * c-basic-offset: 2
+ * End:
+ */
Index: engine/cache.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/cache.c,v
retrieving revision 1.27
diff -u -p -r1.27 cache.c
--- engine/cache.c      4 Aug 2003 23:49:18 -0000       1.27
+++ engine/cache.c      5 Aug 2003 17:09:27 -0000
@@ -519,7 +519,7 @@ hashnode_unlink_closed_results(Hashnode
   /* Traverse all node results. */
   do {
     unsigned int result_remaining_depth = rr_get_remaining_depth(*result);
-    int result_routine = rr_get_routine(*result);
+    enum cache_routine result_routine = rr_get_routine(*result);

     if (debug & DEBUG_READING_PERFORMANCE) {
       int stat_stackp = depth - result_remaining_depth;
@@ -529,7 +529,6 @@ hashnode_unlink_closed_results(Hashnode
       if (stat_stackp < 0)
        stat_stackp = 0;

-      gg_assert(result_routine >= 0 && result_routine < NUM_ROUTINES);
       statistics[result_routine][stat_stackp]++;
     }

@@ -568,12 +567,12 @@ hashtable_partially_clear(Hashtable *tab
   Hashnode *node;
   const int remaining_depth_limit = depth - 3;

-  int statistics[NUM_ROUTINES][20];
+  int statistics[NUM_CACHE_ROUTINES][20];

   if (debug & DEBUG_READING_PERFORMANCE) {
     gprintf("Hashtable cleared because it became full.\n");

-    for (k = 0; k < NUM_ROUTINES; ++k)
+    for (k = 0; k < NUM_CACHE_ROUTINES; ++k)
       for (l = 0; l < 20; ++l)
        statistics[k][l] = 0;
   }
@@ -627,7 +626,7 @@ hashtable_partially_clear(Hashtable *tab

     fprintf(stderr, "routine        total     0     1     2     3     4     5  
   6     7     8     9    10    11    12    13    14    15    16    17    18    
19\n");

-    for (k = 0; k < NUM_ROUTINES; ++k) {
+    for (k = 0; k < NUM_CACHE_ROUTINES; ++k) {
       total = 0;
       for (l = 0; l < 20; ++l)
        total += statistics[k][l];
Index: engine/cache.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/cache.h,v
retrieving revision 1.32
diff -u -p -r1.32 cache.h
--- engine/cache.h      4 Aug 2003 23:49:18 -0000       1.32
+++ engine/cache.h      5 Aug 2003 17:09:27 -0000
@@ -470,38 +470,6 @@ int get_read_result2(int routine, int ko

 #endif

-/* ================================================================ */
-/* Routine numbers. */
-
-#define OWL_ATTACK      0
-#define OWL_DEFEND      1
-#define SEMEAI          2
-
-#define FIND_DEFENSE    3
-#define ATTACK          4
-
-#define CONNECT         5
-#define DISCONNECT      6
-
-#define BREAK_IN       7
-#define BLOCK_OFF      8
-
-#define MAX_ROUTINE     BLOCK_OFF
-#define NUM_ROUTINES    (MAX_ROUTINE + 1)
-
-
-/* Routine numbers for the persistent owl cache, in addition to
- * OWL_ATTACK and OWL_DEFEND defined above.
- */
-#define OWL_THREATEN_ATTACK    2
-#define OWL_THREATEN_DEFENSE   3
-#define OWL_DOES_DEFEND        4
-#define OWL_DOES_ATTACK        5
-#define OWL_CONNECTION_DEFENDS 6
-#define OWL_SUBSTANTIAL        7
-#define OWL_CONFIRM_SAFETY     8
-
-

 /* ================================================================ */
 /* This has actually nothing to do with caching, but is useful in
Index: engine/defs.h
===================================================================
RCS file: engine/defs.h
diff -N engine/defs.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ engine/defs.h       5 Aug 2003 17:09:27 -0000
@@ -0,0 +1,87 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
+ * This is GNU Go, a Go program. Contact address@hidden, or see       *
+ * http://www.gnu.org/software/gnugo/ for more information.          *
+ *                                                                   *
+ * Copyright 1999, 2000, 2001, 2002 and 2003                         *
+ * by the Free Software Foundation.                                  *
+ *                                                                   *
+ * This program is free software; you can redistribute it and/or     *
+ * modify it under the terms of the GNU General Public License as    *
+ * published by the Free Software Foundation - version 2             *
+ *                                                                   *
+ * This program is distributed in the hope that it will be useful,   *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     *
+ * GNU General Public License in file COPYING for more details.      *
+ *                                                                   *
+ * You should have received a copy of the GNU General Public         *
+ * License along with this program; if not, write to the Free        *
+ * Software Foundation, Inc., 59 Temple Place - Suite 330,           *
+ * Boston, MA 02111, USA.                                            *
+\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+#ifndef DEFINE_CACHE_ROUTINE
+#define DEFINE_CACHE_ROUTINE(id, name)
+#endif
+
+DEFINE_CACHE_ROUTINE(OWL_ATTACK, "owl_attack")
+DEFINE_CACHE_ROUTINE(OWL_DEFEND, "owl_defend")
+DEFINE_CACHE_ROUTINE(SEMEAI, "semeai")
+DEFINE_CACHE_ROUTINE(FIND_DEFENSE, "find_defense")
+DEFINE_CACHE_ROUTINE(ATTACK, "attack")
+DEFINE_CACHE_ROUTINE(CONNECT, "connect")
+DEFINE_CACHE_ROUTINE(DISCONNECT, "disconnect")
+DEFINE_CACHE_ROUTINE(BREAK_IN, "break_in")
+DEFINE_CACHE_ROUTINE(BLOCK_OFF, "block_off")
+
+#undef DEFINE_CACHE_ROUTINE
+
+
+#ifndef DEFINE_OWL_ROUTINE
+#define DEFINE_OWL_ROUTINE(id, name)
+#endif
+
+DEFINE_OWL_ROUTINE(OWL_ATTACK_P, "owl_attack")
+DEFINE_OWL_ROUTINE(OWL_DEFEND_P, "owl_defend")
+DEFINE_OWL_ROUTINE(OWL_THREATEN_ATTACK, "owl_threaten_attack")
+DEFINE_OWL_ROUTINE(OWL_THREATEN_DEFENSE, "owl_threatend_defense")
+DEFINE_OWL_ROUTINE(OWL_DOES_DEFEND, "owl_does_defend")
+DEFINE_OWL_ROUTINE(OWL_DOES_ATTACK, "owl_does_attack")
+DEFINE_OWL_ROUTINE(OWL_CONNECTION_DEFENDS, "owl_connection_defends")
+DEFINE_OWL_ROUTINE(OWL_SUBSTANTIAL, "owl_substantial")
+DEFINE_OWL_ROUTINE(OWL_CONFIRM_SAFETY, "owl_confirm_safety")
+
+#undef DEFINE_OWL_ROUTINE
+
+
+#ifndef DEFINE_SAFETY_VALUE
+#define DEFINE_SAFETY_VALUE(id, name)
+#endif
+
+DEFINE_SAFETY_VALUE(DEAD_S, "dead")
+DEFINE_SAFETY_VALUE(ALIVE_S, "alive")
+DEFINE_SAFETY_VALUE(CRITICAL_S, "critical")
+DEFINE_SAFETY_VALUE(INESSENTIAL, "inessential")
+DEFINE_SAFETY_VALUE(TACTICALLY_DEAD, "tactically dead")
+DEFINE_SAFETY_VALUE(ALIVE_IN_SEKI, "alive in seki")
+DEFINE_SAFETY_VALUE(STRONGLY_ALIVE, "strongly alive")
+DEFINE_SAFETY_VALUE(INVINCIBLE, "invincible")
+DEFINE_SAFETY_VALUE(INSUBSTANTIAL, "insubstantial")
+
+#undef DEFINE_SAFETY_VALUE
+
+
+#ifndef DEFINE_DRAGON_STATUS
+#define DEFINE_DRAGON_STATUS(id, name)
+#endif
+
+DEFINE_DRAGON_STATUS(DEAD, "dead")
+DEFINE_DRAGON_STATUS(ALIVE, "alive")
+DEFINE_DRAGON_STATUS(CRITICAL, "critical")
+DEFINE_DRAGON_STATUS(UNKNOWN, "unknown")
+DEFINE_DRAGON_STATUS(UNCHECKED, "unchecked")
+DEFINE_DRAGON_STATUS(CAN_THREATEN_ATTACK, "can threaten attack")
+DEFINE_DRAGON_STATUS(CAN_THREATEN_DEFENSE, "can threaten defense")
+
+#undef DEFINE_DRAGON_STATUS
+
Index: engine/dragon.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/dragon.c,v
retrieving revision 1.119
diff -u -p -r1.119 dragon.c
--- engine/dragon.c     3 Aug 2003 08:03:12 -0000       1.119
+++ engine/dragon.c     5 Aug 2003 17:09:29 -0000
@@ -1435,13 +1435,6 @@ connected_to_eye_recurse(int pos, int st
 void
 show_dragons(void)
 {
-  static const char *snames[] =
-  {"dead", "alive", "critical", "unknown", "unchecked"};
-
-  static const char *safety_names[] =
-  {"dead", "alive", "critical", "[3]", "[4]", "inessential",
-   "tactically dead", "alive_in_seki", "strongly_alive", "invincible"};
-
   int pos;
   int k;

@@ -1531,14 +1524,14 @@ show_dragons(void)
              dd->effective_size,
              eyevalue_to_string(&d2->genus),
              d2->escape_route,
-             snames[dd->crude_status],
-             snames[dd->status],
+             status_to_string(dd->crude_status),
+             status_to_string(dd->status),
              d2->moyo_size,
              d2->moyo_territorial_value,
-             safety_names[d2->safety],
+             safety_to_string(d2->safety),
              d2->weakness_pre_owl,
              d2->weakness);
-      gprintf(", owl status %s\n", snames[d2->owl_status]);
+      gprintf(", owl status %s\n", status_to_string(d2->owl_status));
       if (d2->owl_status == CRITICAL) {
        gprintf("... owl attackable at %1m, code %d\n",
                d2->owl_attack_point, d2->owl_attack_code);
Index: engine/gnugo.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/gnugo.h,v
retrieving revision 1.100
diff -u -p -r1.100 gnugo.h
--- engine/gnugo.h      21 Jul 2003 16:33:19 -0000      1.100
+++ engine/gnugo.h      5 Aug 2003 17:09:30 -0000
@@ -85,23 +85,19 @@ void init_gnugo(float memory, unsigned i
 /* Used by break_through(). Must be different from 0 and WIN. */
 #define CUT  2

-/* Group statuses */
-#define DEAD        0
-#define ALIVE       1
-#define CRITICAL    2
-#define UNKNOWN     3
-#define UNCHECKED   4
-#define MAX_DRAGON_STATUS 4    /* used to size an array in matchpat.c */
-
-/* Dragon safety values. DEAD, ALIVE, and CRITICAL are reused. */
-#define INESSENTIAL     5
-#define TACTICALLY_DEAD 6
-#define ALIVE_IN_SEKI   7
-#define STRONGLY_ALIVE  8
-#define INVINCIBLE      9
-#define INSUBSTANTIAL   10
-#define CAN_THREATEN_ATTACK  11
-#define CAN_THREATEN_DEFENSE 12
+#define DEFINE_DRAGON_STATUS(id, name) id,
+enum dragon_status {
+#include "defs.h"
+  NUM_DRAGON_STATUS
+};
+
+#define DEFINE_SAFETY_VALUE(id, name)  id,
+enum safety_value {
+#include "defs.h"
+  NUM_SAFETIES
+};
+
+

 /* Surrounded */

@@ -340,6 +336,20 @@ void end_draw_board(void);
 void showboard(int xo);  /* ascii rep. of board to stderr */
 void simple_showboard(FILE *outfile);  /* ascii rep. of board to outfile */

+/* Necessary for routine names. */
+#define DEFINE_CACHE_ROUTINE(id, name)          id,
+enum cache_routine {
+#include "defs.h"
+  NUM_CACHE_ROUTINES
+};
+
+#define DEFINE_OWL_ROUTINE(id, name)            id,
+enum owl_routine {
+#include "defs.h"
+         NUM_OWL_ROUTINES
+};
+
+
 /* printutils.c */
 int gprintf(const char *fmt, ...);
 void mprintf(const char *fmt, ...);
@@ -347,10 +357,11 @@ void gfprintf(FILE *outfile, const char
 const char *color_to_string(int color);
 const char *location_to_string(int pos);
 void        location_to_buffer(int pos, char *buf);
-const char *status_to_string(int status);
-const char *safety_to_string(int status);
+const char *status_to_string(enum dragon_status status);
+const char *safety_to_string(enum safety_value safety);
 const char *result_to_string(int result);
-const char *routine_to_string(int routine);
+const char *owl_routine_to_string(enum owl_routine routine);
+const char *cache_routine_to_string(enum cache_routine routine);
 int string_to_location(int boardsize, char *str, int *m, int *n);
 double gg_gettimeofday(void);

Index: engine/hash.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/hash.c,v
retrieving revision 1.18
diff -u -p -r1.18 hash.c
--- engine/hash.c       4 Aug 2003 23:49:18 -0000       1.18
+++ engine/hash.c       5 Aug 2003 17:09:31 -0000
@@ -26,7 +26,7 @@
 #include <stdlib.h>
 #include <limits.h>

-#include "liberty.h"
+#include "board.h"
 #include "hash.h"
 #include "random.h"

@@ -43,11 +43,11 @@ static Hashvalue_ng  white_hash_ng[BOARD
 static Hashvalue_ng  black_hash_ng[BOARDMAX];
 static Hashvalue_ng  ko_hash_ng[BOARDMAX];

-static Hashvalue_ng  komaster_hash[4]; /* EMPTY, BLACK, WHITE, GRAY */
+static Hashvalue_ng  komaster_hash[8]; /* EMPTY, BLACK, WHITE, GRAY */
 static Hashvalue_ng  kom_pos_hash[BOARDMAX];
 static Hashvalue_ng  target1_hash[BOARDMAX];
 static Hashvalue_ng  target2_hash[BOARDMAX];
-static Hashvalue_ng  routine_hash[NUM_ROUTINES];
+static Hashvalue_ng  routine_hash[NUM_CACHE_ROUTINES];

 static struct init_struct {
   Hashvalue_ng  *array;
@@ -56,11 +56,11 @@ static struct init_struct {
   {white_hash_ng, BOARDMAX},
   {black_hash_ng, BOARDMAX},
   {ko_hash_ng,    BOARDMAX},
-  {komaster_hash, 4},
+  {komaster_hash, 8},
   {kom_pos_hash,  BOARDMAX},
   {target1_hash,  BOARDMAX},
   {target2_hash,  BOARDMAX},
-  {routine_hash,  NUM_ROUTINES},
+  {routine_hash,  NUM_CACHE_ROUTINES},
 };


@@ -140,7 +140,8 @@ hashvalue_ng_recalc(Intersection *p, int


 Hashvalue_ng
-calculate_hashval_ng(int komaster, int kom_pos, int routine, int target)
+calculate_hashval_ng(int komaster, int kom_pos,
+                    enum cache_routine routine, int target)
 {
   Hashvalue_ng  hashval;

Index: engine/hash.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/hash.h,v
retrieving revision 1.14
diff -u -p -r1.14 hash.h
--- engine/hash.h       4 Aug 2003 23:49:18 -0000       1.14
+++ engine/hash.h       5 Aug 2003 17:09:31 -0000
@@ -204,10 +204,10 @@ typedef uint64_t      Hashvalue_ng;

 #endif

-
 extern void          hash_ng_init(void);
 extern Hashvalue_ng  calculate_hashval_ng(int komaster, int kom_pos,
-                                         int routine, int target);
+                                         enum cache_routine routine,
+                                         int target);
 extern Hashvalue_ng  hashvalue_ng_recalc(Intersection *p, int ko_pos);
 extern Hashvalue_ng  hashvalue_ng_invert_ko(Hashvalue_ng hashval, int ko_pos);
 extern Hashvalue_ng  hashvalue_ng_invert_stone(Hashvalue_ng hashval,
Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.192
diff -u -p -r1.192 liberty.h
--- engine/liberty.h    4 Aug 2003 23:49:18 -0000       1.192
+++ engine/liberty.h    5 Aug 2003 17:09:32 -0000
@@ -23,36 +23,18 @@
 #ifndef _LIBERTY_H_
 #define _LIBERTY_H_

+#include "board.h"
 #include "gnugo.h"

-/* local versions of absolute value, min and max */
-
-#define gg_abs(x) ((x) < 0 ? -(x) : (x))
-#define gg_min(a, b) ((a)<(b) ? (a) : (b))
-#define gg_max(a, b) ((a)<(b) ? (b) : (a))
-
-/* Avoid compiler warnings with unused parameters */
-#define UNUSED(x)  (void)x
-
-
 /* ================================================================ */
 /*                           public variables                       */
 /* ================================================================ */


 /* We need the defintion of type Hash_data here. */
-#include "hash.h"
 #include "cache.h"
-
-/* Other modules get read-only access to this variable. */
-extern Hash_data     hashdata;
-extern Hashvalue_ng  hashval_ng;
 extern Transposition_table  ttable;

-/* Define if you want the new transposition table. */
-#define USE_HASHTABLE_NG
-
-
 /* ================================================================ */


@@ -61,161 +43,14 @@ extern Transposition_table  ttable;
 #define INHIBIT_CONNECTION 4


-/* A string with n stones can have at most 2(n+1) liberties. From this
- * follows that an upper bound on the number of liberties of a string
- * on a board of size N^2 is 2/3 (N^2+1).
- */
-#define MAXLIBS   (2*(MAX_BOARD*MAX_BOARD + 1)/3)
-/* This is a smaller, practical number of liberties that we care to keep track 
of. */
-#define MAX_LIBERTIES 20
-
-
-/* This is an upper bound of the number of strings that can exist on
- * the board simultaneously.
- * FIXME: This is not sufficiently large;  above stackp==0, the incremental
- *   board code doesn't necessarily re-use all indices.  This is a problem
- *   only in very pathological cases, and is extremely unlikely to occur in
- *   practice.
- */
-#define MAX_STRINGS (2 * MAX_BOARD * MAX_BOARD / 3)
-
-/* Per gf: Unconditional_life() can get very close to filling the
- * entire board under certain circumstances. This was discussed in
- * the list around August 21, 2001, in a thread with the subject
- * "gnugo bug logs".
- */
-#define MAXSTACK  MAX_BOARD * MAX_BOARD
-#define MAXCHAIN  160
-
-/* 1D board macros.
- * Note that POS(-1, -1) == 0
- * DELTA() is defined so that POS(i+di, j+dj) = POS(i, j) + DELTA(di, dj).
- */
-#define BOARDSIZE     ((MAX_BOARD + 2) * (MAX_BOARD + 1) + 1)
-#define BOARDMIN      (MAX_BOARD + 2)
-#define BOARDMAX      (MAX_BOARD + 1) * (MAX_BOARD + 1)
-#define POS(i, j)     ((MAX_BOARD + 2) + (i) * (MAX_BOARD + 1) + (j))
-#define DELTA(di, dj) ((di) * (MAX_BOARD + 1) + (dj))
-#define I(pos)        ((pos) / (MAX_BOARD + 1) - 1)
-#define J(pos)        ((pos) % (MAX_BOARD + 1) - 1)
-#define PASS_MOVE     0
-#define NO_MOVE       PASS_MOVE
-#define NS            (MAX_BOARD + 1)
-#define WE            1
-#define SOUTH(pos)    ((pos) + NS)
-#define WEST(pos)     ((pos) - 1)
-#define NORTH(pos)    ((pos) - NS)
-#define EAST(pos)     ((pos) + 1)
-#define SW(pos)       ((pos) + NS - 1)
-#define NW(pos)       ((pos) - NS - 1)
-#define NE(pos)       ((pos) - NS + 1)
-#define SE(pos)       ((pos) + NS + 1)
-#define SS(pos)       ((pos) + 2 * NS)
-#define WW(pos)       ((pos) - 2)
-#define NN(pos)       ((pos) - 2 * NS)
-#define EE(pos)       ((pos) + 2)
-
-#define BOARD(i, j)   board[POS(i, j)]
-
 #define REVERSE_RESULT(result)         (WIN - result)

-/* Transformation stuff. */
-#define MAX_OFFSET                     (2*MAX_BOARD - 1) * (2*MAX_BOARD - 1)
-#define OFFSET(dx, dy)\
-  ((dy + MAX_BOARD - 1) * (2*MAX_BOARD - 1) + (dx + MAX_BOARD - 1))
-#define OFFSET_DELTA(dx, dy)           (OFFSET(dx, dy) - OFFSET(0, 0))
-#define CENTER_OFFSET(offset)          (offset - OFFSET(0, 0))
-#define TRANSFORM(offset, trans)       (transformation[offset][trans])
-#define AFFINE_TRANSFORM(offset, trans, delta)\
-  (transformation[offset][trans] + delta)
-#define TRANSFORM2(x, y, tx, ty, trans)\
-  do {\
-    *tx = transformation2[trans][0][0] * (x) + transformation2[trans][0][1] * 
(y);\
-    *ty = transformation2[trans][1][0] * (x) + transformation2[trans][1][1] * 
(y);\
-  } while (0)
-
-
-/* This struct holds the internal board state.
- */
-struct board_state {
-  int board_size;
-
-  Intersection board[BOARDSIZE];
-  int board_ko_pos;
-  int black_captured;
-  int white_captured;
-
-  Intersection initial_board[BOARDSIZE];
-  int initial_board_ko_pos;
-  int initial_white_captured;
-  int initial_black_captured;
-  int move_history_color[MAX_MOVE_HISTORY];
-  int move_history_pos[MAX_MOVE_HISTORY];
-  int move_history_pointer;
-
-  float komi;
-  int move_number;
-};
-
-
-/* board utility functions */
-int find_origin(int str);
-int chainlinks(int str, int adj[MAXCHAIN]);
-int chainlinks2(int str, int adj[MAXCHAIN], int lib);
-int chainlinks3(int str, int adj[MAXCHAIN], int lib);
-int extended_chainlinks(int str, int adj[MAXCHAIN], int both_colors);
-
-
-/* This is increased by one anytime a move is (permanently) played or
- * the board is cleared.
- */
-extern int position_number;
-
-
-/* Detect vertex on edge or corner. */
-int is_edge_vertex(int pos);
-int is_corner_vertex(int pos);
-int edge_distance(int pos);
-
-
-/* Count and/or find liberties at (pos). */
-int countlib(int str);
-int findlib(int str, int maxlib, int *libs);
-int fastlib(int pos, int color, int ignore_captures);
-int approxlib(int pos, int color, int maxlib, int *libs);
-int accuratelib(int pos, int color, int maxlib, int *libs);
-int count_common_libs(int str1, int str2);
-int find_common_libs(int str1, int str2, int maxlib, int *libs);
-int have_common_lib(int str1, int str2, int *lib);
-

 void start_timer(int n);
 double time_report(int n, const char *occupation, int move, double mintime);

-
-/* Check for self atari. */
-int is_self_atari(int pos, int color);
-
-/* Count the number of stones in a string. */
-int countstones(int str);
-int findstones(int str, int maxstones, int *stones);
-
-/* Exported from incremental_board.c so that reading.c can use it. */
-void incremental_order_moves(int move, int color, int string,
-                            int *number_edges, int *number_same_string,
-                            int *number_own, int *number_opponent,
-                            int *captured_stones, int *threatened_stones,
-                            int *saved_stones, int *number_open);
-
-/* Board caches initialization functions. */
-void clear_approxlib_cache(void);
-void clear_accuratelib_cache(void);
-
-
 void transformation_init(void);

-
-void dump_stack(void);
 void report_worm(int m, int n);
 void ascii_report_worm(char *string);
 void report_dragon(FILE *outfile, int pos);
@@ -229,42 +64,6 @@ void inv_rotate2(int i, int j, int *ri,
 int rotate1(int pos, int rot);
 int inv_rotate1(int pos, int rot);

-int square_dist(int pos1, int pos2);
-
-/* Is this point inside the board? */
-#if 0
-#define ON_BOARD2(i, j) ((i)>=0 && (j)>=0 && (i)<board_size && (j)<board_size)
-#else
-/*
- * For the case when expr can only be slightly negative,
- *    if (expr < 0 || expr > something)
- * is equivalent to
- *    if ((unsigned) expr > something)
- *
- * (I think gcc knows this trick, but it does no harm to
- *  encode it explicitly since it saves typing !)
- */
-#define ON_BOARD2(i, j) ((unsigned) (i) < (unsigned) board_size &&\
-                        (unsigned) (j) < (unsigned) board_size)
-#endif
-
-#define ASSERT_ON_BOARD2(i, j) ASSERT2(ON_BOARD2((i), (j)), (i), (j))
-
-#define ON_BOARD1(pos) (((unsigned) (pos) < BOARDSIZE) && board[pos] != GRAY)
-#define ON_BOARD(pos) (board[pos] != GRAY)
-#define ASSERT_ON_BOARD1(pos) ASSERT1(ON_BOARD1(pos), (pos))
-
-/* Coordinates for the eight directions, ordered
- * south, west, north, east, southwest, northwest, northeast, southeast.
- * Defined in utils.c.
- */
-extern int deltai[8]; /* = { 1,  0, -1,  0,  1, -1, -1, 1}; */
-extern int deltaj[8]; /* = { 0, -1,  0,  1, -1, -1,  1, 1}; */
-extern int delta[8];  /* = { NS, -1, -NS, 1, NS-1, -NS-1, -NS+1, NS+1}; */
-
-void store_board(struct board_state *state);
-void restore_board(struct board_state *state);
-
 /* Forward struct declarations. */
 struct pattern;
 struct pattern_db;
@@ -334,23 +133,27 @@ void draw_reading_shadow(void);
 /* persistent.c */
 void purge_persistent_reading_cache(void);
 void clear_persistent_reading_cache(void);
-int search_persistent_reading_cache(int routine, int str, int *result,
-                                   int *move);
-void store_persistent_reading_cache(int routine, int str, int result,
-                                   int move, int nodes);
-void delete_persistent_reading_cache_entry(int routine, int str);
+int search_persistent_reading_cache(enum cache_routine routine, int str,
+                                   int *result, int *move);
+void store_persistent_reading_cache(enum cache_routine routine, int str,
+                                   int result, int move, int nodes);
+void delete_persistent_reading_cache_entry(enum cache_routine routine, int 
str);
 void reading_hotspots(float values[BOARDMAX]);
 void purge_persistent_connection_cache(void);
 void clear_persistent_connection_cache(void);
-int search_persistent_connection_cache(int routine, int str1, int str2,
+int search_persistent_connection_cache(enum cache_routine routine,
+                                      int str1, int str2,
                                       int *result, int *move);
-void store_persistent_connection_cache(int routine, int str1, int str2,
+void store_persistent_connection_cache(enum cache_routine routine,
+                                      int str1, int str2,
                                       int result, int move,
                                       int tactical_nodes,
                                       char connection_shadow[BOARDMAX]);
-int search_persistent_breakin_cache(int routine, int str, Hash_data goal_hash,
+int search_persistent_breakin_cache(enum cache_routine routine,
+                                   int str, Hash_data goal_hash,
                                    int *result, int *move);
-void store_persistent_breakin_cache(int routine, int str, Hash_data goal_hash,
+void store_persistent_breakin_cache(enum cache_routine routine,
+                                   int str, Hash_data goal_hash,
                                    int result, int move,
                                    int tactical_nodes,
                                    char breakin_shadow[BOARDMAX]);
@@ -359,10 +162,12 @@ void clear_persistent_breakin_cache(void
 void print_persistent_breakin_cache(void);
 void purge_persistent_owl_cache(void);
 void clear_persistent_owl_cache(void);
-int search_persistent_owl_cache(int routine, int apos, int bpos, int cpos,
+int search_persistent_owl_cache(enum owl_routine routine,
+                               int apos, int bpos, int cpos,
                                int *result, int *move, int *move2,
                                int *certain);
-void store_persistent_owl_cache(int routine, int apos, int bpos, int cpos,
+void store_persistent_owl_cache(enum owl_routine routine,
+                               int apos, int bpos, int cpos,
                                int result, int move, int move2, int certain,
                                int tactical_nodes, char goal[BOARDMAX],
                                int goal_color);
@@ -376,26 +181,6 @@ int non_transitivity(int str1, int str2,
 int break_in(int str, const char goal[BOARDMAX], int *move);
 int block_off(int str1, const char goal[BOARDMAX], int *move);

-/* board.c */
-int liberty_of_string(int pos, int str);
-int second_order_liberty_of_string(int pos, int str);
-int neighbor_of_string(int pos, int str);
-int has_neighbor(int pos, int color);
-int same_string(int str1, int str2);
-int adjacent_strings(int str1, int str2);
-int is_ko(int pos, int color, int *ko_pos);
-int is_ko_point(int pos);
-int komaster_trymove(int pos, int color,
-                    const char *message, int str,
-                    int komaster, int kom_pos,
-                    int *new_komaster, int *new_kom_pos,
-                    int *is_conditional_ko, int consider_conditional_ko);
-int does_capture_something(int pos, int color);
-void mark_string(int str, char mx[BOARDMAX], char mark);
-int move_in_stack(int pos, int cutoff);
-void get_move_from_stack(int k, int *move, int *color);
-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);
@@ -448,7 +233,7 @@ int movelist_move_known(int move, int ma
 void movelist_change_point(int move, int code, int max_points,
                           int points[], int codes[]);

-/* safety.c */
+/* surround.c */
 int compute_surroundings(int pos, int apos, int showboard,
                         int *surround_size);
 int is_surrounded(int pos);
@@ -766,45 +551,15 @@ void goaldump(const char goal[BOARDMAX])
 void move_considered(int move, float value);


-/* SGF routines for debugging purposes in sgffile.c */
-void sgffile_begindump(struct SGFTree_t *tree);
-void sgffile_enddump(const char *filename);
-
-

 /* ================================================================ */
 /*                         global variables                         */
 /* ================================================================ */

-/* The board and the other parameters deciding the current position. */
-extern int          board_size;             /* board size (usually 19) */
-extern Intersection board[BOARDSIZE];       /* go board */
-extern int          board_ko_pos;
-extern int          black_captured;   /* num. of black stones captured */
-extern int          white_captured;
-
-extern Intersection initial_board[BOARDSIZE];
-extern int          initial_board_ko_pos;
-extern int          initial_white_captured;
-extern int          initial_black_captured;
-extern int          move_history_color[MAX_MOVE_HISTORY];
-extern int          move_history_pos[MAX_MOVE_HISTORY];
-extern int          move_history_pointer;
-
-extern float        komi;
-extern int          movenum;      /* movenumber - used for debug output */
-
-extern Intersection shadow[BOARDMAX];      /* reading tree shadow */
-
-
 extern int          disable_threat_computation;
 extern int          disable_endgame_patterns;
 extern int          doing_scoring;

-/* Transformation arrays */
-extern int         transformation[MAX_OFFSET][8];
-extern const int    transformation2[8][2][2];
-
 /* Reading parameters */
 extern int depth;               /* deep reading cutoff */
 extern int backfill_depth;      /* deep reading cutoff */
@@ -834,7 +589,6 @@ extern int semeai_variations;   /* max v
 extern float best_move_values[10];
 extern int best_moves[10];

-extern int chinese_rules;
 extern int experimental_owl_ext;     /* use experimental owl (GAIN/LOSS) */
 extern int experimental_semeai;      /* use experimental semeai module */
 extern int experimental_connections; /* use experimental connection module */
@@ -850,9 +604,6 @@ extern char thrashing_stone[BOARDMAX];
 extern char *rgoal;
 extern int goallib;

-extern int stackp;                /* stack pointer */
-extern int count_variations;      /* count (decidestring) */
-extern SGFTree *sgf_dumptree;

 /* Arrays pointing out the closest worms from each vertex.  The first
  * one is the closest worms of either color, the last two ones ignore
@@ -876,17 +627,6 @@ extern int number_close_white_worms[BOAR
 extern int false_eye_territory[BOARDMAX];
 extern int forced_backfilling_moves[BOARDMAX];

-struct stats_data {
-  int nodes;                     /* Number of visited nodes while reading */
-  int position_entered;          /* Number of Positions entered. */
-  int position_hits;             /* Number of hits of Positions. */
-  int read_result_entered;       /* Number of Read_results entered. */
-  int read_result_hits;          /* Number of hits of Read_results. */
-  int hash_collisions;           /* Number of hash collisions. */
-};
-
-extern struct stats_data stats;
-
 extern double slowest_time;      /* Timing statistics */
 extern int    slowest_move;
 extern int    slowest_movenum;
@@ -985,8 +725,8 @@ struct dragon_data {
                 /* dragon iff they have same origin.                         */
   int size;     /* size of the dragon                                        */
   float effective_size; /* stones and surrounding spaces                     */
-  int crude_status;     /* (ALIVE, DEAD, UNKNOWN, CRITICAL)                  */
-  int status;           /* best trusted status                               */
+  enum dragon_status crude_status; /* (ALIVE, DEAD, UNKNOWN, CRITICAL)       */
+  enum dragon_status status;       /* best trusted status                    */
 };

 extern struct dragon_data dragon[BOARDMAX];
@@ -1005,7 +745,7 @@ struct dragon_data2 {

   int moyo_size;                     /* size of surrounding influence moyo, */
   float moyo_territorial_value;       /* ...and its territorial value        */
-  int safety;                         /* a more detailed status estimate     */
+  enum safety_value safety;           /* a more detailed status estimate     */
   float weakness; /* A new (3.4) continuous estimate of the dragon's safety  */
   float weakness_pre_owl;     /* Dragon safety based on pre-owl computations */
   int escape_route; /* a measurement of likelihood of escape                 */
@@ -1022,8 +762,8 @@ struct dragon_data2 {
   int semeai_defense_certain;
   int semeai_attack_point; /* Move found by semeai code to kill dragon       */
   int semeai_attack_certain;
-  int owl_threat_status;   /* CAN_THREATEN_ATTACK or CAN_THREATEN_DEFENSE    */
-  int owl_status;          /* (ALIVE, DEAD, UNKNOWN, CRITICAL, UNCHECKED)    */
+  enum dragon_status owl_threat_status; /* CAN_THREATEN_ATTACK/DEFENSE       */
+  enum dragon_status owl_status; /* (ALIVE, DEAD, UNKNOWN, CRITICAL, 
UNCHECKED)    */
   int owl_attack_point;    /* vital point for attack                         */
   int owl_attack_code;     /* ko result code                                 */
   int owl_attack_certain;  /* 0 if owl reading node limit is reached         */
@@ -1143,23 +883,6 @@ char *eyevalue_to_string(struct eyevalue

 int is_halfeye(struct half_eye_data heye[BOARDMAX], int pos);
 int is_false_eye(struct half_eye_data heye[BOARDMAX], int pos);
-
-/* Our own abort() which prints board state on the way out.
- * (pos) is a "relevant" board position for info.
- */
-void abortgo(const char *file, int line, const char *msg, int pos);
-
-#ifdef GG_TURN_OFF_ASSERTS
-#define ASSERT2(x, i, j)
-#define ASSERT1(x, pos)
-#else
-/* avoid dangling else */
-/* FIXME: Should probably re-write these using do {...} while (0) idiom. */
-#define ASSERT2(x, i, j) if (x) ; else abortgo(__FILE__, __LINE__, #x, POS(i, 
j))
-#define ASSERT1(x, pos) if (x) ; else abortgo(__FILE__, __LINE__, #x, pos)
-#endif
-
-#define gg_assert(x) ASSERT1(x, NO_MOVE);

 #endif  /* _LIBERTY_H_ */

Index: engine/matchpat.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/matchpat.c,v
retrieving revision 1.57
diff -u -p -r1.57 matchpat.c
--- engine/matchpat.c   18 Jul 2003 18:59:21 -0000      1.57
+++ engine/matchpat.c   5 Aug 2003 17:09:34 -0000
@@ -206,7 +206,7 @@ static const int val_mask[2][8] = {
  * we care about each time.
  */

-static unsigned int class_mask[MAX_DRAGON_STATUS][3];
+static unsigned int class_mask[NUM_DRAGON_STATUS][3];


 /* In the current implementation, the edge constraints depend on
Index: engine/owl.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/owl.c,v
retrieving revision 1.176
diff -u -p -r1.176 owl.c
--- engine/owl.c        18 Jul 2003 18:59:21 -0000      1.176
+++ engine/owl.c        5 Aug 2003 17:09:41 -0000
@@ -1359,7 +1359,7 @@ owl_attack(int target, int *attack_point
     return 1;
   }

-  if (search_persistent_owl_cache(OWL_ATTACK, target, 0, 0, &result,
+  if (search_persistent_owl_cache(OWL_ATTACK_P, target, 0, 0, &result,
                                  attack_point, kworm, certain))
     return result;

@@ -1380,7 +1380,7 @@ owl_attack(int target, int *attack_point
     target, result, move, local_owl_node_counter,
     tactical_nodes, gg_cputime() - start);

-  store_persistent_owl_cache(OWL_ATTACK, target, 0, 0,
+  store_persistent_owl_cache(OWL_ATTACK_P, target, 0, 0,
                             result, move, wpos,
                             result_certain, tactical_nodes,
                             owl->goal, board[target]);
@@ -2000,7 +2000,7 @@ owl_defend(int target, int *defense_poin
   if (worm[target].unconditional_status == DEAD)
     return 0;

-  if (search_persistent_owl_cache(OWL_DEFEND, target, 0, 0, &result,
+  if (search_persistent_owl_cache(OWL_DEFEND_P, target, 0, 0, &result,
                                  defense_point, kworm, certain))
     return result;

@@ -2021,7 +2021,7 @@ owl_defend(int target, int *defense_poin
            target, result, move, local_owl_node_counter,
            tactical_nodes, gg_cputime() - start);

-  store_persistent_owl_cache(OWL_DEFEND, target, 0, 0, result, move, wpos,
+  store_persistent_owl_cache(OWL_DEFEND_P, target, 0, 0, result, move, wpos,
                             result_certain, tactical_nodes, owl->goal,
                             board[target]);

@@ -4155,7 +4155,7 @@ owl_confirm_safety(int move, int target,

   if (trymove(move, color, "owl_confirm_safety", target, EMPTY, NO_MOVE)) {
     /* Check if a compatible owl_attack() is cached. */
-    if (search_persistent_owl_cache(OWL_ATTACK, origin, 0, 0,
+    if (search_persistent_owl_cache(OWL_ATTACK_P, origin, 0, 0,
                                    &result, defense_point, kworm, NULL)) {
       popgo();
       if (result==0)
@@ -4245,7 +4245,7 @@ owl_does_attack(int move, int target, in

     if (trymove(move, other, "owl_does_attack", target, EMPTY, 0)) {
     /* Check if a compatible owl_defend() is cached. */
-    if (search_persistent_owl_cache(OWL_DEFEND, origin, 0, 0,
+    if (search_persistent_owl_cache(OWL_DEFEND_P, origin, 0, 0,
                                    &result, NULL, kworm, NULL)) {
       popgo();
       return REVERSE_RESULT(result);
Index: engine/persistent.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/persistent.c,v
retrieving revision 1.16
diff -u -p -r1.16 persistent.c
--- engine/persistent.c 18 Jul 2003 18:59:21 -0000      1.16
+++ engine/persistent.c 5 Aug 2003 17:09:41 -0000
@@ -76,7 +76,7 @@ struct reading_cache {
   int nodes;
   int score;
   int remaining_depth;
-  int routine;                 /* ATTACK or FIND_DEFENSE */
+  enum cache_routine routine;  /* ATTACK or FIND_DEFENSE */
   int str;                     /* contested string (origin) */
   int result;
   int move;                    /* attack/defense point */
@@ -100,7 +100,7 @@ struct connection_cache {
   int nodes;
   int score;
   int remaining_depth;
-  int routine;                 /* CONNECT or DISCONNECT */
+  enum cache_routine routine;   /* CONNECT or DISCONNECT */
   int str1;                    /* first string to connect (origin) */
   int str2;                    /* second string to connect (origin) */
   int result;
@@ -123,7 +123,7 @@ struct breakin_cache {
   int nodes;
   int score;
   int remaining_depth;
-  int routine;                 /* BREAK_IN or BLOCK_OFF */
+  enum cache_routine routine;  /* BREAK_IN or BLOCK_OFF */
   int str;                     /* string to connect (origin) */
   Hash_data goal_hash;         /* hash of the goal to which to connect to */
   int result;
@@ -146,7 +146,7 @@ struct owl_cache {
   char board[BOARDMAX];
   int movenum;
   int tactical_nodes;
-  int routine;
+  enum owl_routine routine;
   int apos;  /* first input coordinate */
   int bpos;  /* second input coordinate */
   int cpos;  /* third input coordinate */
@@ -168,19 +168,20 @@ static void draw_active_area(char board[
 static int verify_stored_board(char board[BOARDMAX]);

 /* Tactical reading functions. */
-static int find_persistent_reading_cache_entry(int routine, int str);
+static int find_persistent_reading_cache_entry(enum cache_routine routine,
+                                              int str);
 static void print_persistent_reading_cache_entry(int k);
 static void mark_string_hotspot_values(float values[BOARDMAX],
                                       int m, int n, float contribution);

 /* Connection reading functions. */
-static int find_persistent_connection_cache_entry(int routine,
+static int find_persistent_connection_cache_entry(enum cache_routine routine,
                                                  int str1, int str2);
 static void print_persistent_connection_cache_entry(int k);

 /* Breakin reading functions. */
-static int find_persistent_breakin_cache_entry(int routine, int str,
-                                              Hash_data goal_hash);
+static int find_persistent_breakin_cache_entry(enum cache_routine routine,
+                                              int str, Hash_data goal_hash);
 static void print_persistent_breakin_cache_entry(int k);

 /* Owl functions. */
@@ -338,7 +339,7 @@ clear_persistent_reading_cache()
  * entry number or -1 if none found.
  */
 static int
-find_persistent_reading_cache_entry(int routine, int str)
+find_persistent_reading_cache_entry(enum cache_routine routine, int str)
 {
   int k;
   int r;
@@ -378,7 +379,8 @@ find_persistent_reading_cache_entry(int
  * Return 1 if found, 0 otherwise.
  */
 int
-search_persistent_reading_cache(int routine, int str, int *result, int *move)
+search_persistent_reading_cache(enum cache_routine routine, int str,
+                               int *result, int *move)
 {
   int k;
   struct reading_cache *entry;
@@ -418,8 +420,8 @@ search_persistent_reading_cache(int rout

 /* Store a new read result in the persistent cache. */
 void
-store_persistent_reading_cache(int routine, int str, int result, int move,
-                              int nodes)
+store_persistent_reading_cache(enum cache_routine routine, int str,
+                              int result, int move, int nodes)
 {
   char active[BOARDMAX];
   int k;
@@ -566,7 +568,7 @@ store_persistent_reading_cache(int routi

 /* Delete an entry from the cache, if it's there. */
 void
-delete_persistent_reading_cache_entry(int routine, int str)
+delete_persistent_reading_cache_entry(enum cache_routine routine, int str)
 {
   int k = find_persistent_reading_cache_entry(routine, find_origin(str));
   while (k != -1) {
@@ -769,7 +771,8 @@ clear_persistent_connection_cache()
  * entry number or -1 if none found.
  */
 static int
-find_persistent_connection_cache_entry(int routine, int str1, int str2)
+find_persistent_connection_cache_entry(enum cache_routine routine,
+                                      int str1, int str2)
 {
   int k;
   int r;
@@ -813,8 +816,8 @@ find_persistent_connection_cache_entry(i
  * Return 1 if found, 0 otherwise.
  */
 int
-search_persistent_connection_cache(int routine, int str1, int str2,
-                                  int *result, int *move)
+search_persistent_connection_cache(enum cache_routine routine, int str1,
+                                  int str2, int *result, int *move)
 {
   int k;
   struct connection_cache *entry;
@@ -841,7 +844,8 @@ search_persistent_connection_cache(int r

 /* Store a new connection result in the persistent cache. */
 void
-store_persistent_connection_cache(int routine, int str1, int str2,
+store_persistent_connection_cache(enum cache_routine routine,
+                                 int str1, int str2,
                                  int result, int move, int tactical_nodes,
                                  char connection_shadow[BOARDMAX])
 {
@@ -1113,7 +1117,7 @@ clear_persistent_breakin_cache()
  * entry number or -1 if none found.
  */
 static int
-find_persistent_breakin_cache_entry(int routine, int str,
+find_persistent_breakin_cache_entry(enum cache_routine routine, int str,
                                    Hash_data goal_hash)
 {
   int k;
@@ -1148,8 +1152,8 @@ find_persistent_breakin_cache_entry(int
  * Return 1 if found, 0 otherwise.
  */
 int
-search_persistent_breakin_cache(int routine, int str, Hash_data goal_hash,
-                               int *result, int *move)
+search_persistent_breakin_cache(enum cache_routine routine, int str,
+                               Hash_data goal_hash, int *result, int *move)
 {
   int k;
   struct breakin_cache *entry;
@@ -1176,7 +1180,8 @@ search_persistent_breakin_cache(int rout

 /* Store a new breakin result in the persistent cache. */
 void
-store_persistent_breakin_cache(int routine, int str, Hash_data goal_hash,
+store_persistent_breakin_cache(enum cache_routine routine,
+                              int str, Hash_data goal_hash,
                               int result, int move, int tactical_nodes,
                               char breakin_shadow[BOARDMAX])
 {
@@ -1415,7 +1420,8 @@ clear_persistent_owl_cache()
 }

 int
-search_persistent_owl_cache(int routine, int apos, int bpos, int cpos,
+search_persistent_owl_cache(enum owl_routine routine,
+                           int apos, int bpos, int cpos,
                            int *result, int *move, int *move2, int *certain)
 {
   int k;
@@ -1437,7 +1443,7 @@ search_persistent_owl_cache(int routine,

       DEBUG(DEBUG_OWL_PERSISTENT_CACHE,
            "persistent owl cache hit: routine %s at %1m result %d\n",
-           routine_to_string(routine), apos, bpos, cpos,
+           owl_routine_to_string(routine), apos, bpos, cpos,
            result_to_string(persistent_owl_cache[k].result));
       return 1;
     }
@@ -1446,7 +1452,8 @@ search_persistent_owl_cache(int routine,
 }

 void
-store_persistent_owl_cache(int routine, int apos, int bpos, int cpos,
+store_persistent_owl_cache(enum owl_routine routine,
+                          int apos, int bpos, int cpos,
                           int result, int move, int move2, int certain,
                           int tactical_nodes,
                           char goal[BOARDMAX], int goal_color)
@@ -1587,7 +1594,7 @@ print_persistent_owl_cache_entry(int k)
   struct owl_cache *entry = &(persistent_owl_cache[k]);
   gprintf("%omovenum         = %d\n",  entry->movenum);
   gprintf("%otactical_nodes  = %d\n",  entry->tactical_nodes);
-  gprintf("%oroutine         = %s\n",  routine_to_string(entry->routine));
+  gprintf("%oroutine         = %s\n",  owl_routine_to_string(entry->routine));
   gprintf("%o(apos)          = %1m\n", entry->apos);
   gprintf("%o(bpos)          = %1m\n", entry->bpos);
   gprintf("%o(cpos)          = %1m\n", entry->cpos);
Index: engine/printutils.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/printutils.c,v
retrieving revision 1.39
diff -u -p -r1.39 printutils.c
--- engine/printutils.c 18 Jul 2003 18:59:21 -0000      1.39
+++ engine/printutils.c 5 Aug 2003 17:09:41 -0000
@@ -28,8 +28,7 @@
 #include <stdarg.h>
 #include <ctype.h>

-#include "liberty.h"
-#include "gnugo.h"
+#include "board.h"
 #include "gg_utils.h"
 #include "cache.h"

@@ -348,85 +347,60 @@ location_to_buffer(int pos, char *buf)
   *bufp = 0;
 }

+
+#define DEFINE_DRAGON_STATUS(id, name) name,
+static const char* status_names [] = {
+#include "defs.h"
+  ""
+};
+
 /* Convert a status value to a string. */
 const char *
-status_to_string(int status)
+status_to_string(enum dragon_status status)
 {
-  if (status == DEAD)
-    return "DEAD";
-  else if (status == ALIVE)
-    return "ALIVE";
-  else if (status == CRITICAL)
-    return "CRITICAL";
-  else if (status == UNKNOWN)
-    return "UNKNOWN";
-  else if (status == UNCHECKED)
-    return "UNCHECKED";
-  else if (status == CAN_THREATEN_ATTACK)
-    return "CAN_THREATEN_ATTACK";
-  else if (status == CAN_THREATEN_DEFENSE)
-    return "CAN_THREATEN_DEFENSE";
-  else
-    return "ERROR";
+  return status_names[(int) status];
 }

+#define DEFINE_SAFETY_VALUE(id, name)  name,
+static const char* safety_names[] = {
+#include "defs.h"
+  ""
+};

 /* Convert a safety value to a string. */
 const char *
-safety_to_string(int status)
+safety_to_string(enum safety_value safety)
 {
-  if (status == DEAD)
-    return "DEAD";
-  else if (status == ALIVE)
-    return "ALIVE";
-  else if (status == CRITICAL)
-    return "CRITICAL";
-  else if (status == INESSENTIAL)
-    return "INESSENTIAL";
-  else if (status == TACTICALLY_DEAD)
-    return "TACTICALLY_DEAD";
-  else if (status == ALIVE_IN_SEKI)
-    return "ALIVE_IN_SEKI";
-  else if (status == STRONGLY_ALIVE)
-    return "STRONGLY_ALIVE";
-  else if (status == INVINCIBLE)
-    return "INVINCIBLE";
-  else if (status == INSUBSTANTIAL)
-    return "INSUBSTANTIAL";
-  else if (status == CAN_THREATEN_ATTACK)
-    return "CAN_THREATEN_ATTACK";
-  else if (status == CAN_THREATEN_DEFENSE)
-    return "CAN_THREATEN_DEFENSE";
-  else
-    return "ERROR";
+  return safety_names[(int) safety];
 }

-/* Convert a routine to a string. */
+static const char* cache_routine_names[] = {
+#define DEFINE_CACHE_ROUTINE(id, name) name,
+#include "defs.h"
+  ""
+};
+
+/* Convert a routine as used in the cache table to a string. */
 const char *
-routine_to_string(int routine)
+cache_routine_to_string(enum cache_routine routine)
 {
-  if (routine == FIND_DEFENSE)
-    return "FIND_DEFENSE";
-  else if (routine == ATTACK)
-    return "ATTACK";
-  else if (routine == OWL_ATTACK)
-    return "OWL_ATTACK";
-  else if (routine == OWL_DEFEND)
-    return "OWL_DEFEND";
-  else if (routine == SEMEAI)
-    return "SEMEAI";
-  else if (routine == CONNECT)
-    return "CONNECT";
-  else if (routine == DISCONNECT)
-    return "DISCONNECT";
-  else if (routine == BREAK_IN)
-    return "BREAK_IN";
-  else if (routine == BLOCK_OFF)
-    return "BLOCK_OFF";
-  else
-    return "ERROR";
+  return cache_routine_names[(int) routine];
 }

+static const char* owl_routine_names[] = {
+#define DEFINE_OWL_ROUTINE(id, name) name,
+#include "defs.h"
+  ""
+};
+
+const char *
+owl_routine_to_string(enum owl_routine routine)
+{
+  return owl_routine_names[(int) routine];
+}
+
+
+
 /* Convert a read result to a string */
 const char *
 result_to_string(int result)
@@ -439,8 +413,6 @@ result_to_string(int result)
   case KO_A:          return "KO_A";
   case WIN:           return "WIN";

-  /* ALIVE_IN_SEKI is not defined as a return code, but is used here anyhow. */
-  case ALIVE_IN_SEKI: return "SEKI";
   default:            return "ERROR";
   }
 }
Index: engine/semeai.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/semeai.c,v
retrieving revision 1.57
diff -u -p -r1.57 semeai.c
--- engine/semeai.c     18 Jul 2003 18:59:21 -0000      1.57
+++ engine/semeai.c     5 Aug 2003 17:09:42 -0000
@@ -32,10 +32,12 @@
 static void analyze_semeai(int my_dragon, int your_dragon);
 static void add_appropriate_semeai_moves(int move,
                                         int my_dragon, int your_dragon,
-                                        int my_status, int your_status,
+                                        enum dragon_status my_status,
+                                        enum dragon_status your_status,
                                         int margin_of_safety);
 static void small_semeai_analyzer(int str1, int str2, int save_verbose);
-static void update_status(int dr, int new_status, int new_safety);
+static void update_status(int dr, enum dragon_status new_status,
+                         enum safety_value new_safety);


 /* semeai() searches for pairs of dragons of opposite color which
@@ -292,7 +294,8 @@ liberty_of_dragon(int pos, int origin)
 /* Change the status and safety of a dragon */

 static void
-update_status(int dr, int new_status, int new_safety)
+update_status(int dr, enum dragon_status new_status,
+             enum safety_value new_safety)
 {
   int pos;

@@ -307,7 +310,7 @@ update_status(int dr, int new_status, in
   }

   if (DRAGON2(dr).safety != new_safety
-      && (DRAGON2(dr).safety != CRITICAL || new_safety != DEAD)) {
+      && (DRAGON2(dr).safety != CRITICAL_S || new_safety != DEAD_S)) {
     DEBUG(DEBUG_SEMEAI, "Changing safety of %1m from %s to %s.\n", dr,
          safety_to_string(DRAGON2(dr).safety), safety_to_string(new_safety));
     DRAGON2(dr).safety = new_safety;
@@ -792,7 +795,8 @@ analyze_semeai(int my_dragon, int your_d

 static void
 add_appropriate_semeai_moves(int move, int my_dragon, int your_dragon,
-                            int my_status, int your_status,
+                            enum dragon_status my_status,
+                            enum dragon_status your_status,
                             int margin_of_safety)
 {
   if (my_status == CRITICAL)
Index: engine/sgffile.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/sgffile.c,v
retrieving revision 1.28
diff -u -p -r1.28 sgffile.c
--- engine/sgffile.c    18 Jul 2003 18:59:21 -0000      1.28
+++ engine/sgffile.c    5 Aug 2003 17:09:42 -0000
@@ -65,6 +65,8 @@ sgffile_add_debuginfo(SGFNode *node, int
        case CRITICAL:
          sgfLabel(node, "!", m, n);
          break;
+       default:
+         ;
        }
       }

Index: patterns/joseki.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/patterns/joseki.c,v
retrieving revision 1.18
diff -u -p -r1.18 joseki.c
--- patterns/joseki.c   18 Jul 2003 18:59:22 -0000      1.18
+++ patterns/joseki.c   5 Aug 2003 17:09:43 -0000
@@ -28,7 +28,7 @@
 #include <ctype.h>

 #include "../sgf/sgftree.h"
-#include "liberty.h"
+#include "board.h"

 #define USAGE "\
 Usage : joseki prefix filename\n\









reply via email to

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