Ticket #148: worm5.patch

File worm5.patch, 7.7 kB (added by draqo, 17 months ago)

upgraded: attack_threats when liberties==1 and find_lunch - no changes in regression

  • engine/reading.c

    diff -N -r -u -X .ignore gnugo-copy/engine/reading.c gnugo/engine/reading.c
    old new  
    10361036  int other; 
    10371037  int liberties; 
    10381038  int libs[MAXLIBS]; 
    1039   int *cur_lib, *last_lib; 
    10401039  int adjs[MAXCHAIN]; 
    10411040  int *cur_adj, *last_adj; 
    10421041  int r; 
    10431042  int discard; 
    1044   int aa, bb; 
    1045   int acode; 
    1046   const int *cur_delta; 
     1043  int bb; 
     1044  int dcode, acode; 
    10471045 
    10481046  ASSERT1(IS_STONE(board[str]), str); 
    10491047  ASSERT1(!attack(str, NULL), str); 
     
    10581056   * 
    10591057   * The test against 6 liberties is just an optimization. 
    10601058   */ 
    1061   if (liberties == 1) 
    1062     change_tactical_point(str, libs[0], WIN, moves, codes, 
    1063                           worm[str].discarded_att_threats); 
     1059  if (liberties == 1) { 
     1060    bb = libs[0]; 
     1061    discard = 1; 
     1062 
     1063    if (trymove(bb, other, "attack_threats-D", str)) { 
     1064      dcode = find_defense(bb, NULL); 
     1065      if (dcode) { 
     1066        change_tactical_point(str, bb, dcode, moves, codes, 
     1067                              worm[str].discarded_att_threats); 
     1068        discard = 0; 
     1069      } 
     1070      popgo(); 
     1071    } 
     1072 
     1073    if (discard) 
     1074      movelist_change_discarded(bb, MAX_TACTICAL_POINTS, 
     1075                                worm[str].discarded_att_threats); 
     1076  } 
    10641077  else if (liberties < 6) { 
     1078    int aa; 
     1079    int *cur_lib, *last_lib; 
     1080    const int *cur_delta; 
     1081 
    10651082    cur_lib = libs; 
    10661083    last_lib = cur_lib + liberties; 
    10671084 
    10681085    for (; cur_lib < last_lib; cur_lib++) { 
    10691086      aa = *cur_lib; 
     1087      discard = 1; 
    10701088 
    10711089      /* Try to threaten on the liberty. */ 
    10721090      if (trymove(aa, other, "attack_threats-A", str)) { 
    10731091       acode = attack(str, NULL); 
    1074        if (acode) 
     1092       if (acode) { 
    10751093         change_tactical_point(str, aa, acode, moves, codes, 
    10761094                               worm[str].discarded_att_threats); 
     1095         discard = 0; 
     1096       } 
    10771097       popgo(); 
    10781098      } 
    10791099 
     1100      if (discard) 
     1101        movelist_change_discarded(aa, MAX_TACTICAL_POINTS, 
     1102                                  worm[str].discarded_att_threats); 
     1103 
    10801104      /* Try to threaten on second order liberties. */ 
    10811105      for (cur_delta = delta; cur_delta < last_delta_4; cur_delta++) { 
    10821106       bb = aa + *cur_delta; 
     
    11111135  cur_adj = adjs; 
    11121136  last_adj = cur_adj + chainlinks(str, adjs); 
    11131137  for (; cur_adj < last_adj; cur_adj++) { 
    1114     int dcode; 
    1115  
    11161138    if (!attack_and_defend(*cur_adj, &acode, NULL, &dcode, NULL)) 
    11171139      continue; 
    11181140 
  • engine/worm.c

    diff -N -r -u -X .ignore gnugo-copy/engine/worm.c gnugo/engine/worm.c
    old new  
    461461        && worm[pos].origin == pos) { 
    462462 
    463463      /* Find adjacent worms that can be easily captured, aka lunches. */ 
    464       if (find_lunch(pos, &lunch) 
    465           && ((acode = worm[lunch].attack_codes[0]) == WIN 
    466               || acode == KO_A)) { 
     464      if (find_lunch(pos, &lunch)) { 
    467465        DEBUG(DEBUG_WORMS, "lunch found for %1m at %1m\n", pos, lunch); 
    468466        worm[pos].lunch = lunch; 
    469467        propagate_worm(pos); 
    470468      } 
    471469      else { 
    472470        /* Identify INESSENTIAL strings. */ 
    473         if (!worm[pos].genus 
    474             && !worm[pos].liberties2 
     471        if (!worm[pos].liberties2 
     472            && !worm[pos].genus 
    475473            && !worm[pos].cutstone) { 
    476474          if (examine_cavity(pos, &edge) != GRAY && edge < 3) { 
    477475            DEBUG(DEBUG_WORMS, "Worm %1m identified as inessential.\n", pos); 
     
    965963find_lunch(int str, int *lunch) 
    966964{ 
    967965  int pos; 
    968   int k; 
     966  int apos; 
     967  int lunch_pos = NO_MOVE; 
     968  int other = OTHER_COLOR(board[str]); 
     969  const int *cur_delta; 
    969970 
    970971  ASSERT1(IS_STONE(board[str]), str); 
    971972  ASSERT1(stackp == 0, str); 
    972973 
    973   *lunch = NO_MOVE; 
    974974  for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    975     if (board[pos] != OTHER_COLOR(board[str])) 
     975    if (board[pos] != other) 
    976976      continue; 
    977     for (k = 0; k < 8; k++) { 
    978       int apos = pos + delta[k]; 
     977    for (cur_delta = delta; cur_delta < last_delta_8; cur_delta++) { 
     978      apos = pos + *cur_delta; 
    979979      if (IS_STONE(board[apos]) && is_same_worm(apos, str)) { 
    980         if (worm[pos].attack_codes[0] != 0 && !is_ko_point(pos)) { 
     980        if (worm[pos].attack_codes[0] >= KO_A && !is_ko_point(pos)) { 
    981981          /* 
    982982           * If several adjacent lunches are found, we pick the  
    983            * juiciest. First maximize cutstone, then minimize liberties.  
     983           * juiciest. First maximize attack_code, then cutstone, 
     984           * then minimize liberties, then maximize size.  
    984985           * We can only do this if the worm data is available,  
    985986           * i.e. if stackp==0. 
    986987           */ 
    987           if (*lunch == NO_MOVE 
    988               || worm[pos].cutstone > worm[*lunch].cutstone  
    989               || (worm[pos].cutstone == worm[*lunch].cutstone  
    990                   && worm[pos].liberties < worm[*lunch].liberties)) { 
    991             *lunch = worm[pos].origin; 
     988          if (lunch_pos) { 
     989            if (worm[pos].attack_codes[0] 
     990                < worm[lunch_pos].attack_codes[0]) 
     991              break; 
     992            else if (worm[pos].attack_codes[0] 
     993                     == worm[lunch_pos].attack_codes[0]) { 
     994              if (worm[pos].cutstone < worm[lunch_pos].cutstone) 
     995                break; 
     996              else if (worm[pos].cutstone == worm[lunch_pos].cutstone) { 
     997                if (worm[pos].liberties > worm[lunch_pos].liberties) 
     998                  break; 
     999                else if (worm[pos].liberties == worm[lunch_pos].liberties) { 
     1000                  if (worm[pos].size <= worm[lunch_pos].size) 
     1001                    break; 
     1002                } 
     1003              } 
     1004            } 
    9921005          } 
     1006 
     1007          lunch_pos = worm[pos].origin; 
    9931008        } 
    9941009        break; 
    9951010      } 
    9961011    } 
    9971012  } 
    998    
    999   if (*lunch != NO_MOVE) 
    1000     return 1; 
    10011013 
    1002   return 0; 
     1014  *lunch = lunch_pos; 
     1015  return lunch_pos; 
    10031016} 
    10041017 
    10051018 
    10061019/* 
    1007  * Test whether two worms are the same. Used by autohelpers. 
     1020 * Test whether two worms are the same. 
    10081021 * Before this function can be called, build_worms must have been run. 
    10091022 */ 
    10101023 
     
    10391052void 
    10401053change_defense(int str, int move, int dcode) 
    10411054{ 
     1055  DEBUG(DEBUG_WORMS, "change_defense: %1m %1m %d\n", str, move, dcode); 
    10421056  change_tactical_point(str, move, dcode, 
    10431057                        worm[str].defense_points, worm[str].defense_codes, 
    10441058                        worm[str].discarded_defenses); 
     
    10751089void 
    10761090change_defense_threat(int str, int move, int dcode) 
    10771091{ 
     1092  DEBUG(DEBUG_WORMS, "change_defense_threat: %1m %1m %d\n", str, 
     1093        move, dcode); 
    10781094  change_tactical_point(str, move, dcode, 
    10791095                        worm[str].defense_threat_points, 
    10801096                        worm[str].defense_threat_codes, 
     
    10941110void 
    10951111change_attack_threat(int str, int move, int acode) 
    10961112{ 
     1113  DEBUG(DEBUG_WORMS, "change_attack_threat: %1m %1m %d\n", str, 
     1114        move, acode); 
    10971115  change_tactical_point(str, move, acode, 
    10981116                        worm[str].attack_threat_points, 
    10991117                        worm[str].attack_threat_codes, 
     
    12261244    if (!IS_STONE(board[pos]) || !is_worm_origin(pos, pos)) 
    12271245       continue; 
    12281246 
    1229     if (board[pos] == OTHER_COLOR(color)) { 
    1230       for (k = 0; k < MAX_TACTICAL_POINTS; k++) { 
    1231         if (worm[pos].attack_codes[k] != 0) 
    1232           add_attack_move(worm[pos].attack_points[k], pos, 
    1233                           worm[pos].attack_codes[k]); 
    1234         if (worm[pos].attack_threat_codes[k] != 0) 
    1235           add_attack_threat_move(worm[pos].attack_threat_points[k], pos, 
    1236                                  worm[pos].attack_threat_codes[k]); 
    1237       } 
    1238     } 
    1239        
    12401247    if (board[pos] == color) { 
    12411248      for (k = 0; k < MAX_TACTICAL_POINTS; k++) { 
    1242         if (worm[pos].defense_codes[k] != 0) 
     1249        if (worm[pos].defense_codes[k]) 
    12431250          add_defense_move(worm[pos].defense_points[k], pos, 
    12441251                           worm[pos].defense_codes[k]); 
     1252        else 
     1253          break; 
     1254      } 
    12451255 
    1246         if (worm[pos].defense_threat_codes[k] != 0) 
     1256      for (k = 0; k < MAX_TACTICAL_POINTS; k++) { 
     1257        if (worm[pos].defense_threat_codes[k]) 
    12471258          add_defense_threat_move(worm[pos].defense_threat_points[k], pos, 
    12481259                                  worm[pos].defense_threat_codes[k]); 
     1260        else 
     1261          break; 
     1262      } 
     1263    } 
     1264    else { /* board[pos] == other */ 
     1265      for (k = 0; k < MAX_TACTICAL_POINTS; k++) { 
     1266        if (worm[pos].attack_codes[k]) 
     1267          add_attack_move(worm[pos].attack_points[k], pos, 
     1268                          worm[pos].attack_codes[k]); 
     1269        else 
     1270          break; 
     1271      } 
     1272 
     1273      for (k = 0; k < MAX_TACTICAL_POINTS; k++) { 
     1274        if (worm[pos].attack_threat_codes[k]) 
     1275          add_attack_threat_move(worm[pos].attack_threat_points[k], pos, 
     1276                                 worm[pos].attack_threat_codes[k]); 
     1277        else 
     1278          break; 
    12491279      } 
    12501280    } 
    12511281  }