Ticket #145: combination.c.patch

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

    RCS file: /sources/gnugo/gnugo/engine/combination.c,v
    retrieving revision 1.57
    diff -u -r1.57 combination.c
     
    7676      gprintf("Combination attack for %C with size %d found at %1m\n", 
    7777              other, aa_val, attack_point); 
    7878     
    79     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    80       if (ON_BOARD(pos) && defense_points[pos]) { 
     79    scan_board(pos, 
     80      if (defense_points[pos]) { 
    8181        add_your_atari_atari_move(pos, aa_val); 
    8282        if (save_verbose) 
    8383          gprintf("- defense at %1m\n", pos); 
    8484      } 
    85     } 
     85        ) 
    8686  } 
    8787  verbose = save_verbose; 
    8888} 
     
    9393static void 
    9494find_double_threats(int color) 
    9595{ 
    96   int ii; 
    9796  int k; 
    9897  int l; 
     98  int pos; 
    9999 
    100   for (ii = BOARDMIN; ii < BOARDMAX; ii++) { 
     100  scan_board(pos, 
    101101    int num_a_threatened_groups; 
    102102    int a_threatened_groups[MAX_THREATENED_STRINGS]; 
    103103#if 0 
     
    105105    int d_threatened_groups[MAX_THREATENED_STRINGS]; 
    106106#endif 
    107107 
    108     if (!ON_BOARD(ii)) 
    109       continue; 
    110  
    111108    /* Generate an EITHER_MOVE move reasons for each pair of the  
    112109     * threatened strings.  We must also remove the threats, because 
    113110     * otherwise we would get followup points for them as well. 
     
    118115     *     at the same point.  Still, we should find a better way. 
    119116     *   - EITHER_MOVE should be generalized to more than two strings. 
    120117     */ 
    121     num_a_threatened_groups = get_attack_threats(ii, MAX_THREATENED_STRINGS, 
     118    num_a_threatened_groups = get_attack_threats(pos, MAX_THREATENED_STRINGS, 
    122119                                                 a_threatened_groups); 
    123120    if (num_a_threatened_groups > 1) { 
    124       if (trymove(ii, color, "find_double_threats-A", ii)) { 
     121      if (trymove(pos, color, "find_double_threats-A", pos)) { 
    125122        for (k = 0; k < num_a_threatened_groups - 1; ++k) 
    126123          for (l = k + 1; l < num_a_threatened_groups; ++l) { 
    127124            /* Note: If we used attack_either() here instead of trymove() 
     
    131128             * Besides, attack_either is currently (3.1.11) not very good. 
    132129             * 
    133130             * The call to attack() is intended to detect the case 
    134              * where the move at ii is a snapback capture. 
     131             * where the move at pos is a snapback capture. 
    135132             */ 
    136133            if (board[a_threatened_groups[k]] == EMPTY 
    137134                || board[a_threatened_groups[l]] == EMPTY) { 
    138               if (!attack(ii, NULL)) { 
     135              if (!attack(pos, NULL)) { 
    139136                TRACE("Double threat at %1m, either %1m or %1m attacked.\n", 
    140                       ii, a_threatened_groups[k], a_threatened_groups[l]); 
    141                 add_either_move(ii, ATTACK_STRING, a_threatened_groups[k], 
     137                      pos, a_threatened_groups[k], a_threatened_groups[l]); 
     138                add_either_move(pos, ATTACK_STRING, a_threatened_groups[k], 
    142139                                ATTACK_STRING, a_threatened_groups[l]); 
    143                 remove_attack_threat_move(ii, a_threatened_groups[k]); 
    144                 remove_attack_threat_move(ii, a_threatened_groups[l]); 
     140                remove_attack_threat_move(pos, a_threatened_groups[k]); 
     141                remove_attack_threat_move(pos, a_threatened_groups[l]); 
    145142              } 
    146143            } 
    147144            else if (!defend_both(a_threatened_groups[k], 
    148145                                  a_threatened_groups[l])) { 
    149146              TRACE("Double threat at %1m, either %1m or %1m attacked.\n", 
    150                     ii, a_threatened_groups[k], a_threatened_groups[l]); 
    151               add_either_move(ii, ATTACK_STRING, a_threatened_groups[k], 
     147                    pos, a_threatened_groups[k], a_threatened_groups[l]); 
     148              add_either_move(pos, ATTACK_STRING, a_threatened_groups[k], 
    152149                              ATTACK_STRING, a_threatened_groups[l]); 
    153               remove_attack_threat_move(ii, a_threatened_groups[k]); 
    154               remove_attack_threat_move(ii, a_threatened_groups[l]); 
     150              remove_attack_threat_move(pos, a_threatened_groups[k]); 
     151              remove_attack_threat_move(pos, a_threatened_groups[l]); 
    155152            } 
    156153          } 
    157154        popgo(); 
    158155      } 
    159156    } 
    160   } 
     157  ) 
    161158   
    162159   
    163160  /* FIXME: 
     
    312309     * examine which of them really work. 
    313310     */ 
    314311    forbidden[apos] = 0; 
    315     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    316       if (!ON_BOARD(pos) || !defense_moves[pos]) 
     312    scan_board(pos, 
     313      if (!defense_moves[pos]) 
    317314        continue; 
    318315 
    319316      if (!trymove(pos, other, "atari_atari", NO_MOVE)) { 
     
    321318        if (save_verbose) 
    322319          gprintf("%1m deleted defense point, illegal\n", pos); 
    323320        continue; 
    324       } 
     321          } 
    325322 
    326323      if (attack(pos, NULL)) { 
    327324        defense_moves[pos] = 0; 
     
    329326        if (save_verbose) 
    330327          gprintf("%1m deleted defense point, unsafe\n", pos); 
    331328        continue; 
    332       } 
     329          } 
    333330       
    334331      if (do_atari_atari(color, &apos, &dpos, NULL, NO_MOVE, 
    335332                         save_verbose, aa_val, NULL) > 0) { 
    336333        if (save_verbose) 
    337334          gprintf("%1m deleted defense point, didn't work\n", pos); 
    338335        defense_moves[pos] = 0; 
    339       } 
     336          } 
    340337       
    341338      popgo(); 
    342     } 
     339        ) 
    343340  } 
    344341  return aa_val; 
    345342} 
     
    372369  if (defense) { 
    373370    /* Return one arbitrary defense move. */ 
    374371    *defense = NO_MOVE; 
    375     for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    376       if (ON_BOARD(pos) && defense_moves[pos]) { 
     372    scan_board(pos, 
     373      if (defense_moves[pos]) { 
    377374        *defense = pos; 
    378375        break; 
    379       } 
     376          } 
     377        ) 
    380378  } 
    381379   
    382380  return blunder_size >= minsize; 
     
    473471    compute_aa_values(other); 
    474472       
    475473    memcpy(defense_moves, defense_points, sizeof(defense_points)); 
    476     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    477       if (!ON_BOARD(pos) || !defense_moves[pos] || pos == move) 
     474    scan_board(pos, 
     475      if (!defense_moves[pos] || pos == move) 
    478476        continue; 
    479477 
    480478      if (!trymove(pos, color, "atari_atari", NO_MOVE)) { 
     
    504502      popgo(); 
    505503      decrease_depth_values(); 
    506504      popgo(); 
    507     } 
     505        ) 
    508506  } 
    509507   
    510508  return after_aa_val - aa_val; 
     
    540538   * The worm status of empty points is set to UNKNOWN to signal 
    541539   * that stones added along the way need special attention. 
    542540   */ 
    543   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     541  scan_board(pos, 
    544542    if (board[pos] == other) { 
    545543      if (safe_stones) { 
    546544        if (safe_stones[pos]) 
     
    565563    } 
    566564    else if (ON_BOARD(pos)) 
    567565      aa_status[pos] = UNKNOWN; 
    568   } 
     566  ) 
    569567   
    570568  /* reclassify a worm with 2 liberties as INSUBSTANTIAL if capturing 
    571569   * it does not result in a live group. 
    572570   */ 
    573   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     571  scan_board(pos, 
    574572    if (board[pos] == other 
    575573        && worm[pos].origin == pos 
    576574        && worm[pos].liberties == 2 
     
    586584       
    587585      if (!owl_substantial(pos)) { 
    588586        int pos2; 
    589         for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) 
    590           if (ON_BOARD(pos2) && is_worm_origin(pos2, pos)) 
     587        scan_board(pos2, 
     588          if (is_worm_origin(pos2, pos)) 
    591589            aa_status[pos2] = INSUBSTANTIAL; 
    592       } 
     590        ) 
     591          } 
    593592    } 
    594   } 
     593  ) 
    595594     
    596595  if (debug & DEBUG_ATARI_ATARI) { 
    597596    gprintf("compute_aa_status() for %C\n", color); 
    598597    gprintf("aa_status: (ALIVE worms not listed)\n"); 
    599     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     598    scan_board(pos, 
    600599      if (board[pos] == other && is_worm_origin(pos, pos)) { 
    601600        const char *status = "UNKNOWN (shouldn't happen)"; 
    602601        if (aa_status[pos] == DEAD) 
     
    609608        if (aa_status[pos] != ALIVE) 
    610609          gprintf("%1M: %s\n", pos, status); 
    611610      } 
    612     } 
     611        ) 
    613612  } 
    614613 
    615614  sgf_dumptree = save_sgf_dumptree; 
     
    687686    gprintf("%odo_atari_atari: "); 
    688687    dump_stack(); 
    689688    gprintf("%oforbidden moves: "); 
    690     for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    691       if (ON_BOARD(pos) && forbidden[pos]) 
    692         gprintf("%o%1m ", pos); 
     689    scan_board(pos, 
     690      if (forbidden[pos]) 
     691            gprintf("%o%1m ", pos); 
     692        ) 
    693693    gprintf("\n"); 
    694694    gprintf("%ogoal: "); 
    695695    if (!goal) 
    696696      gprintf("none"); 
    697697    else { 
    698       for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    699         if (ON_BOARD(pos) && goal[pos]) 
    700           gprintf("%o%1m ", pos); 
    701     } 
     698      scan_board(pos, 
     699            if (goal[pos]) 
     700              gprintf("%o%1m ", pos); 
     701          ) 
     702        } 
    702703    gprintf("\n"); 
    703704  } 
    704705 
     
    870871  int apos; 
    871872  int other = OTHER_COLOR(color); 
    872873 
    873   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     874  scan_board(pos, 
    874875    if (board[pos] != other) 
    875876      continue; 
    876877     
     
    921922            get_aa_value(pos), pos); 
    922923      return get_aa_value(pos); 
    923924    } 
    924   } 
     925  ) 
    925926   
    926927  return 0; 
    927928} 
     
    985986  if (goal != NULL) { 
    986987    int pos; 
    987988    gprintf("goal:"); 
    988     for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    989       if (ON_BOARD(pos) && goal[pos]) 
    990         gprintf("%o %1m", pos); 
     989    scan_board(pos, 
     990      if (goal[pos]) 
     991            gprintf("%o %1m", pos); 
     992        ) 
    991993    gprintf("%o\n"); 
    992994  } 
    993995#endif 
     
    12101212  int mx[BOARDMAX]; 
    12111213  int r, k; 
    12121214 
    1213   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1215  scan_board(pos, 
    12141216    if (board[pos] != other 
    12151217        || pos != find_origin(pos) 
    12161218        || aa_status[pos] != ALIVE) { 
     
    12441246    aa_values[pos] = value; 
    12451247    if (1) 
    12461248      DEBUG(DEBUG_ATARI_ATARI, "aa_value for %1m = %d\n", pos, value); 
    1247   } 
     1249  ) 
    12481250} 
    12491251 
    12501252/* The aa_value for a string is the sum of the aa_values for all 
     
    13261328   * move is strictly equivalent to a played move in terms of goal 
    13271329   * mapping. I doubt it would be anything worth though... 
    13281330   */ 
    1329   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    1330     if (ON_BOARD(pos) && forbidden[pos]) { 
     1331  scan_board(pos, 
     1332    if (forbidden[pos]) { 
    13311333      dists[pos] = 1; 
    13321334      queue[queue_end++] = pos; 
    13331335    } 
    1334   } 
     1336  ) 
    13351337#endif 
    13361338 
    13371339  if (queue_end == 0)