Ticket #145: value_moves.c.patch

File value_moves.c.patch, 8.9 kB (added by draqo, 2 years ago)
  • 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
     
    146146  TRACE("\nLooking for additional attack and defense moves. Trying moves ...\n"); 
    147147   
    148148  /* Identify the unstable worms and store them in a list. */ 
    149   for (ii = BOARDMIN; ii < BOARDMAX; ii++) { 
     149  scan_board(ii, 
    150150    if (IS_STONE(board[ii]) 
    151151        && worm[ii].origin == ii 
    152152        && worm[ii].attack_codes[0] != 0 
     
    154154      unstable_worms[N] = ii; 
    155155      N++; 
    156156    } 
    157   } 
     157  ) 
    158158   
    159159  /* To avoid horizon effects, we temporarily increase the depth values. */ 
    160160  increase_depth_values(); 
    161161   
    162   for (ii = BOARDMIN; ii < BOARDMAX; ii++) { 
    163     if (!ON_BOARD(ii)) 
    164       continue; 
     162  scan_board(ii, 
    165163 
    166164    /* Don't consider send-two-return-one moves here. */ 
    167165    if (send_two_return_one(ii, color)) 
     
    278276      } 
    279277      popgo(); 
    280278    } 
    281   } 
     279  ) 
    282280   
    283281  TRACE("\n"); 
    284282  decrease_depth_values(); 
     
    577575  if (verbose) 
    578576    gprintf("\nTrying to upgrade strategical attack and defense moves.\n"); 
    579577 
    580   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    581     if (!ON_BOARD(pos)) 
    582       continue; 
     578  scan_board(pos, 
    583579       
    584580    for (k = 0; k < MAX_REASONS; k++) { 
    585581      int r = move[pos].reason[k]; 
     
    590586                                                move_reasons[r].type, 
    591587                                                move_reasons[r].what); 
    592588    } 
    593   } 
     589  ) 
    594590 
    595591  if (verbose) 
    596592    gprintf("\nTrying vital eye moves as owl attacks.\n"); 
     
    607603    your_vital_points = white_vital_points; 
    608604  } 
    609605 
    610   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    611     if (!ON_BOARD(pos)) 
    612       continue; 
     606  scan_board(pos, 
    613607    if (our_eyes[pos].origin == pos 
    614608        && our_vital_points[pos].defense_points[0] != NO_MOVE) { 
    615       int k, dr; 
     609      int k; 
     610          int dr; 
    616611      find_eye_dragons(pos, our_eyes, color, &dr, 1); 
    617612      for (k = 0; k < MAX_EYE_ATTACKS; k++) { 
    618613        int move = our_vital_points[pos].defense_points[k]; 
     
    624619    } 
    625620    if (your_eyes[pos].origin == pos 
    626621        && your_vital_points[pos].attack_points[0] != NO_MOVE) { 
    627       int k, dr; 
     622      int k; 
     623          int dr; 
    628624      find_eye_dragons(pos, your_eyes, OTHER_COLOR(color), &dr, 1); 
    629625      for (k = 0; k < MAX_EYE_ATTACKS; k++) { 
    630626        int move = your_vital_points[pos].attack_points[k]; 
     
    634630                                                  VITAL_EYE_MOVE, dr); 
    635631      } 
    636632    } 
    637   } 
     633  ) 
    638634 
    639635  save_verbose = verbose; 
    640636  if (verbose > 0) 
     
    643639  /* If two critical dragons are adjacent, test whether a move to owl 
    644640   * attack or defend one also is effective on the other. 
    645641   */ 
    646   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     642  scan_board(pos, 
    647643    if (IS_STONE(board[pos]) 
    648644        && dragon[pos].origin == pos 
    649645        && DRAGON2(pos).owl_status == CRITICAL) { 
    650       for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { 
     646      scan_board(pos2, 
    651647        if (board[pos2] != EMPTY) 
    652648          continue; 
    653649        worth_trying = 0; 
     
    701697            } 
    702698          } 
    703699        } 
    704       } 
    705     } 
    706   } 
     700          ) 
     701        } 
     702  ) 
    707703 
    708704  verbose = save_verbose; 
    709705} 
     
    760756  if (verbose > 0) 
    761757    verbose--; 
    762758 
    763   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    764     int k, r; 
     759  scan_board(pos, 
     760    int k; 
     761    int r; 
    765762    int potential_semeai_move_found = 0; 
    766763    int other_move_reason_found = 0; 
    767764 
    768     if (!ON_BOARD1(pos)) 
    769       continue; 
    770765    for (k = 0; k < MAX_REASONS; k++) { 
    771766      r = move[pos].reason[k]; 
    772767      if (r < 0) 
     
    794789          || move_reasons[r].type == POTENTIAL_SEMEAI_DEFENSE) 
    795790        try_potential_semeai_move(pos, color, &(move_reasons[r])); 
    796791    } 
    797   } 
     792  ) 
    798793  verbose = save_verbose; 
    799794} 
    800795 
     
    827822  int i, j; 
    828823  int aa; 
    829824   
    830   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    831     if (!ON_BOARD(pos)) 
    832       continue; 
     825  scan_board(pos, 
    833826     
    834827    for (k = 0; k < MAX_REASONS; k++) { 
    835828      int r = move[pos].reason[k]; 
     
    841834          || move_reasons[r].type == DEFEND_MOVE) { 
    842835        int attack_move; 
    843836        int color_to_move; 
    844         int num_adj, adjs[MAXCHAIN]; 
     837        int num_adj; 
     838        int adjs[MAXCHAIN]; 
    845839         
    846840        aa = move_reasons[r].what; 
    847841         
     
    10091003        int worm1 = conn_worm1[move_reasons[r].what]; 
    10101004        int worm2 = conn_worm2[move_reasons[r].what]; 
    10111005        int pos2; 
    1012         for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { 
    1013           if (ON_BOARD(pos2) && board[pos2] == EMPTY 
     1006        scan_board(pos2, 
     1007          if (board[pos2] == EMPTY 
    10141008              && cut_possible(pos2, OTHER_COLOR(color)) 
    10151009              && square_dist(pos, pos2) <= 5) { 
    10161010            for (j = 0; j < 8; j++) { 
     
    10431037              } 
    10441038            } 
    10451039          } 
    1046         } 
     1040        ) 
    10471041      } 
    10481042    } 
    1049   } 
     1043  ) 
    10501044} 
    10511045 
    10521046 
     
    10631057  int k; 
    10641058   
    10651059  start_timer(3); 
    1066   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1060  scan_board(pos, 
    10671061    int safety = 0; 
    10681062    int tactical_safety = 0; 
    1069     if (!ON_BOARD(pos)) 
    1070       continue; 
    10711063       
    10721064    for (k = 0; k < MAX_REASONS; k++) { 
    10731065      int r = move[pos].reason[k]; 
     
    11701162             * below if we were certain that the capturable string 
    11711163             * had not been amalgamated with a living dragon. 
    11721164             */ 
    1173             int num_adj, adjs[MAXCHAIN]; 
     1165            int num_adj; 
     1166                int adjs[MAXCHAIN]; 
    11741167             
    11751168            num_adj = chainlinks(aa, adjs); 
    11761169            for (m = 0; m < num_adj; m++) { 
     
    13221315      move[pos].move_safety = 0; 
    13231316     
    13241317    time_report(3, "    examine_move_safety: ", pos, 1.0); 
    1325   } 
     1318  ) 
    13261319} 
    13271320 
    13281321 
     
    29332926    } 
    29342927  } 
    29352928   
    2936   for (aa = BOARDMIN; aa < BOARDMAX; aa++) { 
     2929  scan_board(aa, 
    29372930    if (dragon_value[aa] == 0.0) 
    29382931      continue; 
    29392932 
     
    29962989    TRACE("  %1m: %f - strategic effect on %1m\n", 
    29972990          pos, dragon_value[aa], aa); 
    29982991    tot_value += dragon_value[aa]; 
    2999   } 
     2992  ) 
    30002993 
    30012994  /* Finally, subtract penalty for invasion type moves. */ 
    30022995  this_value = strategic_penalty(pos, color); 
     
    33323325{ 
    33333326  int pos; 
    33343327   
    3335   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    3336     if (!ON_BOARD(pos) || move[pos].final_value <= 0.0) 
     3328  scan_board(pos, 
     3329    if (move[pos].final_value <= 0.0) 
    33373330      continue; 
    33383331       
    33393332    gfprintf(output, "%1M %f\n", pos, move[pos].final_value); 
    3340   } 
     3333  ) 
    33413334} 
    33423335 
    33433336/* Search through all board positions for the 10 highest valued 
     
    33553348    best_moves[k] = NO_MOVE; 
    33563349    best_move_values[k] = 0.0; 
    33573350  } 
    3358   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    3359     if (!ON_BOARD(pos) || move[pos].final_value <= 0.0) 
     3351  scan_board(pos, 
     3352    if (move[pos].final_value <= 0.0) 
    33603353      continue; 
    33613354       
    33623355    tval = move[pos].final_value; 
    33633356    record_top_move(pos, tval); 
    3364   } 
     3357  ) 
    33653358   
    33663359  if (verbose > 0 || (debug & DEBUG_TOP_MOVES)) { 
    33673360    gprintf("\nTop moves:\n"); 
     
    34423435  } 
    34433436   
    34443437  TRACE("Reevaluating ko threats.\n"); 
    3445   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     3438  scan_board(pos, 
    34463439    int threat_quality = 0; 
    34473440 
    3448     if (!ON_BOARD(pos) || pos == ko_move) 
     3441    if (pos == ko_move) 
    34493442      continue; 
    34503443    if (move[pos].additional_ko_value <= 0.0)  
    34513444      continue; 
     
    36013594        DEBUG(DEBUG_MOVE_REASONS, 
    36023595              "%1m: no additional ko value (threat does not work as ko threat)\n", pos); 
    36033596    } 
    3604   } 
     3597  ) 
    36053598 
    36063599  for (k = 0; k < num_good_threats; k++) { 
    36073600    pos = good_threats[k]; 
     
    36353628  int source; 
    36363629  int target; 
    36373630 
    3638   for (target = BOARDMIN; target < BOARDMAX; target++) 
    3639     if (ON_BOARD(target)) 
    3640       move[target].final_value = move[target].value; 
     3631  scan_board(target, 
     3632    move[target].final_value = move[target].value; 
     3633  ) 
    36413634   
    3642   for (source = BOARDMIN; source < BOARDMAX; source++) { 
    3643     if (!ON_BOARD(source)) 
    3644       continue; 
     3635  scan_board(source, 
    36453636    target = replacement_map[source]; 
    36463637    if (target == NO_MOVE) 
    36473638      continue; 
     
    36533644    } 
    36543645    TRACE("%1m is now valued 0.\n", source); 
    36553646    move[source].final_value = 0.0; 
    3656   } 
     3647  ) 
    36573648} 
    36583649 
    36593650/* This selects the best move available according to their valuations. 
     
    36783669    best_move = NO_MOVE; 
    36793670 
    36803671    /* Search through all board positions for the highest valued move. */ 
    3681     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     3672    scan_board(pos, 
    36823673      float this_value = move[pos].final_value; 
    36833674      if (allowed_moves && !allowed_moves[pos]) 
    36843675        continue; 
    3685       if (!ON_BOARD(pos) || move[pos].final_value == 0.0) 
     3676      if (move[pos].final_value == 0.0) 
    36863677        continue; 
    36873678         
    36883679      if (this_value > best_value) { 
     
    36973688          move[pos].final_value = 0.0; 
    36983689        } 
    36993690      } 
    3700     } 
     3691        ) 
    37013692     
    37023693    /* If the best move is an illegal ko capture, reevaluate ko 
    37033694     * threats and search again. 
     
    39453936  double common_lower_limit = 0.0; 
    39463937 
    39473938  /* Find all moves with positive values. */ 
    3948   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     3939  scan_board(pos, 
    39493940    probabilities[pos] = 0.0; 
    39503941 
    3951     if (ON_BOARD(pos)) { 
    39523942      /* FIXME: what about point redistribution? */ 
    39533943      if (move[pos].final_value > 0.0) { 
    39543944        double scale = 0.01 * (double) move[pos].randomness_scaling; 
     
    39643954 
    39653955        num_moves++; 
    39663956      } 
    3967     } 
    3968   } 
     3957  ) 
    39693958 
    39703959  /* Compute probability of each move. */ 
    39713960  for (k = 0; k < num_moves; k++) {