Ticket #148: worm1.diff

File worm1.diff, 6.2 kB (added by draqo, 21 months ago)

worm cleanup patch nr 1 (no logic changes) - apply after code.diff

  • engine/globals.c

    diff -r -u -X .ignore gnugo-copy/engine/globals.c gnugo/engine/globals.c
    old new  
    133133float black_score; 
    134134 
    135135/* Close worms data. See liberty.h */ 
    136 int close_worms[BOARDMAX][MAX_CLOSE_WORMS]; 
    137 int number_close_worms[BOARDMAX]; 
    138136int close_black_worms[BOARDMAX][MAX_CLOSE_WORMS]; 
    139137int number_close_black_worms[BOARDMAX]; 
    140138int close_white_worms[BOARDMAX][MAX_CLOSE_WORMS]; 
  • engine/liberty.h

    diff -r -u -X .ignore gnugo-copy/engine/liberty.h gnugo/engine/liberty.h
    old new  
    740740extern const int transformation2[8][2][2]; 
    741741 
    742742 
    743 /* Arrays pointing out the closest worms from each vertex.  The first 
    744  * one is the closest worms of either color, the last two ones ignore 
    745  * worms of the other color.  Beyond a certain distance from any worm 
    746  * no close worm is listed at all.  Only the closest worm is listed 
    747  * and if more than one are equally close they are all listed. The 
    748  * number of equally close worms is given in the number_*_worms 
    749  * arrays. If more than MAX_CLOSE_WORMS are equally close, none is 
    750  * listed. 
     743/* Arrays pointing out the closest worms (of given color) from each 
     744 * vertex.  Beyond a certain distance from any worm no close worm is 
     745 * listed at all.  Only the closest worm is listed and if more than 
     746 * one are equally close they are all listed. The number of equally 
     747 * close worms is given in the number_*_worms arrays. If more than 
     748 * MAX_CLOSE_WORMS are equally close, none is listed. 
    751749 * 
    752750 * See compute_effective_worm_sizes() in worm.c for details. 
    753751 */ 
    754752#define MAX_CLOSE_WORMS 4 
    755 extern int close_worms[BOARDMAX][MAX_CLOSE_WORMS]; 
    756 extern int number_close_worms[BOARDMAX]; 
    757753extern int close_black_worms[BOARDMAX][MAX_CLOSE_WORMS]; 
    758754extern int number_close_black_worms[BOARDMAX]; 
    759755extern int close_white_worms[BOARDMAX][MAX_CLOSE_WORMS]; 
  • engine/worm.c

    diff -r -u -X .ignore gnugo-copy/engine/worm.c gnugo/engine/worm.c
    old new  
    553553 * territorial value of capturing a worm. Intersections that are 
    554554 * shared are counted with equal fractional values for each worm. 
    555555 * 
    556  * We never count intersections further away than distance 3. 
     556 * We never count intersections further away than distance 3 (distance 
     557 * is number of intersections between a worm and checked intersection - 
     558 * so when an intersection is adjacent to a worm, it distance is 0). 
    557559 * 
    558560 * This function is also used to compute arrays with information about 
    559  * the distances to worms of both or either color. In the latter case 
    560  * we count intersections up to a distance of 5. 
     561 * the distances to worms of either color. In this case we count 
     562 * intersections up to a distance of 5. 
    561563 */ 
    562564 
    563565static void 
    564566compute_effective_worm_sizes() 
    565567{ 
    566   do_compute_effective_worm_sizes(BLACK | WHITE, close_worms, 
    567                                   number_close_worms, 3); 
     568  do_compute_effective_worm_sizes(BLACK | WHITE, NULL, NULL, 3); 
    568569  do_compute_effective_worm_sizes(BLACK, close_black_worms, 
    569570                                  number_close_black_worms, 5); 
    570571  do_compute_effective_worm_sizes(WHITE, close_white_worms, 
     
    611612   
    612613  dist = 0; 
    613614  found_one = 1; 
     615 
     616  /* in each iteration dist is increased; found_one 
     617     means, that at least one unchecked intersection 
     618     was found in previous iteration */ 
    614619  while (found_one && dist <= max_distance) { 
    615620    found_one = 0; 
    616621    dist++; 
     
    618623      if (distance[pos] != -1 || !ON_BOARD(pos)) 
    619624        continue; /* already claimed */ 
    620625 
     626      /* when unchecked intersection is found, all neighboring 
     627         intersections are checked for equally close worms */ 
    621628      for (r = 0; r < 4; r++) { 
    622         int pos2 = pos + delta[r]; 
     629        int neigbor_pos = pos + delta[r]; 
    623630         
    624         if (ON_BOARD(pos2) && distance[pos2] == dist - 1) { 
     631        if (ON_BOARD(neigbor_pos) && distance[neigbor_pos] == dist - 1) { 
    625632          found_one = 1; 
    626633          distance[pos] = dist; 
    627           for (k = 0; k < nworms[pos2]; k++) { 
     634 
     635          /* we check, if a worm is already written into list of equally 
     636             close worms for checked position; if not we add new entry 
     637             in worms[pos] */ 
     638          for (k = 0; k < nworms[neigbor_pos]; k++) { 
    628639            int already_counted = 0; 
    629640            for (l = 0; l < nworms[pos]; l++) 
    630               if (worms[pos][l] == worms[pos2][k]) { 
     641              if (worms[pos][l] == worms[neigbor_pos][k]) { 
    631642                already_counted = 1; 
    632643                break; 
    633644              } 
    634645            if (!already_counted) { 
    635646              ASSERT1(nworms[pos] < 2*(board_size-1), pos); 
    636               worms[pos][nworms[pos]++] = worms[pos2][k]; 
     647              worms[pos][nworms[pos]++] = worms[neigbor_pos][k]; 
    637648            } 
    638649          } 
    639650        } 
     
    641652    } 
    642653  } 
    643654 
    644   /* Compute the effective sizes but only when all worms are considered. */ 
     655  /* Compute the effective sizes but only when all worms are considered... */ 
    645656  if (color == (BLACK | WHITE)) { 
    646657    /* Distribute (fractional) contributions to the worms. */ 
    647658    for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     
    659670     
    660671    /* Propagate the effective size values all over the worms. */ 
    661672    for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    662       if (IS_STONE(board[pos]) && is_worm_origin(pos, pos)) 
    663         propagate_worm(pos); 
     673      if (IS_STONE(board[pos])) 
     674        worm[pos].effective_size = worm[worm[pos].origin].effective_size; 
    664675  } 
     676  else 
     677  /* ... or fill in the appropriate close_*_worms (cw) and 
     678     number_close_*_worms (ncw) arrays. */ 
     679  { 
     680    int worms_count; 
    665681 
    666   /* Fill in the appropriate close_*_worms (cw) and 
    667    * number_close_*_worms (ncw) arrays. 
    668    */ 
    669   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    670     if (!ON_BOARD(pos)) 
    671       continue; 
     682    for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     683      if (!ON_BOARD(pos)) 
     684        continue; 
    672685 
    673     if (nworms[pos] > MAX_CLOSE_WORMS) 
    674       ncw[pos] = 0; 
    675     else 
    676       ncw[pos] = nworms[pos]; 
     686      worms_count = nworms[pos]; 
    677687 
    678     for (k = 0; k < ncw[pos]; k++) 
    679       cw[pos][k] = worms[pos][k]; 
     688      if (worms_count > MAX_CLOSE_WORMS) { 
     689        ncw[pos] = 0; 
     690        continue; 
     691      } 
     692      else 
     693        ncw[pos] = worms_count; 
     694 
     695      memcpy(cw[pos], worms[pos], worms_count * sizeof(int)); 
     696    } 
    680697  } 
    681698} 
    682699