Ticket #172: read-trymoves.patch

File read-trymoves.patch, 4.0 KB (added by draqo, 3 years ago)
  • engine/reading.c

    diff -N -r -u -X .ignore gnugo-copy/engine/reading.c gnugo/engine/reading.c
    old new  
    131131 * is a defense version. 
    132132 */ 
    133133#define DEFEND_TRY_MOVES(no_deep_branching, attack_hint)                \ 
     134  DEFEND_TRY_MOVES_LIMIT(no_deep_branching, attack_hint, WIN) 
     135 
     136/* Like DEFEND_TRY_MOVES but called when the best possible result is 
     137 * known - we can finish trying moves earlier. 
     138 */ 
     139#define DEFEND_TRY_MOVES_LIMIT(no_deep_branching, attack_hint, limit)   \ 
    134140  do {                                                                  \ 
    135141    int k;                                                              \ 
    136142                                                                        \ 
     
    139145      int dpos = moves.pos[k];                                          \ 
    140146                                                                        \ 
    141147      if (komaster_trymove(dpos, color, moves.message[k], str, &ko_move,\ 
    142                            stackp <= ko_depth && savecode == 0)) {      \ 
     148                           stackp <= ko_depth && !savecode)) {          \ 
    143149        int acode = do_attack(str, (attack_hint));                      \ 
    144150        popgo();                                                        \ 
    145151                                                                        \ 
     
    153159            savecode = KO_B;                                            \ 
    154160          }                                                             \ 
    155161        }                                                               \ 
    156       }                                                                 \ 
    157162                                                                        \ 
    158       if ((no_deep_branching) && stackp >= branch_depth)                \ 
    159         RETURN_RESULT(savecode, savemove, move, "branching limit");     \ 
     163        if (savecode == (limit))                                        \ 
     164          RETURN_RESULT(savecode, savemove, move, "best defense");      \ 
     165                                                                        \ 
     166        if ((no_deep_branching) && stackp >= branch_depth)              \ 
     167          RETURN_RESULT(savecode, savemove, move, "branching limit");   \ 
     168      }                                                                 \ 
    160169    }                                                                   \ 
    161170                                                                        \ 
    162171    moves.num_tried = moves.num;                                        \ 
     
    177186                                                                        \ 
    178187      if ((board_ko_pos || !send_two_return_one(apos, other))           \ 
    179188          && komaster_trymove(apos, other,moves.message[k],str,&ko_move,\ 
    180                               stackp <= ko_depth && savecode == 0)) {   \ 
     189                              stackp <= ko_depth && !savecode)) {       \ 
    181190        int dcode = do_find_defense(str, (defense_hint));               \ 
    182191                                                                        \ 
    183192        if (REVERSE_RESULT(dcode) > savecode                            \ 
    184193            && do_attack(str, NULL)) {  \ 
    185194          if (!ko_move) {                                               \ 
    186             if (dcode == 0) {                                           \ 
     195            if (!dcode) {                                               \ 
    187196              popgo();                                                  \ 
    188197              RETURN_RESULT(WIN, apos, move, "attack effective");       \ 
    189198            }                                                           \ 
     
    198207        }                                                               \ 
    199208                                                                        \ 
    200209        popgo();                                                        \ 
    201       }                                                                 \ 
    202210                                                                        \ 
    203       if ((no_deep_branching) && stackp >= branch_depth)                \ 
    204         RETURN_RESULT(savecode, savemove, move, "branching limit");     \ 
     211        if ((no_deep_branching) && stackp >= branch_depth)              \ 
     212          RETURN_RESULT(savecode, savemove, move, "branching limit");   \ 
     213      }                                                                 \ 
    205214    }                                                                   \ 
    206215                                                                        \ 
    207216    moves.num_tried = moves.num;                                        \ 
     
    14201429  int savecode = 0; 
    14211430  int liberties; 
    14221431  int k; 
     1432  int suggest_move; 
    14231433 
    14241434  SETUP_TRACE_INFO("defend1", str); 
    14251435  reading_node_counter++; 
     
    14441454  moves.message[0] = "liberty"; 
    14451455  moves.num = 1; 
    14461456  moves.num_tried = 0; 
     1457  suggest_move = NO_MOVE; 
    14471458 
    14481459  break_chain_moves(str, &moves); 
    14491460  set_up_snapback_moves(str, lib, &moves); 
    14501461 
    14511462  order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    1452   DEFEND_TRY_MOVES(0, NULL); 
     1463  DEFEND_TRY_MOVES(0, &suggest_move); 
    14531464 
    14541465  /* If the string is a single stone and a capture would give a ko, 
    14551466   * try to defend it with ko by backfilling or killing neighbors 
     
    14831494     * (see trevord:700 for example, when these moves could be 
    14841495     * helpful). */ 
    14851496    if (!savecode && stackp <= break_chain_depth) { 
    1486       int k; 
    1487  
    14881497      /* Find neighbors of group created by filling a ko, which 
    14891498       * have up to two liberties and aren't neighbors of a ko 
    14901499       * stone. 
     
    14971506      popgo(); 
    14981507 
    14991508      order_moves(str, &moves, color, READ_FUNCTION_NAME, *move); 
    1500  
    1501       for (k = moves.num_tried; k < moves.num; k++) { 
    1502         int dpos = moves.pos[k]; 
    1503         if (komaster_trymove(dpos, color, moves.message[k], str, 
    1504                              &ko_move, stackp <= ko_depth)) { 
    1505           int acode = do_attack(str, NULL); 
    1506           popgo(); 
    1507           CHECK_RESULT(savecode, savemove, acode, dpos, move, 
    1508                        "defense effective"); 
    1509  
    1510           if (savecode) 
    1511             break; 
    1512         } 
    1513       } 
     1509      DEFEND_TRY_MOVES_LIMIT(0, &suggest_move, KO_B); 
    15141510    } 
    15151511  } 
    15161512