Ticket #148: cleanup.diff

File cleanup.diff, 12.4 kB (added by draqo, 20 months ago)

cleanup patch nr 3 (apply after patch nr 2)

  • config.vcin

    diff -N -r -u -X .ignore gnugo-copy/config.vcin gnugo/config.vcin
    old new  
    1919#define DEFAULT_LEVEL 10 
    2020 
    2121/* Default hash table size in megabytes */ 
    22 #define DEFAULT_MEMORY 8 
     22#define DEFAULT_MEMORY -1 
    2323 
    2424/* Compile support for GTP communication over TCP/IP channel. */ 
    2525#define ENABLE_SOCKET_SUPPORT 1 
  • engine/board.c

    diff -N -r -u -X .ignore gnugo-copy/engine/board.c gnugo/engine/board.c
    old new  
    693693      return 0; 
    694694     
    695695    /* 4. Test if the location is the ko point. */ 
    696         if (pos == board_ko_pos) { 
     696    if (pos == board_ko_pos) { 
    697697      /*    The ko position is guaranteed to have all neighbors of the 
    698698       *    same color, or off board. If that color is the same as the 
    699699       *    move the ko is being filled, it is always allowed. This 
    700700       *    could be tested with has_neighbor() but here a faster test 
    701701       *    suffices. 
    702702       */ 
    703           if (board[WEST(pos)] == OTHER_COLOR(color) 
    704               || board[EAST(pos)] == OTHER_COLOR(color)) 
    705         *ko_move_allowed = 1; 
    706         } 
     703      if (board[WEST(pos)] == OTHER_COLOR(color) 
     704          || board[EAST(pos)] == OTHER_COLOR(color)) 
     705        *ko_move_allowed = 1; 
     706    } 
    707707 
    708708    /* 5. Test for suicide. */ 
    709         if (is_suicide(pos, color)) { 
     709    if (is_suicide(pos, color)) { 
    710710      *ko_move_allowed = 0; 
    711711      return 0; 
    712712    } 
     
    17581758int 
    17591759findlib(int str_pos, int maxlib, int *libs) 
    17601760{ 
    1761   int k; 
    17621761  int liberties; 
    17631762  int to_copy; 
    17641763  int str_nr; 
     
    17781777  liberties = string[str_nr].liberties; 
    17791778  to_copy = maxlib > liberties ? liberties : maxlib; 
    17801779 
    1781   if (to_copy <= MAX_LIBERTIES) { 
     1780  if (to_copy <= MAX_LIBERTIES) 
    17821781    /* The easy case, it suffices to copy liberty locations from the 
    17831782     * incrementally updated list. 
    17841783     */ 
    1785     for (k = 0; k < to_copy; k++) 
    1786       libs[k] = string_libs[str_nr].list[k]; 
    1787   } 
     1784    memcpy(libs, string_libs[str_nr].list, to_copy * sizeof(libs[0])); 
    17881785  else { 
    17891786    /* The harder case, where we have to traverse the stones in the 
    17901787     * string. We don't have to check explicitly if we are back to 
    17911788     * the start of the chain since we will run out of liberties 
    17921789     * before that happens. 
    17931790     */ 
    1794     int pos, checked_pos; 
     1791    int pos; 
     1792    int checked_pos; 
     1793    int k; 
     1794 
    17951795    liberty_mark++; 
    17961796    for (k = 0, pos = FIRST_STONE(str_nr); 
    17971797         k < to_copy; 
  • engine/liberty.h

    diff -N -r -u -X .ignore gnugo-copy/engine/liberty.h gnugo/engine/liberty.h
    old new  
    22 * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see       * 
    33 * http://www.gnu.org/software/gnugo/ for more information.          * 
    44 *                                                                   * 
    5  * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006      * 
     5 * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 * 
    66 * by the Free Software Foundation.                                  * 
    77 *                                                                   * 
    88 * This program is free software; you can redistribute it and/or     * 
     
    337337void movelist_change_point(int move, int code, int max_points,  
    338338                           int points[], int codes[]); 
    339339 
     340/* worm.c */ 
     341void change_tactical_point(int str, int move, int code, 
     342                           int points[], int codes[]); 
     343 
    340344/* surround.c */ 
    341345int compute_surroundings(int pos, int apos, int showboard, 
    342346                         int *surround_size); 
  • engine/movelist.c

    diff -N -r -u -X .ignore gnugo-copy/engine/movelist.c gnugo/engine/movelist.c
    old new  
    22 * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see       * 
    33 * http://www.gnu.org/software/gnugo/ for more information.          * 
    44 *                                                                   * 
    5  * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006      * 
     5 * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 * 
    66 * by the Free Software Foundation.                                  * 
    77 *                                                                   * 
    88 * This program is free software; you can redistribute it and/or     * 
     
    2929#include "liberty.h" 
    3030 
    3131 
    32 static void movelist_sort_points(int max_points, int points[], int codes[]); 
    33 static void swap_points_and_codes(int points[], int codes[], int m, int n); 
     32static void move_up_list(int points[], int codes[], int inserted_index); 
     33static void move_down_list(int last_index, int points[], int codes[], int changed_index); 
    3434 
    3535 
    3636/* Return the code for the move if it is known. 
     
    6969 
    7070  /* Yes, we do. */ 
    7171  if (k < max_points) { 
    72     if (codes[k] <= code) 
     72    if (code >= codes[k]) 
    7373      return; /* Old news. */ 
    7474 
    7575    codes[k] = code; 
    76     movelist_sort_points(max_points, points, codes); 
    77     return; 
     76    move_down_list(k, points, codes, k); 
    7877  } 
    79  
    8078  /* This tactical point is new to us. */ 
    81   if (code > codes[max_points - 1]) { 
    82     points[max_points - 1] = move; 
    83     codes[max_points - 1] = code; 
    84     movelist_sort_points(max_points, points, codes); 
     79  else { 
     80    k--; /* last index */ 
     81    if (code <= codes[k]) 
     82      return; /* Too bad move to store. */ 
     83 
     84    points[k] = move; 
     85    codes[k] = code; 
     86    move_up_list(points, codes, k); 
    8587  } 
    8688} 
    8789 
    8890 
    89 /* Sort the tactical points so we have it sorted in falling order on 
    90  * the code values. 
    91  * 
    92  * We use shaker sort because we prefer a stable sort and in all use 
    93  * cases we can expect it to suffice with one turn through the outer 
    94  * loop. 
     91/* Sort the changed tactical point. We set it to the higher value, so 
     92 * we just have to move it up the table. 
    9593 */ 
    9694 
    9795static void 
    98 movelist_sort_points(int max_points, int points[], int codes[]) 
     96move_up_list(int points[], int codes[], int inserted_index) 
    9997{ 
    100   int start = 0; 
    101   int end = max_points - 1; 
    102   int new_start; 
    103   int new_end; 
    104   int k; 
    105    
    106   while (start < end) { 
    107     new_start = end; 
    108     for (k = end; k > start; k--) 
    109       if (codes[k] > codes[k-1]) { 
    110         swap_points_and_codes(points, codes, k, k-1); 
    111         new_start = k; 
    112       } 
    113     start = new_start; 
    114     new_end = start; 
    115     for (k = start; k < end - 1; k++) 
    116       if (codes[k] < codes[k+1]) { 
    117         swap_points_and_codes(points, codes, k, k+1); 
    118         new_end = k; 
    119       } 
    120     end = new_end; 
     98  int new_index; 
     99  int inserted_code = codes[inserted_index]; 
     100 
     101  for (new_index = inserted_index; new_index > 0; new_index--) { 
     102    if (inserted_code <= codes[new_index - 1]) 
     103      break; 
     104  } 
     105 
     106  if (new_index != inserted_index) { 
     107    int tmp = points[inserted_index]; 
     108    memmove(points + new_index + 1, points + new_index, 
     109            (inserted_index - new_index) * sizeof(int)); 
     110    points[new_index] = tmp; 
     111 
     112    memmove(codes + new_index + 1, codes + new_index, 
     113            (inserted_index - new_index) * sizeof(int)); 
     114    codes[new_index] = inserted_code; 
    121115  } 
    122116} 
    123117 
     118 
     119/* Sort the changed tactical point. We set it to the lower value, so 
     120 * we just have to move it down the table. 
     121 */ 
     122 
    124123static void 
    125 swap_points_and_codes(int points[], int codes[], int m, int n) 
     124move_down_list(int last_index, int points[], int codes[], int changed_index) 
    126125{ 
    127   int tmp = points[m]; 
    128   points[m] = points[n]; 
    129   points[n] = tmp; 
    130   tmp = codes[m]; 
    131   codes[m] = codes[n]; 
    132   codes[n] = tmp; 
     126  int new_index; 
     127  int inserted_code = codes[changed_index]; 
     128 
     129  for (new_index = changed_index; new_index < last_index; new_index++) { 
     130    if (inserted_code >= codes[new_index + 1]) 
     131      break; 
     132  } 
     133 
     134  if (new_index != changed_index) { 
     135    int tmp = points[changed_index]; 
     136    memmove(points + changed_index, points + changed_index + 1, 
     137            (new_index - changed_index) * sizeof(int)); 
     138    points[new_index] = tmp; 
     139 
     140    memmove(codes + changed_index, codes + changed_index + 1, 
     141            (new_index - changed_index) * sizeof(int)); 
     142    codes[new_index] = inserted_code; 
     143  } 
    133144} 
    134145 
    135146 
  • engine/persistent.c

    diff -N -r -u -X .ignore gnugo-copy/engine/persistent.c gnugo/engine/persistent.c
    old new  
    22 * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see       * 
    33 * http://www.gnu.org/software/gnugo/ for more information.          * 
    44 *                                                                   * 
    5  * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006      * 
     5 * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 * 
    66 * by the Free Software Foundation.                                  * 
    77 *                                                                   * 
    88 * This program is free software; you can redistribute it and/or     * 
     
    445445    print_persistent_cache_entry(entry); 
    446446  } 
    447447  /* FIXME: This is an ugly hack. */ 
    448   if (cache->name == "reading cache" 
     448  if (strcmp(cache->name, "reading cache") == 0 
    449449      && (debug & DEBUG_READING_PERFORMANCE) 
    450450      && entry->cost >= MIN_READING_NODES_TO_REPORT) { 
    451451    if (entry->result != 0) 
  • engine/reading.c

    diff -N -r -u -X .ignore gnugo-copy/engine/reading.c gnugo/engine/reading.c
    old new  
    22 * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see       * 
    33 * http://www.gnu.org/software/gnugo/ for more information.          * 
    44 *                                                                   * 
    5  * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 and 2006      * 
     5 * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 and 2007 * 
    66 * by the Free Software Foundation.                                  * 
    77 *                                                                   * 
    88 * This program is free software; you can redistribute it and/or     * 
     
    10551055      if (trymove(aa, other, "attack_threats-A", str)) { 
    10561056       int acode = attack(str, NULL); 
    10571057       if (acode != 0) 
    1058          movelist_change_point(aa, acode, max_points, moves, codes); 
     1058         change_tactical_point(str, aa, acode, moves, codes); 
    10591059       popgo(); 
    10601060      } 
    10611061 
     
    10711071       if (trymove(bb, other, "attack_threats-B", str)) { 
    10721072         int acode = attack(str, NULL); 
    10731073         if (acode != 0) 
    1074            movelist_change_point(bb, acode, max_points, moves, codes); 
     1074           change_tactical_point(str, bb, acode, moves, codes); 
    10751075         popgo(); 
    10761076       } 
    10771077      } 
     
    11171117        else 
    11181118          acode = attack(str, NULL); 
    11191119        if (acode != 0) 
    1120           movelist_change_point(bb, acode, max_points, moves, codes); 
     1120          change_tactical_point(str, bb, acode, moves, codes); 
    11211121        popgo(); 
    11221122      } 
    11231123    } 
  • engine/worm.c

    diff -N -r -u -X .ignore gnugo-copy/engine/worm.c gnugo/engine/worm.c
    old new  
    3737static void find_worm_attacks_and_defenses(void); 
    3838static void find_worm_threats(void); 
    3939static int find_lunch(int str, int *lunch); 
    40 static void change_tactical_point(int str, int move, int code, 
    41                                   int points[MAX_TACTICAL_POINTS], 
    42                                   int codes[MAX_TACTICAL_POINTS]); 
    4340static void propagate_worm2(int str); 
    4441static int genus(int str); 
    4542static void markcomponent(int str, int pos, int mg[BOARDMAX]); 
     
    758755      continue; 
    759756 
    760757    TRACE("considering attack of %1m\n", str); 
    761     /* Initialize all relevant fields at once. */ 
    762     for (k = 0; k < MAX_TACTICAL_POINTS; k++) { 
    763       worm[str].attack_codes[k]   = 0; 
    764       worm[str].attack_points[k]  = 0; 
    765       worm[str].defense_codes[k]  = 0; 
    766       worm[str].defense_points[k] = 0; 
    767     } 
    768     propagate_worm(str); 
    769758     
    770759    acode = attack(str, &attack_point); 
    771760    if (acode != 0) { 
     
    11821171 * change_defense_threat(). 
    11831172 */ 
    11841173 
    1185 static void 
     1174void 
    11861175change_tactical_point(int str, int move, int code, 
    11871176                      int points[MAX_TACTICAL_POINTS], 
    11881177                      int codes[MAX_TACTICAL_POINTS]) 
  • makevcdist.pl

    diff -N -r -u -X .ignore gnugo-copy/makevcdist.pl gnugo/makevcdist.pl
    old new  
    99   RESIGNATION_ALLOWED => 1, 
    1010   HASHING_SCHEME => 2, 
    1111   DEFAULT_LEVEL => 10, 
    12    DEFAULT_MEMORY => 8, 
     12   DEFAULT_MEMORY => -1, 
    1313   ENABLE_SOCKET_SUPPORT => 1, 
    1414   ALTERNATE_CONNECTIONS => 1, 
    1515   SEMEAI_NODE_LIMIT => 500,