Ticket #148: changes2.diff

File changes2.diff, 97.1 KB (added by draqo, 4 years ago)
  • gnugo/engine/board.h

    RCS file: /sources/gnugo/gnugo/engine/board.h,v
    retrieving revision 1.34
    diff -u -r1.34 board.h
     
    3636 * character access is very slow. 
    3737 */ 
    3838 
     39/* simple test for old machines */ 
     40#if SIZEOF_INT >= 4 
     41#define INT_INTERSECTION 
     42typedef int Intersection; 
     43#else 
    3944typedef unsigned char Intersection; 
     45#endif 
    4046 
    4147/* FIXME: This is very ugly but we can't include hash.h until we have 
    4248 * defined Intersection. And we do need to include it before using 
     
    135141 
    136142/* Note that POS(-1, -1) == 0 
    137143 * DELTA() is defined so that POS(i+di, j+dj) = POS(i, j) + DELTA(di, dj). 
     144 * For details look in the documentation. 
    138145 */ 
    139146#define BOARDSIZE     ((MAX_BOARD + 2) * (MAX_BOARD + 1) + 1) 
    140147#define BOARDMIN      (MAX_BOARD + 2) 
     
    148155#define NS            (MAX_BOARD + 1) 
    149156#define WE            1 
    150157#define SOUTH(pos)    ((pos) + NS) 
    151 #define WEST(pos)     ((pos) - 1) 
     158#define WEST(pos)     ((pos) - WE) 
    152159#define NORTH(pos)    ((pos) - NS) 
    153 #define EAST(pos)     ((pos) + 1) 
    154 #define SW(pos)       ((pos) + NS - 1) 
    155 #define NW(pos)       ((pos) - NS - 1) 
    156 #define NE(pos)       ((pos) - NS + 1) 
    157 #define SE(pos)       ((pos) + NS + 1) 
     160#define EAST(pos)     ((pos) + WE) 
     161#define SW(pos)       ((pos) + NS - WE) 
     162#define NW(pos)       ((pos) - NS - WE) 
     163#define NE(pos)       ((pos) - NS + WE) 
     164#define SE(pos)       ((pos) + NS + WE) 
    158165#define SS(pos)       ((pos) + 2 * NS) 
    159 #define WW(pos)       ((pos) - 2) 
     166#define WW(pos)       ((pos) - 2 * WE) 
    160167#define NN(pos)       ((pos) - 2 * NS) 
    161 #define EE(pos)       ((pos) + 2) 
     168#define EE(pos)       ((pos) + 2 * WE) 
    162169 
    163170#define DIRECT_NEIGHBORS(pos1, pos2)            \ 
    164171  ((pos1) == SOUTH(pos2)                        \ 
     
    260267/* Functions handling the permanent board state. */ 
    261268void clear_board(void); 
    262269int test_gray_border(void); 
    263 void setup_board(Intersection new_board[MAX_BOARD][MAX_BOARD], int ko_pos, 
    264                  int *last, float new_komi, int w_captured, int b_captured); 
    265270void add_stone(int pos, int color); 
    266271void remove_stone(int pos); 
    267272void play_move(int pos, int color); 
     
    271276void restore_board(struct board_state *state); 
    272277 
    273278/* Information about the permanent board. */ 
    274 int get_last_move(void); 
    275 int get_last_player(void); 
     279inline int get_last_move(void); 
     280inline int get_last_player(void); 
    276281int get_last_opponent_move(int color); 
    277282int stones_on_board(int color); 
    278283 
    279284/* Functions handling the variable board state. */ 
    280 int trymove(int pos, int color, const char *message, int str); 
     285int trymove(int pos, int color, const char *message, int str_pos); 
    281286int tryko(int pos, int color, const char *message); 
    282287void popgo(void); 
    283288int komaster_trymove(int pos, int color, 
    284289                     const char *message, int str, 
    285290                     int *is_conditional_ko, int consider_conditional_ko); 
    286 int get_komaster(void); 
    287 int get_kom_pos(void); 
     291inline int get_komaster(void); 
     292inline int get_kom_pos(void); 
    288293 
    289294int move_in_stack(int pos, int cutoff); 
    290 void get_move_from_stack(int k, int *move, int *color); 
     295inline void get_move_from_stack(int k, int *move, int *color); 
    291296void dump_stack(void); 
    292297void do_dump_stack(void); 
    293298 
    294 void reset_trymove_counter(void); 
    295 int get_trymove_counter(void); 
     299void dump_incremental_board(void); 
     300 
     301inline void reset_trymove_counter(void); 
     302inline int get_trymove_counter(void); 
    296303 
    297304/* move properties */ 
    298 int is_pass(int pos); 
     305inline int is_pass(int pos); 
    299306int is_legal(int pos, int color); 
    300307int is_suicide(int pos, int color); 
    301 int is_illegal_ko_capture(int pos, int color); 
     308inline int is_illegal_ko_capture(int pos, int color); 
    302309int is_allowed_move(int pos, int color); 
    303310int is_ko(int pos, int color, int *ko_pos); 
    304311int is_ko_point(int pos); 
     
    306313int is_self_atari(int pos, int color); 
    307314 
    308315/* Purely gemoetric functions */ 
    309 int is_edge_vertex(int pos); 
    310 int is_corner_vertex(int pos); 
    311 int edge_distance(int pos); 
    312 int square_dist(int pos1, int pos2); 
     316inline int is_edge_vertex(int pos); 
     317inline int is_corner_vertex(int pos); 
     318inline int edge_distance(int pos); 
     319inline int square_dist(int pos1, int pos2); 
    313320 
    314321/* Basic string information. */ 
    315 int find_origin(int str); 
    316 int chainlinks(int str, int adj[MAXCHAIN]); 
    317 int chainlinks2(int str, int adj[MAXCHAIN], int lib); 
    318 int chainlinks3(int str, int adj[MAXCHAIN], int lib); 
    319 int extended_chainlinks(int str, int adj[MAXCHAIN], int both_colors); 
    320  
    321 int liberty_of_string(int pos, int str); 
    322 int second_order_liberty_of_string(int pos, int str); 
    323 int neighbor_of_string(int pos, int str); 
    324 int has_neighbor(int pos, int color); 
    325 int same_string(int str1, int str2); 
    326 int adjacent_strings(int str1, int str2); 
     322inline int find_origin(int str_pos); 
     323int chainlinks(int str_pos, int adj[MAXCHAIN]); 
     324int chainlinks2(int str_pos, int adj[MAXCHAIN], int lib); 
     325int chainlinks3(int str_pos, int adj[MAXCHAIN], int lib); 
     326int extended_chainlinks(int str_pos, int adj[MAXCHAIN], int both_colors); 
     327 
     328int liberty_of_string(int pos, int str_pos); 
     329int liberty_of_string2(int pos, int str_pos); 
     330int second_order_liberty_of_string(int pos, int str_pos); 
     331int neighbor_of_string(int pos, int str_pos); 
     332inline int has_neighbor(int pos, int color); 
     333inline int same_string(int str1_pos, int str2_pos); 
     334int adjacent_strings(int str1_pos, int str2_pos); 
    327335void mark_string(int str, signed char mx[BOARDMAX], signed char mark); 
    328336int are_neighbors(int pos1, int pos2); 
    329337 
    330 /* Count and/or find liberties at (pos). */ 
    331 int countlib(int str); 
    332 int findlib(int str, int maxlib, int *libs); 
     338/* Count and/or find liberties at (pos) */ 
     339inline int countlib(int str_pos); 
     340int findlib(int str_pos, int maxlib, int *libs); 
    333341int fastlib(int pos, int color, int ignore_captures); 
    334342int approxlib(int pos, int color, int maxlib, int *libs); 
    335343int accuratelib(int pos, int color, int maxlib, int *libs); 
    336 int count_common_libs(int str1, int str2); 
    337 int find_common_libs(int str1, int str2, int maxlib, int *libs); 
    338 int have_common_lib(int str1, int str2, int *lib); 
     344int count_common_libs(int str1_pos, int str2_pos); 
     345int find_common_libs(int str1_pos, int str2_pos, int maxlib, int *libs); 
     346int have_common_lib(int str1_pos, int str2_pos, int *lib); 
    339347 
    340348/* Count the number of stones in a string. */ 
    341 int countstones(int str); 
    342 int findstones(int str, int maxstones, int *stones); 
    343 int count_adjacent_stones(int str1, int str2, int maxstones); 
     349inline int countstones(int str_pos); 
     350int findstones(int str_pos, int maxstones, int *stones); 
     351int count_adjacent_stones(int str1_pos, int str2_pos, int maxstones); 
    344352 
    345353/* Special function for reading.c */ 
    346 void incremental_order_moves(int move, int color, int string, 
     354void incremental_order_moves(int move, int color, int target_pos, 
    347355                             int *number_edges, int *number_same_string, 
    348356                             int *number_own, int *number_opponent, 
    349357                             int *captured_stones, int *threatened_stones, 
    350358                             int *saved_stones, int *number_open); 
    351359 
    352360/* Board caches initialization functions. */ 
    353 void clear_approxlib_cache(void); 
    354 void clear_accuratelib_cache(void); 
     361inline void clear_approxlib_cache(void); 
     362inline void clear_accuratelib_cache(void); 
    355363   
    356364 
    357365/* Is this point inside the board? */ 
     
    381389 * south, west, north, east, southwest, northwest, northeast, southeast. 
    382390 * Defined in board.c. 
    383391 */ 
    384 extern int deltai[8]; /* = { 1,  0, -1,  0,  1, -1, -1, 1}; */ 
    385 extern int deltaj[8]; /* = { 0, -1,  0,  1, -1, -1,  1, 1}; */ 
    386 extern int delta[8];  /* = { NS, -1, -NS, 1, NS-1, -NS-1, -NS+1, NS+1}; */ 
     392extern const int deltai[8]; /* = { 1,  0, -1,  0,  1, -1, -1, 1}; */ 
     393extern const int deltaj[8]; /* = { 0, -1,  0,  1, -1, -1,  1, 1}; */ 
     394extern const int delta[8];  /* = { NS, -WE, -NS, WE, NS-WE, -NS-WE, -NS+WE, NS+WE}; */ 
    387395 
    388396 
    389397 
  • gnugo/engine/boardlib.c

    RCS file: /sources/gnugo/gnugo/engine/boardlib.c,v
    retrieving revision 1.12
    diff -u -r1.12 boardlib.c
     
    2929/* The board state itself. */ 
    3030int          board_size = DEFAULT_BOARD_SIZE; /* board size */ 
    3131Intersection board[BOARDSIZE]; 
    32 int          board_ko_pos; 
     32int          board_ko_pos;      /* Position of a ko (captured stone). */ 
    3333int          white_captured;    /* number of black and white stones captured */ 
    3434int          black_captured; 
    3535 
     
    5454/* Hashing of positions. */ 
    5555Hash_data board_hash; 
    5656 
    57 int stackp;             /* stack pointer */ 
     57int stackp;             /* moves stack depth */ 
    5858int position_number;    /* position number */ 
    5959 
    6060/* Some statistics gathered partly in board.c and hash.c */ 
  • gnugo/engine/breakin.c

    RCS file: /sources/gnugo/gnugo/engine/breakin.c,v
    retrieving revision 1.26
    diff -u -r1.26 breakin.c
     
    367367 
    368368        if (used[pos2]) 
    369369          break; 
    370       } 
     370          } 
    371371 
    372372      used[pos] = 1; 
    373373      if (ON_BOARD(pos2)) 
     
    440440  } 
    441441} 
    442442 
    443 void 
     443inline void 
    444444clear_break_in_list() 
    445445{ 
    446446  num_break_ins = 0; 
  • gnugo/engine/cache.c

    RCS file: /sources/gnugo/gnugo/engine/cache.c,v
    retrieving revision 1.50
    diff -u -r1.50 cache.c
     
    3939/* ---------------------------------------------------------------- */ 
    4040 
    4141static void tt_init(Transposition_table *table, int memsize); 
    42 static void tt_clear(Transposition_table *table); 
     42inline static void tt_clear(Transposition_table *table); 
    4343 
    4444/* The transposition table itself. */ 
    4545Transposition_table ttable; 
     
    7272calculate_hashval_for_tt(Hash_data *hashdata, int routine, int target1, 
    7373                         int target2, Hash_data *extra_hash) 
    7474{  
    75   *hashdata = board_hash;                /* from globals.c */ 
     75  *hashdata = board_hash;                /* from boardlib.c */ 
    7676  hashdata_xor(*hashdata, routine_hash[routine]); 
    7777  hashdata_xor(*hashdata, target1_hash[target1]); 
    7878  if (target2 != NO_MOVE) 
     
    9797  keyhash_init(); 
    9898 
    9999  if (memsize > 0) 
    100     num_entries = memsize / sizeof(table->entries[0]); 
     100    num_entries = memsize / sizeof(Hashentry); 
    101101  else 
    102102    num_entries = DEFAULT_NUMBER_OF_CACHE_ENTRIES; 
    103103 
    104104  table->num_entries = num_entries; 
    105   table->entries     = malloc(num_entries * sizeof(table->entries[0])); 
     105  table->entries     = malloc(num_entries * sizeof(Hashentry)); 
    106106 
    107107  if (table->entries == NULL) { 
    108108    perror("Couldn't allocate memory for transposition table. \n"); 
    109109    exit(1); 
    110110  } 
    111111 
    112   table->is_clean = 0; 
    113112  tt_clear(table); 
    114113} 
    115114 
    116115 
    117116/* Clear the transposition table. */ 
    118117 
    119 static void 
     118inline static void 
    120119tt_clear(Transposition_table *table) 
    121120{ 
    122   if (!table->is_clean) { 
    123     memset(table->entries, 0, table->num_entries * sizeof(table->entries[0])); 
    124     table->is_clean = 1; 
    125   } 
     121  memset(table->entries, 0, table->num_entries * sizeof(Hashentry)); 
    126122} 
    127   
    128   
     123 
     124 
    129125/* Free the transposition table. */ 
    130126 
    131 void 
     127inline void 
    132128tt_free(Transposition_table *table) 
    133129{ 
    134130  free(table->entries); 
    135131} 
    136132 
    137133 
    138 /* Get result and move. Return value: 
     134/* Get result and move (the bigger remaining depth the lower depth). 
     135 * Return value: 
    139136 *   0 if not found 
    140  *   1 if found, but depth too small to be trusted.  In this case the move 
     137 *   1 if found, but depth too big to be trusted.  In this case the move 
    141138 *     can be used for move ordering. 
    142  *   2 if found and depth is enough so that the result can be trusted. 
     139 *   2 if found and depth is small enough so that the result can be trusted. 
    143140 */ 
    144141  
    145142int 
     
    162159 
    163160  /* Get the correct entry and node. */ 
    164161  entry = &table->entries[hashdata_remainder(hashval, table->num_entries)]; 
    165   if (hashdata_is_equal(hashval, entry->deepest.key)) 
    166     node = &entry->deepest; 
     162 
     163  if (hashdata_is_equal(hashval, entry->most_reliable.key)) 
     164    node = &entry->most_reliable; 
    167165  else if (hashdata_is_equal(hashval, entry->newest.key)) 
    168166    node = &entry->newest; 
    169167  else 
    170168    return 0; 
    171169 
    172   stats.read_result_hits++; 
     170#ifndef GG_TURN_OFF_STATS 
     171  ++stats.read_result_hits; 
     172#endif 
    173173 
    174174  /* Return data.  Only set the result if remaining depth in the table 
    175175   * is big enough to be trusted.  The move can always be used for move 
     
    177177   */ 
    178178  if (move) 
    179179    *move = hn_get_move(node->data); 
     180 
    180181  if (remaining_depth <= (int) hn_get_remaining_depth(node->data)) { 
    181182    if (value1) 
    182183      *value1 = hn_get_value1(node->data); 
    183184    if (value2) 
    184185      *value2 = hn_get_value2(node->data); 
    185     stats.trusted_read_result_hits++; 
     186 
     187#ifndef GG_TURN_OFF_STATS 
     188    ++stats.trusted_read_result_hits; 
     189#endif 
     190 
    186191    return 2; 
    187192  } 
    188193 
     
    201206{ 
    202207  Hash_data hashval; 
    203208  Hashentry *entry; 
    204   Hashnode *deepest; 
     209  Hashnode *most_reliable; 
    205210  Hashnode *newest; 
    206211  unsigned int data; 
    207212  /* Get routine costs definitions from liberty.h. */ 
     
    220225 
    221226  /* Get the entry and nodes. */  
    222227  entry = &table->entries[hashdata_remainder(hashval, table->num_entries)]; 
    223   deepest = &entry->deepest; 
     228  most_reliable = &entry->most_reliable; 
    224229  newest  = &entry->newest; 
    225230  
    226231  /* See if we found an already existing node. */ 
    227   if (hashdata_is_equal(hashval, deepest->key) 
    228       && remaining_depth >= (int) hn_get_remaining_depth(deepest->data)) { 
    229  
    230     /* Found deepest */ 
    231     deepest->data = data; 
    232  
     232  if (hashdata_is_equal(hashval, most_reliable->key)) 
     233  { 
     234    /* Found shallower node (can be trusted more likely) */ 
     235    if (remaining_depth > (int) hn_get_remaining_depth(most_reliable->data)) 
     236      most_reliable->data = data; 
    233237  } 
    234   else if (hashdata_is_equal(hashval, newest->key) 
    235            && remaining_depth >= (int) hn_get_remaining_depth(newest->data)) { 
    236  
     238  else if (hashdata_is_equal(hashval, newest->key)) 
     239  { 
    237240    /* Found newest */ 
    238     newest->data = data; 
    239  
    240     /* If newest has become deeper than deepest, then switch them. */ 
    241     if (hn_get_remaining_depth(newest->data) 
    242         > hn_get_remaining_depth(deepest->data)) { 
    243       Hashnode temp; 
    244  
    245       temp = *deepest; 
    246       *deepest = *newest; 
    247       *newest = temp; 
     241    if (remaining_depth > (int) hn_get_remaining_depth(newest->data)) 
     242    { 
     243      newest->data = data; 
     244 
     245      /* If newest reliability is bigger than most_reliable, switch them. */ 
     246      if (hn_get_reliability(newest->data) > 
     247          hn_get_reliability(most_reliable->data)) 
     248      { 
     249        Hashnode temp; 
     250 
     251        temp = *most_reliable; 
     252        *most_reliable = *newest; 
     253        *newest = temp; 
     254      } 
    248255    } 
    249  
    250256  } 
    251   else if (hn_get_total_cost(data) > hn_get_total_cost(deepest->data)) { 
    252     if (hn_get_total_cost(newest->data) < hn_get_total_cost(deepest->data)) 
    253       *newest = *deepest; 
    254     deepest->key  = hashval; 
    255     deepest->data = data; 
    256   }  
    257   else { 
     257  /* Have new node. */ 
     258  else if (hn_get_reliability(data) > 
     259           hn_get_reliability(most_reliable->data)) 
     260  { 
     261    /* Replace most_reliable. */ 
     262    most_reliable->key  = hashval; 
     263    most_reliable->data = data; 
     264  } 
     265  else 
     266  { 
    258267    /* Replace newest. */ 
    259268    newest->key  = hashval; 
    260269    newest->data = data; 
    261270  } 
    262271 
    263   stats.read_result_entered++; 
    264   table->is_clean = 0; 
     272#ifndef GG_TURN_OFF_STATS 
     273  ++stats.read_result_entered; 
     274#endif 
    265275} 
    266276 
    267277 
     
    270280}; 
    271281 
    272282/* Convert a routine as used in the cache table to a string. */ 
    273 const char * 
     283inline const char * 
    274284routine_id_to_string(enum routine_id routine) 
    275285{ 
    276286  return routine_names[(int) routine]; 
     
    282292 * allocate a single node or if the allocation fails, the caching is 
    283293 * disabled. 
    284294 */ 
    285 void 
     295inline void 
    286296reading_cache_init(int bytes) 
    287297{ 
    288298  tt_init(&ttable, bytes); 
     
    290300 
    291301 
    292302/* Clear the cache for read results. */ 
    293 void 
     303inline void 
    294304reading_cache_clear() 
    295305{ 
    296306  tt_clear(&ttable); 
    297307} 
    298308 
    299 float 
     309inline float 
    300310reading_cache_default_size() 
    301311{ 
    302312  return DEFAULT_NUMBER_OF_CACHE_ENTRIES * sizeof(Hashentry) / 1024.0 / 1024.0; 
  • gnugo/engine/cache.h

    RCS file: /sources/gnugo/gnugo/engine/cache.h,v
    retrieving revision 1.54
    diff -u -r1.54 cache.h
     
    3232 * (Reading/Hashing) for more information.   
    3333 */ 
    3434 
     35#if SIZEOF_INT == 4 
     36  typedef unsigned int HASHNODE_DATATYPE; 
     37#elif SIZEOF_LONG == 4 
     38  typedef unsigned long HASHNODE_DATATYPE; 
     39#elif SIZEOF_INT > 4 
     40  typedef unsigned short HASHNODE_DATATYPE; 
     41#elif 
     42  #error Long type size has to be at least 4 bytes. 
     43#endif 
    3544 
    3645/* Hashnode: a node stored in the transposition table. 
    3746 * 
    3847 * In addition to the position, the hash lock encodes the following data, 
    3948 * all hashed: 
    40  *   komaster 
    41  *   kom_pos 
     49 *   ko 
     50 *   komaster (look in doc) 
     51 *   kom_pos (look in doc) 
    4252 *   routine 
    43  *   str1 
    44  *   str2 
     53 *   target1 
     54 *   target2 
    4555 *   extra hashvalue, optional (e.g. encoding a goal array) 
    4656 * 
    4757 * The data field packs into 32 bits the following 
     
    5464 *   cost           :  4 bits 
    5565 *   remaining_depth:  5 bits (depth - stackp)  NOTE: HN_MAX_REMAINING_DEPTH 
    5666 * 
    57  *   The last 9 bits together give an index for the total costs. 
     67 *   The last 9 bits together give a reliability index (bigger index means 
     68 *   more reliable result). 
     69 *   Values are results of analyzed position (WIN, LOSE, etc.) 
    5870 */ 
    5971typedef struct { 
    6072  Hash_data key; 
    61   unsigned int data; /* Should be 32 bits, but only wastes 25% if 64 bits. */ 
     73  HASHNODE_DATATYPE data; /* 32-bit value */ 
    6274} Hashnode; 
    6375 
    6476#define HN_MAX_REMAINING_DEPTH 31 
     
    6779/* Hashentry: an entry, with two nodes of the hash_table 
    6880 */ 
    6981typedef struct { 
    70   Hashnode deepest; 
     82  Hashnode most_reliable; 
    7183  Hashnode newest; 
    7284} Hashentry; 
    7385 
     
    7688#define hn_get_value2(hn)           ((hn >> 19) & 0x0f) 
    7789#define hn_get_move(hn)             ((hn >>  9) & 0x3ff) 
    7890#define hn_get_cost(hn)             ((hn >>  5) & 0x0f) 
    79 #define hn_get_remaining_depth(hn)  ((hn >>  0) & 0x1f) 
    80 #define hn_get_total_cost(hn)       ((hn >>  0) & 0x1ff) 
     91#define hn_get_remaining_depth(hn)  ((hn/*>>  0*/) & 0x1f) 
     92#define hn_get_reliability(hn)      ((hn/*>>  0*/) & 0x1ff) 
    8193 
    8294#define hn_create_data(remaining_depth, value1, value2, move, cost) \ 
    8395    ((((value1)         & 0x0f)  << 23) \ 
    8496   | (((value2)         & 0x0f)  << 19) \ 
    8597   | (((move)           & 0x3ff) <<  9) \ 
    8698   | (((cost)           & 0x0f)  <<  5) \ 
    87    | (((remaining_depth & 0x1f)  <<  0))) 
     99   | (((remaining_depth & 0x1f)/*<<  0*/))) 
    88100 
    89101 
    90102/* Transposition_table: transposition table used for caching. */ 
    91103typedef struct { 
    92104  unsigned int num_entries; 
    93105  Hashentry *entries; 
    94   int is_clean; 
    95106} Transposition_table; 
    96107 
    97108extern Transposition_table ttable; 
     
    101112 */ 
    102113#define DEFAULT_NUMBER_OF_CACHE_ENTRIES 350000 
    103114 
    104 void tt_free(Transposition_table *table); 
     115inline void tt_free(Transposition_table *table); 
    105116int  tt_get(Transposition_table *table, enum routine_id routine, 
    106117            int target1, int target2, int remaining_depth, 
    107118            Hash_data *extra_hash, 
     
    141152  int q1 = board[str1] == EMPTY ? str1 : find_origin(str1); \ 
    142153  int q2 = board[str2] == EMPTY ? str2 : find_origin(str2); 
    143154 
     155#define READ_FUNCTION_NAME read_function_name 
     156 
    144157#else 
    145158 
    146159#define TRACE_CACHED_RESULT(result, move) 
    147160#define TRACE_CACHED_RESULT2(result1, result2, move) 
    148161 
     162#ifndef GG_TURN_OFF_TRACES 
     163 
    149164#define SETUP_TRACE_INFO(name, str) \ 
    150165  const char *read_function_name = name; \ 
    151166  int q = str; 
     
    155170  int q1 = str1; \ 
    156171  int q2 = str2; 
    157172 
    158 #endif 
    159  
    160 /* Trace messages in decidestring/decidedragon sgf file. */ 
    161 void sgf_trace(const char *func, int str, int move, int result, 
    162                const char *message); 
    163 /* Trace messages in decideconnection sgf file. */ 
    164 void sgf_trace2(const char *func, int str1, int str2, int move,  
    165                 const char *result, const char *message); 
    166 /* Trace messages in decidesemeai sgf file. */ 
    167 void sgf_trace_semeai(const char *func, int str1, int str2, int move,  
    168                       int result1, int result2, const char *message); 
    169  
    170173/* Macro to hide the call to sgf_trace(). Notice that a little black 
    171174 * magic is going on here. Before using this macro, SETUP_TRACE_INFO 
    172175 * must have been called to provide the variables read_function_name 
     
    190193    sgf_trace_semeai(read_function_name, q1, q2, move, \ 
    191194                     result1, result2, message) 
    192195 
     196#define READ_FUNCTION_NAME read_function_name 
     197 
     198#else // #ifndef GG_TURN_OFF_TRACES 
     199 
     200#define SETUP_TRACE_INFO(name, str) 
     201#define SETUP_TRACE_INFO2(name, str1, str2) 
     202#define SGFTRACE(move, result, message) (void)0 
     203#define SGFTRACE2(move, result, message) (void)0 
     204#define SGFTRACE_SEMEAI(move, result1, result2, message) (void)0 
     205#define READ_FUNCTION_NAME NULL 
     206 
     207#endif // #ifndef GG_TURN_OFF_TRACES 
     208 
     209#endif // #if TRACE_READ_RESULTS 
     210 
     211/* Trace messages in decidestring/decidedragon sgf file. */ 
     212void sgf_trace(const char *func, int str, int move, int result, 
     213               const char *message); 
     214/* Trace messages in decideconnection sgf file. */ 
     215void sgf_trace2(const char *func, int str1, int str2, int move,  
     216                const char *result, const char *message); 
     217/* Trace messages in decidesemeai sgf file. */ 
     218void sgf_trace_semeai(const char *func, int str1, int str2, int move,  
     219                      int result1, int result2, const char *message); 
     220 
    193221 
    194222/* ================================================================ */ 
    195223 
     
    212240  do { \ 
    213241    tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, NULL,\ 
    214242              value, 0, move);\ 
    215     if ((value) != 0 && (point) != 0) *(point) = (move); \ 
     243    if ((point) != NULL && (value) != 0) \ 
     244      *(point) = (move); \ 
    216245    return (value); \ 
    217246  } while (0) 
    218247 
     
    220249  do { \ 
    221250    tt_update(&ttable, routine, str1, str2, remaining_depth, NULL, \ 
    222251              value1, value2, move); \ 
    223     if ((value1) != 0 && (point) != 0) *(point) = (move); \ 
     252    if ((point) != NULL && (value1) != 0) \ 
     253      *(point) = (move); \ 
    224254    return; \ 
    225255  } while (0) 
    226256 
     
    228258  do { \ 
    229259    tt_update(&ttable, routine, str1, str2, remaining_depth, NULL,\ 
    230260              value, 0, move);\ 
    231     if ((value) != 0 && (point) != 0) *(point) = (move); \ 
     261    if ((point) != NULL && (value) != 0) \ 
     262      *(point) = (move); \ 
    232263    return (value); \ 
    233264  } while (0) 
    234265 
     
    236267  do { \ 
    237268    tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, hash,\ 
    238269              value, 0, move);\ 
    239     if ((value) != 0 && (point) != 0) *(point) = (move); \ 
     270    if ((point) != NULL && (value) != 0) \ 
     271      *(point) = (move); \ 
    240272    return (value); \ 
    241273  } while (0) 
    242274 
     
    244276  do { \ 
    245277    tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, NULL,\ 
    246278              value1, value2, move);\ 
    247     if ((value1) != 0 && (point) != 0) *(point) = (move); \ 
     279    if ((point) != NULL && (value1) != 0) \ 
     280      *(point) = (move); \ 
    248281    return (value1); \ 
    249282  } while (0) 
    250283 
  • gnugo/engine/clock.c

    RCS file: /sources/gnugo/gnugo/engine/clock.c,v
    retrieving revision 1.26
    diff -u -r1.26 clock.c
     
    3838#include "clock.h" 
    3939#include "gg_utils.h" 
    4040#include "board.h" 
     41#include "gnugo.h" 
    4142 
    4243/* Level data */ 
    4344static int level             = DEFAULT_LEVEL; /* current level */ 
     
    6869}; 
    6970 
    7071struct timer_data { 
    71   struct remaining_time_data official; 
    72   struct remaining_time_data estimated; 
     72  struct remaining_time_data official; // time received from external source 
     73  struct remaining_time_data estimated; // time counted by GnuGO 
    7374  int time_out; 
    7475}; 
    7576 
     
    127128 * 
    128129 *  byo_time > 0 and byo_stones == 0 means no time settings. 
    129130 */ 
    130 void 
     131inline void 
    131132clock_settings(int time, int byo_time, int byo_stones) 
    132133{ 
    133134  if (time >= 0) 
     
    142143/* Get time settings. Returns 1 if any time settings have been made, 
    143144 * 0 otherwise. 
    144145 */ 
    145 int 
     146inline int 
    146147have_time_settings(void) 
    147148{ 
    148149  /* According to the semantics of the GTP command 'time_settings', the 
     
    220221  static int last_movenum = -1; 
    221222  struct timer_data* const td 
    222223    = (color == BLACK) ? &black_time_data : &white_time_data; 
    223   double now = gg_gettimeofday(); 
     224  double now; 
    224225 
    225226  if (!have_time_settings()) 
    226227    return; 
    227228 
     229  now = gg_gettimeofday(); 
     230 
    228231  if (last_movenum >= 0 
    229       && movenum == last_movenum + 1 
    230       && movenum > td->estimated.movenum) { 
     232      && movenum == last_movenum + 1) { 
    231233    double time_used = now - last_time; 
    232234    td->estimated.time_left -= time_used; 
    233235    td->estimated.movenum = movenum; 
    234236    td->estimated.time_for_last_move = time_used; 
    235237    if (td->estimated.time_left < 0) { 
    236238      if (td->estimated.in_byoyomi || byoyomi_stones == 0) { 
     239 
     240#ifndef GG_TURN_OFF_DEBUGS 
    237241        DEBUG(DEBUG_TIME, "%s ran out of time.\n", color_to_string(color)); 
    238242        if (debug & DEBUG_TIME) 
    239243          clock_print(color); 
     244#endif 
     245 
    240246        td->time_out = 1; 
    241247      } 
    242248      else { 
     
    251257    } 
    252258    else if (td->estimated.stones > 0) { 
    253259      gg_assert(td->estimated.in_byoyomi); 
    254       td->estimated.stones = td->estimated.stones - 1; 
     260      --td->estimated.stones; 
    255261      if (td->estimated.stones == 0) { 
    256262        td->estimated.time_left = byoyomi_time; 
    257263        td->estimated.stones = byoyomi_stones; 
     
    262268  last_movenum = movenum; 
    263269  last_time = now; 
    264270 
     271#ifndef GG_TURN_OFF_DEBUGS 
    265272  /* Update main timer. */ 
    266273  if (debug & DEBUG_TIME) 
    267274    clock_print(color); 
     275#endif 
    268276} 
    269277 
    270278 
     
    297305 
    298306  if (timer->stones == 0) { 
    299307    /* Main time running. */ 
    300     *time_left = timer->time_left + byoyomi_time; 
     308    *time_left = timer->time_left; 
    301309    if (byoyomi_time > 0) 
     310    { 
     311      *time_left += byoyomi_time; 
    302312      *stones_left = byoyomi_stones; 
     313    } 
    303314    else { 
    304315      /* Absolute time. Here we aim to be able to play at least X more 
    305316       * moves or a total of Y moves. We choose Y as a third of the 
     
    331342adjust_level_offset(int color) 
    332343{ 
    333344  double time_for_last_move; 
    334   double time_left; 
     345  double time_left, estimated_time; 
    335346  int stones_left; 
    336347 
    337348  if (!analyze_time_data(color, &time_for_last_move, &time_left, &stones_left)) 
     
    342353   * 
    343354   * FIXME: Use rules with at least some theoretical basis. 
    344355   */ 
    345   if (time_left < time_for_last_move * (stones_left + 3)) 
    346     level_offset--; 
    347   if (time_left < time_for_last_move * stones_left) 
    348     level_offset--; 
    349   if (3 * time_left < 2 * time_for_last_move * stones_left) 
    350     level_offset--; 
    351   if (2 * time_left < time_for_last_move * stones_left) 
    352     level_offset--; 
    353   if (3 * time_left < time_for_last_move * stones_left) 
    354     level_offset--; 
    355  
    356   if (time_for_last_move == 0) 
    357     time_for_last_move = 1; 
    358   if (time_left > time_for_last_move * (stones_left + 6)) 
    359     level_offset++; 
    360   if (time_left > 2 * time_for_last_move * (stones_left + 6)) 
    361     level_offset++; 
     356  if (time_for_last_move < 0.1) 
     357    time_for_last_move = 0.1; 
     358 
     359  estimated_time = time_for_last_move * stones_left; 
     360 
     361  if (time_left < estimated_time) 
     362  { 
     363    --level_offset; 
     364 
     365    if (1.33 * time_left < estimated_time) 
     366    { 
     367      --level_offset; 
     368 
     369      if (2 * time_left < estimated_time) 
     370      { 
     371        level_offset -= 2; 
     372 
     373        if (4 * time_left < estimated_time) 
     374          level_offset -= 2; 
     375      } 
     376    } 
     377  } 
     378  else if (0.8 * time_left > estimated_time) 
     379  { 
     380    ++level_offset; 
     381 
     382    if (0.5 * time_left > estimated_time) 
     383      level_offset += 2; 
     384  } 
    362385 
    363386  if (level + level_offset < min_level) 
    364387    level_offset = min_level - level; 
    365  
    366   if (level + level_offset > max_level) 
     388  else if (level + level_offset > max_level) 
    367389    level_offset = max_level - level; 
    368390 
    369391  DEBUG(DEBUG_TIME, "New level %d (%d %C %f %f %d)\n", level + level_offset, 
     
    375397/* Interface to level settings. */ 
    376398/********************************/ 
    377399 
    378 int 
     400inline int 
    379401get_level() 
    380402{ 
    381403  return level + level_offset; 
    382404} 
    383405 
    384 void 
     406inline void 
    385407set_level(int new_level) 
    386408{ 
    387409  level = new_level; 
     
    392414    min_level = level; 
    393415} 
    394416 
    395 void 
     417inline void 
    396418set_max_level(int new_max) 
    397419{ 
    398420  max_level = new_max; 
    399421} 
    400422 
    401 void 
     423inline void 
    402424set_min_level(int new_min) 
    403425{ 
    404426  min_level = new_min; 
  • gnugo/engine/clock.h

    RCS file: /sources/gnugo/gnugo/engine/clock.h,v
    retrieving revision 1.15
    diff -u -r1.15 clock.h
     
    2626#include "gnugo.h" 
    2727 
    2828/* initialization and activation */ 
    29 void clock_settings(int maintime, int byotime, int byostones); 
     29inline void clock_settings(int maintime, int byotime, int byostones); 
    3030void init_timers(void); 
    3131  
    3232/* main access */ 
    3333void clock_push_button(int color); 
    3434void update_time_left(int color, int time_left, int stones); 
    3535void clock_print(int color); 
    36 int have_time_settings(void); 
     36inline int have_time_settings(void); 
    3737 
    3838void adjust_level_offset(int color); 
    3939 
    4040/* Access to level settings. */ 
    41 int get_level(void); 
    42 void set_level(int new_level); 
    43 void set_max_level(int new_max); 
    44 void set_min_level(int new_min); 
     41inline int get_level(void); 
     42inline void set_level(int new_level); 
     43inline void set_max_level(int new_max); 
     44inline void set_min_level(int new_min); 
    4545 
    4646 
    4747#endif  /* _CLOCK_H_ */ 
  • gnugo/engine/combination.c

    RCS file: /sources/gnugo/gnugo/engine/combination.c,v
    retrieving revision 1.57
    diff -u -r1.57 combination.c
     
    761761        if (num_libs == 2) 
    762762          all_potential_defenses[libs[1]] = 1; 
    763763      } 
    764     } 
     764        } 
    765765 
    766766    if (!IS_STONE(board[str])) { 
    767767      /* Error situation. This could be caused by a wrong matcher status. */ 
     
    889889      continue; 
    890890     
    891891    if (board[last_friendly] == EMPTY 
    892         && !liberty_of_string(last_friendly, pos)) 
     892        && !liberty_of_string2(last_friendly, pos)) 
    893893      continue; 
    894894     
    895895    if (debug & DEBUG_ATARI_ATARI) 
     
    10541054 
    10551055        if (!safe_move(move, color)) 
    10561056          continue; 
    1057       } 
     1057          } 
    10581058       
    10591059      /* 
    10601060       * Play (move) and see if there is an attack. 
  • gnugo/engine/dragon.c

    RCS file: /sources/gnugo/gnugo/engine/dragon.c,v
    retrieving revision 1.162
    diff -u -r1.162 dragon.c
     
    594594          propagate_worm(str); 
    595595        } 
    596596      } 
    597     } 
     597        } 
    598598 
    599599  /* Revise essentiality of critical dragons. Specifically, a critical 
    600600   * dragon consisting entirely of inessential worms is considered 
  • gnugo/engine/endgame.c

    RCS file: /sources/gnugo/gnugo/engine/endgame.c,v
    retrieving revision 1.13
    diff -u -r1.13 endgame.c
     
    461461  int liberties; 
    462462  int libs[MAXLIBS]; 
    463463  int k; 
     464  int color = board[str]; 
     465  int origin = find_origin(str); 
    464466 
    465   ASSERT1(IS_STONE(board[str]), str); 
     467  ASSERT1(IS_STONE(color), str); 
    466468 
    467469  *essential_liberties = 0; 
    468470  *inessential_liberties = 0; 
     
    494496        if (worm[pos].attack_codes[0] != 0 || dragon[pos].status != ALIVE) 
    495497          return 0; 
    496498 
    497         if (board[pos] == board[str]) { 
    498           if (find_origin(pos) != find_origin(str)) 
     499        if (board[pos] == color) { 
     500          if (find_origin(pos) != origin) 
    499501            essential = 1; 
    500502        } 
    501503        else 
  • gnugo/engine/filllib.c

    RCS file: /sources/gnugo/gnugo/engine/filllib.c,v
    retrieving revision 1.37
    diff -u -r1.37 filllib.c
     
    310310      DEBUG(DEBUG_FILLLIB, 
    311311            "Filllib: Nothing found, looking for threat to back-capture.\n"); 
    312312      for (k = 0; k < 4; k++) { 
    313         int d = delta[k]; 
    314         if (board[pos + d] == other 
    315             && worm[pos + d].attack_codes[0] != 0) { 
     313        int checked_pos = pos + delta[k]; 
     314        if (board[checked_pos] == other 
     315            && worm[checked_pos].attack_codes[0] != 0) { 
    316316          /* Just pick some other liberty. */ 
    317317          /* FIXME: Something is odd about this code. */ 
    318318          int libs[2]; 
    319           if (findlib(pos + d, 2, libs) > 1) { 
     319          if (findlib(checked_pos, 2, libs) > 1) { 
    320320            if (is_legal(libs[0], color)) 
    321321              *move = libs[0]; 
    322322            else if (is_legal(libs[1], color)) 
     
    394394   */ 
    395395  acode = attack(move, &apos); 
    396396  gg_assert(acode != 0 && apos != NO_MOVE); 
    397    
     397 
    398398  /* Find liberties. */ 
    399399  liberties = findlib(move, MAXLIBS, libs); 
    400400 
     
    435435      if (attack(adjs[k], &bpos) == WIN) { 
    436436        if (forbidden_moves[bpos]) 
    437437          continue; 
    438         if (liberty_of_string(bpos, adjs[k])) { 
     438        if (liberty_of_string2(bpos, adjs[k])) { 
    439439          *backfill_move = bpos; 
    440440          return 1; 
    441441        } 
     
    464464        if (attack(adjs[k], &bpos) == WIN) { 
    465465          if (forbidden_moves[bpos]) 
    466466            continue; 
    467           if (liberty_of_string(bpos, adjs[k])) { 
     467          if (liberty_of_string2(bpos, adjs[k])) { 
    468468            *backfill_move = bpos; 
    469469            return 1; 
    470470          } 
     
    496496    popgo(); 
    497497    for (k = 0; k < neighbors; k++) { 
    498498      if (attack(adjs[k], &bpos) == WIN) { 
    499         if (!forbidden_moves[bpos] && liberty_of_string(bpos, adjs[k])) { 
     499        if (!forbidden_moves[bpos] && liberty_of_string2(bpos, adjs[k])) { 
    500500          *backfill_move = bpos; 
    501501          return 1; 
    502502        } 
  • gnugo/engine/genmove.c

    RCS file: /sources/gnugo/gnugo/engine/genmove.c,v
    retrieving revision 1.116
    diff -u -r1.116 genmove.c
     
    7373void 
    7474reset_engine() 
    7575{ 
     76  static int last_level = -1; 
     77  int act_level; 
     78 
    7679  /* To improve the reproducability of games, we restart the random 
    7780   * number generator with the same seed for each move. Thus we don't 
    7881   * have to know how many previous moves have been played, nor 
     
    98101  clear_break_in_list(); 
    99102 
    100103  /* Set up depth values (see comments there for details). */ 
    101   set_depth_values(get_level(), 0); 
     104  act_level = get_level(); 
     105  if (last_level != act_level) 
     106  { 
     107    set_depth_values(act_level, 0); 
     108    last_level = act_level; 
     109  } 
    102110} 
    103111 
    104112/* 
     
    117125void 
    118126examine_position(int how_much, int aftermath_play) 
    119127{ 
     128#ifndef GG_TURN_OFF_TRACES 
    120129  int save_verbose = verbose; 
     130#endif 
    121131 
    122132  purge_persistent_caches(); 
    123133   
     134#ifndef GG_TURN_OFF_TRACES 
    124135  /* Don't print reading traces during make_worms and make_dragons unless  
    125136   * the user really wants it (verbose == 3).  
    126137   */ 
    127138  if (verbose == 1 || verbose == 2) 
    128139    --verbose; 
     140#endif 
    129141 
    130142  if (NEEDS_UPDATE(worms_examined)) { 
     143 
     144#ifndef GG_TURN_OFF_TRACES 
    131145    start_timer(0); 
     146#endif 
     147 
    132148    make_worms(); 
     149 
     150#ifndef GG_TURN_OFF_TRACES 
    133151    time_report(0, "  make worms", NO_MOVE, 1.0); 
     152#endif 
    134153  } 
    135154 
    136155  if (how_much == EXAMINE_WORMS) { 
     156 
     157#ifndef GG_TURN_OFF_TRACES 
    137158    verbose = save_verbose; 
     159#endif 
     160 
    138161    gg_assert(test_gray_border() < 0); 
    139162    return; 
    140163  } 
     
    142165  if (stones_on_board(BLACK | WHITE) != 0) { 
    143166    if (NEEDS_UPDATE(initial_influence_examined)) 
    144167      compute_worm_influence(); 
     168 
    145169    if (how_much == EXAMINE_INITIAL_INFLUENCE) { 
     170 
     171#ifndef GG_TURN_OFF_TRACES 
    146172      verbose = save_verbose; 
     173#endif 
     174 
    147175      gg_assert(test_gray_border() < 0); 
    148176      return; 
    149177    } 
     
    151179    if (how_much == EXAMINE_DRAGONS_WITHOUT_OWL) { 
    152180      if (NEEDS_UPDATE(dragons_examined_without_owl)) 
    153181        make_dragons(1); 
     182 
     183#ifndef GG_TURN_OFF_TRACES 
    154184      verbose = save_verbose; 
     185#endif 
     186 
    155187      gg_assert(test_gray_border() < 0); 
    156188      return; 
    157189    } 
     
    163195      dragons_examined_without_owl = position_number; 
    164196    } 
    165197    if (how_much == EXAMINE_DRAGONS) { 
     198 
     199#ifndef GG_TURN_OFF_TRACES 
    166200      verbose = save_verbose; 
     201#endif 
     202 
    167203      gg_assert(test_gray_border() < 0); 
    168204      return; 
    169205    } 
     
    173209           || how_much == EXAMINE_ALL) { 
    174210    initialize_dragon_data(); 
    175211    compute_scores(chinese_rules || aftermath_play); 
     212 
     213#ifndef GG_TURN_OFF_TRACES 
    176214    verbose = save_verbose; 
     215#endif 
     216 
    177217    gg_assert(test_gray_border() < 0); 
    178218    return; 
    179219  } 
    180220   
     221#ifndef GG_TURN_OFF_TRACES 
    181222  verbose = save_verbose; 
     223#endif 
    182224 
    183225  if (NEEDS_UPDATE(initial_influence2_examined)) { 
    184226    compute_dragon_influence(); 
     
    197239    return; 
    198240  } 
    199241 
     242#ifndef GG_TURN_OFF_TRACES 
    200243  if (printworms) 
    201244    show_dragons(); 
     245#endif 
    202246} 
    203247 
    204248 
     
    283327/* This function collects move reasons can be generated immediately from 
    284328 * the data gathered in the examine_position() phase. 
    285329 */ 
    286 void 
     330inline void 
    287331collect_move_reasons(int color) 
    288332{ 
    289333  worm_reasons(color); 
     
    306350           int allowed_moves[BOARDMAX], float *value, int *resign) 
    307351{ 
    308352  float average_score, pessimistic_score, optimistic_score; 
    309   int save_verbose; 
    310   int save_depth; 
    311353  int move; 
    312354  float dummy_value; 
    313355  int use_thrashing_dragon_heuristics = 0; 
    314356 
     357#ifndef GG_TURN_OFF_TRACES 
     358  int save_verbose; 
     359#endif 
     360 
     361#ifndef GG_TURN_OFF_ASSERTS 
     362  int save_depth; 
     363#endif 
     364 
    315365  if (!value) 
    316366    value = &dummy_value; 
    317367 
     368#ifndef GG_TURN_OFF_TRACES 
    318369  start_timer(0); 
     370#endif 
     371 
     372#ifndef GG_TURN_OFF_STATS 
    319373  clearstats(); 
     374#endif 
    320375 
    321376  /* Usually we would not recommend resignation. */ 
    322377  if (resign) 
     
    332387  /* Prepare pattern matcher and reading code. */ 
    333388  reset_engine(); 
    334389 
     390#ifndef GG_TURN_OFF_ASSERTS 
    335391  /* Store the depth value so we can check that it hasn't changed when 
    336392   * we leave this function. 
    337393   */ 
    338394  save_depth = depth; 
     395#endif 
    339396 
    340397  /* If in mirror mode, try to find a mirror move. */ 
    341398  if (play_mirror_go 
     
    348405  } 
    349406 
    350407  /* Find out information about the worms and dragons. */ 
     408#ifndef GG_TURN_OFF_TRACES 
    351409  start_timer(1); 
     410#endif 
     411 
    352412  examine_position(EXAMINE_ALL, 0); 
     413 
     414#ifndef GG_TURN_OFF_TRACES 
    353415  time_report(1, "examine position", NO_MOVE, 1.0); 
     416#endif 
    354417 
    355418 
    356419  /* The score will be used to determine when we are safely 
     
    374437    average_score = -(white_score + black_score)/2.0; 
    375438  choose_strategy(color, average_score, game_status(color)); 
    376439 
     440#ifndef GG_TURN_OFF_TRACES 
    377441  if (printboard) { 
    378442    if (printboard == 1) 
    379443      fprintf(stderr, "\n          dragon_status display:\n\n"); 
     
    387451      showboard(4); 
    388452    } 
    389453  } 
     454#endif 
    390455   
    391456  gg_assert(stackp == 0); 
    392457   
     
    396461 
    397462   
    398463  /* Pick up moves that we know of already. */ 
     464#ifndef GG_TURN_OFF_TRACES 
    399465  save_verbose = verbose; 
    400466  if (verbose > 0) 
    401467    verbose--; 
     468#endif 
     469 
    402470  collect_move_reasons(color); 
     471 
     472#ifndef GG_TURN_OFF_TRACES 
    403473  verbose = save_verbose; 
    404474  time_report(1, "generate move reasons", NO_MOVE, 1.0); 
     475#endif 
    405476   
    406477  /* Try to find empty corner moves. */ 
    407478  fuseki(color); 
     
    420491   
    421492  /* The general pattern database. */ 
    422493  shapes(color); 
     494 
     495#ifndef GG_TURN_OFF_TRACES 
    423496  time_report(1, "shapes", NO_MOVE, 1.0); 
     497#endif 
     498 
    424499  gg_assert(stackp == 0); 
    425500 
    426501  /* Look for combination attacks and defenses against them. */ 
    427502  combinations(color); 
     503 
     504#ifndef GG_TURN_OFF_TRACES 
    428505  time_report(1, "combinations", NO_MOVE, 1.0); 
     506#endif 
     507 
    429508  gg_assert(stackp == 0); 
    430509 
    431510  /* Review the move reasons and estimate move values. */ 
     
    433512                          pure_threat_value, pessimistic_score, allowed_moves, 
    434513                          use_thrashing_dragon_heuristics)) 
    435514    TRACE("Move generation likes %1m with value %f\n", move, *value); 
     515 
    436516  gg_assert(stackp == 0); 
     517 
     518#ifndef GG_TURN_OFF_TRACES 
    437519  time_report(1, "review move reasons", NO_MOVE, 1.0); 
     520#endif 
    438521 
    439522 
    440523  /* If the move value is 6 or lower, we look for endgame patterns too. */ 
     
    447530                            use_thrashing_dragon_heuristics)) 
    448531      TRACE("Move generation likes %1m with value %f\n", move, *value); 
    449532    gg_assert(stackp == 0); 
     533 
     534#ifndef GG_TURN_OFF_TRACES 
    450535    time_report(1, "endgame", NO_MOVE, 1.0); 
     536#endif 
    451537  } 
    452538   
    453539  /* If no move found yet, revisit any semeai and change the 
     
    465551              move, *value);  
    466552      } 
    467553    } 
    468     time_report(1, "move reasons with revised semeai status", 
    469                 NO_MOVE, 1.0); 
     554 
     555#ifndef GG_TURN_OFF_TRACES 
     556    time_report(1, "move reasons with revised semeai status", NO_MOVE, 1.0); 
     557#endif 
    470558  } 
    471559 
    472560  /* If still no move, fill a remaining liberty. This should pick up 
     
    478566      *value = 1.0; 
    479567      TRACE("Filling a liberty at %1m\n", move); 
    480568      record_top_move(move, *value); 
    481       move_considered(move, *value); 
     569 
     570#ifndef GG_TURN_OFF_TRACES 
     571          move_considered(move, *value); 
    482572      time_report(1, "fill liberty", NO_MOVE, 1.0); 
     573#endif 
    483574    } 
    484575    else 
    485576      move = PASS_MOVE; 
     
    492583  if (move == PASS_MOVE) { 
    493584    if (play_out_aftermath  
    494585        || capture_all_dead  
    495         || (!doing_scoring && thrashing_dragon && pessimistic_score > 15.0)) 
     586        || (!doing_scoring && thrashing_dragon && pessimistic_score > 1.0)) 
    496587      move = aftermath_genmove(color, 0, allowed_moves); 
    497588       
    498589    /* If we're instructed to capture all dead opponent stones, generate 
     
    506597      *value = 1.0; 
    507598      TRACE("Aftermath move at %1m\n", move); 
    508599      record_top_move(move, *value); 
     600 
     601#ifndef GG_TURN_OFF_TRACES 
    509602      move_considered(move, *value); 
    510603      time_report(1, "aftermath_genmove", NO_MOVE, 1.0); 
     604#endif 
    511605    } 
    512606  } 
    513607 
     
    534628    *resign = 1; 
    535629  } 
    536630   
     631#ifndef GG_TURN_OFF_STATS 
    537632  /* If statistics is turned on, this is the place to show it. */ 
    538633  if (showstatistics) 
    539634    showstats(); 
     635#endif 
    540636 
     637#ifndef GG_TURN_OFF_TRACES 
    541638  if (showtime) { 
    542639    double spent = time_report(0, "TIME to generate move at ", move, 1.0); 
    543640    total_time += spent; 
     
    547644      slowest_movenum = movenum + 1; 
    548645    } 
    549646  } 
     647#endif 
    550648 
    551649  /* Some consistency checks to verify that things are properly 
    552650   * restored and/or have not been corrupted. 
    553651   */ 
    554652  gg_assert(stackp == 0); 
    555653  gg_assert(test_gray_border() < 0); 
     654 
     655#ifndef GG_TURN_OFF_ASSERTS 
    556656  gg_assert(depth == save_depth); 
     657#endif 
    557658 
    558659  return move; 
    559660} 
     
    565666 * have considered. 
    566667 */ 
    567668 
    568 void  
     669inline void  
    569670move_considered(int move, float value) 
    570671{ 
    571672  if (value > potential_moves[move]) 
     
    682783  return 0; 
    683784} 
    684785 
    685 /* Computer two territory estimates: for *upper, the status of all 
     786/* Compute two territory estimates: for *upper, the status of all 
    686787 * cricital stones gets resolved in White's favor; vice verso for 
    687788 * black. 
    688789 */ 
     
    701802                    NO_MOVE, "White territory estimate"); 
    702803  black_score = influence_score(&move_influence, use_chinese_rules); 
    703804 
     805#ifndef GG_TURN_OFF_TRACES 
    704806  if (verbose || showscore) { 
    705807    if (white_score == black_score) 
    706808      gprintf("Score estimate: %s %f\n", 
     
    711813              white_score > 0 ? "W " : "B ", gg_abs(white_score)); 
    712814    fflush(stderr); 
    713815  } 
     816#endif 
    714817} 
    715818 
    716819 
  • gnugo/engine/globals.c

    RCS file: /sources/gnugo/gnugo/engine/globals.c,v
    retrieving revision 1.81
    diff -u -r1.81 globals.c
     
    132132float white_score; 
    133133float black_score; 
    134134 
    135 int close_worms[BOARDMAX][4]; 
     135/* Close worms data. See liberty.h */ 
     136int close_worms[BOARDMAX][MAX_CLOSE_WORMS]; 
    136137int number_close_worms[BOARDMAX]; 
    137 int close_black_worms[BOARDMAX][4]; 
     138int close_black_worms[BOARDMAX][MAX_CLOSE_WORMS]; 
    138139int number_close_black_worms[BOARDMAX]; 
    139 int close_white_worms[BOARDMAX][4]; 
     140int close_white_worms[BOARDMAX][MAX_CLOSE_WORMS]; 
    140141int number_close_white_worms[BOARDMAX]; 
    141142 
    142143int false_eye_territory[BOARDMAX]; 
  • gnugo/engine/gnugo.h

    RCS file: /sources/gnugo/gnugo/engine/gnugo.h,v
    retrieving revision 1.133
    diff -u -r1.133 gnugo.h
     
    114114/*                           global variables                       */ 
    115115/* ================================================================ */ 
    116116 
     117// final release option 
     118 
     119#if FINAL_RELEASE == 1 
     120 
     121#define GG_TURN_OFF_ASSERTS 
     122#define GG_TURN_OFF_TRACES 
     123#define GG_TURN_OFF_STATS 
     124#define GG_TURN_OFF_DEBUGS 
     125 
     126#endif 
    117127 
    118128/* Miscellaneous debug options. */ 
    119129extern int quiet;               /* Minimal output. */ 
     
    269279/* influence.c */ 
    270280void debug_influence_move(int move); 
    271281 
    272  
     282#ifdef GG_TURN_OFF_TRACES 
     283#define TRACE (1) ? (void)0 : (void)gprintf 
     284#else 
    273285#define TRACE  (!(verbose)) ? (void)0 : (void)gprintf 
     286#endif 
     287 
     288#ifdef GG_TURN_OFF_DEBUGS 
     289#define DEBUG (1) ? (void)0 : (void)DEBUG_func 
     290int DEBUG_func(int level, const char *fmt, ...); 
     291#else 
    274292 
    275293#ifdef HAVE_VARIADIC_DEFINE 
    276294 
     
    286304 
    287305#endif  /*HAVE_VARIADIC_DEFINE*/ 
    288306 
     307#endif /*GG_TURN_OFF_DEBUGS*/ 
     308 
    289309 
    290310/* genmove.c */ 
    291311#define EXAMINE_WORMS               1 
  • gnugo/engine/hash.c

    RCS file: /sources/gnugo/gnugo/engine/hash.c,v
    retrieving revision 1.38
    diff -u -r1.38 hash.c
     
    2424#include "board.h" 
    2525#include "hash.h" 
    2626#include "random.h" 
     27#include "gnugo.h" 
    2728 
    2829#include <stdio.h> 
    2930#include <stdlib.h> 
    3031#include <limits.h> 
     32#include <string.h> 
    3133 
    3234 
    3335 
     
    5860{ 
    5961  int i; 
    6062  Hashvalue h = 0; 
     63  const int limit = CHAR_BIT * sizeof(Hashvalue); 
    6164 
    62   for (i = 0; 32*i < (int) (CHAR_BIT*sizeof(Hashvalue)); i++) 
    63     h |= (Hashvalue) gg_urand() << 32*i; 
     65  for (i = 0; i < limit; i += 32) 
     66    h |= ((Hashvalue) gg_urand()) << i; 
    6467 
    6568  return h; 
    6669} 
     
    118121      hashdata_xor(*target, black_hash[pos]); 
    119122  } 
    120123 
    121   if (ko_pos != 0) 
     124  if (ko_pos != NO_MOVE) 
    122125    hashdata_xor(*target, ko_hash[ko_pos]); 
    123126} 
    124127 
    125128/* Clear hashdata. */ 
    126 void 
     129inline void 
    127130hashdata_clear(Hash_data *hd) 
    128131{ 
    129   int i; 
    130   for (i = 0; i < NUM_HASHVALUES; i++) 
    131     hd->hashval[i] = 0; 
     132  memset(hd->hashval, 0, NUM_HASHVALUES * sizeof(Hashvalue)); 
    132133} 
    133134 
    134135/* Set or remove ko in the hash value and hash position.  */ 
    135 void 
     136inline void 
    136137hashdata_invert_ko(Hash_data *hd, int pos) 
    137138{ 
    138139  hashdata_xor(*hd, ko_hash[pos]); 
     
    140141 
    141142 
    142143/* Set or remove a stone of COLOR at pos in a Hash_data.  */ 
    143 void 
     144inline void 
    144145hashdata_invert_stone(Hash_data *hd, int pos, int color) 
    145146{ 
    146147  if (color == BLACK) 
     
    151152 
    152153 
    153154/* Set or remove the komaster value in the hash data. */ 
    154 void 
     155inline void 
    155156hashdata_invert_komaster(Hash_data *hd, int komaster) 
    156157{ 
    157158  hashdata_xor(*hd, komaster_hash[komaster]); 
    158159} 
    159160 
    160161/* Set or remove the komaster position in the hash data. */ 
    161 void 
     162inline void 
    162163hashdata_invert_kom_pos(Hash_data *hd, int kom_pos) 
    163164{ 
    164165  hashdata_xor(*hd, kom_pos_hash[kom_pos]); 
  • gnugo/engine/hash.h

    RCS file: /sources/gnugo/gnugo/engine/hash.h,v
    retrieving revision 1.37
    diff -u -r1.37 hash.h
     
    8787#define INIT_ZOBRIST_ARRAY(a) \ 
    8888  hash_init_zobrist_array(a, (int) (sizeof(a) / sizeof(a[0]))) 
    8989 
    90 void hashdata_clear(Hash_data *hd); 
     90inline void hashdata_clear(Hash_data *hd); 
    9191void hashdata_recalc(Hash_data *hd, Intersection *board, int ko_pos); 
    92 void hashdata_invert_ko(Hash_data *hd, int pos); 
    93 void hashdata_invert_stone(Hash_data *hd, int pos, int color); 
    94 void hashdata_invert_komaster(Hash_data *hd, int komaster); 
    95 void hashdata_invert_kom_pos(Hash_data *hd, int kom_pos); 
     92inline void hashdata_invert_ko(Hash_data *hd, int pos); 
     93inline void hashdata_invert_stone(Hash_data *hd, int pos, int color); 
     94inline void hashdata_invert_komaster(Hash_data *hd, int komaster); 
     95inline void hashdata_invert_kom_pos(Hash_data *hd, int kom_pos); 
    9696 
    9797char *hashdata_to_string(Hash_data *hashdata); 
    9898 
     
    100100 
    101101/* ---------------------------------------------------------------- */ 
    102102 
    103 /* There is no need to involve all bits in the remainder computation 
    104  * as long as we only use it to compute a key into a hash table. 32 
    105  * random bits are sufficient to get an even distribution within any 
    106  * hashtable of reasonable size. By never using more than 32 bits we 
    107  * also reduce the platform dependency of the GNU Go engine. 
    108 */ 
     103/* Calculates a place in the transposition table where to look up for 
     104   a hash value. If sizeof(long) > sizeof(int) we truncate long to int 
     105   because size of the transposition table wouldn't be greater than 
     106   int. */ 
    109107#define hashdata_remainder(hd, num) \ 
    110   (((hd).hashval[0] & 0xffffffffU) % (num)) 
     108  (*((unsigned int*)((hd).hashval)) % (num)) 
     109 
    111110 
    112111#if NUM_HASHVALUES == 1 
    113112 
  • gnugo/engine/liberty.h

    RCS file: /sources/gnugo/gnugo/engine/liberty.h,v
    retrieving revision 1.258
    diff -u -r1.258 liberty.h
     
    9797  "analyze_semeai" 
    9898 
    9999/* To prioritize between different types of reading, we give a cost 
    100  * ranking to each of the routines above: 
     100 * ranking to each of the routines above (bigger index means bigger 
     101 * cost): 
    101102 * 
    102103 * 4 semeai 
    103104 * 3 owl 
     
    111112  3, 3, 4, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, -1 
    112113   
    113114 
    114 const char *routine_id_to_string(enum routine_id routine); 
     115inline const char *routine_id_to_string(enum routine_id routine); 
    115116 
    116117 
    117118/* This is used for both the dragon status and safety fields. 
     
    119120 * final status computed by the aftermath code. 
    120121 */ 
    121122enum dragon_status { 
     123  UNKNOWN, 
    122124  DEAD, 
    123125  ALIVE, 
    124126  CRITICAL, 
    125   UNKNOWN, 
    126127  UNCHECKED, 
    127128  CAN_THREATEN_ATTACK, 
    128129  CAN_THREATEN_DEFENSE,  
     
    139140}; 
    140141 
    141142#define DRAGON_STATUS_NAMES \ 
     143  "unknown", \ 
    142144  "dead", \ 
    143145  "alive", \ 
    144146  "critical", \ 
    145   "unknown", \ 
    146147  "unchecked", \ 
    147148  "can threaten attack", \ 
    148149  "can threaten defense", \ 
     
    194195                     struct corner_db *database); 
    195196void dfa_match_init(void); 
    196197 
    197 void reading_cache_init(int bytes); 
    198 void reading_cache_clear(void); 
    199 float reading_cache_default_size(void); 
     198inline void reading_cache_init(int bytes); 
     199inline void reading_cache_clear(void); 
     200inline float reading_cache_default_size(void); 
    200201 
    201202/* reading.c */ 
    202203int attack(int str, int *move); 
     
    345346int surround_map(int dr, int pos); 
    346347 
    347348/* functions to add (or remove) move reasons */ 
    348 void collect_move_reasons(int color); 
     349inline void collect_move_reasons(int color); 
    349350 
    350351void clear_move_reasons(void); 
    351352void add_lunch(int eater, int food); 
     
    652653 
    653654void break_territories(int color_to_move, struct influence_data *q, 
    654655                       int store, int pos); 
    655 void clear_break_in_list(void); 
     656inline void clear_break_in_list(void); 
    656657void break_in_move_reasons(int color); 
    657658 
    658659void choose_strategy(int color, float our_score, float game_status); 
     
    669670 
    670671/* debugging support */ 
    671672void goaldump(const signed char goal[BOARDMAX]); 
    672 void move_considered(int move, float value); 
     673inline void move_considered(int move, float value); 
    673674 
    674675 
    675676/* Transformation stuff. */ 
  • 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
     
    15531553{ 
    15541554  float new_strength; 
    15551555  int ii; 
     1556  int aff_stone = board[affected]; 
    15561557 
    1557   ASSERT1(IS_STONE(board[affected]), affected); 
     1558  ASSERT1(IS_STONE(aff_stone), affected); 
    15581559 
    15591560  if (new_status == 0) 
    15601561    new_strength = 0.0; 
     
    15631564    new_strength = DEFAULT_STRENGTH; 
    15641565  } 
    15651566  for (ii = BOARDMIN; ii < BOARDMAX; ii++) 
    1566     if (board[ii] == board[affected] 
     1567    if (board[ii] == aff_stone 
    15671568        && same_string(ii, affected)) { 
    15681569      strength[ii] = new_strength; 
    15691570      safe_stones[ii] = new_status; 
  • gnugo/engine/optics.c

    RCS file: /sources/gnugo/gnugo/engine/optics.c,v
    retrieving revision 1.105
    diff -u -r1.105 optics.c
     
    17481748  int defense_point; 
    17491749  int attack_value; 
    17501750  int defense_value; 
     1751  int other = OTHER_COLOR(color); 
    17511752 
    17521753  memset(attack_values, 0, sizeof(attack_values)); 
    17531754  memset(defense_values, 0, sizeof(defense_values)); 
     
    18461847     *           string neighbors more than one empty vertex in the 
    18471848     *           same eyespace. 
    18481849     */ 
    1849     if (val < 2.0 && board[pos] == EMPTY && board[diag] == OTHER_COLOR(color) 
     1850    if (val < 2.0 && board[pos] == EMPTY && board[diag] == other 
    18501851        && !is_edge_vertex(pos) && neighbor_of_string(pos, diag) 
    18511852        && countstones(diag) >= 3) { 
    18521853      int strings[3]; 
     
    18801881            continue; 
    18811882 
    18821883          for (r = 0; r < lib_count && adj_eye_count < 2; r++) 
    1883             if (my_eye[libs[r]].color == OTHER_COLOR(color) 
     1884            if (my_eye[libs[r]].color == other 
    18841885                && !my_eye[libs[r]].marginal) 
    18851886              adj_eye_count++; 
    18861887          if (adj_eye_count < 2) { 
     
    18891890          } 
    18901891        } 
    18911892      } 
    1892     } 
     1893        } 
    18931894 
    18941895    sum += val; 
    18951896 
     
    24022403   * liberties empty. 
    24032404   */ 
    24042405  for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    2405     if (mx[pos] == 1 || board[pos] != EMPTY || liberty_of_string(pos, str)) 
     2406    if (mx[pos] == 1 || board[pos] != EMPTY || liberty_of_string2(pos, str)) 
    24062407      continue; 
    24072408    for (k = 0; k < 8; k++) { 
    2408       if (ON_BOARD(pos + delta[k]) 
    2409           && liberty_of_string(pos + delta[k], str)) { 
     2409      int checked_pos = pos + delta[k]; 
     2410      if (ON_BOARD(checked_pos) 
     2411          && liberty_of_string(checked_pos, str)) { 
    24102412        play_move(pos, BLACK); 
    24112413        break; 
    24122414      } 
     
    26952697  int eyes; 
    26962698   
    26972699  for (k = 0; k < 4; k++) { 
    2698     if (board[vertex + delta[k]] == BLACK) { 
     2700    int checked_pos = vertex + delta[k]; 
     2701    if (board[checked_pos] == BLACK) { 
    26992702      eyes = 0; 
    2700       num_libs = findlib(vertex + delta[k], MAXLIBS, libs); 
     2703      num_libs = findlib(checked_pos, MAXLIBS, libs); 
    27012704       
    27022705      for (r = 0; r < num_libs; r++) 
    27032706        if (is_suicide(libs[r], WHITE)) 
     
    36463649  /* If there are any isolated O stones, those should also be added to 
    36473650   * the playable vertices. 
    36483651   */ 
    3649   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    3650     if (board[pos] == WHITE && !same_string(pos, POS(1, 0))) { 
    3651       vertices[num_vertices] = vertices[num_vertices - 1]; 
    3652       vertices[num_vertices - 1] = vertices[num_vertices - 2]; 
    3653       vertices[num_vertices - 2] = vertices[num_vertices - 3]; 
    3654       vertices[num_vertices - 3] = pos; 
    3655       num_vertices++; 
    3656     } 
     3652  { 
     3653    int pos_1_0 = POS(1, 0); 
     3654    for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
     3655      if (board[pos] == WHITE && !same_string(pos, pos_1_0)) { 
     3656        vertices[num_vertices] = vertices[num_vertices - 1]; 
     3657        vertices[num_vertices - 1] = vertices[num_vertices - 2]; 
     3658        vertices[num_vertices - 2] = vertices[num_vertices - 3]; 
     3659        vertices[num_vertices - 3] = pos; 
     3660        num_vertices++; 
     3661      } 
     3662  } 
    36573663 
    36583664  if (verbose) { 
    36593665    int k; 
  • gnugo/engine/owl.c

    RCS file: /sources/gnugo/gnugo/engine/owl.c,v
    retrieving revision 1.251
    diff -u -r1.251 owl.c
     
    480480            && !is_same_dragon(adjs[k], bpos) 
    481481            && dragon[adjs[k]].crude_status == ALIVE) 
    482482          adjacent_to_outside = 1; 
    483       } 
     483          } 
    484484       
    485485      if ((adjacent_to_outside || countstones(str) > 6) 
    486486          && s_worms < MAX_SEMEAI_WORMS) { 
     
    15761576    for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    15771577      if (IS_STONE(board[pos]) 
    15781578          && pos == find_origin(pos)) { 
    1579         if (owla->goal[pos]) 
    1580           net -= 75*countlib(pos); 
    1581         if (owlb->goal[pos]) 
    1582           net += 100*countlib(pos);        
     1579        int count_lib = -1; 
     1580        if (owla->goal[pos]) { 
     1581          count_lib = countlib(pos); 
     1582          net -= 75 * count_lib; 
     1583        } 
     1584        if (owlb->goal[pos]) { 
     1585          if (count_lib < 0) 
     1586            count_lib = countlib(pos); 
     1587          net += 100 * count_lib; 
     1588        } 
    15831589      } 
    15841590    } 
    15851591    if (!trymove(move, color, NULL, 0)) { 
     
    15891595    for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    15901596      if (IS_STONE(board[pos]) 
    15911597          && pos == find_origin(pos)) { 
     1598        int count_lib = -1; 
    15921599        if (owla->goal[pos] 
    1593             || (pos == move && liberty_of_goal(move, owla))) 
    1594           net += 75*countlib(pos); 
    1595         if (owlb->goal[pos]) 
    1596           net -= 100*countlib(pos); 
     1600            || (pos == move && liberty_of_goal(move, owla))) { 
     1601          count_lib = countlib(pos); 
     1602          net += 75 * count_lib; 
     1603        } 
     1604        if (owlb->goal[pos]) { 
     1605          if (count_lib < 0) 
     1606            count_lib = countlib(pos); 
     1607          net -= 100 * count_lib; 
     1608        } 
    15971609      } 
    15981610    } 
    15991611 
     
    19291941      int size = 0; 
    19301942      saveworm = MAX_GOAL_WORMS; 
    19311943      for (k = 0; k < MAX_GOAL_WORMS; k++) { 
    1932         if (owl_goal_worm[k] == NO_MOVE) 
     1944        int worm_goal = owl_goal_worm[k]; 
     1945        if (worm_goal == NO_MOVE) 
    19331946          break; 
    1934         if (board[owl_goal_worm[k]] == EMPTY 
    1935             || countlib(owl_goal_worm[k]) > 1) 
     1947        if (board[worm_goal] == EMPTY 
     1948            || countlib(worm_goal) > 1) 
    19361949          continue; 
    1937         if (worm[owl_goal_worm[k]].size > size) { 
     1950        if (worm[worm_goal].size > size) { 
    19381951          saveworm = k; 
    1939           size = worm[owl_goal_worm[k]].size; 
     1952          size = worm[worm_goal].size; 
    19401953        } 
    19411954      } 
    19421955      if (saveworm != MAX_GOAL_WORMS && size >= 3) { 
     
    35543567    if (ON_BOARD(*move + delta[k]) && board[*move + delta[k]] != color) 
    35553568      return 0; 
    35563569 
    3557   for (r = 4; r < 8; r++) 
    3558     if (board[*move + delta[r]] == other 
    3559         && countlib(*move + delta[r]) == 1) { 
    3560       for (k = 0; k < 4; k++) 
    3561         if (board[*move + delta[k]] == color 
    3562             && countlib(*move + delta[k]) == 1 
    3563             && !adjacent_strings(*move + delta[r], *move + delta[k])) 
     3570  for (r = 4; r < 8; r++) { 
     3571    int checked_pos_r = *move + delta[r]; 
     3572    if (board[checked_pos_r] == other 
     3573        && countlib(checked_pos_r) == 1) { 
     3574      for (k = 0; k < 4; k++) { 
     3575        int checked_pos_k = *move + delta[k]; 
     3576        if (board[checked_pos_k] == color 
     3577            && countlib(checked_pos_k) == 1 
     3578            && !adjacent_strings(checked_pos_r, checked_pos_k)) 
    35643579          break; 
     3580      } 
    35653581 
    35663582      if (k == 4) { 
    35673583        int new_move; 
    3568         findlib(*move + delta[r], 1, &new_move); 
     3584        findlib(checked_pos_r, 1, &new_move); 
    35693585        TRACE("Changing eyefilling move at %1m to capture at %1m.\n", 
    35703586              *move, new_move); 
    35713587        *move = new_move; 
    35723588        return 1; 
    35733589      } 
    35743590    } 
     3591  } 
    35753592   
    35763593  return 0;     
    35773594} 
     
    49995016        mark_string(pos, component2, closest_component); 
    50005017        component_size[closest_component] += countstones(pos); 
    50015018      } 
    5002     } 
     5019        } 
    50035020 
    50045021    /* Now find the biggest_component. */ 
    50055022    { 
  • gnugo/engine/persistent.c

    RCS file: /sources/gnugo/gnugo/engine/persistent.c,v
    retrieving revision 1.40
    diff -u -r1.40 persistent.c
     
    233233      return 0; 
    234234    else if (!(p[pos] & (HIGH_LIBERTY_BIT | HIGH_LIBERTY_BIT2))) 
    235235      continue; 
    236     else if (((p[pos] & HIGH_LIBERTY_BIT) && countlib(pos) <= 4) 
    237              || (p[pos] & HIGH_LIBERTY_BIT2 && countlib(pos) <= 3)) 
    238       return 0; 
     236    else { 
     237      int count_lib = countlib(pos); 
     238      if (((p[pos] & HIGH_LIBERTY_BIT) && count_lib <= 4) 
     239          || ((p[pos] & HIGH_LIBERTY_BIT2) && count_lib <= 3)) 
     240        return 0; 
     241    } 
    239242  } 
    240243   
    241244  return 1; 
     
    336339    else { 
    337340      for (r = 0; r < MAX_CACHE_DEPTH; r++) { 
    338341        int apos = entry->stack[r]; 
    339         int color = entry->move_color[r]; 
    340         if (apos == 0) 
     342        int color; 
     343        if (apos == NO_MOVE) 
    341344          break; 
     345        color = entry->move_color[r]; 
    342346        if (board[apos] == EMPTY 
    343347            && trymove(apos, color, "purge_persistent_cache", 0)) 
    344348          played_moves++; 
     
    354358      /* Move the last entry in the cache here and back up the loop 
    355359       * counter to redo the test at this position in the cache. 
    356360       */ 
    357       if (0) 
     361#if 0 
    358362        gprintf("Purging entry %d from cache.\n", k); 
     363#endif 
    359364      if (k < cache->current_size - 1) 
    360365        *entry = cache->table[cache->current_size - 1]; 
    361366      k--; 
     
    718723                           int m, int n, float contribution) 
    719724{ 
    720725  int i, j, k; 
     726  int pos_mn; 
    721727   
    722728  /* If p[m][n] is EMPTY, we just give the contribution to close empty 
    723729   * vertices. This is a rough simplification. 
     
    733739  /* Otherwise we give contribution to liberties and diagonal 
    734740   * neighbors of the string at (m, n). 
    735741   */ 
     742  pos_mn = POS(m, n); 
    736743  for (i = 0; i < board_size; i++) 
    737744    for (j = 0; j < board_size; j++) { 
    738745      if (BOARD(i, j) != EMPTY) 
    739746        continue; 
    740747      for (k = 0; k < 8; k++) { 
    741         int di = deltai[k]; 
    742         int dj = deltaj[k]; 
    743         if (IS_STONE(BOARD(i+di, j+dj)) 
    744             && same_string(POS(i+di, j+dj), POS(m, n))) { 
     748        int di = i + deltai[k]; 
     749        int dj = j + deltaj[k]; 
     750        if (IS_STONE(BOARD(di, dj)) 
     751            && same_string(POS(di, dj), pos_mn)) { 
    745752          if (k < 4) { 
    746753            values[POS(i, j)] += contribution; 
    747754            break; 
    748755          } 
    749756          else { 
    750             if (BOARD(i+di, j) == EMPTY || countlib(POS(i+di, j)) <= 2 
    751                 || BOARD(i, j+dj) == EMPTY || countlib(POS(i, j+dj)) <= 2) 
     757            if (BOARD(di, j) == EMPTY || countlib(POS(di, j)) <= 2 
     758                || BOARD(i, dj) == EMPTY || countlib(POS(i, dj)) <= 2) 
    752759              values[POS(i, j)] += contribution; 
    753760            break; 
    754761          } 
     
    13451352    if (board[pos] != EMPTY) 
    13461353      continue; 
    13471354    for (k = 0; k < 8; k++) { 
     1355      int same_dragon; 
    13481356      int pos2 = pos + delta[k]; 
    13491357      if (IS_STONE(board[pos2]) 
    1350           && (is_same_dragon(pos2, dr) 
     1358          && ((same_dragon = is_same_dragon(pos2, dr)) 
    13511359              || (are_neighbor_dragons(pos2, dr) 
    13521360                  && board[pos2] == board[dr])) 
    13531361          && (countlib(pos2) <= 4 
    13541362              || is_edge_vertex(pos))) { 
    13551363        if (k < 4) { 
    1356           if (is_same_dragon(pos2, dr)) 
     1364          if (same_dragon) 
    13571365            values[pos] += contribution; 
    13581366          else 
    13591367            values[pos] += 0.5 * contribution; 
  • gnugo/engine/printutils.c

    RCS file: /sources/gnugo/gnugo/engine/printutils.c,v
    retrieving revision 1.56
    diff -u -r1.56 printutils.c
     
    2424#include "hash.h" 
    2525#include "gg_utils.h" 
    2626#include "sgftree.h" 
     27#include "gnugo.h" 
    2728 
    2829#include <stdio.h> 
    2930#include <string.h> 
     
    3536 * This function underpins all the TRACE and DEBUG stuff. 
    3637 * It accepts %c, %d, %f, %s, and %x as usual. But it 
    3738 * also accepts %m, which takes TWO integers and writes a move. 
     39 * It is possible to specify %1m, which takes one integer and 
     40 * prints a move (integer means the board array index). 
    3841 * Other accepted formats are 
    3942 * %H: Print a hashvalue. 
    4043 * %C: Print a color as a string. 
  • gnugo/engine/readconnect.c

    RCS file: /sources/gnugo/gnugo/engine/readconnect.c,v
    retrieving revision 1.99
    diff -u -r1.99 readconnect.c
     
    246246   
    247247  /* if only one liberty after capture */ 
    248248  if (trymove(lib, OTHER_COLOR(board[str]), "snapback", str)) { 
    249     liberties = 0; 
    250     if (IS_STONE(board[lib])) 
    251       liberties = countlib(lib); 
     249    liberties = countlib(lib); 
    252250    popgo(); 
    253251    sgf_dumptree = save_sgf_dumptree; 
    254252    if (liberties > 1) 
     
    271269  int liberties, libs[MAXLIBS]; 
    272270  int adj, adjs[MAXCHAIN]; 
    273271  int neighb, neighbs[MAXCHAIN]; 
     272  int color = board[str1]; 
     273  int other = OTHER_COLOR(color); 
    274274 
    275275  /* finds connection through two forbidden liberties for 
    276276   * the opponent 
     
    288288   */ 
    289289  liberties = findlib(str1, MAXLIBS, libs); 
    290290  for (r = 0; r < liberties; r++) 
    291     if (is_self_atari(libs[r], OTHER_COLOR(board[str1])))  
     291    if (is_self_atari(libs[r], other))  
    292292      for (k = 0; k < 4; k++) { 
    293293        int pos = libs[r] + delta[k]; 
    294         if (board[pos] == board[str1] 
     294        if (board[pos] == color 
    295295            && !same_string(pos, str1) 
    296296            && !same_string(pos, str2)) { 
    297297          /* try to connect pos to str2 in one move */ 
    298298          /* play a common liberty */ 
    299299          neighb = findlib(pos, MAXLIBS, neighbs); 
    300300          for (s = 0; s < neighb; s++) 
    301             if (liberty_of_string(neighbs[s], str2)) { 
     301            if (liberty_of_string2(neighbs[s], str2)) { 
    302302              res = 1; 
    303303              add_zone(zn, libs[r]); 
    304304              add_zone(zn, neighbs[s]); 
     
    492492    liberties = findlib(adjs[r], MAXLIBS, libs); 
    493493    common_adj_liberty = 0; 
    494494    for (s = 0; s < liberties; s++) 
    495       if (liberty_of_string(libs[s], str2)) 
     495      if (liberty_of_string2(libs[s], str2)) 
    496496        common_adj_liberty = 1; 
    497497    if (common_adj_liberty || adjacent_strings(adjs[r], str2)) { 
    498498      for (s = 0; s < liberties; s++) 
     
    511511    liberties = findlib(adjs[r], MAXLIBS, libs); 
    512512    common_adj_liberty = 0; 
    513513    for (s = 0; s < liberties; s++) 
    514       if (liberty_of_string(libs[s], str1)) 
     514      if (liberty_of_string2(libs[s], str1)) 
    515515        common_adj_liberty = 1; 
    516516    if (common_adj_liberty || adjacent_strings(adjs[r], str1)) { 
    517517      for (s = 0; s < liberties; s++) 
     
    530530  liberties = findlib(str1, MAXLIBS, libs); 
    531531  for (r = 0; r < liberties; r++) { 
    532532    if (board[SOUTH(libs[r])] == EMPTY) { 
    533       if (liberty_of_string(SOUTH(libs[r]), str2)) { 
     533      if (liberty_of_string2(SOUTH(libs[r]), str2)) { 
    534534        add_array(moves, libs[r]); 
    535535        add_array(moves, SOUTH(libs[r])); 
    536536      } 
    537537    } 
    538538     
    539539    if (board[WEST(libs[r])] == EMPTY) { 
    540       if (liberty_of_string(WEST(libs[r]), str2)) { 
     540      if (liberty_of_string2(WEST(libs[r]), str2)) { 
    541541        add_array(moves, libs[r]); 
    542542        add_array(moves, WEST(libs[r])); 
    543543      } 
    544544    } 
    545545 
    546546    if (board[NORTH(libs[r])] == EMPTY) { 
    547       if (liberty_of_string(NORTH(libs[r]), str2)) { 
     547      if (liberty_of_string2(NORTH(libs[r]), str2)) { 
    548548        add_array(moves, libs[r]); 
    549549        add_array(moves, NORTH(libs[r])); 
    550550      } 
    551551    } 
    552552 
    553553    if (board[EAST(libs[r])] == EMPTY) { 
    554       if (liberty_of_string(EAST(libs[r]), str2)) { 
     554      if (liberty_of_string2(EAST(libs[r]), str2)) { 
    555555        add_array(moves, libs[r]); 
    556556        add_array(moves, EAST(libs[r])); 
    557557      } 
     
    561561  /* Liberties of str1 which are adjacent to a friendly string with 
    562562   * common liberty with str2. 
    563563   */ 
    564   liberties = findlib(str1, MAXLIBS, libs); 
     564 
     565#ifndef GG_TURN_OFF_ASSERTS 
     566/* We got liberties from previous call to findlib. */ 
     567  { 
     568    int test_libs[MAXLIBS]; 
     569    int t; 
     570    gg_assert(liberties == findlib(str1, MAXLIBS, test_libs)); 
     571    for (t = 0; t < liberties; ++t) 
     572      gg_assert(libs[t] == test_libs[t]); 
     573  } 
     574#endif 
     575 
    565576  for (r = 0; r < liberties; r++) { 
    566577    for (k = 0; k < 4; k++) { 
    567578      int pos = libs[r] + delta[k]; 
     
    14951506  SGFTree *save_sgf_dumptree = sgf_dumptree; 
    14961507  int save_count_variations = count_variations; 
    14971508  int result = 0; 
     1509  int count_lib = countlib(str); 
    14981510 
    14991511  /* We turn off the sgf traces here to avoid cluttering them up with 
    15001512   * naive_ladder moves. 
     
    15021514  sgf_dumptree = NULL; 
    15031515  count_variations = 0; 
    15041516 
    1505   if (countlib(str) == 1) { 
     1517  if (count_lib == 1) { 
    15061518    findlib(str, 1, move); 
    15071519    result = WIN; 
    15081520  } 
    1509   else if (countlib(str) == 2) 
     1521  else if (count_lib == 2) 
    15101522    result = simple_ladder(str, move); 
    15111523 
    15121524  /* Turn the sgf traces back on. */ 
     
    23172329  SGFTree *save_sgf_dumptree = sgf_dumptree; 
    23182330  int save_count_variations = count_variations; 
    23192331  int distance_limit; 
     2332  int str2_onboard; 
    23202333 
    23212334  /* We turn off the sgf traces here to avoid cluttering them up with 
    23222335   * tactical reading moves. 
     
    24472460  } 
    24482461 
    24492462  /* Modify the distance values for the moves with various bonuses. */ 
     2463  if (ON_BOARD(str2)) 
     2464    str2_onboard = 1; 
     2465  else 
     2466    str2_onboard = 0; 
     2467 
    24502468  for (r = 0; r < num_moves; r++) { 
    24512469    int move = moves[r]; 
    24522470    int adjacent_to_attacker = 0; 
     
    24762494              gprintf("%o%1M -0.7, capture or atari of immediately connecting string\n", move); 
    24772495          } 
    24782496        } 
    2479       } 
     2497          } 
    24802498      else if (board[pos] == color) { 
    2481         if (countlib(pos) <= 2) { 
     2499        int count_lib = countlib(pos); 
     2500        if (count_lib <= 2) { 
    24822501          distances[r] -= FP(0.2); 
    24832502          if (verbose > 0) 
    24842503            gprintf("%o%1M -0.2, adjacent to defender string with at most two liberties\n", move); 
     
    24912510         * The following code compensates in such kind of situations. 
    24922511         * See connection:111 and gunnar:53 for example. 
    24932512         */ 
    2494         if (!connect_move && countlib(pos) == 1 
     2513        if (!connect_move && count_lib == 1 
    24952514            /* let's avoid ko and snapbacks */ 
    24962515            && accuratelib(move, other, 2, NULL) > 1) { 
    24972516          int adjs[MAXCHAIN]; 
     
    25232542     * Neighbor strings with less than 3 liberties have already 
    25242543     * generated a bonus above. 
    25252544     */ 
    2526     if ((liberty_of_string(move, str1) 
     2545    if ((liberty_of_string2(move, str1) 
    25272546         && countlib(str1) == 3) 
    2528         || (ON_BOARD(str2) && liberty_of_string(move, str2) 
     2547        || (str2_onboard && liberty_of_string2(move, str2) 
    25292548            && countlib(str2) == 3)) { 
    25302549      distances[r] -= FP(0.1); 
    25312550      if (verbose > 0) 
     
    42354254  int save_count_variations = count_variations; 
    42364255  int adj[MAXCHAIN]; 
    42374256  int libs[2]; 
     4257  int count_lib = countlib(str); 
    42384258   
    42394259  /* We turn off the sgf traces here to avoid cluttering them up with 
    42404260   * tactical reading moves. 
     
    42424262  sgf_dumptree = NULL; 
    42434263  count_variations = 0; 
    42444264   
    4245   if (countlib(str) == 1 && find_defense(str, NULL) == 0) 
     4265  if (count_lib == 1 && find_defense(str, NULL) == 0) 
    42464266    result = 1; 
    42474267 
    4248   if (countlib(str) == 2 
     4268  if (count_lib == 2 
    42494269      && chainlinks2(str, adj, 1) == 0 
    42504270      && findlib(str, 2, libs) == 2 
    42514271      && approxlib(libs[0], board[str], 2, NULL) == 1 
     
    43324352  if (apos == bpos) 
    43334353    return 1; 
    43344354 
    4335   for (k = 0; k < 4; k++) 
    4336     if (board[apos + delta[k]] == color 
    4337         && countlib(apos + delta[k]) <= 3 
    4338         && liberty_of_string(bpos, apos + delta[k])) 
     4355  for (k = 0; k < 4; k++) { 
     4356    int checked_pos = apos + delta[k]; 
     4357    if (board[checked_pos] == color 
     4358        && countlib(checked_pos) <= 3 
     4359        && liberty_of_string(bpos, checked_pos)) 
    43394360      return 1; 
     4361  } 
    43404362 
    43414363  return 0; 
    43424364} 
  • gnugo/engine/reading.c

    RCS file: /sources/gnugo/gnugo/engine/reading.c,v
    retrieving revision 1.168
    diff -u -r1.168 reading.c
     
    10321032  int r; 
    10331033 
    10341034  ASSERT1(IS_STONE(board[str]), str); 
    1035   other = OTHER_COLOR(board[str]); 
    10361035 
    10371036  /* Only handle strings with no way to capture immediately. 
    10381037   * For now, we treat ko the same as unconditionally. */ 
     
    10461045   * 
    10471046   * The test against 6 liberties is just an optimization. 
    10481047   */ 
     1048  other = OTHER_COLOR(board[str]); 
    10491049  liberties = findlib(str, MAXLIBS, libs); 
    10501050  if (liberties > 1 && liberties < 6) { 
    10511051    for (k = 0; k < liberties; k++) { 
     
    10651065 
    10661066       if (!ON_BOARD(bb) 
    10671067           || IS_STONE(board[bb]) 
    1068            || liberty_of_string(bb, str)) 
     1068           || liberty_of_string2(bb, str)) 
    10691069         continue; 
    10701070 
    10711071       if (trymove(bb, other, "attack_threats-B", str)) { 
     
    13221322     * it has already been done in the first loop of this function. 
    13231323     */ 
    13241324    num_adjacent_stones = count_adjacent_stones(adjs[j], str, missing); 
    1325     if (!liberty_of_string(lib, str) 
     1325    if (!liberty_of_string2(lib, str) 
    13261326        && num_adjacent_stones >= missing) { 
    13271327      *move = lib; 
    13281328      return 1; 
     
    14441444  break_chain_moves(str, &moves); 
    14451445  set_up_snapback_moves(str, lib, &moves); 
    14461446 
    1447   order_moves(str, &moves, color, read_function_name, *move); 
     1447  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    14481448  DEFEND_TRY_MOVES(0, NULL); 
    14491449 
    14501450  /* If the string is a single stone and a capture would give a ko, 
     
    15521552  if (stackp <= backfill_depth) 
    15531553    special_rescue2_moves(str, libs, &moves); 
    15541554 
    1555   order_moves(str, &moves, color, read_function_name, *move); 
     1555  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    15561556  DEFEND_TRY_MOVES(0, &suggest_move); 
    15571557 
    15581558  /* Look for backfilling moves. */ 
     
    15861586  special_rescue4_moves(str, libs, &moves); 
    15871587   
    15881588  /* Only order and test the new set of moves. */ 
    1589   order_moves(str, &moves, color, read_function_name, *move); 
     1589  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    15901590  DEFEND_TRY_MOVES(0, &suggest_move); 
    15911591 
    15921592  /* If we haven't found any useful moves in first batches, be more 
     
    16181618    break_chain4_moves(str, &moves, be_aggressive); 
    16191619 
    16201620  /* Only order and test the new set of moves. */ 
    1621   order_moves(str, &moves, color, read_function_name, *move); 
     1621  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    16221622  DEFEND_TRY_MOVES(0, &suggest_move); 
    16231623 
    16241624  RETURN_RESULT(savecode, savemove, move, "saved move"); 
     
    16801680  if (stackp <= backfill2_depth) 
    16811681    hane_rescue_moves(str, libs, &moves); 
    16821682 
    1683   order_moves(str, &moves, color, read_function_name, *move); 
     1683  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    16841684  DEFEND_TRY_MOVES(1, &suggest_move); 
    16851685 
    16861686  /* This looks a little too expensive. */ 
     
    17681768  } 
    17691769 
    17701770  /* Only order and test the new set of moves. */ 
    1771   order_moves(str, &moves, color, read_function_name, *move); 
     1771  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    17721772  DEFEND_TRY_MOVES(1, &suggest_move); 
    17731773 
    17741774  /* If nothing else works, we try playing a liberty of the 
     
    17831783    break_chain3_moves(str, &moves, 0); 
    17841784 
    17851785  /* Only order and test the new set of moves. */ 
    1786   order_moves(str, &moves, color, read_function_name, *move); 
     1786  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    17871787  DEFEND_TRY_MOVES(1, &suggest_move); 
    17881788 
    17891789  RETURN_RESULT(savecode, savemove, move, "saved move"); 
     
    18501850    squeeze_moves(str, &moves); 
    18511851  } 
    18521852 
    1853   order_moves(str, &moves, color, read_function_name, *move); 
     1853  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    18541854  DEFEND_TRY_MOVES(1, &suggest_move); 
    18551855 
    18561856  if (stackp <= depth) { 
     
    18591859    bamboo_rescue_moves(str, liberties, libs, &moves); 
    18601860  } 
    18611861 
    1862   order_moves(str, &moves, color, read_function_name, *move); 
     1862  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    18631863  DEFEND_TRY_MOVES(1, &suggest_move); 
    18641864 
    18651865  RETURN_RESULT(savecode, savemove, move, "saved move"); 
     
    20052005  int other = OTHER_COLOR(color); 
    20062006  int newlibs[4]; 
    20072007  int liberties; 
    2008   int newstr; 
     2008  int astr_pos; 
    20092009  int k, r, s; 
    20102010   
    20112011  for (r = 0; r < 2; r++) { 
     
    20172017      continue; 
    20182018 
    20192019    for (k = 0; k < 4; k++) { 
    2020       if (board[alib + delta[k]] == color 
    2021           && !same_string(alib + delta[k], str)) { 
    2022         newstr = alib + delta[k]; 
    2023         liberties = findlib(newstr, 4, newlibs); 
     2020      astr_pos = alib + delta[k]; 
     2021      if (board[astr_pos] == color 
     2022          && !same_string(astr_pos, str)) { 
     2023        liberties = findlib(astr_pos, 4, newlibs); 
    20242024         
    20252025        for (s = 0; s < liberties && s < 4; s++) { 
    20262026          if (!is_self_atari(newlibs[s], color)) 
    20272027            ADD_CANDIDATE_MOVE(newlibs[s], 0, *moves, "special_rescue2"); 
    20282028        } 
    2029         break_chain_moves(newstr, moves); 
    2030         break_chain2_efficient_moves(newstr, moves); 
    2031         edge_clamp_moves(newstr, moves); 
     2029        break_chain_moves(astr_pos, moves); 
     2030        break_chain2_efficient_moves(astr_pos, moves); 
     2031        edge_clamp_moves(astr_pos, moves); 
    20322032      } 
    20332033    } 
    20342034  } 
     
    22842284 
    22852285      liberties2 = findlib(bpos, 4, libs2); 
    22862286      for (s = 0; s < liberties2; s++) 
    2287         if (!liberty_of_string(libs2[s], str) 
     2287        if (!liberty_of_string2(libs2[s], str) 
    22882288            && !is_self_atari(libs2[s], color)) 
    22892289          ADD_CANDIDATE_MOVE(libs2[s], 0, *moves, "special_rescue5-A"); 
    22902290 
     
    24692469      int alibs[2]; 
    24702470      int alib = accuratelib(apos, other, 2, alibs); 
    24712471 
    2472       if (liberty_of_string(apos, str)) 
     2472      if (liberty_of_string2(apos, str)) 
    24732473        continue; 
    24742474 
    24752475      if (alib >= 2) 
     
    25212521      continue; 
    25222522 
    25232523    for (r = 0; r < num_libs2; r++) 
    2524       if (!liberty_of_string(libs2[r], str)) { 
     2524      if (!liberty_of_string2(libs2[r], str)) { 
    25252525        potential_move = libs2[r]; 
    25262526        break; 
    25272527      } 
     
    25422542        previous_liberty = potential_move; 
    25432543        potential_move = libs2[0]; 
    25442544      } 
    2545       if (liberty_of_string(potential_move, str)) { 
     2545      if (liberty_of_string2(potential_move, str)) { 
    25462546        potential_move = NO_MOVE; 
    25472547        break; 
    25482548      } 
     
    26422642        if (board[cpos] != color || !same_string(cpos, str)) 
    26432643          continue; 
    26442644 
    2645         if (board[dpos] != EMPTY || !liberty_of_string(dpos, apos)) 
     2645        if (board[dpos] != EMPTY || !liberty_of_string2(dpos, apos)) 
    26462646          continue; 
    26472647 
    26482648        epos = dpos + up; 
    26492649 
    2650         if (board[epos] != EMPTY || !liberty_of_string(epos, apos)) 
     2650        if (board[epos] != EMPTY || !liberty_of_string2(epos, apos)) 
    26512651          continue; 
    26522652 
    26532653        if (approxlib(dpos, color, 3, NULL) < 3) 
     
    31123112        /* If stackp > depth and any boundary chain is in atari, assume safe. 
    31133113         * However, if the captured chain is only of size 1, there can still 
    31143114         * be a working ladder, so continue if that is the case. 
    3115         * Also if the string in atari shares its liberty with the 
    3116         * attacked string, drawing it out may enable the ladder to 
    3117         * continue. 
     3115        * Also if the string in atari shares its liberty with the 
     3116        * attacked string, drawing it out may enable the ladder to 
     3117        * continue. 
    31183118         */ 
    31193119        if (stackp > depth 
    31203120            && countstones(adjs[r]) > 1 
     
    31903190      adj = chainlinks2(str, adjs, 2); 
    31913191      for (r = 0; r < adj; r++) { 
    31923192        int apos = adjs[r]; 
    3193         if (liberty_of_string(libs[0], apos) 
    3194             && liberty_of_string(libs[1], apos)) 
     3193        if (liberty_of_string2(libs[0], apos) 
     3194            && liberty_of_string2(libs[1], apos)) 
    31953195          break_chain_moves(apos, &moves); 
    31963196      } 
    31973197 
     
    32303230      abort(); 
    32313231    } /* switch (pass) */ 
    32323232 
    3233     order_moves(str, &moves, other, read_function_name, *move); 
     3233    order_moves(str, &moves, other, READ_FUNCTION_NAME, *move); 
    32343234    ATTACK_TRY_MOVES(0, &suggest_move); 
    32353235  } 
    32363236 
     
    33733373      abort(); 
    33743374    } 
    33753375 
    3376     order_moves(str, &moves, other, read_function_name, *move); 
     3376    order_moves(str, &moves, other, READ_FUNCTION_NAME, *move); 
    33773377    ATTACK_TRY_MOVES(1, &suggest_move); 
    33783378  } /* for (pass... */ 
    33793379 
     
    34673467      abort(); 
    34683468    } 
    34693469 
    3470     order_moves(str, &moves, other, read_function_name, *move); 
     3470    order_moves(str, &moves, other, READ_FUNCTION_NAME, *move); 
    34713471    ATTACK_TRY_MOVES(1, &suggest_move); 
    34723472  } /* for (pass = ... */ 
    34733473 
     
    36813681     * chain links. 
    36823682     */ 
    36833683    for (s = 0; s < adj; s++) 
    3684       if (liberty_of_string(apos, adjs[s])) { 
     3684      if (liberty_of_string2(apos, adjs[s])) { 
    36853685        bpos = adjs[s]; 
    36863686        break; 
    36873687      } 
     
    37733773  for (r = 0; r < adj; r++) { 
    37743774    findlib(adjs[r], 2, libs); 
    37753775    for (k = 0; k < 2; k++) { 
    3776       if (!liberty_of_string(libs[k], str) 
     3776      if (!liberty_of_string2(libs[k], str) 
    37773777             && ((ON_BOARD1(SOUTH(libs[k])) 
    37783778                     && liberty_of_string(SOUTH(libs[k]), str)) 
    37793779              || (ON_BOARD1(WEST(libs[k])) 
     
    40194019  for (k = 0; k < 4; k++) { 
    40204020    int l; 
    40214021    int up = delta[k]; 
     4022    int up_apos; 
    40224023 
    40234024    if (ON_BOARD(apos - up)) 
    40244025      continue; 
    4025     if (board[apos + up] != color || !same_string(apos + up, str)) 
     4026    up_apos = apos + up; 
     4027    if (board[up_apos] != color || !same_string(up_apos, str)) 
    40264028      return; 
    40274029     
    40284030    for (l = 0; l < 2; l++) { 
     
    40364038        right = -right; 
    40374039 
    40384040      cpos = apos + right; 
    4039       dpos = apos + right + up; 
     4041      dpos = up_apos + right; 
    40404042      epos = cpos + right; 
    40414043      fpos = dpos + right; 
    40424044 
     
    41594161    int min_liberties) 
    41604162{ 
    41614163  int r, s, t; 
    4162   int color = OTHER_COLOR(board[str]); 
     4164  int color = board[str]; 
     4165  int other = OTHER_COLOR(color); 
    41634166  int xpos; 
    41644167  int adj; 
    41654168  int adj2; 
     
    41784181    findlib(adjs[r], 2, libs); 
    41794182    for (t = 0; t < 2; t++) { 
    41804183      xpos = libs[t]; 
    4181       if (approxlib(xpos, color, min_liberties, NULL) 
     4184      if (approxlib(xpos, other, min_liberties, NULL) 
    41824185          + neighbor_of_string(xpos, str) >= min_liberties) 
    41834186        ADD_CANDIDATE_MOVE(xpos, 0, *moves, "defend_secondary_chain2-A"); 
    41844187    } 
     
    41874190    adj2 = chainlinks2(adjs[r], adjs2, 1); 
    41884191    for (s = 0; s < adj2; s++) { 
    41894192      findlib(adjs2[s], 1, &xpos); 
    4190       if (!is_self_atari(xpos, color)) 
     4193      if (!is_self_atari(xpos, other)) 
    41914194        ADD_CANDIDATE_MOVE(xpos, 0, *moves, "defend_secondary_chain2-B"); 
    41924195    } 
    41934196 
     
    41974200      findlib(adjs2[s], 2, libs); 
    41984201      for (t = 0; t < 2; t++) { 
    41994202        /* Only atari if target has no easy escape with his other liberty. */ 
    4200         if (approxlib(libs[1-t], OTHER_COLOR(color), 3, NULL) < 3  
    4201             &&  !is_self_atari(libs[t], color)) { 
     4203        if (approxlib(libs[1-t], color, 3, NULL) < 3  
     4204            &&  !is_self_atari(libs[t], other)) { 
    42024205          ADD_CANDIDATE_MOVE(libs[t], 0, *moves, "defend_secondary_chain2-C"); 
    42034206        } 
    42044207      } 
     
    43654368        if (!defend_secondary_chain1_moves(adjs[r], moves, 2)) 
    43664369          defend_secondary_chain2_moves(adjs[r], moves, 2); 
    43674370      } 
    4368     } 
     4371        } 
    43694372 
    43704373    if (unsafe[0] && unsafe[1] 
    43714374        && (stackp <= backfill2_depth || have_common_lib(str, apos, NULL))) { 
     
    48234826 
    48244827  break_chain_moves(str, &moves); 
    48254828  set_up_snapback_moves(str, lib, &moves); 
    4826   order_moves(str, &moves, color, read_function_name, NO_MOVE); 
     4829  order_moves(str, &moves, color, READ_FUNCTION_NAME, NO_MOVE); 
    48274830 
    48284831  for (k = 0; k < moves.num; k++) { 
    48294832    int ko_capture; 
     
    48694872         * better. 
    48704873         */ 
    48714874        UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos); 
    4872       } 
     4875          } 
    48734876      else 
    48744877        popgo(); 
    4875     } 
     4878        } 
    48764879    else { 
    48774880      int ko_pos; 
    48784881      if (stackp <= ko_depth 
     
    56265629  if (approxlib(libs[1], color, 4, NULL) <= 3) 
    56275630    ADD_CANDIDATE_MOVE(libs[0], 0, moves, "simple_ladder"); 
    56285631 
    5629   order_moves(str, &moves, other, read_function_name, NO_MOVE); 
     5632  order_moves(str, &moves, other, READ_FUNCTION_NAME, NO_MOVE); 
    56305633 
    56315634  for (k = 0; k < moves.num; k++) { 
    56325635    int ko_move; 
     
    56885691  moves.num_tried = 0; 
    56895692 
    56905693  break_chain_moves(str, &moves); 
    5691   order_moves(str, &moves, color, read_function_name, NO_MOVE); 
     5694  order_moves(str, &moves, color, READ_FUNCTION_NAME, NO_MOVE); 
    56925695 
    56935696  for (k = 0; k < moves.num; k++) { 
    56945697    int ko_move; 
  • gnugo/engine/showbord.c

    RCS file: /sources/gnugo/gnugo/engine/showbord.c,v
    retrieving revision 1.29
    diff -u -r1.29 showbord.c
     
    343343} 
    344344 
    345345 
    346 #ifndef HAVE_VARIADIC_DEFINE 
     346#if !defined(HAVE_VARIADIC_DEFINE) || defined(GG_TURN_OFF_DEBUGS) 
    347347 
    348348/* See gnugo.h for related TRACE family macro definitions */ 
    349349 
  • gnugo/engine/unconditional.c

    RCS file: /sources/gnugo/gnugo/engine/unconditional.c,v
    retrieving revision 1.5
    diff -u -r1.5 unconditional.c
     
    343343     
    344344    findstones(pos, 2, stones); 
    345345    for (k = 0; k < 2 && isolated; k++) { 
    346       for (r = 0; r < 8 && isolated; r++) { 
     346      for (r = 0; r < 8; r++) { 
    347347        pos2 = stones[k] + delta[r]; 
    348348        if (!ON_BOARD(pos2) 
    349349            || (board[pos2] == color 
    350350                && !same_string(pos, pos2))) 
     351        { 
    351352          isolated = 0; 
     353          break; 
     354        } 
    352355      } 
    353356    } 
    354357 
     
    457460            locally_played_moves--; 
    458461          } 
    459462        } 
    460       } 
     463          } 
    461464      if (countstones(pos) > 2) 
    462465        break; 
    463     } 
     466        } 
    464467  } 
    465468 
    466469  /* Capture the strings involved in potential sekis. */ 
  • gnugo/engine/utils.c

    RCS file: /sources/gnugo/gnugo/engine/utils.c,v
    retrieving revision 1.115
    diff -u -r1.115 utils.c
     
    731731void 
    732732set_depth_values(int level, int report_levels) 
    733733{ 
    734   static int node_limits[] = {500, 500, 450, 400, 400, 325, 275, 
    735                               200, 150, 100, 75, 50}; 
     734  const int node_limits[] = {500, 500, 450, 400, 400, 325, 275, 
     735                             200, 150, 100, 75, 50}; 
    736736  int depth_level; 
    737737 
    738738  /* 
     
    858858 
    859859  depth_offset = 0; 
    860860   
     861#ifndef GG_TURN_OFF_TRACES 
    861862  if (report_levels) { 
    862863    fprintf(stderr, "at level %d:\n\n\ 
    863864depth: %d\n\ 
     
    889890            connect_depth2, connection_node_limit, breakin_depth,  
    890891            breakin_node_limit); 
    891892  } 
     893#else 
     894  UNUSED(report_levels); 
     895#endif 
    892896} 
    893897 
    894898 
  • 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
     
    6969  } 
    7070 
    7171  for (k = 0; k < strings; k++) { 
     72    int count_lib; 
    7273    if (worm[ss[k]].invincible) 
    7374      continue; 
     75    count_lib = countlib(ss[k]); 
    7476    if (board[ss[k]] == color) { 
    7577      int newlibs = approxlib(pos, color, MAXLIBS, NULL); 
    7678      own_strings++; 
    77       if (newlibs >= countlib(ss[k])) { 
    78         if (countlib(ss[k]) <= 4) 
     79      if (newlibs >= count_lib) { 
     80        if (count_lib <= 4) 
    7981          fewlibs++; 
    80         if (countlib(ss[k]) <= 2) 
     82        if (count_lib <= 2) 
    8183          fewlibs++; 
    8284      } 
    8385    } 
    8486    else { 
    85       if (countlib(ss[k]) <= 2) 
     87      if (count_lib <= 2) 
    8688        fewlibs++; 
    87       if (countlib(ss[k]) <= 1 && to_move) { 
     89      if (count_lib <= 1 && to_move) { 
    8890        int dummy[MAXCHAIN]; 
    8991        fewlibs++; 
    9092        fewlibs += chainlinks2(ss[k], dummy, 1); 
     
    765767    int potential_semeai_move_found = 0; 
    766768    int other_move_reason_found = 0; 
    767769 
    768     if (!ON_BOARD1(pos)) 
     770    if (!ON_BOARD(pos)) 
    769771      continue; 
    770772    for (k = 0; k < MAX_REASONS; k++) { 
    771773<