Index: gnugo/engine/board.h
===================================================================
RCS file: /sources/gnugo/gnugo/engine/board.h,v
retrieving revision 1.34
diff -u -r1.34 board.h
--- gnugo/engine/board.h	18 May 2006 04:09:28 -0000	1.34
+++ gnugo/engine/board.h	28 Nov 2006 22:08:26 -0000
@@ -36,7 +36,13 @@
  * character access is very slow.
  */
 
+/* simple test for old machines */
+#if SIZEOF_INT >= 4
+#define INT_INTERSECTION
+typedef int Intersection;
+#else
 typedef unsigned char Intersection;
+#endif
 
 /* FIXME: This is very ugly but we can't include hash.h until we have
  * defined Intersection. And we do need to include it before using
@@ -135,6 +141,7 @@
 
 /* Note that POS(-1, -1) == 0
  * DELTA() is defined so that POS(i+di, j+dj) = POS(i, j) + DELTA(di, dj).
+ * For details look in the documentation.
  */
 #define BOARDSIZE     ((MAX_BOARD + 2) * (MAX_BOARD + 1) + 1)
 #define BOARDMIN      (MAX_BOARD + 2)
@@ -148,17 +155,17 @@
 #define NS            (MAX_BOARD + 1)
 #define WE            1
 #define SOUTH(pos)    ((pos) + NS)
-#define WEST(pos)     ((pos) - 1)
+#define WEST(pos)     ((pos) - WE)
 #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 EAST(pos)     ((pos) + WE)
+#define SW(pos)       ((pos) + NS - WE)
+#define NW(pos)       ((pos) - NS - WE)
+#define NE(pos)       ((pos) - NS + WE)
+#define SE(pos)       ((pos) + NS + WE)
 #define SS(pos)       ((pos) + 2 * NS)
-#define WW(pos)       ((pos) - 2)
+#define WW(pos)       ((pos) - 2 * WE)
 #define NN(pos)       ((pos) - 2 * NS)
-#define EE(pos)       ((pos) + 2)
+#define EE(pos)       ((pos) + 2 * WE)
 
 #define DIRECT_NEIGHBORS(pos1, pos2)		\
   ((pos1) == SOUTH(pos2)			\
@@ -260,8 +267,6 @@
 /* Functions handling the permanent board state. */
 void clear_board(void);
 int test_gray_border(void);
-void setup_board(Intersection new_board[MAX_BOARD][MAX_BOARD], int ko_pos,
-                 int *last, float new_komi, int w_captured, int b_captured);
 void add_stone(int pos, int color);
 void remove_stone(int pos);
 void play_move(int pos, int color);
@@ -271,34 +276,36 @@
 void restore_board(struct board_state *state);
 
 /* Information about the permanent board. */
-int get_last_move(void);
-int get_last_player(void);
+inline int get_last_move(void);
+inline int get_last_player(void);
 int get_last_opponent_move(int color);
 int stones_on_board(int color);
 
 /* Functions handling the variable board state. */
-int trymove(int pos, int color, const char *message, int str);
+int trymove(int pos, int color, const char *message, int str_pos);
 int tryko(int pos, int color, const char *message);
 void popgo(void);
 int komaster_trymove(int pos, int color,
 		     const char *message, int str,
 		     int *is_conditional_ko, int consider_conditional_ko);
-int get_komaster(void);
-int get_kom_pos(void);
+inline int get_komaster(void);
+inline int get_kom_pos(void);
 
 int move_in_stack(int pos, int cutoff);
-void get_move_from_stack(int k, int *move, int *color);
+inline void get_move_from_stack(int k, int *move, int *color);
 void dump_stack(void);
 void do_dump_stack(void);
 
-void reset_trymove_counter(void);
-int get_trymove_counter(void);
+void dump_incremental_board(void);
+
+inline void reset_trymove_counter(void);
+inline int get_trymove_counter(void);
 
 /* move properties */
-int is_pass(int pos);
+inline int is_pass(int pos);
 int is_legal(int pos, int color);
 int is_suicide(int pos, int color);
-int is_illegal_ko_capture(int pos, int color);
+inline int is_illegal_ko_capture(int pos, int color);
 int is_allowed_move(int pos, int color);
 int is_ko(int pos, int color, int *ko_pos);
 int is_ko_point(int pos);
@@ -306,52 +313,53 @@
 int is_self_atari(int pos, int color);
 
 /* Purely gemoetric functions */
-int is_edge_vertex(int pos);
-int is_corner_vertex(int pos);
-int edge_distance(int pos);
-int square_dist(int pos1, int pos2);
+inline int is_edge_vertex(int pos);
+inline int is_corner_vertex(int pos);
+inline int edge_distance(int pos);
+inline int square_dist(int pos1, int pos2);
 
 /* Basic string information. */
-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);
-
-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);
+inline int find_origin(int str_pos);
+int chainlinks(int str_pos, int adj[MAXCHAIN]);
+int chainlinks2(int str_pos, int adj[MAXCHAIN], int lib);
+int chainlinks3(int str_pos, int adj[MAXCHAIN], int lib);
+int extended_chainlinks(int str_pos, int adj[MAXCHAIN], int both_colors);
+
+int liberty_of_string(int pos, int str_pos);
+int liberty_of_string2(int pos, int str_pos);
+int second_order_liberty_of_string(int pos, int str_pos);
+int neighbor_of_string(int pos, int str_pos);
+inline int has_neighbor(int pos, int color);
+inline int same_string(int str1_pos, int str2_pos);
+int adjacent_strings(int str1_pos, int str2_pos);
 void mark_string(int str, signed char mx[BOARDMAX], signed char mark);
 int are_neighbors(int pos1, int pos2);
 
-/* Count and/or find liberties at (pos). */
-int countlib(int str);
-int findlib(int str, int maxlib, int *libs);
+/* Count and/or find liberties at (pos) */
+inline int countlib(int str_pos);
+int findlib(int str_pos, 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);
+int count_common_libs(int str1_pos, int str2_pos);
+int find_common_libs(int str1_pos, int str2_pos, int maxlib, int *libs);
+int have_common_lib(int str1_pos, int str2_pos, int *lib);
 
 /* Count the number of stones in a string. */
-int countstones(int str);
-int findstones(int str, int maxstones, int *stones);
-int count_adjacent_stones(int str1, int str2, int maxstones);
+inline int countstones(int str_pos);
+int findstones(int str_pos, int maxstones, int *stones);
+int count_adjacent_stones(int str1_pos, int str2_pos, int maxstones);
 
 /* Special function for reading.c */
-void incremental_order_moves(int move, int color, int string,
+void incremental_order_moves(int move, int color, int target_pos,
 			     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);
+inline void clear_approxlib_cache(void);
+inline void clear_accuratelib_cache(void);
   
 
 /* Is this point inside the board? */
@@ -381,9 +389,9 @@
  * south, west, north, east, southwest, northwest, northeast, southeast.
  * Defined in board.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}; */
+extern const int deltai[8]; /* = { 1,  0, -1,  0,  1, -1, -1, 1}; */
+extern const int deltaj[8]; /* = { 0, -1,  0,  1, -1, -1,  1, 1}; */
+extern const int delta[8];  /* = { NS, -WE, -NS, WE, NS-WE, -NS-WE, -NS+WE, NS+WE}; */
 
 
 
Index: gnugo/engine/boardlib.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/boardlib.c,v
retrieving revision 1.12
diff -u -r1.12 boardlib.c
--- gnugo/engine/boardlib.c	18 May 2006 04:09:28 -0000	1.12
+++ gnugo/engine/boardlib.c	28 Nov 2006 22:08:26 -0000
@@ -29,7 +29,7 @@
 /* The board state itself. */
 int          board_size = DEFAULT_BOARD_SIZE; /* board size */
 Intersection board[BOARDSIZE];
-int          board_ko_pos;
+int          board_ko_pos;	/* Position of a ko (captured stone). */
 int          white_captured;    /* number of black and white stones captured */
 int          black_captured;
 
@@ -54,7 +54,7 @@
 /* Hashing of positions. */
 Hash_data board_hash;
 
-int stackp;             /* stack pointer */
+int stackp;             /* moves stack depth */
 int position_number;    /* position number */
 
 /* Some statistics gathered partly in board.c and hash.c */
Index: gnugo/engine/breakin.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/breakin.c,v
retrieving revision 1.26
diff -u -r1.26 breakin.c
--- gnugo/engine/breakin.c	15 Sep 2006 01:00:31 -0000	1.26
+++ gnugo/engine/breakin.c	28 Nov 2006 22:08:27 -0000
@@ -367,7 +367,7 @@
 
 	if (used[pos2])
 	  break;
-      }
+	  }
 
       used[pos] = 1;
       if (ON_BOARD(pos2))
@@ -440,7 +440,7 @@
   }
 }
 
-void
+inline void
 clear_break_in_list()
 {
   num_break_ins = 0;
Index: gnugo/engine/cache.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/cache.c,v
retrieving revision 1.50
diff -u -r1.50 cache.c
--- gnugo/engine/cache.c	23 Jan 2006 18:15:50 -0000	1.50
+++ gnugo/engine/cache.c	28 Nov 2006 22:08:29 -0000
@@ -39,7 +39,7 @@
 /* ---------------------------------------------------------------- */
 
 static void tt_init(Transposition_table *table, int memsize);
-static void tt_clear(Transposition_table *table);
+inline static void tt_clear(Transposition_table *table);
 
 /* The transposition table itself. */
 Transposition_table ttable;
@@ -72,7 +72,7 @@
 calculate_hashval_for_tt(Hash_data *hashdata, int routine, int target1,
 			 int target2, Hash_data *extra_hash)
 { 
-  *hashdata = board_hash;                /* from globals.c */
+  *hashdata = board_hash;                /* from boardlib.c */
   hashdata_xor(*hashdata, routine_hash[routine]);
   hashdata_xor(*hashdata, target1_hash[target1]);
   if (target2 != NO_MOVE)
@@ -97,49 +97,46 @@
   keyhash_init();
 
   if (memsize > 0)
-    num_entries = memsize / sizeof(table->entries[0]);
+    num_entries = memsize / sizeof(Hashentry);
   else
     num_entries = DEFAULT_NUMBER_OF_CACHE_ENTRIES;
 
   table->num_entries = num_entries;
-  table->entries     = malloc(num_entries * sizeof(table->entries[0]));
+  table->entries     = malloc(num_entries * sizeof(Hashentry));
 
   if (table->entries == NULL) {
     perror("Couldn't allocate memory for transposition table. \n");
     exit(1);
   }
 
-  table->is_clean = 0;
   tt_clear(table);
 }
 
 
 /* Clear the transposition table. */
 
-static void
+inline static void
 tt_clear(Transposition_table *table)
 {
-  if (!table->is_clean) {
-    memset(table->entries, 0, table->num_entries * sizeof(table->entries[0]));
-    table->is_clean = 1;
-  }
+  memset(table->entries, 0, table->num_entries * sizeof(Hashentry));
 }
- 
- 
+
+
 /* Free the transposition table. */
 
-void
+inline void
 tt_free(Transposition_table *table)
 {
   free(table->entries);
 }
 
 
-/* Get result and move. Return value:
+/* Get result and move (the bigger remaining depth the lower depth).
+ * Return value:
  *   0 if not found
- *   1 if found, but depth too small to be trusted.  In this case the move
+ *   1 if found, but depth too big to be trusted.  In this case the move
  *     can be used for move ordering.
- *   2 if found and depth is enough so that the result can be trusted.
+ *   2 if found and depth is small enough so that the result can be trusted.
  */
  
 int
@@ -162,14 +159,17 @@
 
   /* Get the correct entry and node. */
   entry = &table->entries[hashdata_remainder(hashval, table->num_entries)];
-  if (hashdata_is_equal(hashval, entry->deepest.key))
-    node = &entry->deepest;
+
+  if (hashdata_is_equal(hashval, entry->most_reliable.key))
+    node = &entry->most_reliable;
   else if (hashdata_is_equal(hashval, entry->newest.key))
     node = &entry->newest;
   else
     return 0;
 
-  stats.read_result_hits++;
+#ifndef GG_TURN_OFF_STATS
+  ++stats.read_result_hits;
+#endif
 
   /* Return data.  Only set the result if remaining depth in the table
    * is big enough to be trusted.  The move can always be used for move
@@ -177,12 +177,17 @@
    */
   if (move)
     *move = hn_get_move(node->data);
+
   if (remaining_depth <= (int) hn_get_remaining_depth(node->data)) {
     if (value1)
       *value1 = hn_get_value1(node->data);
     if (value2)
       *value2 = hn_get_value2(node->data);
-    stats.trusted_read_result_hits++;
+
+#ifndef GG_TURN_OFF_STATS
+    ++stats.trusted_read_result_hits;
+#endif
+
     return 2;
   }
 
@@ -201,7 +206,7 @@
 {
   Hash_data hashval;
   Hashentry *entry;
-  Hashnode *deepest;
+  Hashnode *most_reliable;
   Hashnode *newest;
   unsigned int data;
   /* Get routine costs definitions from liberty.h. */
@@ -220,48 +225,53 @@
 
   /* Get the entry and nodes. */ 
   entry = &table->entries[hashdata_remainder(hashval, table->num_entries)];
-  deepest = &entry->deepest;
+  most_reliable = &entry->most_reliable;
   newest  = &entry->newest;
  
   /* See if we found an already existing node. */
-  if (hashdata_is_equal(hashval, deepest->key)
-      && remaining_depth >= (int) hn_get_remaining_depth(deepest->data)) {
-
-    /* Found deepest */
-    deepest->data = data;
-
+  if (hashdata_is_equal(hashval, most_reliable->key))
+  {
+    /* Found shallower node (can be trusted more likely) */
+    if (remaining_depth > (int) hn_get_remaining_depth(most_reliable->data))
+      most_reliable->data = data;
   }
-  else if (hashdata_is_equal(hashval, newest->key)
-           && remaining_depth >= (int) hn_get_remaining_depth(newest->data)) {
-
+  else if (hashdata_is_equal(hashval, newest->key))
+  {
     /* Found newest */
-    newest->data = data;
-
-    /* If newest has become deeper than deepest, then switch them. */
-    if (hn_get_remaining_depth(newest->data)
-	> hn_get_remaining_depth(deepest->data)) {
-      Hashnode temp;
-
-      temp = *deepest;
-      *deepest = *newest;
-      *newest = temp;
+    if (remaining_depth > (int) hn_get_remaining_depth(newest->data))
+    {
+      newest->data = data;
+
+      /* If newest reliability is bigger than most_reliable, switch them. */
+      if (hn_get_reliability(newest->data) >
+          hn_get_reliability(most_reliable->data))
+      {
+        Hashnode temp;
+
+        temp = *most_reliable;
+        *most_reliable = *newest;
+        *newest = temp;
+      }
     }
-
   }
-  else if (hn_get_total_cost(data) > hn_get_total_cost(deepest->data)) {
-    if (hn_get_total_cost(newest->data) < hn_get_total_cost(deepest->data))
-      *newest = *deepest;
-    deepest->key  = hashval;
-    deepest->data = data;
-  } 
-  else {
+  /* Have new node. */
+  else if (hn_get_reliability(data) >
+           hn_get_reliability(most_reliable->data))
+  {
+    /* Replace most_reliable. */
+    most_reliable->key  = hashval;
+    most_reliable->data = data;
+  }
+  else
+  {
     /* Replace newest. */
     newest->key  = hashval;
     newest->data = data;
   }
 
-  stats.read_result_entered++;
-  table->is_clean = 0;
+#ifndef GG_TURN_OFF_STATS
+  ++stats.read_result_entered;
+#endif
 }
 
 
@@ -270,7 +280,7 @@
 };
 
 /* Convert a routine as used in the cache table to a string. */
-const char *
+inline const char *
 routine_id_to_string(enum routine_id routine)
 {
   return routine_names[(int) routine];
@@ -282,7 +292,7 @@
  * allocate a single node or if the allocation fails, the caching is
  * disabled.
  */
-void
+inline void
 reading_cache_init(int bytes)
 {
   tt_init(&ttable, bytes);
@@ -290,13 +300,13 @@
 
 
 /* Clear the cache for read results. */
-void
+inline void
 reading_cache_clear()
 {
   tt_clear(&ttable);
 }
 
-float
+inline float
 reading_cache_default_size()
 {
   return DEFAULT_NUMBER_OF_CACHE_ENTRIES * sizeof(Hashentry) / 1024.0 / 1024.0;
Index: gnugo/engine/cache.h
===================================================================
RCS file: /sources/gnugo/gnugo/engine/cache.h,v
retrieving revision 1.54
diff -u -r1.54 cache.h
--- gnugo/engine/cache.h	23 Jan 2006 18:15:50 -0000	1.54
+++ gnugo/engine/cache.h	28 Nov 2006 22:08:30 -0000
@@ -32,16 +32,26 @@
  * (Reading/Hashing) for more information.  
  */
 
+#if SIZEOF_INT == 4
+  typedef unsigned int HASHNODE_DATATYPE;
+#elif SIZEOF_LONG == 4
+  typedef unsigned long HASHNODE_DATATYPE;
+#elif SIZEOF_INT > 4
+  typedef unsigned short HASHNODE_DATATYPE;
+#elif
+  #error Long type size has to be at least 4 bytes.
+#endif
 
 /* Hashnode: a node stored in the transposition table.
  *
  * In addition to the position, the hash lock encodes the following data,
  * all hashed:
- *   komaster
- *   kom_pos
+ *   ko
+ *   komaster (look in doc)
+ *   kom_pos (look in doc)
  *   routine
- *   str1
- *   str2
+ *   target1
+ *   target2
  *   extra hashvalue, optional (e.g. encoding a goal array)
  *
  * The data field packs into 32 bits the following
@@ -54,11 +64,13 @@
  *   cost           :  4 bits
  *   remaining_depth:  5 bits (depth - stackp)  NOTE: HN_MAX_REMAINING_DEPTH
  *
- *   The last 9 bits together give an index for the total costs.
+ *   The last 9 bits together give a reliability index (bigger index means
+ *   more reliable result).
+ *   Values are results of analyzed position (WIN, LOSE, etc.)
  */
 typedef struct {
   Hash_data key;
-  unsigned int data; /* Should be 32 bits, but only wastes 25% if 64 bits. */
+  HASHNODE_DATATYPE data; /* 32-bit value */
 } Hashnode;
 
 #define HN_MAX_REMAINING_DEPTH 31
@@ -67,7 +79,7 @@
 /* Hashentry: an entry, with two nodes of the hash_table
  */
 typedef struct {
-  Hashnode deepest;
+  Hashnode most_reliable;
   Hashnode newest;
 } Hashentry;
 
@@ -76,22 +88,21 @@
 #define hn_get_value2(hn)           ((hn >> 19) & 0x0f)
 #define hn_get_move(hn)             ((hn >>  9) & 0x3ff)
 #define hn_get_cost(hn)             ((hn >>  5) & 0x0f)
-#define hn_get_remaining_depth(hn)  ((hn >>  0) & 0x1f)
-#define hn_get_total_cost(hn)       ((hn >>  0) & 0x1ff)
+#define hn_get_remaining_depth(hn)  ((hn/*>>  0*/) & 0x1f)
+#define hn_get_reliability(hn)      ((hn/*>>  0*/) & 0x1ff)
 
 #define hn_create_data(remaining_depth, value1, value2, move, cost) \
     ((((value1)         & 0x0f)  << 23) \
    | (((value2)         & 0x0f)  << 19) \
    | (((move)           & 0x3ff) <<  9) \
    | (((cost)           & 0x0f)  <<  5) \
-   | (((remaining_depth & 0x1f)  <<  0)))
+   | (((remaining_depth & 0x1f)/*<<  0*/)))
 
 
 /* Transposition_table: transposition table used for caching. */
 typedef struct {
   unsigned int num_entries;
   Hashentry *entries;
-  int is_clean;
 } Transposition_table;
 
 extern Transposition_table ttable;
@@ -101,7 +112,7 @@
  */
 #define DEFAULT_NUMBER_OF_CACHE_ENTRIES 350000
 
-void tt_free(Transposition_table *table);
+inline void tt_free(Transposition_table *table);
 int  tt_get(Transposition_table *table, enum routine_id routine,
 	    int target1, int target2, int remaining_depth,
 	    Hash_data *extra_hash,
@@ -141,11 +152,15 @@
   int q1 = board[str1] == EMPTY ? str1 : find_origin(str1); \
   int q2 = board[str2] == EMPTY ? str2 : find_origin(str2);
 
+#define READ_FUNCTION_NAME read_function_name
+
 #else
 
 #define TRACE_CACHED_RESULT(result, move)
 #define TRACE_CACHED_RESULT2(result1, result2, move)
 
+#ifndef GG_TURN_OFF_TRACES
+
 #define SETUP_TRACE_INFO(name, str) \
   const char *read_function_name = name; \
   int q = str;
@@ -155,18 +170,6 @@
   int q1 = str1; \
   int q2 = str2;
 
-#endif
-
-/* Trace messages in decidestring/decidedragon sgf file. */
-void sgf_trace(const char *func, int str, int move, int result,
-	       const char *message);
-/* Trace messages in decideconnection sgf file. */
-void sgf_trace2(const char *func, int str1, int str2, int move, 
-	        const char *result, const char *message);
-/* Trace messages in decidesemeai sgf file. */
-void sgf_trace_semeai(const char *func, int str1, int str2, int move, 
-		      int result1, int result2, const char *message);
-
 /* Macro to hide the call to sgf_trace(). Notice that a little black
  * magic is going on here. Before using this macro, SETUP_TRACE_INFO
  * must have been called to provide the variables read_function_name
@@ -190,6 +193,31 @@
     sgf_trace_semeai(read_function_name, q1, q2, move, \
 	             result1, result2, message)
 
+#define READ_FUNCTION_NAME read_function_name
+
+#else // #ifndef GG_TURN_OFF_TRACES
+
+#define SETUP_TRACE_INFO(name, str)
+#define SETUP_TRACE_INFO2(name, str1, str2)
+#define SGFTRACE(move, result, message) (void)0
+#define SGFTRACE2(move, result, message) (void)0
+#define SGFTRACE_SEMEAI(move, result1, result2, message) (void)0
+#define READ_FUNCTION_NAME NULL
+
+#endif // #ifndef GG_TURN_OFF_TRACES
+
+#endif // #if TRACE_READ_RESULTS
+
+/* Trace messages in decidestring/decidedragon sgf file. */
+void sgf_trace(const char *func, int str, int move, int result,
+	       const char *message);
+/* Trace messages in decideconnection sgf file. */
+void sgf_trace2(const char *func, int str1, int str2, int move, 
+	        const char *result, const char *message);
+/* Trace messages in decidesemeai sgf file. */
+void sgf_trace_semeai(const char *func, int str1, int str2, int move, 
+		      int result1, int result2, const char *message);
+
 
 /* ================================================================ */
 
@@ -212,7 +240,8 @@
   do { \
     tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, NULL,\
               value, 0, move);\
-    if ((value) != 0 && (point) != 0) *(point) = (move); \
+    if ((point) != NULL && (value) != 0) \
+      *(point) = (move); \
     return (value); \
   } while (0)
 
@@ -220,7 +249,8 @@
   do { \
     tt_update(&ttable, routine, str1, str2, remaining_depth, NULL, \
               value1, value2, move); \
-    if ((value1) != 0 && (point) != 0) *(point) = (move); \
+    if ((point) != NULL && (value1) != 0) \
+      *(point) = (move); \
     return; \
   } while (0)
 
@@ -228,7 +258,8 @@
   do { \
     tt_update(&ttable, routine, str1, str2, remaining_depth, NULL,\
               value, 0, move);\
-    if ((value) != 0 && (point) != 0) *(point) = (move); \
+    if ((point) != NULL && (value) != 0) \
+      *(point) = (move); \
     return (value); \
   } while (0)
 
@@ -236,7 +267,8 @@
   do { \
     tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, hash,\
               value, 0, move);\
-    if ((value) != 0 && (point) != 0) *(point) = (move); \
+    if ((point) != NULL && (value) != 0) \
+      *(point) = (move); \
     return (value); \
   } while (0)
 
@@ -244,7 +276,8 @@
   do { \
     tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, NULL,\
               value1, value2, move);\
-    if ((value1) != 0 && (point) != 0) *(point) = (move); \
+    if ((point) != NULL && (value1) != 0) \
+      *(point) = (move); \
     return (value1); \
   } while (0)
 
Index: gnugo/engine/clock.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/clock.c,v
retrieving revision 1.26
diff -u -r1.26 clock.c
--- gnugo/engine/clock.c	23 Jan 2006 18:15:50 -0000	1.26
+++ gnugo/engine/clock.c	28 Nov 2006 22:08:30 -0000
@@ -38,6 +38,7 @@
 #include "clock.h"
 #include "gg_utils.h"
 #include "board.h"
+#include "gnugo.h"
 
 /* Level data */
 static int level             = DEFAULT_LEVEL; /* current level */
@@ -68,8 +69,8 @@
 };
 
 struct timer_data {
-  struct remaining_time_data official;
-  struct remaining_time_data estimated;
+  struct remaining_time_data official; // time received from external source
+  struct remaining_time_data estimated; // time counted by GnuGO
   int time_out;
 };
 
@@ -127,7 +128,7 @@
  *
  *  byo_time > 0 and byo_stones == 0 means no time settings.
  */
-void
+inline void
 clock_settings(int time, int byo_time, int byo_stones)
 {
   if (time >= 0)
@@ -142,7 +143,7 @@
 /* Get time settings. Returns 1 if any time settings have been made,
  * 0 otherwise.
  */
-int
+inline int
 have_time_settings(void)
 {
   /* According to the semantics of the GTP command 'time_settings', the
@@ -220,23 +221,28 @@
   static int last_movenum = -1;
   struct timer_data* const td
     = (color == BLACK) ? &black_time_data : &white_time_data;
-  double now = gg_gettimeofday();
+  double now;
 
   if (!have_time_settings())
     return;
 
+  now = gg_gettimeofday();
+
   if (last_movenum >= 0
-      && movenum == last_movenum + 1
-      && movenum > td->estimated.movenum) {
+      && movenum == last_movenum + 1) {
     double time_used = now - last_time;
     td->estimated.time_left -= time_used;
     td->estimated.movenum = movenum;
     td->estimated.time_for_last_move = time_used;
     if (td->estimated.time_left < 0) {
       if (td->estimated.in_byoyomi || byoyomi_stones == 0) {
+
+#ifndef GG_TURN_OFF_DEBUGS
 	DEBUG(DEBUG_TIME, "%s ran out of time.\n", color_to_string(color));
 	if (debug & DEBUG_TIME)
 	  clock_print(color);
+#endif
+
 	td->time_out = 1;
       }
       else {
@@ -251,7 +257,7 @@
     }
     else if (td->estimated.stones > 0) {
       gg_assert(td->estimated.in_byoyomi);
-      td->estimated.stones = td->estimated.stones - 1;
+      --td->estimated.stones;
       if (td->estimated.stones == 0) {
 	td->estimated.time_left = byoyomi_time;
 	td->estimated.stones = byoyomi_stones;
@@ -262,9 +268,11 @@
   last_movenum = movenum;
   last_time = now;
 
+#ifndef GG_TURN_OFF_DEBUGS
   /* Update main timer. */
   if (debug & DEBUG_TIME)
     clock_print(color);
+#endif
 }
 
 
@@ -297,9 +305,12 @@
 
   if (timer->stones == 0) {
     /* Main time running. */
-    *time_left = timer->time_left + byoyomi_time;
+    *time_left = timer->time_left;
     if (byoyomi_time > 0)
+    {
+      *time_left += byoyomi_time;
       *stones_left = byoyomi_stones;
+    }
     else {
       /* Absolute time. Here we aim to be able to play at least X more
        * moves or a total of Y moves. We choose Y as a third of the
@@ -331,7 +342,7 @@
 adjust_level_offset(int color)
 {
   double time_for_last_move;
-  double time_left;
+  double time_left, estimated_time;
   int stones_left;
 
   if (!analyze_time_data(color, &time_for_last_move, &time_left, &stones_left))
@@ -342,28 +353,39 @@
    *
    * FIXME: Use rules with at least some theoretical basis.
    */
-  if (time_left < time_for_last_move * (stones_left + 3))
-    level_offset--;
-  if (time_left < time_for_last_move * stones_left)
-    level_offset--;
-  if (3 * time_left < 2 * time_for_last_move * stones_left)
-    level_offset--;
-  if (2 * time_left < time_for_last_move * stones_left)
-    level_offset--;
-  if (3 * time_left < time_for_last_move * stones_left)
-    level_offset--;
-
-  if (time_for_last_move == 0)
-    time_for_last_move = 1;
-  if (time_left > time_for_last_move * (stones_left + 6))
-    level_offset++;
-  if (time_left > 2 * time_for_last_move * (stones_left + 6))
-    level_offset++;
+  if (time_for_last_move < 0.1)
+    time_for_last_move = 0.1;
+
+  estimated_time = time_for_last_move * stones_left;
+
+  if (time_left < estimated_time)
+  {
+    --level_offset;
+
+    if (1.33 * time_left < estimated_time)
+    {
+      --level_offset;
+
+      if (2 * time_left < estimated_time)
+      {
+        level_offset -= 2;
+
+        if (4 * time_left < estimated_time)
+          level_offset -= 2;
+      }
+    }
+  }
+  else if (0.8 * time_left > estimated_time)
+  {
+    ++level_offset;
+
+    if (0.5 * time_left > estimated_time)
+      level_offset += 2;
+  }
 
   if (level + level_offset < min_level)
     level_offset = min_level - level;
-
-  if (level + level_offset > max_level)
+  else if (level + level_offset > max_level)
     level_offset = max_level - level;
 
   DEBUG(DEBUG_TIME, "New level %d (%d %C %f %f %d)\n", level + level_offset,
@@ -375,13 +397,13 @@
 /* Interface to level settings. */
 /********************************/
 
-int
+inline int
 get_level()
 {
   return level + level_offset;
 }
 
-void
+inline void
 set_level(int new_level)
 {
   level = new_level;
@@ -392,13 +414,13 @@
     min_level = level;
 }
 
-void
+inline void
 set_max_level(int new_max)
 {
   max_level = new_max;
 }
 
-void
+inline void
 set_min_level(int new_min)
 {
   min_level = new_min;
Index: gnugo/engine/clock.h
===================================================================
RCS file: /sources/gnugo/gnugo/engine/clock.h,v
retrieving revision 1.15
diff -u -r1.15 clock.h
--- gnugo/engine/clock.h	27 Jan 2006 01:17:34 -0000	1.15
+++ gnugo/engine/clock.h	28 Nov 2006 22:08:31 -0000
@@ -26,22 +26,22 @@
 #include "gnugo.h"
 
 /* initialization and activation */
-void clock_settings(int maintime, int byotime, int byostones);
+inline void clock_settings(int maintime, int byotime, int byostones);
 void init_timers(void);
  
 /* main access */
 void clock_push_button(int color);
 void update_time_left(int color, int time_left, int stones);
 void clock_print(int color);
-int have_time_settings(void);
+inline int have_time_settings(void);
 
 void adjust_level_offset(int color);
 
 /* Access to level settings. */
-int get_level(void);
-void set_level(int new_level);
-void set_max_level(int new_max);
-void set_min_level(int new_min);
+inline int get_level(void);
+inline void set_level(int new_level);
+inline void set_max_level(int new_max);
+inline void set_min_level(int new_min);
 
 
 #endif  /* _CLOCK_H_ */
Index: gnugo/engine/combination.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/combination.c,v
retrieving revision 1.57
diff -u -r1.57 combination.c
--- gnugo/engine/combination.c	4 Feb 2006 10:17:17 -0000	1.57
+++ gnugo/engine/combination.c	28 Nov 2006 22:08:37 -0000
@@ -761,7 +761,7 @@
 	if (num_libs == 2)
 	  all_potential_defenses[libs[1]] = 1;
       }
-    }
+	}
 
     if (!IS_STONE(board[str])) {
       /* Error situation. This could be caused by a wrong matcher status. */
@@ -889,7 +889,7 @@
       continue;
     
     if (board[last_friendly] == EMPTY
-	&& !liberty_of_string(last_friendly, pos))
+	&& !liberty_of_string2(last_friendly, pos))
       continue;
     
     if (debug & DEBUG_ATARI_ATARI)
@@ -1054,7 +1054,7 @@
 
 	if (!safe_move(move, color))
 	  continue;
-      }
+	  }
       
       /*
        * Play (move) and see if there is an attack.
Index: gnugo/engine/dragon.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/dragon.c,v
retrieving revision 1.162
diff -u -r1.162 dragon.c
--- gnugo/engine/dragon.c	18 May 2006 03:54:42 -0000	1.162
+++ gnugo/engine/dragon.c	28 Nov 2006 22:08:50 -0000
@@ -594,7 +594,7 @@
 	  propagate_worm(str);
 	}
       }
-    }
+	}
 
   /* Revise essentiality of critical dragons. Specifically, a critical
    * dragon consisting entirely of inessential worms is considered
Index: gnugo/engine/endgame.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/endgame.c,v
retrieving revision 1.13
diff -u -r1.13 endgame.c
--- gnugo/engine/endgame.c	23 Jan 2006 18:15:50 -0000	1.13
+++ gnugo/engine/endgame.c	28 Nov 2006 22:08:51 -0000
@@ -461,8 +461,10 @@
   int liberties;
   int libs[MAXLIBS];
   int k;
+  int color = board[str];
+  int origin = find_origin(str);
 
-  ASSERT1(IS_STONE(board[str]), str);
+  ASSERT1(IS_STONE(color), str);
 
   *essential_liberties = 0;
   *inessential_liberties = 0;
@@ -494,8 +496,8 @@
 	if (worm[pos].attack_codes[0] != 0 || dragon[pos].status != ALIVE)
 	  return 0;
 
-	if (board[pos] == board[str]) {
-	  if (find_origin(pos) != find_origin(str))
+	if (board[pos] == color) {
+	  if (find_origin(pos) != origin)
 	    essential = 1;
 	}
 	else
Index: gnugo/engine/filllib.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/filllib.c,v
retrieving revision 1.37
diff -u -r1.37 filllib.c
--- gnugo/engine/filllib.c	17 Apr 2006 07:56:14 -0000	1.37
+++ gnugo/engine/filllib.c	28 Nov 2006 22:08:53 -0000
@@ -310,13 +310,13 @@
       DEBUG(DEBUG_FILLLIB,
 	    "Filllib: Nothing found, looking for threat to back-capture.\n");
       for (k = 0; k < 4; k++) {
-	int d = delta[k];
-	if (board[pos + d] == other
-	    && worm[pos + d].attack_codes[0] != 0) {
+	int checked_pos = pos + delta[k];
+	if (board[checked_pos] == other
+	    && worm[checked_pos].attack_codes[0] != 0) {
 	  /* Just pick some other liberty. */
 	  /* FIXME: Something is odd about this code. */
 	  int libs[2];
-	  if (findlib(pos + d, 2, libs) > 1) {
+	  if (findlib(checked_pos, 2, libs) > 1) {
 	    if (is_legal(libs[0], color))
 	      *move = libs[0];
 	    else if (is_legal(libs[1], color))
@@ -394,7 +394,7 @@
    */
   acode = attack(move, &apos);
   gg_assert(acode != 0 && apos != NO_MOVE);
-  
+
   /* Find liberties. */
   liberties = findlib(move, MAXLIBS, libs);
 
@@ -435,7 +435,7 @@
       if (attack(adjs[k], &bpos) == WIN) {
 	if (forbidden_moves[bpos])
 	  continue;
-	if (liberty_of_string(bpos, adjs[k])) {
+	if (liberty_of_string2(bpos, adjs[k])) {
 	  *backfill_move = bpos;
 	  return 1;
 	}
@@ -464,7 +464,7 @@
 	if (attack(adjs[k], &bpos) == WIN) {
 	  if (forbidden_moves[bpos])
 	    continue;
-	  if (liberty_of_string(bpos, adjs[k])) {
+	  if (liberty_of_string2(bpos, adjs[k])) {
 	    *backfill_move = bpos;
 	    return 1;
 	  }
@@ -496,7 +496,7 @@
     popgo();
     for (k = 0; k < neighbors; k++) {
       if (attack(adjs[k], &bpos) == WIN) {
-	if (!forbidden_moves[bpos] && liberty_of_string(bpos, adjs[k])) {
+	if (!forbidden_moves[bpos] && liberty_of_string2(bpos, adjs[k])) {
 	  *backfill_move = bpos;
 	  return 1;
 	}
Index: gnugo/engine/genmove.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/genmove.c,v
retrieving revision 1.116
diff -u -r1.116 genmove.c
--- gnugo/engine/genmove.c	17 Sep 2006 23:29:22 -0000	1.116
+++ gnugo/engine/genmove.c	28 Nov 2006 22:08:58 -0000
@@ -73,6 +73,9 @@
 void
 reset_engine()
 {
+  static int last_level = -1;
+  int act_level;
+
   /* To improve the reproducability of games, we restart the random
    * number generator with the same seed for each move. Thus we don't
    * have to know how many previous moves have been played, nor
@@ -98,7 +101,12 @@
   clear_break_in_list();
 
   /* Set up depth values (see comments there for details). */
-  set_depth_values(get_level(), 0);
+  act_level = get_level();
+  if (last_level != act_level)
+  {
+    set_depth_values(act_level, 0);
+    last_level = act_level;
+  }
 }
 
 /*
@@ -117,24 +125,39 @@
 void
 examine_position(int how_much, int aftermath_play)
 {
+#ifndef GG_TURN_OFF_TRACES
   int save_verbose = verbose;
+#endif
 
   purge_persistent_caches();
   
+#ifndef GG_TURN_OFF_TRACES
   /* Don't print reading traces during make_worms and make_dragons unless 
    * the user really wants it (verbose == 3). 
    */
   if (verbose == 1 || verbose == 2)
     --verbose;
+#endif
 
   if (NEEDS_UPDATE(worms_examined)) {
+
+#ifndef GG_TURN_OFF_TRACES
     start_timer(0);
+#endif
+
     make_worms();
+
+#ifndef GG_TURN_OFF_TRACES
     time_report(0, "  make worms", NO_MOVE, 1.0);
+#endif
   }
 
   if (how_much == EXAMINE_WORMS) {
+
+#ifndef GG_TURN_OFF_TRACES
     verbose = save_verbose;
+#endif
+
     gg_assert(test_gray_border() < 0);
     return;
   }
@@ -142,8 +165,13 @@
   if (stones_on_board(BLACK | WHITE) != 0) {
     if (NEEDS_UPDATE(initial_influence_examined))
       compute_worm_influence();
+
     if (how_much == EXAMINE_INITIAL_INFLUENCE) {
+
+#ifndef GG_TURN_OFF_TRACES
       verbose = save_verbose;
+#endif
+
       gg_assert(test_gray_border() < 0);
       return;
     }
@@ -151,7 +179,11 @@
     if (how_much == EXAMINE_DRAGONS_WITHOUT_OWL) {
       if (NEEDS_UPDATE(dragons_examined_without_owl))
 	make_dragons(1);
+
+#ifndef GG_TURN_OFF_TRACES
       verbose = save_verbose;
+#endif
+
       gg_assert(test_gray_border() < 0);
       return;
     }
@@ -163,7 +195,11 @@
       dragons_examined_without_owl = position_number;
     }
     if (how_much == EXAMINE_DRAGONS) {
+
+#ifndef GG_TURN_OFF_TRACES
       verbose = save_verbose;
+#endif
+
       gg_assert(test_gray_border() < 0);
       return;
     }
@@ -173,12 +209,18 @@
 	   || how_much == EXAMINE_ALL) {
     initialize_dragon_data();
     compute_scores(chinese_rules || aftermath_play);
+
+#ifndef GG_TURN_OFF_TRACES
     verbose = save_verbose;
+#endif
+
     gg_assert(test_gray_border() < 0);
     return;
   }
   
+#ifndef GG_TURN_OFF_TRACES
   verbose = save_verbose;
+#endif
 
   if (NEEDS_UPDATE(initial_influence2_examined)) {
     compute_dragon_influence();
@@ -197,8 +239,10 @@
     return;
   }
 
+#ifndef GG_TURN_OFF_TRACES
   if (printworms)
     show_dragons();
+#endif
 }
 
 
@@ -283,7 +327,7 @@
 /* This function collects move reasons can be generated immediately from
  * the data gathered in the examine_position() phase.
  */
-void
+inline void
 collect_move_reasons(int color)
 {
   worm_reasons(color);
@@ -306,17 +350,28 @@
 	   int allowed_moves[BOARDMAX], float *value, int *resign)
 {
   float average_score, pessimistic_score, optimistic_score;
-  int save_verbose;
-  int save_depth;
   int move;
   float dummy_value;
   int use_thrashing_dragon_heuristics = 0;
 
+#ifndef GG_TURN_OFF_TRACES
+  int save_verbose;
+#endif
+
+#ifndef GG_TURN_OFF_ASSERTS
+  int save_depth;
+#endif
+
   if (!value)
     value = &dummy_value;
 
+#ifndef GG_TURN_OFF_TRACES
   start_timer(0);
+#endif
+
+#ifndef GG_TURN_OFF_STATS
   clearstats();
+#endif
 
   /* Usually we would not recommend resignation. */
   if (resign)
@@ -332,10 +387,12 @@
   /* Prepare pattern matcher and reading code. */
   reset_engine();
 
+#ifndef GG_TURN_OFF_ASSERTS
   /* Store the depth value so we can check that it hasn't changed when
    * we leave this function.
    */
   save_depth = depth;
+#endif
 
   /* If in mirror mode, try to find a mirror move. */
   if (play_mirror_go
@@ -348,9 +405,15 @@
   }
 
   /* Find out information about the worms and dragons. */
+#ifndef GG_TURN_OFF_TRACES
   start_timer(1);
+#endif
+
   examine_position(EXAMINE_ALL, 0);
+
+#ifndef GG_TURN_OFF_TRACES
   time_report(1, "examine position", NO_MOVE, 1.0);
+#endif
 
 
   /* The score will be used to determine when we are safely
@@ -374,6 +437,7 @@
     average_score = -(white_score + black_score)/2.0;
   choose_strategy(color, average_score, game_status(color));
 
+#ifndef GG_TURN_OFF_TRACES
   if (printboard) {
     if (printboard == 1)
       fprintf(stderr, "\n          dragon_status display:\n\n");
@@ -387,6 +451,7 @@
       showboard(4);
     }
   }
+#endif
   
   gg_assert(stackp == 0);
   
@@ -396,12 +461,18 @@
 
   
   /* Pick up moves that we know of already. */
+#ifndef GG_TURN_OFF_TRACES
   save_verbose = verbose;
   if (verbose > 0)
     verbose--;
+#endif
+
   collect_move_reasons(color);
+
+#ifndef GG_TURN_OFF_TRACES
   verbose = save_verbose;
   time_report(1, "generate move reasons", NO_MOVE, 1.0);
+#endif
   
   /* Try to find empty corner moves. */
   fuseki(color);
@@ -420,12 +491,20 @@
   
   /* The general pattern database. */
   shapes(color);
+
+#ifndef GG_TURN_OFF_TRACES
   time_report(1, "shapes", NO_MOVE, 1.0);
+#endif
+
   gg_assert(stackp == 0);
 
   /* Look for combination attacks and defenses against them. */
   combinations(color);
+
+#ifndef GG_TURN_OFF_TRACES
   time_report(1, "combinations", NO_MOVE, 1.0);
+#endif
+
   gg_assert(stackp == 0);
 
   /* Review the move reasons and estimate move values. */
@@ -433,8 +512,12 @@
 			  pure_threat_value, pessimistic_score, allowed_moves,
 			  use_thrashing_dragon_heuristics))
     TRACE("Move generation likes %1m with value %f\n", move, *value);
+
   gg_assert(stackp == 0);
+
+#ifndef GG_TURN_OFF_TRACES
   time_report(1, "review move reasons", NO_MOVE, 1.0);
+#endif
 
 
   /* If the move value is 6 or lower, we look for endgame patterns too. */
@@ -447,7 +530,10 @@
 			    use_thrashing_dragon_heuristics))
       TRACE("Move generation likes %1m with value %f\n", move, *value);
     gg_assert(stackp == 0);
+
+#ifndef GG_TURN_OFF_TRACES
     time_report(1, "endgame", NO_MOVE, 1.0);
+#endif
   }
   
   /* If no move found yet, revisit any semeai and change the
@@ -465,8 +551,10 @@
 	      move, *value); 
       }
     }
-    time_report(1, "move reasons with revised semeai status",
-		NO_MOVE, 1.0);
+
+#ifndef GG_TURN_OFF_TRACES
+    time_report(1, "move reasons with revised semeai status", NO_MOVE, 1.0);
+#endif
   }
 
   /* If still no move, fill a remaining liberty. This should pick up
@@ -478,8 +566,11 @@
       *value = 1.0;
       TRACE("Filling a liberty at %1m\n", move);
       record_top_move(move, *value);
-      move_considered(move, *value);
+
+#ifndef GG_TURN_OFF_TRACES
+	  move_considered(move, *value);
       time_report(1, "fill liberty", NO_MOVE, 1.0);
+#endif
     }
     else
       move = PASS_MOVE;
@@ -492,7 +583,7 @@
   if (move == PASS_MOVE) {
     if (play_out_aftermath 
 	|| capture_all_dead 
-	|| (!doing_scoring && thrashing_dragon && pessimistic_score > 15.0))
+	|| (!doing_scoring && thrashing_dragon && pessimistic_score > 1.0))
       move = aftermath_genmove(color, 0, allowed_moves);
       
     /* If we're instructed to capture all dead opponent stones, generate
@@ -506,8 +597,11 @@
       *value = 1.0;
       TRACE("Aftermath move at %1m\n", move);
       record_top_move(move, *value);
+
+#ifndef GG_TURN_OFF_TRACES
       move_considered(move, *value);
       time_report(1, "aftermath_genmove", NO_MOVE, 1.0);
+#endif
     }
   }
 
@@ -534,10 +628,13 @@
     *resign = 1;
   }
   
+#ifndef GG_TURN_OFF_STATS
   /* If statistics is turned on, this is the place to show it. */
   if (showstatistics)
     showstats();
+#endif
 
+#ifndef GG_TURN_OFF_TRACES
   if (showtime) {
     double spent = time_report(0, "TIME to generate move at ", move, 1.0);
     total_time += spent;
@@ -547,13 +644,17 @@
       slowest_movenum = movenum + 1;
     }
   }
+#endif
 
   /* Some consistency checks to verify that things are properly
    * restored and/or have not been corrupted.
    */
   gg_assert(stackp == 0);
   gg_assert(test_gray_border() < 0);
+
+#ifndef GG_TURN_OFF_ASSERTS
   gg_assert(depth == save_depth);
+#endif
 
   return move;
 }
@@ -565,7 +666,7 @@
  * have considered.
  */
 
-void 
+inline void 
 move_considered(int move, float value)
 {
   if (value > potential_moves[move])
@@ -682,7 +783,7 @@
   return 0;
 }
 
-/* Computer two territory estimates: for *upper, the status of all
+/* Compute two territory estimates: for *upper, the status of all
  * cricital stones gets resolved in White's favor; vice verso for
  * black.
  */
@@ -701,6 +802,7 @@
       		    NO_MOVE, "White territory estimate");
   black_score = influence_score(&move_influence, use_chinese_rules);
 
+#ifndef GG_TURN_OFF_TRACES
   if (verbose || showscore) {
     if (white_score == black_score)
       gprintf("Score estimate: %s %f\n",
@@ -711,6 +813,7 @@
 	      white_score > 0 ? "W " : "B ", gg_abs(white_score));
     fflush(stderr);
   }
+#endif
 }
 
 
Index: gnugo/engine/globals.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/globals.c,v
retrieving revision 1.81
diff -u -r1.81 globals.c
--- gnugo/engine/globals.c	11 Feb 2006 13:46:20 -0000	1.81
+++ gnugo/engine/globals.c	28 Nov 2006 22:08:59 -0000
@@ -132,11 +132,12 @@
 float white_score;
 float black_score;
 
-int close_worms[BOARDMAX][4];
+/* Close worms data. See liberty.h */
+int close_worms[BOARDMAX][MAX_CLOSE_WORMS];
 int number_close_worms[BOARDMAX];
-int close_black_worms[BOARDMAX][4];
+int close_black_worms[BOARDMAX][MAX_CLOSE_WORMS];
 int number_close_black_worms[BOARDMAX];
-int close_white_worms[BOARDMAX][4];
+int close_white_worms[BOARDMAX][MAX_CLOSE_WORMS];
 int number_close_white_worms[BOARDMAX];
 
 int false_eye_territory[BOARDMAX];
Index: gnugo/engine/gnugo.h
===================================================================
RCS file: /sources/gnugo/gnugo/engine/gnugo.h,v
retrieving revision 1.133
diff -u -r1.133 gnugo.h
--- gnugo/engine/gnugo.h	11 Feb 2006 13:46:20 -0000	1.133
+++ gnugo/engine/gnugo.h	28 Nov 2006 22:09:01 -0000
@@ -114,6 +114,16 @@
 /*                           global variables                       */
 /* ================================================================ */
 
+// final release option
+
+#if FINAL_RELEASE == 1
+
+#define GG_TURN_OFF_ASSERTS
+#define GG_TURN_OFF_TRACES
+#define GG_TURN_OFF_STATS
+#define GG_TURN_OFF_DEBUGS
+
+#endif
 
 /* Miscellaneous debug options. */
 extern int quiet;		/* Minimal output. */
@@ -269,8 +279,16 @@
 /* influence.c */
 void debug_influence_move(int move);
 
-
+#ifdef GG_TURN_OFF_TRACES
+#define TRACE (1) ? (void)0 : (void)gprintf
+#else
 #define TRACE  (!(verbose)) ? (void)0 : (void)gprintf
+#endif
+
+#ifdef GG_TURN_OFF_DEBUGS
+#define DEBUG (1) ? (void)0 : (void)DEBUG_func
+int DEBUG_func(int level, const char *fmt, ...);
+#else
 
 #ifdef HAVE_VARIADIC_DEFINE
 
@@ -286,6 +304,8 @@
 
 #endif  /*HAVE_VARIADIC_DEFINE*/
 
+#endif /*GG_TURN_OFF_DEBUGS*/
+
 
 /* genmove.c */
 #define EXAMINE_WORMS               1
Index: gnugo/engine/hash.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/hash.c,v
retrieving revision 1.38
diff -u -r1.38 hash.c
--- gnugo/engine/hash.c	23 Jan 2006 18:15:50 -0000	1.38
+++ gnugo/engine/hash.c	28 Nov 2006 22:09:02 -0000
@@ -24,10 +24,12 @@
 #include "board.h"
 #include "hash.h"
 #include "random.h"
+#include "gnugo.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <limits.h>
+#include <string.h>
 
 
 
@@ -58,9 +60,10 @@
 {
   int i;
   Hashvalue h = 0;
+  const int limit = CHAR_BIT * sizeof(Hashvalue);
 
-  for (i = 0; 32*i < (int) (CHAR_BIT*sizeof(Hashvalue)); i++)
-    h |= (Hashvalue) gg_urand() << 32*i;
+  for (i = 0; i < limit; i += 32)
+    h |= ((Hashvalue) gg_urand()) << i;
 
   return h;
 }
@@ -118,21 +121,19 @@
       hashdata_xor(*target, black_hash[pos]);
   }
 
-  if (ko_pos != 0)
+  if (ko_pos != NO_MOVE)
     hashdata_xor(*target, ko_hash[ko_pos]);
 }
 
 /* Clear hashdata. */
-void
+inline void
 hashdata_clear(Hash_data *hd)
 {
-  int i;
-  for (i = 0; i < NUM_HASHVALUES; i++)
-    hd->hashval[i] = 0;
+  memset(hd->hashval, 0, NUM_HASHVALUES * sizeof(Hashvalue));
 }
 
 /* Set or remove ko in the hash value and hash position.  */
-void
+inline void
 hashdata_invert_ko(Hash_data *hd, int pos)
 {
   hashdata_xor(*hd, ko_hash[pos]);
@@ -140,7 +141,7 @@
 
 
 /* Set or remove a stone of COLOR at pos in a Hash_data.  */
-void
+inline void
 hashdata_invert_stone(Hash_data *hd, int pos, int color)
 {
   if (color == BLACK)
@@ -151,14 +152,14 @@
 
 
 /* Set or remove the komaster value in the hash data. */
-void
+inline void
 hashdata_invert_komaster(Hash_data *hd, int komaster)
 {
   hashdata_xor(*hd, komaster_hash[komaster]);
 }
 
 /* Set or remove the komaster position in the hash data. */
-void
+inline void
 hashdata_invert_kom_pos(Hash_data *hd, int kom_pos)
 {
   hashdata_xor(*hd, kom_pos_hash[kom_pos]);
Index: gnugo/engine/hash.h
===================================================================
RCS file: /sources/gnugo/gnugo/engine/hash.h,v
retrieving revision 1.37
diff -u -r1.37 hash.h
--- gnugo/engine/hash.h	23 Jan 2006 18:15:50 -0000	1.37
+++ gnugo/engine/hash.h	28 Nov 2006 22:09:02 -0000
@@ -87,12 +87,12 @@
 #define INIT_ZOBRIST_ARRAY(a) \
   hash_init_zobrist_array(a, (int) (sizeof(a) / sizeof(a[0])))
 
-void hashdata_clear(Hash_data *hd);
+inline void hashdata_clear(Hash_data *hd);
 void hashdata_recalc(Hash_data *hd, Intersection *board, int ko_pos);
-void hashdata_invert_ko(Hash_data *hd, int pos);
-void hashdata_invert_stone(Hash_data *hd, int pos, int color);
-void hashdata_invert_komaster(Hash_data *hd, int komaster);
-void hashdata_invert_kom_pos(Hash_data *hd, int kom_pos);
+inline void hashdata_invert_ko(Hash_data *hd, int pos);
+inline void hashdata_invert_stone(Hash_data *hd, int pos, int color);
+inline void hashdata_invert_komaster(Hash_data *hd, int komaster);
+inline void hashdata_invert_kom_pos(Hash_data *hd, int kom_pos);
 
 char *hashdata_to_string(Hash_data *hashdata);
 
@@ -100,14 +100,13 @@
 
 /* ---------------------------------------------------------------- */
 
-/* There is no need to involve all bits in the remainder computation
- * as long as we only use it to compute a key into a hash table. 32
- * random bits are sufficient to get an even distribution within any
- * hashtable of reasonable size. By never using more than 32 bits we
- * also reduce the platform dependency of the GNU Go engine.
-*/
+/* Calculates a place in the transposition table where to look up for
+   a hash value. If sizeof(long) > sizeof(int) we truncate long to int
+   because size of the transposition table wouldn't be greater than
+   int. */
 #define hashdata_remainder(hd, num) \
-  (((hd).hashval[0] & 0xffffffffU) % (num))
+  (*((unsigned int*)((hd).hashval)) % (num))
+
 
 #if NUM_HASHVALUES == 1
 
Index: gnugo/engine/liberty.h
===================================================================
RCS file: /sources/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.258
diff -u -r1.258 liberty.h
--- gnugo/engine/liberty.h	19 Feb 2006 19:39:17 -0000	1.258
+++ gnugo/engine/liberty.h	28 Nov 2006 22:09:07 -0000
@@ -97,7 +97,8 @@
   "analyze_semeai"
 
 /* To prioritize between different types of reading, we give a cost
- * ranking to each of the routines above:
+ * ranking to each of the routines above (bigger index means bigger
+ * cost):
  *
  * 4 semeai
  * 3 owl
@@ -111,7 +112,7 @@
   3, 3, 4, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, -1
   
 
-const char *routine_id_to_string(enum routine_id routine);
+inline const char *routine_id_to_string(enum routine_id routine);
 
 
 /* This is used for both the dragon status and safety fields.
@@ -119,10 +120,10 @@
  * final status computed by the aftermath code.
  */
 enum dragon_status {
+  UNKNOWN,
   DEAD,
   ALIVE,
   CRITICAL,
-  UNKNOWN,
   UNCHECKED,
   CAN_THREATEN_ATTACK,
   CAN_THREATEN_DEFENSE, 
@@ -139,10 +140,10 @@
 };
 
 #define DRAGON_STATUS_NAMES \
+  "unknown", \
   "dead", \
   "alive", \
   "critical", \
-  "unknown", \
   "unchecked", \
   "can threaten attack", \
   "can threaten defense", \
@@ -194,9 +195,9 @@
 		     struct corner_db *database);
 void dfa_match_init(void);
 
-void reading_cache_init(int bytes);
-void reading_cache_clear(void);
-float reading_cache_default_size(void);
+inline void reading_cache_init(int bytes);
+inline void reading_cache_clear(void);
+inline float reading_cache_default_size(void);
 
 /* reading.c */
 int attack(int str, int *move);
@@ -345,7 +346,7 @@
 int surround_map(int dr, int pos);
 
 /* functions to add (or remove) move reasons */
-void collect_move_reasons(int color);
+inline void collect_move_reasons(int color);
 
 void clear_move_reasons(void);
 void add_lunch(int eater, int food);
@@ -652,7 +653,7 @@
 
 void break_territories(int color_to_move, struct influence_data *q,
 		       int store, int pos);
-void clear_break_in_list(void);
+inline void clear_break_in_list(void);
 void break_in_move_reasons(int color);
 
 void choose_strategy(int color, float our_score, float game_status);
@@ -669,7 +670,7 @@
 
 /* debugging support */
 void goaldump(const signed char goal[BOARDMAX]);
-void move_considered(int move, float value);
+inline void move_considered(int move, float value);
 
 
 /* Transformation stuff. */
Index: gnugo/engine/move_reasons.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/move_reasons.c,v
retrieving revision 1.135
diff -u -r1.135 move_reasons.c
--- gnugo/engine/move_reasons.c	11 Feb 2006 13:46:20 -0000	1.135
+++ gnugo/engine/move_reasons.c	28 Nov 2006 22:09:13 -0000
@@ -1553,8 +1553,9 @@
 {
   float new_strength;
   int ii;
+  int aff_stone = board[affected];
 
-  ASSERT1(IS_STONE(board[affected]), affected);
+  ASSERT1(IS_STONE(aff_stone), affected);
 
   if (new_status == 0)
     new_strength = 0.0;
@@ -1563,7 +1564,7 @@
     new_strength = DEFAULT_STRENGTH;
   }
   for (ii = BOARDMIN; ii < BOARDMAX; ii++)
-    if (board[ii] == board[affected]
+    if (board[ii] == aff_stone
 	&& same_string(ii, affected)) {
       strength[ii] = new_strength;
       safe_stones[ii] = new_status;
Index: gnugo/engine/optics.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/optics.c,v
retrieving revision 1.105
diff -u -r1.105 optics.c
--- gnugo/engine/optics.c	5 Feb 2006 11:29:45 -0000	1.105
+++ gnugo/engine/optics.c	28 Nov 2006 22:09:25 -0000
@@ -1748,6 +1748,7 @@
   int defense_point;
   int attack_value;
   int defense_value;
+  int other = OTHER_COLOR(color);
 
   memset(attack_values, 0, sizeof(attack_values));
   memset(defense_values, 0, sizeof(defense_values));
@@ -1846,7 +1847,7 @@
      *           string neighbors more than one empty vertex in the
      *           same eyespace.
      */
-    if (val < 2.0 && board[pos] == EMPTY && board[diag] == OTHER_COLOR(color)
+    if (val < 2.0 && board[pos] == EMPTY && board[diag] == other
 	&& !is_edge_vertex(pos) && neighbor_of_string(pos, diag)
 	&& countstones(diag) >= 3) {
       int strings[3];
@@ -1880,7 +1881,7 @@
 	    continue;
 
 	  for (r = 0; r < lib_count && adj_eye_count < 2; r++)
-	    if (my_eye[libs[r]].color == OTHER_COLOR(color)
+	    if (my_eye[libs[r]].color == other
 		&& !my_eye[libs[r]].marginal)
 	      adj_eye_count++;
 	  if (adj_eye_count < 2) {
@@ -1889,7 +1890,7 @@
 	  }
 	}
       }
-    }
+	}
 
     sum += val;
 
@@ -2402,11 +2403,12 @@
    * liberties empty.
    */
   for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
-    if (mx[pos] == 1 || board[pos] != EMPTY || liberty_of_string(pos, str))
+    if (mx[pos] == 1 || board[pos] != EMPTY || liberty_of_string2(pos, str))
       continue;
     for (k = 0; k < 8; k++) {
-      if (ON_BOARD(pos + delta[k])
-	  && liberty_of_string(pos + delta[k], str)) {
+      int checked_pos = pos + delta[k];
+      if (ON_BOARD(checked_pos)
+	  && liberty_of_string(checked_pos, str)) {
 	play_move(pos, BLACK);
 	break;
       }
@@ -2695,9 +2697,10 @@
   int eyes;
   
   for (k = 0; k < 4; k++) {
-    if (board[vertex + delta[k]] == BLACK) {
+    int checked_pos = vertex + delta[k];
+    if (board[checked_pos] == BLACK) {
       eyes = 0;
-      num_libs = findlib(vertex + delta[k], MAXLIBS, libs);
+      num_libs = findlib(checked_pos, MAXLIBS, libs);
       
       for (r = 0; r < num_libs; r++)
 	if (is_suicide(libs[r], WHITE))
@@ -3646,14 +3649,17 @@
   /* If there are any isolated O stones, those should also be added to
    * the playable vertices.
    */
-  for (pos = BOARDMIN; pos < BOARDMAX; pos++)
-    if (board[pos] == WHITE && !same_string(pos, POS(1, 0))) {
-      vertices[num_vertices] = vertices[num_vertices - 1];
-      vertices[num_vertices - 1] = vertices[num_vertices - 2];
-      vertices[num_vertices - 2] = vertices[num_vertices - 3];
-      vertices[num_vertices - 3] = pos;
-      num_vertices++;
-    }
+  {
+    int pos_1_0 = POS(1, 0);
+    for (pos = BOARDMIN; pos < BOARDMAX; pos++)
+      if (board[pos] == WHITE && !same_string(pos, pos_1_0)) {
+        vertices[num_vertices] = vertices[num_vertices - 1];
+        vertices[num_vertices - 1] = vertices[num_vertices - 2];
+        vertices[num_vertices - 2] = vertices[num_vertices - 3];
+        vertices[num_vertices - 3] = pos;
+        num_vertices++;
+      }
+  }
 
   if (verbose) {
     int k;
Index: gnugo/engine/owl.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/owl.c,v
retrieving revision 1.251
diff -u -r1.251 owl.c
--- gnugo/engine/owl.c	15 Sep 2006 01:05:48 -0000	1.251
+++ gnugo/engine/owl.c	28 Nov 2006 22:10:06 -0000
@@ -480,7 +480,7 @@
 	    && !is_same_dragon(adjs[k], bpos)
 	    && dragon[adjs[k]].crude_status == ALIVE)
 	  adjacent_to_outside = 1;
-      }
+	  }
       
       if ((adjacent_to_outside || countstones(str) > 6)
 	  && s_worms < MAX_SEMEAI_WORMS) {
@@ -1576,10 +1576,16 @@
     for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
       if (IS_STONE(board[pos])
 	  && pos == find_origin(pos)) {
-	if (owla->goal[pos])
-	  net -= 75*countlib(pos);
-	if (owlb->goal[pos])
-	  net += 100*countlib(pos);	  
+	int count_lib = -1;
+	if (owla->goal[pos]) {
+	  count_lib = countlib(pos);
+	  net -= 75 * count_lib;
+	}
+	if (owlb->goal[pos]) {
+	  if (count_lib < 0)
+	    count_lib = countlib(pos);
+	  net += 100 * count_lib;
+	}
       }
     }
     if (!trymove(move, color, NULL, 0)) {
@@ -1589,11 +1595,17 @@
     for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
       if (IS_STONE(board[pos])
 	  && pos == find_origin(pos)) {
+	int count_lib = -1;
 	if (owla->goal[pos]
-	    || (pos == move && liberty_of_goal(move, owla)))
-	  net += 75*countlib(pos);
-	if (owlb->goal[pos])
-	  net -= 100*countlib(pos);
+	    || (pos == move && liberty_of_goal(move, owla))) {
+	  count_lib = countlib(pos);
+	  net += 75 * count_lib;
+	}
+	if (owlb->goal[pos]) {
+	  if (count_lib < 0)
+	    count_lib = countlib(pos);
+	  net -= 100 * count_lib;
+	}
       }
     }
 
@@ -1929,14 +1941,15 @@
       int size = 0;
       saveworm = MAX_GOAL_WORMS;
       for (k = 0; k < MAX_GOAL_WORMS; k++) {
-	if (owl_goal_worm[k] == NO_MOVE)
+	int worm_goal = owl_goal_worm[k];
+	if (worm_goal == NO_MOVE)
 	  break;
-	if (board[owl_goal_worm[k]] == EMPTY
-	    || countlib(owl_goal_worm[k]) > 1)
+	if (board[worm_goal] == EMPTY
+	    || countlib(worm_goal) > 1)
 	  continue;
-	if (worm[owl_goal_worm[k]].size > size) {
+	if (worm[worm_goal].size > size) {
 	  saveworm = k;
-	  size = worm[owl_goal_worm[k]].size;
+	  size = worm[worm_goal].size;
 	}
       }
       if (saveworm != MAX_GOAL_WORMS && size >= 3) {
@@ -3554,24 +3567,28 @@
     if (ON_BOARD(*move + delta[k]) && board[*move + delta[k]] != color)
       return 0;
 
-  for (r = 4; r < 8; r++)
-    if (board[*move + delta[r]] == other
-	&& countlib(*move + delta[r]) == 1) {
-      for (k = 0; k < 4; k++)
-	if (board[*move + delta[k]] == color
-	    && countlib(*move + delta[k]) == 1
-	    && !adjacent_strings(*move + delta[r], *move + delta[k]))
+  for (r = 4; r < 8; r++) {
+    int checked_pos_r = *move + delta[r];
+    if (board[checked_pos_r] == other
+	&& countlib(checked_pos_r) == 1) {
+      for (k = 0; k < 4; k++) {
+	int checked_pos_k = *move + delta[k];
+	if (board[checked_pos_k] == color
+	    && countlib(checked_pos_k) == 1
+	    && !adjacent_strings(checked_pos_r, checked_pos_k))
 	  break;
+      }
 
       if (k == 4) {
 	int new_move;
-	findlib(*move + delta[r], 1, &new_move);
+	findlib(checked_pos_r, 1, &new_move);
 	TRACE("Changing eyefilling move at %1m to capture at %1m.\n",
 	      *move, new_move);
 	*move = new_move;
 	return 1;
       }
     }
+  }
   
   return 0;    
 }
@@ -4999,7 +5016,7 @@
 	mark_string(pos, component2, closest_component);
 	component_size[closest_component] += countstones(pos);
       }
-    }
+	}
 
     /* Now find the biggest_component. */
     {
Index: gnugo/engine/persistent.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/persistent.c,v
retrieving revision 1.40
diff -u -r1.40 persistent.c
--- gnugo/engine/persistent.c	15 Sep 2006 00:55:14 -0000	1.40
+++ gnugo/engine/persistent.c	28 Nov 2006 22:10:10 -0000
@@ -233,9 +233,12 @@
       return 0;
     else if (!(p[pos] & (HIGH_LIBERTY_BIT | HIGH_LIBERTY_BIT2)))
       continue;
-    else if (((p[pos] & HIGH_LIBERTY_BIT) && countlib(pos) <= 4)
-             || (p[pos] & HIGH_LIBERTY_BIT2 && countlib(pos) <= 3))
-      return 0;
+    else {
+      int count_lib = countlib(pos);
+      if (((p[pos] & HIGH_LIBERTY_BIT) && count_lib <= 4)
+          || ((p[pos] & HIGH_LIBERTY_BIT2) && count_lib <= 3))
+        return 0;
+    }
   }
   
   return 1;
@@ -336,9 +339,10 @@
     else {
       for (r = 0; r < MAX_CACHE_DEPTH; r++) {
 	int apos = entry->stack[r];
-	int color = entry->move_color[r];
-	if (apos == 0)
+	int color;
+	if (apos == NO_MOVE)
 	  break;
+	color = entry->move_color[r];
 	if (board[apos] == EMPTY
 	    && trymove(apos, color, "purge_persistent_cache", 0))
 	  played_moves++;
@@ -354,8 +358,9 @@
       /* Move the last entry in the cache here and back up the loop
        * counter to redo the test at this position in the cache.
        */
-      if (0)
+#if 0
 	gprintf("Purging entry %d from cache.\n", k);
+#endif
       if (k < cache->current_size - 1)
 	*entry = cache->table[cache->current_size - 1];
       k--;
@@ -718,6 +723,7 @@
 			   int m, int n, float contribution)
 {
   int i, j, k;
+  int pos_mn;
   
   /* If p[m][n] is EMPTY, we just give the contribution to close empty
    * vertices. This is a rough simplification.
@@ -733,22 +739,23 @@
   /* Otherwise we give contribution to liberties and diagonal
    * neighbors of the string at (m, n).
    */
+  pos_mn = POS(m, n);
   for (i = 0; i < board_size; i++)
     for (j = 0; j < board_size; j++) {
       if (BOARD(i, j) != EMPTY)
 	continue;
       for (k = 0; k < 8; k++) {
-	int di = deltai[k];
-	int dj = deltaj[k];
-	if (IS_STONE(BOARD(i+di, j+dj))
-	    && same_string(POS(i+di, j+dj), POS(m, n))) {
+	int di = i + deltai[k];
+	int dj = j + deltaj[k];
+	if (IS_STONE(BOARD(di, dj))
+	    && same_string(POS(di, dj), pos_mn)) {
 	  if (k < 4) {
 	    values[POS(i, j)] += contribution;
 	    break;
 	  }
 	  else {
-	    if (BOARD(i+di, j) == EMPTY || countlib(POS(i+di, j)) <= 2
-		|| BOARD(i, j+dj) == EMPTY || countlib(POS(i, j+dj)) <= 2)
+	    if (BOARD(di, j) == EMPTY || countlib(POS(di, j)) <= 2
+	        || BOARD(i, dj) == EMPTY || countlib(POS(i, dj)) <= 2)
 	      values[POS(i, j)] += contribution;
 	    break;
 	  }
@@ -1345,15 +1352,16 @@
     if (board[pos] != EMPTY)
       continue;
     for (k = 0; k < 8; k++) {
+      int same_dragon;
       int pos2 = pos + delta[k];
       if (IS_STONE(board[pos2])
-	  && (is_same_dragon(pos2, dr)
+	  && ((same_dragon = is_same_dragon(pos2, dr))
 	      || (are_neighbor_dragons(pos2, dr)
 		  && board[pos2] == board[dr]))
 	  && (countlib(pos2) <= 4
 	      || is_edge_vertex(pos))) {
 	if (k < 4) {
-	  if (is_same_dragon(pos2, dr))
+	  if (same_dragon)
 	    values[pos] += contribution;
 	  else
 	    values[pos] += 0.5 * contribution;
Index: gnugo/engine/printutils.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/printutils.c,v
retrieving revision 1.56
diff -u -r1.56 printutils.c
--- gnugo/engine/printutils.c	29 Jan 2006 18:36:59 -0000	1.56
+++ gnugo/engine/printutils.c	28 Nov 2006 22:10:11 -0000
@@ -24,6 +24,7 @@
 #include "hash.h"
 #include "gg_utils.h"
 #include "sgftree.h"
+#include "gnugo.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -35,6 +36,8 @@
  * This function underpins all the TRACE and DEBUG stuff.
  * It accepts %c, %d, %f, %s, and %x as usual. But it
  * also accepts %m, which takes TWO integers and writes a move.
+ * It is possible to specify %1m, which takes one integer and
+ * prints a move (integer means the board array index).
  * Other accepted formats are
  * %H: Print a hashvalue.
  * %C: Print a color as a string.
Index: gnugo/engine/readconnect.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/readconnect.c,v
retrieving revision 1.99
diff -u -r1.99 readconnect.c
--- gnugo/engine/readconnect.c	23 Jan 2006 18:15:50 -0000	1.99
+++ gnugo/engine/readconnect.c	28 Nov 2006 22:10:33 -0000
@@ -246,9 +246,7 @@
   
   /* if only one liberty after capture */
   if (trymove(lib, OTHER_COLOR(board[str]), "snapback", str)) {
-    liberties = 0;
-    if (IS_STONE(board[lib]))
-      liberties = countlib(lib);
+    liberties = countlib(lib);
     popgo();
     sgf_dumptree = save_sgf_dumptree;
     if (liberties > 1)
@@ -271,6 +269,8 @@
   int liberties, libs[MAXLIBS];
   int adj, adjs[MAXCHAIN];
   int neighb, neighbs[MAXCHAIN];
+  int color = board[str1];
+  int other = OTHER_COLOR(color);
 
   /* finds connection through two forbidden liberties for
    * the opponent
@@ -288,17 +288,17 @@
    */
   liberties = findlib(str1, MAXLIBS, libs);
   for (r = 0; r < liberties; r++)
-    if (is_self_atari(libs[r], OTHER_COLOR(board[str1]))) 
+    if (is_self_atari(libs[r], other)) 
       for (k = 0; k < 4; k++) {
 	int pos = libs[r] + delta[k];
-	if (board[pos] == board[str1]
+	if (board[pos] == color
 	    && !same_string(pos, str1)
 	    && !same_string(pos, str2)) {
 	  /* try to connect pos to str2 in one move */
 	  /* play a common liberty */
 	  neighb = findlib(pos, MAXLIBS, neighbs);
 	  for (s = 0; s < neighb; s++)
-	    if (liberty_of_string(neighbs[s], str2)) {
+	    if (liberty_of_string2(neighbs[s], str2)) {
 	      res = 1;
 	      add_zone(zn, libs[r]);
 	      add_zone(zn, neighbs[s]);
@@ -492,7 +492,7 @@
     liberties = findlib(adjs[r], MAXLIBS, libs);
     common_adj_liberty = 0;
     for (s = 0; s < liberties; s++)
-      if (liberty_of_string(libs[s], str2))
+      if (liberty_of_string2(libs[s], str2))
 	common_adj_liberty = 1;
     if (common_adj_liberty || adjacent_strings(adjs[r], str2)) {
       for (s = 0; s < liberties; s++)
@@ -511,7 +511,7 @@
     liberties = findlib(adjs[r], MAXLIBS, libs);
     common_adj_liberty = 0;
     for (s = 0; s < liberties; s++)
-      if (liberty_of_string(libs[s], str1))
+      if (liberty_of_string2(libs[s], str1))
 	common_adj_liberty = 1;
     if (common_adj_liberty || adjacent_strings(adjs[r], str1)) {
       for (s = 0; s < liberties; s++)
@@ -530,28 +530,28 @@
   liberties = findlib(str1, MAXLIBS, libs);
   for (r = 0; r < liberties; r++) {
     if (board[SOUTH(libs[r])] == EMPTY) {
-      if (liberty_of_string(SOUTH(libs[r]), str2)) {
+      if (liberty_of_string2(SOUTH(libs[r]), str2)) {
 	add_array(moves, libs[r]);
 	add_array(moves, SOUTH(libs[r]));
       }
     }
     
     if (board[WEST(libs[r])] == EMPTY) {
-      if (liberty_of_string(WEST(libs[r]), str2)) {
+      if (liberty_of_string2(WEST(libs[r]), str2)) {
 	add_array(moves, libs[r]);
 	add_array(moves, WEST(libs[r]));
       }
     }
 
     if (board[NORTH(libs[r])] == EMPTY) {
-      if (liberty_of_string(NORTH(libs[r]), str2)) {
+      if (liberty_of_string2(NORTH(libs[r]), str2)) {
 	add_array(moves, libs[r]);
 	add_array(moves, NORTH(libs[r]));
       }
     }
 
     if (board[EAST(libs[r])] == EMPTY) {
-      if (liberty_of_string(EAST(libs[r]), str2)) {
+      if (liberty_of_string2(EAST(libs[r]), str2)) {
 	add_array(moves, libs[r]);
 	add_array(moves, EAST(libs[r]));
       }
@@ -561,7 +561,18 @@
   /* Liberties of str1 which are adjacent to a friendly string with
    * common liberty with str2.
    */
-  liberties = findlib(str1, MAXLIBS, libs);
+
+#ifndef GG_TURN_OFF_ASSERTS
+/* We got liberties from previous call to findlib. */
+  {
+    int test_libs[MAXLIBS];
+    int t;
+    gg_assert(liberties == findlib(str1, MAXLIBS, test_libs));
+    for (t = 0; t < liberties; ++t)
+      gg_assert(libs[t] == test_libs[t]);
+  }
+#endif
+
   for (r = 0; r < liberties; r++) {
     for (k = 0; k < 4; k++) {
       int pos = libs[r] + delta[k];
@@ -1495,6 +1506,7 @@
   SGFTree *save_sgf_dumptree = sgf_dumptree;
   int save_count_variations = count_variations;
   int result = 0;
+  int count_lib = countlib(str);
 
   /* We turn off the sgf traces here to avoid cluttering them up with
    * naive_ladder moves.
@@ -1502,11 +1514,11 @@
   sgf_dumptree = NULL;
   count_variations = 0;
 
-  if (countlib(str) == 1) {
+  if (count_lib == 1) {
     findlib(str, 1, move);
     result = WIN;
   }
-  else if (countlib(str) == 2)
+  else if (count_lib == 2)
     result = simple_ladder(str, move);
 
   /* Turn the sgf traces back on. */
@@ -2317,6 +2329,7 @@
   SGFTree *save_sgf_dumptree = sgf_dumptree;
   int save_count_variations = count_variations;
   int distance_limit;
+  int str2_onboard;
 
   /* We turn off the sgf traces here to avoid cluttering them up with
    * tactical reading moves.
@@ -2447,6 +2460,11 @@
   }
 
   /* Modify the distance values for the moves with various bonuses. */
+  if (ON_BOARD(str2))
+    str2_onboard = 1;
+  else
+    str2_onboard = 0;
+
   for (r = 0; r < num_moves; r++) {
     int move = moves[r];
     int adjacent_to_attacker = 0;
@@ -2476,9 +2494,10 @@
 	      gprintf("%o%1M -0.7, capture or atari of immediately connecting string\n", move);
 	  }
 	}
-      }
+	  }
       else if (board[pos] == color) {
-	if (countlib(pos) <= 2) {
+	int count_lib = countlib(pos);
+	if (count_lib <= 2) {
 	  distances[r] -= FP(0.2);
 	  if (verbose > 0)
 	    gprintf("%o%1M -0.2, adjacent to defender string with at most two liberties\n", move);
@@ -2491,7 +2510,7 @@
 	 * The following code compensates in such kind of situations.
 	 * See connection:111 and gunnar:53 for example.
 	 */
-	if (!connect_move && countlib(pos) == 1
+	if (!connect_move && count_lib == 1
 	    /* let's avoid ko and snapbacks */
 	    && accuratelib(move, other, 2, NULL) > 1) {
 	  int adjs[MAXCHAIN];
@@ -2523,9 +2542,9 @@
      * Neighbor strings with less than 3 liberties have already
      * generated a bonus above.
      */
-    if ((liberty_of_string(move, str1)
+    if ((liberty_of_string2(move, str1)
 	 && countlib(str1) == 3)
-	|| (ON_BOARD(str2) && liberty_of_string(move, str2)
+	|| (str2_onboard && liberty_of_string2(move, str2)
 	    && countlib(str2) == 3)) {
       distances[r] -= FP(0.1);
       if (verbose > 0)
@@ -4235,6 +4254,7 @@
   int save_count_variations = count_variations;
   int adj[MAXCHAIN];
   int libs[2];
+  int count_lib = countlib(str);
   
   /* We turn off the sgf traces here to avoid cluttering them up with
    * tactical reading moves.
@@ -4242,10 +4262,10 @@
   sgf_dumptree = NULL;
   count_variations = 0;
   
-  if (countlib(str) == 1 && find_defense(str, NULL) == 0)
+  if (count_lib == 1 && find_defense(str, NULL) == 0)
     result = 1;
 
-  if (countlib(str) == 2
+  if (count_lib == 2
       && chainlinks2(str, adj, 1) == 0
       && findlib(str, 2, libs) == 2
       && approxlib(libs[0], board[str], 2, NULL) == 1
@@ -4332,11 +4352,13 @@
   if (apos == bpos)
     return 1;
 
-  for (k = 0; k < 4; k++)
-    if (board[apos + delta[k]] == color
-	&& countlib(apos + delta[k]) <= 3
-	&& liberty_of_string(bpos, apos + delta[k]))
+  for (k = 0; k < 4; k++) {
+    int checked_pos = apos + delta[k];
+    if (board[checked_pos] == color
+	&& countlib(checked_pos) <= 3
+	&& liberty_of_string(bpos, checked_pos))
       return 1;
+  }
 
   return 0;
 }
Index: gnugo/engine/reading.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/reading.c,v
retrieving revision 1.168
diff -u -r1.168 reading.c
--- gnugo/engine/reading.c	4 Feb 2006 18:46:04 -0000	1.168
+++ gnugo/engine/reading.c	28 Nov 2006 22:10:45 -0000
@@ -1032,7 +1032,6 @@
   int r;
 
   ASSERT1(IS_STONE(board[str]), str);
-  other = OTHER_COLOR(board[str]);
 
   /* Only handle strings with no way to capture immediately.
    * For now, we treat ko the same as unconditionally. */
@@ -1046,6 +1045,7 @@
    *
    * The test against 6 liberties is just an optimization.
    */
+  other = OTHER_COLOR(board[str]);
   liberties = findlib(str, MAXLIBS, libs);
   if (liberties > 1 && liberties < 6) {
     for (k = 0; k < liberties; k++) {
@@ -1065,7 +1065,7 @@
 
        if (!ON_BOARD(bb)
            || IS_STONE(board[bb])
-           || liberty_of_string(bb, str))
+           || liberty_of_string2(bb, str))
          continue;
 
        if (trymove(bb, other, "attack_threats-B", str)) {
@@ -1322,7 +1322,7 @@
      * it has already been done in the first loop of this function.
      */
     num_adjacent_stones = count_adjacent_stones(adjs[j], str, missing);
-    if (!liberty_of_string(lib, str)
+    if (!liberty_of_string2(lib, str)
 	&& num_adjacent_stones >= missing) {
       *move = lib;
       return 1;
@@ -1444,7 +1444,7 @@
   break_chain_moves(str, &moves);
   set_up_snapback_moves(str, lib, &moves);
 
-  order_moves(str, &moves, color, read_function_name, *move);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move);
   DEFEND_TRY_MOVES(0, NULL);
 
   /* If the string is a single stone and a capture would give a ko,
@@ -1552,7 +1552,7 @@
   if (stackp <= backfill_depth)
     special_rescue2_moves(str, libs, &moves);
 
-  order_moves(str, &moves, color, read_function_name, *move);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move);
   DEFEND_TRY_MOVES(0, &suggest_move);
 
   /* Look for backfilling moves. */
@@ -1586,7 +1586,7 @@
   special_rescue4_moves(str, libs, &moves);
   
   /* Only order and test the new set of moves. */
-  order_moves(str, &moves, color, read_function_name, *move);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move);
   DEFEND_TRY_MOVES(0, &suggest_move);
 
   /* If we haven't found any useful moves in first batches, be more
@@ -1618,7 +1618,7 @@
     break_chain4_moves(str, &moves, be_aggressive);
 
   /* Only order and test the new set of moves. */
-  order_moves(str, &moves, color, read_function_name, *move);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move);
   DEFEND_TRY_MOVES(0, &suggest_move);
 
   RETURN_RESULT(savecode, savemove, move, "saved move");
@@ -1680,7 +1680,7 @@
   if (stackp <= backfill2_depth)
     hane_rescue_moves(str, libs, &moves);
 
-  order_moves(str, &moves, color, read_function_name, *move);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move);
   DEFEND_TRY_MOVES(1, &suggest_move);
 
   /* This looks a little too expensive. */
@@ -1768,7 +1768,7 @@
   }
 
   /* Only order and test the new set of moves. */
-  order_moves(str, &moves, color, read_function_name, *move);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move);
   DEFEND_TRY_MOVES(1, &suggest_move);
 
   /* If nothing else works, we try playing a liberty of the
@@ -1783,7 +1783,7 @@
     break_chain3_moves(str, &moves, 0);
 
   /* Only order and test the new set of moves. */
-  order_moves(str, &moves, color, read_function_name, *move);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move);
   DEFEND_TRY_MOVES(1, &suggest_move);
 
   RETURN_RESULT(savecode, savemove, move, "saved move");
@@ -1850,7 +1850,7 @@
     squeeze_moves(str, &moves);
   }
 
-  order_moves(str, &moves, color, read_function_name, *move);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move);
   DEFEND_TRY_MOVES(1, &suggest_move);
 
   if (stackp <= depth) {
@@ -1859,7 +1859,7 @@
     bamboo_rescue_moves(str, liberties, libs, &moves);
   }
 
-  order_moves(str, &moves, color, read_function_name, *move);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move);
   DEFEND_TRY_MOVES(1, &suggest_move);
 
   RETURN_RESULT(savecode, savemove, move, "saved move");
@@ -2005,7 +2005,7 @@
   int other = OTHER_COLOR(color);
   int newlibs[4];
   int liberties;
-  int newstr;
+  int astr_pos;
   int k, r, s;
   
   for (r = 0; r < 2; r++) {
@@ -2017,18 +2017,18 @@
       continue;
 
     for (k = 0; k < 4; k++) {
-      if (board[alib + delta[k]] == color
-	  && !same_string(alib + delta[k], str)) {
-	newstr = alib + delta[k];
-	liberties = findlib(newstr, 4, newlibs);
+      astr_pos = alib + delta[k];
+      if (board[astr_pos] == color
+	  && !same_string(astr_pos, str)) {
+	liberties = findlib(astr_pos, 4, newlibs);
 	
 	for (s = 0; s < liberties && s < 4; s++) {
 	  if (!is_self_atari(newlibs[s], color))
 	    ADD_CANDIDATE_MOVE(newlibs[s], 0, *moves, "special_rescue2");
 	}
-	break_chain_moves(newstr, moves);
-	break_chain2_efficient_moves(newstr, moves);
-	edge_clamp_moves(newstr, moves);
+	break_chain_moves(astr_pos, moves);
+	break_chain2_efficient_moves(astr_pos, moves);
+	edge_clamp_moves(astr_pos, moves);
       }
     }
   }
@@ -2284,7 +2284,7 @@
 
       liberties2 = findlib(bpos, 4, libs2);
       for (s = 0; s < liberties2; s++)
-	if (!liberty_of_string(libs2[s], str)
+	if (!liberty_of_string2(libs2[s], str)
 	    && !is_self_atari(libs2[s], color))
 	  ADD_CANDIDATE_MOVE(libs2[s], 0, *moves, "special_rescue5-A");
 
@@ -2469,7 +2469,7 @@
       int alibs[2];
       int alib = accuratelib(apos, other, 2, alibs);
 
-      if (liberty_of_string(apos, str))
+      if (liberty_of_string2(apos, str))
 	continue;
 
       if (alib >= 2)
@@ -2521,7 +2521,7 @@
       continue;
 
     for (r = 0; r < num_libs2; r++)
-      if (!liberty_of_string(libs2[r], str)) {
+      if (!liberty_of_string2(libs2[r], str)) {
 	potential_move = libs2[r];
 	break;
       }
@@ -2542,7 +2542,7 @@
 	previous_liberty = potential_move;
 	potential_move = libs2[0];
       }
-      if (liberty_of_string(potential_move, str)) {
+      if (liberty_of_string2(potential_move, str)) {
 	potential_move = NO_MOVE;
 	break;
       }
@@ -2642,12 +2642,12 @@
 	if (board[cpos] != color || !same_string(cpos, str))
 	  continue;
 
-	if (board[dpos] != EMPTY || !liberty_of_string(dpos, apos))
+	if (board[dpos] != EMPTY || !liberty_of_string2(dpos, apos))
 	  continue;
 
 	epos = dpos + up;
 
-	if (board[epos] != EMPTY || !liberty_of_string(epos, apos))
+	if (board[epos] != EMPTY || !liberty_of_string2(epos, apos))
 	  continue;
 
 	if (approxlib(dpos, color, 3, NULL) < 3)
@@ -3112,9 +3112,9 @@
         /* If stackp > depth and any boundary chain is in atari, assume safe.
          * However, if the captured chain is only of size 1, there can still
          * be a working ladder, so continue if that is the case.
-	 * Also if the string in atari shares its liberty with the
-	 * attacked string, drawing it out may enable the ladder to
-	 * continue.
+         * Also if the string in atari shares its liberty with the
+         * attacked string, drawing it out may enable the ladder to
+         * continue.
          */
         if (stackp > depth
 	    && countstones(adjs[r]) > 1
@@ -3190,8 +3190,8 @@
       adj = chainlinks2(str, adjs, 2);
       for (r = 0; r < adj; r++) {
         int apos = adjs[r];
-        if (liberty_of_string(libs[0], apos)
-	    && liberty_of_string(libs[1], apos))
+        if (liberty_of_string2(libs[0], apos)
+	    && liberty_of_string2(libs[1], apos))
           break_chain_moves(apos, &moves);
       }
 
@@ -3230,7 +3230,7 @@
       abort();
     } /* switch (pass) */
 
-    order_moves(str, &moves, other, read_function_name, *move);
+    order_moves(str, &moves, other, READ_FUNCTION_NAME, *move);
     ATTACK_TRY_MOVES(0, &suggest_move);
   }
 
@@ -3373,7 +3373,7 @@
       abort();
     }
 
-    order_moves(str, &moves, other, read_function_name, *move);
+    order_moves(str, &moves, other, READ_FUNCTION_NAME, *move);
     ATTACK_TRY_MOVES(1, &suggest_move);
   } /* for (pass... */
 
@@ -3467,7 +3467,7 @@
       abort();
     }
 
-    order_moves(str, &moves, other, read_function_name, *move);
+    order_moves(str, &moves, other, READ_FUNCTION_NAME, *move);
     ATTACK_TRY_MOVES(1, &suggest_move);
   } /* for (pass = ... */
 
@@ -3681,7 +3681,7 @@
      * chain links.
      */
     for (s = 0; s < adj; s++)
-      if (liberty_of_string(apos, adjs[s])) {
+      if (liberty_of_string2(apos, adjs[s])) {
 	bpos = adjs[s];
 	break;
       }
@@ -3773,7 +3773,7 @@
   for (r = 0; r < adj; r++) {
     findlib(adjs[r], 2, libs);
     for (k = 0; k < 2; k++) {
-      if (!liberty_of_string(libs[k], str)
+      if (!liberty_of_string2(libs[k], str)
 	     && ((ON_BOARD1(SOUTH(libs[k]))
 		     && liberty_of_string(SOUTH(libs[k]), str))
 	      || (ON_BOARD1(WEST(libs[k]))
@@ -4019,10 +4019,12 @@
   for (k = 0; k < 4; k++) {
     int l;
     int up = delta[k];
+    int up_apos;
 
     if (ON_BOARD(apos - up))
       continue;
-    if (board[apos + up] != color || !same_string(apos + up, str))
+    up_apos = apos + up;
+    if (board[up_apos] != color || !same_string(up_apos, str))
       return;
     
     for (l = 0; l < 2; l++) {
@@ -4036,7 +4038,7 @@
 	right = -right;
 
       cpos = apos + right;
-      dpos = apos + right + up;
+      dpos = up_apos + right;
       epos = cpos + right;
       fpos = dpos + right;
 
@@ -4159,7 +4161,8 @@
     int min_liberties)
 {
   int r, s, t;
-  int color = OTHER_COLOR(board[str]);
+  int color = board[str];
+  int other = OTHER_COLOR(color);
   int xpos;
   int adj;
   int adj2;
@@ -4178,7 +4181,7 @@
     findlib(adjs[r], 2, libs);
     for (t = 0; t < 2; t++) {
       xpos = libs[t];
-      if (approxlib(xpos, color, min_liberties, NULL)
+      if (approxlib(xpos, other, min_liberties, NULL)
 	  + neighbor_of_string(xpos, str) >= min_liberties)
 	ADD_CANDIDATE_MOVE(xpos, 0, *moves, "defend_secondary_chain2-A");
     }
@@ -4187,7 +4190,7 @@
     adj2 = chainlinks2(adjs[r], adjs2, 1);
     for (s = 0; s < adj2; s++) {
       findlib(adjs2[s], 1, &xpos);
-      if (!is_self_atari(xpos, color))
+      if (!is_self_atari(xpos, other))
 	ADD_CANDIDATE_MOVE(xpos, 0, *moves, "defend_secondary_chain2-B");
     }
 
@@ -4197,8 +4200,8 @@
       findlib(adjs2[s], 2, libs);
       for (t = 0; t < 2; t++) {
 	/* Only atari if target has no easy escape with his other liberty. */
-	if (approxlib(libs[1-t], OTHER_COLOR(color), 3, NULL) < 3 
-	    &&  !is_self_atari(libs[t], color)) {
+	if (approxlib(libs[1-t], color, 3, NULL) < 3 
+	    &&  !is_self_atari(libs[t], other)) {
 	  ADD_CANDIDATE_MOVE(libs[t], 0, *moves, "defend_secondary_chain2-C");
 	}
       }
@@ -4365,7 +4368,7 @@
 	if (!defend_secondary_chain1_moves(adjs[r], moves, 2))
 	  defend_secondary_chain2_moves(adjs[r], moves, 2);
       }
-    }
+	}
 
     if (unsafe[0] && unsafe[1]
 	&& (stackp <= backfill2_depth || have_common_lib(str, apos, NULL))) {
@@ -4823,7 +4826,7 @@
 
   break_chain_moves(str, &moves);
   set_up_snapback_moves(str, lib, &moves);
-  order_moves(str, &moves, color, read_function_name, NO_MOVE);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, NO_MOVE);
 
   for (k = 0; k < moves.num; k++) {
     int ko_capture;
@@ -4869,10 +4872,10 @@
 	 * better.
 	 */
 	UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos);
-      }
+	  }
       else
 	popgo();
-    }
+	}
     else {
       int ko_pos;
       if (stackp <= ko_depth
@@ -5626,7 +5629,7 @@
   if (approxlib(libs[1], color, 4, NULL) <= 3)
     ADD_CANDIDATE_MOVE(libs[0], 0, moves, "simple_ladder");
 
-  order_moves(str, &moves, other, read_function_name, NO_MOVE);
+  order_moves(str, &moves, other, READ_FUNCTION_NAME, NO_MOVE);
 
   for (k = 0; k < moves.num; k++) {
     int ko_move;
@@ -5688,7 +5691,7 @@
   moves.num_tried = 0;
 
   break_chain_moves(str, &moves);
-  order_moves(str, &moves, color, read_function_name, NO_MOVE);
+  order_moves(str, &moves, color, READ_FUNCTION_NAME, NO_MOVE);
 
   for (k = 0; k < moves.num; k++) {
     int ko_move;
Index: gnugo/engine/showbord.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/showbord.c,v
retrieving revision 1.29
diff -u -r1.29 showbord.c
--- gnugo/engine/showbord.c	23 Jan 2006 18:15:50 -0000	1.29
+++ gnugo/engine/showbord.c	28 Nov 2006 22:10:48 -0000
@@ -343,7 +343,7 @@
 }
 
 
-#ifndef HAVE_VARIADIC_DEFINE
+#if !defined(HAVE_VARIADIC_DEFINE) || defined(GG_TURN_OFF_DEBUGS)
 
 /* See gnugo.h for related TRACE family macro definitions */
 
Index: gnugo/engine/unconditional.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/unconditional.c,v
retrieving revision 1.5
diff -u -r1.5 unconditional.c
--- gnugo/engine/unconditional.c	23 Jan 2006 18:15:50 -0000	1.5
+++ gnugo/engine/unconditional.c	28 Nov 2006 22:10:49 -0000
@@ -343,12 +343,15 @@
     
     findstones(pos, 2, stones);
     for (k = 0; k < 2 && isolated; k++) {
-      for (r = 0; r < 8 && isolated; r++) {
+      for (r = 0; r < 8; r++) {
 	pos2 = stones[k] + delta[r];
 	if (!ON_BOARD(pos2)
 	    || (board[pos2] == color
 		&& !same_string(pos, pos2)))
+	{
 	  isolated = 0;
+	  break;
+	}
       }
     }
 
@@ -457,10 +460,10 @@
 	    locally_played_moves--;
 	  }
 	}
-      }
+	  }
       if (countstones(pos) > 2)
 	break;
-    }
+	}
   }
 
   /* Capture the strings involved in potential sekis. */
Index: gnugo/engine/utils.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/utils.c,v
retrieving revision 1.115
diff -u -r1.115 utils.c
--- gnugo/engine/utils.c	17 Apr 2006 07:42:58 -0000	1.115
+++ gnugo/engine/utils.c	28 Nov 2006 22:10:54 -0000
@@ -731,8 +731,8 @@
 void
 set_depth_values(int level, int report_levels)
 {
-  static int node_limits[] = {500, 500, 450, 400, 400, 325, 275,
-			      200, 150, 100, 75, 50};
+  const int node_limits[] = {500, 500, 450, 400, 400, 325, 275,
+                             200, 150, 100, 75, 50};
   int depth_level;
 
   /*
@@ -858,6 +858,7 @@
 
   depth_offset = 0;
   
+#ifndef GG_TURN_OFF_TRACES
   if (report_levels) {
     fprintf(stderr, "at level %d:\n\n\
 depth: %d\n\
@@ -889,6 +890,9 @@
             connect_depth2, connection_node_limit, breakin_depth, 
 	    breakin_node_limit);
   }
+#else
+  UNUSED(report_levels);
+#endif
 }
 
 
Index: gnugo/engine/value_moves.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/value_moves.c,v
retrieving revision 1.170
diff -u -r1.170 value_moves.c
--- gnugo/engine/value_moves.c	18 May 2006 04:09:28 -0000	1.170
+++ gnugo/engine/value_moves.c	28 Nov 2006 22:11:07 -0000
@@ -69,22 +69,24 @@
   }
 
   for (k = 0; k < strings; k++) {
+    int count_lib;
     if (worm[ss[k]].invincible)
       continue;
+    count_lib = countlib(ss[k]);
     if (board[ss[k]] == color) {
       int newlibs = approxlib(pos, color, MAXLIBS, NULL);
       own_strings++;
-      if (newlibs >= countlib(ss[k])) {
-	if (countlib(ss[k]) <= 4)
+      if (newlibs >= count_lib) {
+	if (count_lib <= 4)
 	  fewlibs++;
-	if (countlib(ss[k]) <= 2)
+	if (count_lib <= 2)
 	  fewlibs++;
       }
     }
     else {
-      if (countlib(ss[k]) <= 2)
+      if (count_lib <= 2)
 	fewlibs++;
-      if (countlib(ss[k]) <= 1 && to_move) {
+      if (count_lib <= 1 && to_move) {
 	int dummy[MAXCHAIN];
 	fewlibs++;
 	fewlibs += chainlinks2(ss[k], dummy, 1);
@@ -765,7 +767,7 @@
     int potential_semeai_move_found = 0;
     int other_move_reason_found = 0;
 
-    if (!ON_BOARD1(pos))
+    if (!ON_BOARD(pos))
       continue;
     for (k = 0; k < MAX_REASONS; k++) {
       r = move[pos].reason[k];
@@ -2267,7 +2269,7 @@
        */
       if (dragon[aa].size == 1
 	  && is_ko_point(aa)
-	  && liberty_of_string(pos, aa)) {
+	  && liberty_of_string2(pos, aa)) {
 	TRACE("  %1m: -0.5 - penalty for ko stone %1m (workaround)\n",
 	      pos, aa);
 	tot_value -= 0.5;
Index: gnugo/engine/worm.c
===================================================================
RCS file: /sources/gnugo/gnugo/engine/worm.c,v
retrieving revision 1.72
diff -u -r1.72 worm.c
--- gnugo/engine/worm.c	18 May 2006 03:54:42 -0000	1.72
+++ gnugo/engine/worm.c	28 Nov 2006 22:11:11 -0000
@@ -76,7 +76,7 @@
  * though its location is irrelevant for applications. To see if two
  * stones lie in the same worm, compare their origins.
  *
- * We will use the field dragon[ii].genus to keep track of
+ * We will use the field dragon[pos].genus to keep track of
  * black- or white-bordered cavities (essentially eyes) which are found.  
  * so this field must be zero'd now.
  */
@@ -521,27 +521,24 @@
 build_worms()
 {
   int pos;
+  int stone;
 
   /* Set all worm data fields to 0. */
   memset(worm, 0 , sizeof(worm));
 
-  /* Initialize the worm data for each worm. */
-  for (pos = BOARDMIN; pos < BOARDMAX; pos++)
-    if (ON_BOARD(pos))
-      worm[pos].origin = NO_MOVE;
+  /* Worm statuses must be set to UNKNOWN. Now memset does it. */
+  gg_assert(UNKNOWN == 0);
   
+  /* Initialize the worm data for each worm. */
   for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
     if (!ON_BOARD(pos) || worm[pos].origin != NO_MOVE)
       continue;
-    worm[pos].color = board[pos];
-    worm[pos].origin = pos;
-    worm[pos].inessential = 0;
-    worm[pos].invincible = 0;
-    worm[pos].unconditional_status = UNKNOWN;
-    worm[pos].effective_size = 0.0;
-    if (IS_STONE(board[pos])) {
-      worm[pos].liberties = countlib(pos);
+    stone = board[pos];
+    worm[pos].color = stone;
+    if (IS_STONE(stone)) {
+      worm[pos].origin = pos;
       worm[pos].size = countstones(pos);
+      worm[pos].liberties = countlib(pos);
       propagate_worm(pos);
     }
   }
@@ -584,6 +581,7 @@
    * a stone at the location, 1 a liberty of a stone, and so on.
    */
   int distance[BOARDMAX];
+
   /* Pointer to the origin of the closest worms. A very large number of
    * worms may potentially be equally close, but no more than
    * 2*(board_size-1).
@@ -596,22 +594,19 @@
   int r;
     
   /* Initialize arrays. */
+  memset(worms, NO_MOVE, sizeof(worms));
+  memset(nworms, 0, sizeof(nworms));
+  memset(distance, -1, sizeof(distance));
+
   for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
     if (!ON_BOARD(pos))
       continue;
 
-    for (k = 0; k < 2*(board_size-1); k++)
-      worms[pos][k] = NO_MOVE;
-    
-    nworms[pos] = 0;
-    
     if (board[pos] & color) {
       distance[pos] = 0;
       worms[pos][0] = worm[pos].origin;
-      nworms[pos]++;
+      nworms[pos] = 1;
     }
-    else
-      distance[pos] = -1;
   }
   
   dist = 0;
@@ -620,7 +615,7 @@
     found_one = 0;
     dist++;
     for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
-      if (!ON_BOARD(pos) || distance[pos] != -1)
+      if (distance[pos] != -1 || !ON_BOARD(pos))
 	continue; /* already claimed */
 
       for (r = 0; r < 4; r++) {
@@ -638,8 +633,7 @@
 	      }
 	    if (!already_counted) {
 	      ASSERT1(nworms[pos] < 2*(board_size-1), pos);
-	      worms[pos][nworms[pos]] = worms[pos2][k];
-	      nworms[pos]++;
+	      worms[pos][nworms[pos]++] = worms[pos2][k];
 	    }
 	  }
 	}
@@ -789,7 +783,7 @@
 	 * defense, so we try and see if it defends.
 	 */
 	attack_point = worm[str].attack_points[0];
-	if (!liberty_of_string(attack_point, str))
+	if (!liberty_of_string2(attack_point, str))
 	  if (trymove(attack_point, worm[str].color, "make_worms", NO_MOVE)) {
 	    int acode = attack(str, NULL);
 	    if (acode != WIN) {
@@ -924,7 +918,7 @@
     /* Only try those worms that have an attack. */
     if (worm[str].attack_codes[0] != 0
 	&& worm[str].defense_codes[0] == 0) {
-      
+
       liberties = findlib(str, MAXLIBS, libs);
       
       for (k = 0; k < liberties; k++) {
@@ -946,7 +940,7 @@
 	  
 	  if (!ON_BOARD(bb)
 	      || IS_STONE(board[bb])
-	      || liberty_of_string(bb, str))
+	      || liberty_of_string2(bb, str))
 	    continue;
 	  
 	  if (trymove(bb, color, "threaten defense", str)) {
@@ -958,7 +952,7 @@
 	    popgo();
 	  }
 	}
-      }
+	  }
       
       /* It might be interesting to look for defense threats by
        * attacking weak neighbors, similar to threatening attack by
@@ -1204,7 +1198,7 @@
   num_stones = findstones(pos, MAX_BOARD * MAX_BOARD, stones);
   for (k = 0; k < num_stones; k++)
     if (stones[k] != pos)
-      worm[stones[k]] = worm[pos];
+      memcpy(worm + stones[k], worm + pos, sizeof(struct worm_data));
 }
 
 
@@ -1707,9 +1701,8 @@
 get_lively_stones(int color, signed char safe_stones[BOARDMAX])
 {
   int ii;
-  memset(safe_stones, 0, BOARDMAX * sizeof(*safe_stones));
-  for (ii = BOARDMIN; ii < BOARDMAX; ii++)
-    ASSERT1(safe_stones[ii] == 0, ii);
+  gg_assert(sizeof(*safe_stones) == sizeof(signed char));
+  memset(safe_stones, 0, BOARDMAX * sizeof(signed char));
   for (ii = BOARDMIN; ii < BOARDMAX; ii++)
     if (IS_STONE(board[ii])
 	&& worm[ii].origin == ii) {
Index: gnugo/interface/main.c
===================================================================
RCS file: /sources/gnugo/gnugo/interface/main.c,v
retrieving revision 1.136
diff -u -r1.136 main.c
--- gnugo/interface/main.c	18 May 2006 21:29:45 -0000	1.136
+++ gnugo/interface/main.c	28 Nov 2006 22:11:20 -0000
@@ -97,7 +97,6 @@
       OPT_DECIDE_SEMEAI,
       OPT_DECIDE_SURROUNDED,
       OPT_DECIDE_TACTICAL_SEMEAI,
-      OPT_DECIDE_ORACLE,
       OPT_EXPERIMENTAL_SEMEAI,
       OPT_EXPERIMENTAL_OWL_EXT,
       OPT_SEMEAI_NODE_LIMIT,
@@ -140,8 +139,6 @@
       OPT_PRINTSGF,
       OPT_PROFILE_PATTERNS,
       OPT_CHINESE_RULES,
-      OPT_OWL_THREATS,
-      OPT_NO_OWL_THREATS,
       OPT_JAPANESE_RULES,
       OPT_FORBID_SUICIDE,
       OPT_ALLOW_SUICIDE,
@@ -289,7 +286,6 @@
   {"decide-surrounded",  required_argument, 0, OPT_DECIDE_SURROUNDED},
   {"decide-eye",     required_argument, 0, OPT_DECIDE_EYE},
   {"decide-combination", no_argument,   0, OPT_DECIDE_COMBINATION},
-  {"decide-oracle",  no_argument,       0, OPT_DECIDE_ORACLE},
   {"nofusekidb",     no_argument,       0, OPT_NOFUSEKIDB},
   {"nofuseki",       no_argument,       0, OPT_NOFUSEKI},
   {"nojosekidb",     no_argument,       0, OPT_NOJOSEKIDB},
@@ -353,12 +349,28 @@
   
   /* Weed through all of the command line options. */
   while ((i = gg_getopt_long(argc, argv, 
-                            "-ab:B:d:D:EF:gh::K:l:L:M:m:o:O:p:r:fsStTvw",
+                            "-ab:B:d:D:EF:h::K:l:L:M:m:o:O:r:StTvw",
 			     long_options, NULL)) != EOF)
     {
       switch (i) {
-      case 'T': printboard++; break;
-      case 't': ++verbose; break;
+
+      case 'T':
+#ifdef GG_TURN_OFF_TRACES
+        fprintf(stdout, "board printing not supported in final release\n");
+#else
+        printboard++;
+#endif
+        break;
+
+      case 't':
+#ifdef GG_TURN_OFF_TRACES
+        fprintf(stdout, "tracing not supported in final release\n");
+#else
+        ++verbose;
+#endif
+        break;
+
+
       case 'a': allpats = 1; break;
 
       case  1 :
@@ -367,11 +379,35 @@
 	
       case 'b': benchmark = atoi(gg_optarg); playmode = MODE_SOLO; break;
       case 'r': seed = atoi(gg_optarg); seed_specified = 1; break;
-      case 'S': showstatistics = 1; break;
-      case 'w': printworms = 1; break;
+
+      case 'S':
+#ifdef GG_TURN_OFF_STATS
+        fprintf(stdout, "statistics not supported in final release\n");
+#else
+        showstatistics = 1;
+#endif
+        break;
+
+      case 'w':
+#ifdef GG_TURN_OFF_TRACES
+        fprintf(stdout, "worm printing not supported in final release\n");
+#else
+        printworms = 1;
+#endif
+        break;
+
       case 'm': printmoyo = strtol(gg_optarg, NULL, 0);  /* allows 0x... */ 
 	break;
-      case 'd': debug ^= strtol(gg_optarg, NULL, 0);  /* allows 0x... */ break;
+
+      case 'd':
+#ifdef GG_TURN_OFF_DEBUGS
+        fprintf(stdout, "debugging not supported in final release\n");
+        debug = 0;
+#else
+        debug ^= strtol(gg_optarg, NULL, 0);  /* allows 0x... */
+#endif
+        break;
+
       case 'D': mandated_depth = atoi(gg_optarg); break;
       case 'M': memory = atof(gg_optarg); break; /* floating point number */
       case 'E': printboard = 2; break;
@@ -445,6 +481,7 @@
 	break;
 	
       case OPT_OPTIONS:
+	fprintf(stdout, "Default level: %d\n", DEFAULT_LEVEL);
 	if (USE_BREAK_IN)
 	  fprintf(stdout,
 		  "configure option enabled: experimental break-ins\n");
@@ -468,7 +505,7 @@
 		  "configure option enabled: owl threats\n");
 	if (RESIGNATION_ALLOWED)
 	  fprintf(stdout,
-		  "configure option enabled: resination allowed\n");
+		  "configure option enabled: resignation allowed\n");
 	if (ORACLE)
 	  fprintf(stdout,
 		  "configure option enabled: oracle\n");
@@ -486,12 +523,20 @@
 	break;
 
       case OPT_SHOWTIME:
-	showtime = 1;
-	break;
+#ifdef GG_TURN_OFF_TRACES
+        fprintf(stdout, "time showing not supported in final release\n");
+#else
+        showtime = 1;
+#endif
+        break;
 	
       case OPT_SHOWSCORE:
-	showscore = 1;
-	break;
+#ifdef GG_TURN_OFF_TRACES
+        fprintf(stdout, "score showing not supported in final release\n");
+#else
+        showscore = 1;
+#endif
+        break;
 	
       case OPT_HANDICAPSTONES:
 	{
@@ -535,14 +580,6 @@
 	chinese_rules = 1;
 	break;
 
-      case OPT_OWL_THREATS: 
-	owl_threats = 1;
-	break;
-
-      case OPT_NO_OWL_THREATS: 
-	owl_threats = 0;
-	break;
-
       case OPT_METAMACHINE:
         metamachine = 1;
 	break;
@@ -762,10 +799,6 @@
 	playmode = MODE_DECIDE_SURROUNDED;
 	break;
 	
-      case OPT_DECIDE_ORACLE:
-	playmode = MODE_DECIDE_ORACLE;
-	break;
-	
       case OPT_BRANCH_DEPTH:
 	mandated_branch_depth = atoi(gg_optarg);
 	break;
@@ -951,11 +984,15 @@
 	break;
 
       case OPT_PRINT_LEVELS:
+#ifdef GG_TURN_OFF_TRACES
+	fprintf(stdout, "levels printing not supported in final release\n");
+#else
 	{
 	  int lev;
 	  for (lev = 12; lev >= 0; lev--)
 	    set_depth_values(lev, 1);
 	}
+#endif
 	return EXIT_SUCCESS;
 	break;
 
Index: gnugo/patterns/dfa-mkpat.h
===================================================================
RCS file: /sources/gnugo/gnugo/patterns/dfa-mkpat.h,v
retrieving revision 1.6
diff -u -r1.6 dfa-mkpat.h
--- gnugo/patterns/dfa-mkpat.h	23 Jan 2006 18:15:51 -0000	1.6
+++ gnugo/patterns/dfa-mkpat.h	28 Nov 2006 22:11:33 -0000
@@ -41,9 +41,6 @@
  *    Data types definition     *
  ********************************/
 
-/* Intersections. */
-typedef unsigned short Intersection_t;
-
 /* Attribute list. */
 typedef struct attrib
 {
Index: gnugo/patterns/helpers.c
===================================================================
RCS file: /sources/gnugo/gnugo/patterns/helpers.c,v
retrieving revision 1.72
diff -u -r1.72 helpers.c
--- gnugo/patterns/helpers.c	23 Jan 2006 18:15:51 -0000	1.72
+++ gnugo/patterns/helpers.c	28 Nov 2006 22:11:39 -0000
@@ -617,12 +617,14 @@
 
 
   if (TRYMOVE(Apos, color)) {
-    for (k = 0; k < 4; k++)
-      if (board[cpos + delta[k]] == other
-	  && neighbor_of_string(cpos + delta[k], Apos)) {
-	epos = cpos + delta[k];
+    for (k = 0; k < 4; k++) {
+      int checked_pos = cpos + delta[k];
+      if (board[checked_pos] == other
+	  && neighbor_of_string(checked_pos, Apos)) {
+	epos = checked_pos;
 	break;
       }
+    }
 
     gg_assert(epos != NO_MOVE);
     
Index: gnugo/utils/gg_utils.c
===================================================================
RCS file: /sources/gnugo/gnugo/utils/gg_utils.c,v
retrieving revision 1.38
diff -u -r1.38 gg_utils.c
--- gnugo/utils/gg_utils.c	8 Mar 2006 08:50:04 -0000	1.38
+++ gnugo/utils/gg_utils.c	28 Nov 2006 22:11:47 -0000
@@ -551,7 +551,7 @@
 /* Restart the pseudo-random sequence with the initialization given
  * by the random seed. Should be called at each move.
  */
-void
+inline void
 reuse_random_seed()
 {
   gg_srand(random_seed);
Index: gnugo/utils/gg_utils.h
===================================================================
RCS file: /sources/gnugo/gnugo/utils/gg_utils.h,v
retrieving revision 1.20
diff -u -r1.20 gg_utils.h
--- gnugo/utils/gg_utils.h	23 Jan 2006 18:15:51 -0000	1.20
+++ gnugo/utils/gg_utils.h	28 Nov 2006 22:11:47 -0000
@@ -89,7 +89,7 @@
 void update_random_seed(void);
 void set_random_seed(unsigned int seed);
 unsigned int get_random_seed(void);
-void reuse_random_seed(void);
+inline void reuse_random_seed(void);
 
 
 #endif /* _GG_UTILS_H_ */
