Ticket #145: aftermath.c.patch

File aftermath.c.patch, 6.9 kB (added by draqo, 2 years ago)
  • gnugo/engine/aftermath.c

    RCS file: /sources/gnugo/gnugo/engine/aftermath.c,v
    retrieving revision 1.61
    diff -u -r1.61 aftermath.c
     
    159159  reading_hotspots(reading_hotspot); 
    160160   
    161161  /* As a preparation we compute a distance map to the invincible strings. */ 
    162   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    163     if (!ON_BOARD(pos)) 
    164       continue; 
    165     else if (board[pos] == color && worm[pos].invincible) 
     162  scan_board(pos, 
     163    if (board[pos] == color && worm[pos].invincible) 
    166164      distance[pos] = 0; 
    167165    else if (!do_capture_dead_stones 
    168166             && ((board[pos] == other  
     
    172170      distance[pos] = 0; 
    173171    else 
    174172      distance[pos] = -1; 
    175   } 
     173  ) 
    176174   
    177175  d = 0; 
    178176  do { 
    179177    something_found = 0; 
    180     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    181       if (ON_BOARD(pos) && distance[pos] == -1) { 
     178    scan_board(pos, 
     179      if (distance[pos] == -1) { 
    182180        for (k = 0; k < 4; k++) { 
    183181          int pos2 = pos + delta[k]; 
    184182          if (!ON_BOARD(pos2)) 
     
    202200            break; 
    203201          } 
    204202        } 
    205       } 
    206     } 
     203          } 
     204        ) 
    207205    d++; 
    208206  } while (something_found); 
    209207 
    210208  if (under_control) { 
    211     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    212       if (!ON_BOARD(pos)) 
    213         continue; 
    214       else if (distance[pos] == -1) 
     209    scan_board(pos, 
     210      if (distance[pos] == -1) 
    215211        under_control[pos] = 0; 
    216212      else 
    217213        under_control[pos] = 1; 
    218     } 
     214        ) 
    219215  } 
    220216   
    221217  if (debug & DEBUG_AFTERMATH) { 
     
    272268   */ 
    273269  best_scoring_move = NO_MOVE; 
    274270  best_score = 5; 
    275   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     271  scan_board(pos, 
    276272    int libs; 
    277273    if (board[pos] != EMPTY 
    278274        || distance[pos] == 0) 
     
    304300        } 
    305301      } 
    306302    } 
    307   } 
     303  ) 
    308304   
    309305  if (best_scoring_move != NO_MOVE 
    310306      && safe_move(best_scoring_move, color) == WIN) { 
     
    313309  } 
    314310 
    315311  /* Case 1. */ 
    316   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     312  scan_board(pos, 
    317313    int lib; 
    318314    if (board[pos] == other 
    319315        && worm[pos].unconditional_status != DEAD 
     
    328324        return lib; 
    329325      } 
    330326    } 
    331   } 
     327  ) 
    332328 
    333329  /* Cases 2--4. */ 
    334330  if (closest_opponent != NO_MOVE || closest_own != NO_MOVE) { 
     
    345341      best_score = 0; 
    346342      best_scoring_move = move; 
    347343 
    348       for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     344      scan_board(pos, 
    349345        int score = 0; 
    350346        int move_ok = 0; 
    351         if (!ON_BOARD(pos) || distance[pos] != 1) 
     347        if (distance[pos] != 1) 
    352348          continue; 
    353349        mark++; 
    354350        for (k = 0; k < 4; k++) { 
     
    397393          best_score = score; 
    398394          best_scoring_move = pos; 
    399395        } 
    400       } 
     396          ) 
    401397      move = best_scoring_move; 
    402398    } 
    403399 
     
    410406          move = pos2; 
    411407          break; 
    412408        } 
    413       } 
    414     } 
     409          } 
     410        } 
    415411    return move; 
    416412  } 
    417413   
     
    423419   * and with at least one alive but not invincible stone adjacent or 
    424420   * diagonal. 
    425421   */ 
    426   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     422  scan_board(pos, 
    427423    int eyespace_neighbors = 0; 
    428424    int own_neighbors = 0; 
    429425    int own_diagonals = 0; 
     
    479475            bonus += 3; 
    480476        } 
    481477        mx[origin] = 1; 
    482       } 
     478          } 
    483479      else if (board[pos2] == color) { 
    484480        dragons[pos] = pos2; 
    485481         
     
    532528        else 
    533529          own_diagonals++; 
    534530      } 
    535     } 
     531        } 
    536532    if (safety == DEAD || safety == UNKNOWN 
    537533        || eyespace_neighbors == 0 
    538534        || (own_neighbors + own_diagonals) == 0) 
     
    573569      if (1 && (debug & DEBUG_AFTERMATH)) 
    574570        gprintf("Score %1M = %d (hotspot bonus %d + %d)\n", pos, score[pos], 
    575571                owl_hotspot_bonus, reading_hotspot_bonus); 
    576     } 
     572        } 
    577573     
    578574    /* Avoid taking ko. */ 
    579575    if (is_ko(pos, color, NULL)) 
    580576      score[pos] = (score[pos] + 1) / 2; 
    581   } 
     577  ) 
    582578   
    583579  while (1) { 
    584580    int bb; 
    585581    best_score = 0; 
    586582    move = NO_MOVE; 
    587     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    588       if (ON_BOARD(pos) && score[pos] > best_score) { 
     583    scan_board(pos, 
     584      if (score[pos] > best_score) { 
    589585        best_score = score[pos]; 
    590586        move = pos; 
    591587      } 
    592     } 
     588        ) 
    593589 
    594590    if (move == NO_MOVE) 
    595591      break; 
     
    659655   * Finally we try to play on liberties of remaining DEAD opponent 
    660656   * dragons, carefully checking against mistakes. 
    661657   */ 
    662   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     658  scan_board(pos, 
    663659    int target; 
    664660    int cc = NO_MOVE; 
    665661    int self_atari_ok = 0; 
     
    680676          target = pos2; 
    681677          break; 
    682678        } 
    683       } 
    684     } 
     679          } 
     680        } 
    685681    if (target == NO_MOVE) 
    686682      continue; 
    687683     
     
    722718        self_atari_ok = 0; 
    723719        cc = pos + delta[k]; 
    724720        break; 
    725       } 
    726     } 
     721          } 
     722        } 
    727723     
    728724    /* Copy the potential move to (move). */ 
    729725    move = pos; 
     
    739735        move = lib; 
    740736        if (!trymove(move, color, "aftermath-B", target)) 
    741737          break; 
    742       } 
     738          } 
    743739       
    744740      if (countlib(pos) == 1) 
    745741        move = NO_MOVE; 
    746     } 
     742        } 
    747743 
    748744    while (stackp > 0) 
    749745      popgo(); 
     
    768764       * verify that it remains safe. 
    769765       */ 
    770766      if (cc != NO_MOVE && !owl_does_defend(move, cc, NULL)) { 
    771         int resulta, resultb; 
     767        int resulta; 
     768        int resultb; 
    772769        owl_analyze_semeai_after_move(move, color, target, cc, 
    773770                                      &resulta, &resultb, NULL, 1, NULL, 1); 
    774771        if (resulta != 0) 
    775772          continue; 
    776       } 
     773          } 
    777774 
    778775      /* If we don't allow self atari, also call confirm safety to 
    779776       * avoid setting up combination attacks. 
     
    783780           
    784781      DEBUG(DEBUG_AFTERMATH, "Filling opponent liberty at %1m\n", move); 
    785782      return move; 
    786     } 
    787   } 
     783        } 
     784  ) 
    788785   
    789786  /* Case 7. 
    790787   * In very rare cases it turns out we need yet another pass. An 
     
    805802   * The solution is to look for tactically attackable opponent stones 
    806803   * that still remain on the board but should be removed. 
    807804   */ 
    808   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     805  scan_board(pos, 
    809806    if (board[pos] == other 
    810807        && (worm[pos].unconditional_status == UNKNOWN 
    811808            || do_capture_dead_stones) 
     
    817814            pos, worm[pos].attack_points[0]); 
    818815      return worm[pos].attack_points[0]; 
    819816    } 
    820   } 
     817  ) 
    821818   
    822819  /* No move found. */ 
    823820  return PASS_MOVE; 
     
    954951    cached_board = 0; 
    955952  } 
    956953 
    957   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    958     if (ON_BOARD(pos) && board[pos] != current_board[pos]) { 
     954  scan_board(pos, 
     955    if (board[pos] != current_board[pos]) { 
    959956      current_board[pos] = board[pos]; 
    960957      cached_board = 0; 
    961958    } 
    962   } 
     959  ) 
    963960 
    964961  /* If this is exactly the same position as the one we analyzed the 
    965962   * last time, the content of the aftermath struct is up to date. 
     
    980977  do_play_aftermath(color, a, aftermath_sgftree); 
    981978  restore_board(&saved_board); 
    982979   
    983   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    984     if (!ON_BOARD(pos)) 
    985       continue; 
     980  scan_board(pos, 
    986981    if (a->black_control[pos]) { 
    987982      a->black_area++; 
    988983      if (board[pos] == WHITE) { 
     
    10221017          a->black_area++; 
    10231018      } 
    10241019    } 
    1025   } 
     1020  ) 
    10261021 
    10271022  if (debug & DEBUG_AFTERMATH) { 
    10281023    gprintf("White captured: %d\n", a->white_captured);