Ticket #148: worm2.diff

File worm2.diff, 14.0 kB (added by draqo, 19 months ago)

worm cleanup patch nr 2 (no logic changes, added discarded moves) - apply to 3.7.11 ver and after all mine previous patches and tickets 162-164

  • engine/board.c

    diff -N -r -u -X .ignore gnugo-copy/engine/board.c gnugo/engine/board.c
    old new  
    874874      return 0; 
    875875     
    876876    /* 4. The location must not be the ko point, unless ignore_ko == 1. */ 
    877         if (!ignore_ko && pos == board_ko_pos) { 
     877    if (!ignore_ko && pos == board_ko_pos) { 
    878878      /*    The ko position is guaranteed to have all neighbors of the 
    879879       *    same color, or off board. If that color is the same as the 
    880880       *    move the ko is being filled, it is always allowed. This 
     
    884884      if (board[WEST(pos)] == OTHER_COLOR(color) 
    885885          || board[EAST(pos)] == OTHER_COLOR(color)) 
    886886        return 0; 
    887         } 
     887    } 
    888888 
    889889    /* 5. Test for suicide. */ 
    890890    if (is_suicide(pos, color)) 
  • engine/liberty.h

    diff -N -r -u -X .ignore gnugo-copy/engine/liberty.h gnugo/engine/liberty.h
    old new  
    336336/* movelist.c */ 
    337337int movelist_move_known(int move, int max_points, int points[], int codes[]); 
    338338void movelist_change_point(int move, int code, int max_points,  
    339                            int points[], int codes[]); 
     339                           int points[], int codes[], int discarded_points[]); 
     340int discarded_move_known(int move, int max_points, int points[]); 
     341void movelist_change_discarded(int move, int max_points, int points[]); 
    340342 
    341343/* worm.c */ 
    342344void change_tactical_point(int str, int move, int code, 
    343                            int points[], int codes[]); 
     345                           int points[], int codes[], int discarded_points[]); 
    344346 
    345347/* surround.c */ 
    346348int compute_surroundings(int pos, int apos, int showboard, 
     
    837839   */ 
    838840  int attack_points[MAX_TACTICAL_POINTS]; 
    839841  int attack_codes[MAX_TACTICAL_POINTS]; 
     842  int discarded_attacks[MAX_TACTICAL_POINTS]; 
    840843  int defense_points[MAX_TACTICAL_POINTS]; 
    841844  int defense_codes[MAX_TACTICAL_POINTS]; 
     845  int discarded_defenses[MAX_TACTICAL_POINTS]; 
    842846  int attack_threat_points[MAX_TACTICAL_POINTS]; 
    843847  int attack_threat_codes[MAX_TACTICAL_POINTS];  
     848  int discarded_att_threats[MAX_TACTICAL_POINTS]; 
    844849  int defense_threat_points[MAX_TACTICAL_POINTS]; 
    845850  int defense_threat_codes[MAX_TACTICAL_POINTS]; 
     851  int discarded_def_threats[MAX_TACTICAL_POINTS]; 
    846852}; 
    847853 
    848854extern struct worm_data worm[BOARDMAX]; 
  • engine/movelist.c

    diff -N -r -u -X .ignore gnugo-copy/engine/movelist.c gnugo/engine/movelist.c
    old new  
    4141  int k; 
    4242 
    4343  for (k = 0; k < max_points; k++) { 
    44     if (codes[k] == 0) 
     44    if (points[k] == 0) 
    4545      return 0; 
    4646    if (points[k] == move) 
    4747      return codes[k]; 
     
    5050} 
    5151 
    5252 
     53/* Return true if the move was previously discarded. 
     54 */ 
     55int 
     56discarded_move_known(int move, int max_points, int points[]) 
     57{ 
     58  int k; 
     59 
     60  for (k = 0; k < max_points; k++) { 
     61    if (points[k] == 0) 
     62      return 0; 
     63    if (points[k] == move) 
     64      return 1; 
     65  } 
     66  return 0; 
     67} 
     68 
     69 
    5370/* 
    5471 * This function does the real work for change_attack(), 
    5572 * change_defense(), change_attack_threat(), and 
     
    5875 
    5976void 
    6077movelist_change_point(int move, int code, int max_points, 
    61                       int points[], int codes[]) 
     78                      int points[], int codes[], int discarded_points[]) 
    6279{ 
    6380  int k; 
    6481 
    6582  /* First see if we already know about this point. */ 
    66   for (k = 0; k < max_points; k++) 
     83  for (k = 0; k < max_points; k++) { 
    6784    if (points[k] == move) 
    6885      break; 
    6986 
     87    if (points[k] == 0) { 
     88      /* We have empty space to store the move. */ 
     89      points[k] = move; 
     90      codes[k] = code; 
     91      move_up_list(points, codes, k); 
     92      return; 
     93    } 
     94  } 
     95 
    7096  /* Yes, we do. */ 
    7197  if (k < max_points) { 
    7298    if (code >= codes[k]) 
     
    78104  /* This tactical point is new to us. */ 
    79105  else { 
    80106    k--; /* last index */ 
    81     if (code <= codes[k]) 
     107    if (code <= codes[k]) { 
     108      movelist_change_discarded(move, max_points, discarded_points); 
    82109      return; /* Too bad move to store. */ 
     110    } 
    83111 
    84112    points[k] = move; 
    85113    codes[k] = code; 
     
    88116} 
    89117 
    90118 
     119/* 
     120 * This function changes discarded moves list. 
     121 */ 
     122void 
     123movelist_change_discarded(int move, int max_points, int points[]) 
     124{ 
     125  int k; 
     126 
     127  /* We store only max_points discarded moves. */ 
     128  for (k = 0; k < max_points; k++) { 
     129    if (points[k] == move) 
     130      return; 
     131 
     132    if (points[k] == 0) { 
     133      points[k] = move; 
     134      return; 
     135    } 
     136  } 
     137} 
     138 
     139 
    91140/* Sort the changed tactical point. We set it to the higher value, so 
    92141 * we just have to move it up the table. 
    93142 */ 
  • engine/owl.c

    diff -N -r -u -X .ignore gnugo-copy/engine/owl.c gnugo/engine/owl.c
    old new  
    927927        case 5: 
    928928          checked_moves = shape_offensive_moves; 
    929929          break; 
     930        default: 
     931          checked_moves = NULL; 
     932          gg_assert(0); 
    930933        } 
    931934 
    932935        for (k = 0; k < MAX_MOVES; k++) { 
  • engine/reading.c

    diff -N -r -u -X .ignore gnugo-copy/engine/reading.c gnugo/engine/reading.c
    old new  
    10351035  int k; 
    10361036  int l; 
    10371037  int r; 
     1038  int discard; 
    10381039 
    10391040  ASSERT1(IS_STONE(board[str]), str); 
    10401041 
     
    10601061      if (trymove(aa, other, "attack_threats-A", str)) { 
    10611062       int acode = attack(str, NULL); 
    10621063       if (acode != 0) 
    1063          change_tactical_point(str, aa, acode, moves, codes); 
     1064         change_tactical_point(str, aa, acode, moves, codes, 
     1065                               worm[str].discarded_att_threats); 
    10641066       popgo(); 
    10651067      } 
    10661068 
     
    10701072 
    10711073       if (!ON_BOARD(bb) 
    10721074           || IS_STONE(board[bb]) 
     1075           || attack_threat_move_known(bb, str) 
     1076           || discarded_move_known(bb, MAX_TACTICAL_POINTS, 
     1077                                   worm[str].discarded_att_threats) 
    10731078           || liberty_of_string2(bb, str)) 
    10741079         continue; 
    10751080 
     1081       discard = 1; 
     1082 
    10761083       if (trymove(bb, other, "attack_threats-B", str)) { 
    10771084         int acode = attack(str, NULL); 
    1078          if (acode != 0) 
    1079            change_tactical_point(str, bb, acode, moves, codes); 
     1085         if (acode != 0) { 
     1086           change_tactical_point(str, bb, acode, moves, codes, 
     1087                                 worm[str].discarded_att_threats); 
     1088           discard = 0; 
     1089         } 
    10801090         popgo(); 
    10811091       } 
     1092 
     1093       if (discard) 
     1094         movelist_change_discarded(bb, MAX_TACTICAL_POINTS, 
     1095                                   worm[str].discarded_att_threats); 
    10821096      } 
    10831097    } 
    10841098  } 
     
    10871101  num_adj = chainlinks(str, adjs); 
    10881102  for (k = 0; k < num_adj; k++) { 
    10891103    int bb; 
    1090     int dd;  /* Defense point of weak neighbor. */ 
    10911104    int acode; 
    10921105    int dcode; 
    10931106 
    1094     attack_and_defend(adjs[k], &acode, NULL, &dcode, &dd); 
     1107    attack_and_defend(adjs[k], &acode, NULL, &dcode, NULL); 
    10951108    if (acode == 0 || dcode == 0) 
    10961109      continue; 
    10971110 
    1098     /* The strange code using r == -1 below is only avoid duplication 
    1099      * of the code starting with "if (trymove..)" below. 
    1100      * If r == -1 and stackp == 0 then use the defense point what we got from 
    1101      * attack_and_defend above. Otherwise step through all defense points. 
    1102      */ 
    1103     for (r = -1; r < max_points; r++) { 
    1104       if (stackp == 0) { 
    1105         if (r == -1) 
    1106           continue; 
    1107         if (worm[adjs[k]].defense_codes[r] == 0) 
    1108           break; 
    1109         bb = worm[adjs[k]].defense_points[r]; 
    1110       } 
    1111       else { 
    1112         if (r == -1) 
    1113           bb = dd; 
    1114         else 
    1115           break; 
    1116       } 
     1111    /* Step through all defense points. */ 
     1112    for (r = 0; r < max_points; r++) { 
     1113      if (worm[adjs[k]].defense_codes[r] == 0) 
     1114        break; 
     1115      bb = worm[adjs[k]].defense_points[r]; 
    11171116 
    11181117      /* Test the move and see if it is a threat. */ 
    11191118      if (trymove(bb, other, "attack_threats-C", str)) { 
     
    11221121        else 
    11231122          acode = attack(str, NULL); 
    11241123        if (acode != 0) 
    1125           change_tactical_point(str, bb, acode, moves, codes); 
     1124          change_tactical_point(str, bb, acode, moves, codes, 
     1125                                worm[str].discarded_att_threats); 
    11261126        popgo(); 
    11271127      } 
    11281128    } 
    11291129  } 
    11301130 
    11311131  /* Return actual number of threats found regardless of attack code. */ 
    1132   if (codes[max_points - 1] > 0) 
    1133     return max_points; 
    11341132  for (num_threats = 0; num_threats < max_points; num_threats++) 
    11351133    if (codes[num_threats] == 0) 
    11361134      break; 
  • engine/unconditional.c

    diff -N -r -u -X .ignore gnugo-copy/engine/unconditional.c gnugo/engine/unconditional.c
    old new  
    676676void 
    677677clear_unconditionally_meaningless_moves() 
    678678{ 
    679   int pos; 
    680    
    681   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    682     if (ON_BOARD(pos)) { 
    683       meaningless_black_moves[pos] = -1; 
    684       meaningless_white_moves[pos] = -1; 
    685     } 
     679  memset(meaningless_black_moves, -1, sizeof(meaningless_black_moves)); 
     680  memset(meaningless_white_moves, -1, sizeof(meaningless_black_moves)); 
    686681} 
    687682 
    688683/* Pick up antisuji and replacement move reasons found by analysis 
  • engine/worm.c

    diff -N -r -u -X .ignore gnugo-copy/engine/worm.c gnugo/engine/worm.c
    old new  
    884884  int k; 
    885885  int l; 
    886886  int color; 
     887  int discard; 
    887888   
    888889  for (str = BOARDMIN; str < BOARDMAX; str++) { 
    889890    color = board[str]; 
     
    951952           
    952953          if (!ON_BOARD(bb) 
    953954              || IS_STONE(board[bb]) 
     955              || defense_threat_move_known(bb, str) 
     956              || discarded_move_known(bb, MAX_TACTICAL_POINTS, 
     957                                      worm[str].discarded_def_threats) 
    954958              || liberty_of_string2(bb, str)) 
    955959            continue; 
     960 
     961          discard = 1; 
    956962           
    957963          if (trymove(bb, color, "threaten defense", str)) { 
    958964            if (attack(str, NULL) == WIN) { 
    959965              int dcode = find_defense(str, NULL); 
    960               if (dcode != 0) 
     966              if (dcode != 0) { 
    961967                change_defense_threat(str, bb, dcode); 
     968                discard = 0; 
     969              } 
    962970            } 
    963971            popgo(); 
    964972          } 
     973 
     974          if (discard) 
     975            movelist_change_discarded(bb, MAX_TACTICAL_POINTS, 
     976                                      worm[str].discarded_def_threats); 
    965977        } 
    966978      } 
    967979       
     
    10631075void 
    10641076change_defense(int str, int move, int dcode) 
    10651077{ 
    1066   str = worm[str].origin; 
    10671078  change_tactical_point(str, move, dcode, 
    1068                         worm[str].defense_points, worm[str].defense_codes); 
     1079                        worm[str].defense_points, worm[str].defense_codes, 
     1080                        worm[str].discarded_defenses); 
    10691081} 
    10701082 
    10711083 
     
    10801092void 
    10811093change_attack(int str, int move, int acode) 
    10821094{ 
    1083   str = worm[str].origin; 
    10841095  DEBUG(DEBUG_WORMS, "change_attack: %1m %1m %d\n", str, move, acode); 
    10851096  change_tactical_point(str, move, acode, 
    1086                         worm[str].attack_points, worm[str].attack_codes); 
     1097                        worm[str].attack_points, worm[str].attack_codes, 
     1098                        worm[str].discarded_attacks); 
    10871099} 
    10881100 
    10891101 
     
    10991111void 
    11001112change_defense_threat(int str, int move, int dcode) 
    11011113{ 
    1102   str = worm[str].origin; 
    11031114  change_tactical_point(str, move, dcode, 
    11041115                        worm[str].defense_threat_points, 
    1105                         worm[str].defense_threat_codes); 
     1116                        worm[str].defense_threat_codes, 
     1117                        worm[str].discarded_def_threats); 
    11061118} 
    11071119 
    11081120 
     
    11181130void 
    11191131change_attack_threat(int str, int move, int acode) 
    11201132{ 
    1121   str = worm[str].origin; 
    11221133  change_tactical_point(str, move, acode, 
    11231134                        worm[str].attack_threat_points, 
    1124                         worm[str].attack_threat_codes); 
     1135                        worm[str].attack_threat_codes, 
     1136                        worm[str].discarded_att_threats); 
    11251137} 
    11261138 
    11271139 
     
    11811193void 
    11821194change_tactical_point(int str, int move, int code, 
    11831195                      int points[MAX_TACTICAL_POINTS], 
    1184                       int codes[MAX_TACTICAL_POINTS]) 
     1196                      int codes[MAX_TACTICAL_POINTS], 
     1197                      int discarded_points[MAX_TACTICAL_POINTS]) 
    11851198{ 
    11861199  ASSERT_ON_BOARD1(str); 
    1187   ASSERT1(str == worm[str].origin, str); 
    11881200   
    1189   movelist_change_point(move, code, MAX_TACTICAL_POINTS, points, codes); 
     1201  movelist_change_point(move, code, MAX_TACTICAL_POINTS, points, codes, 
     1202                        discarded_points); 
    11901203  propagate_worm2(str); 
    11911204} 
    11921205 
     
    16021615      if (countlib(str) > 4) 
    16031616        continue; 
    16041617 
    1605       if (attack_move_known(move, str)) 
     1618      if (attack_move_known(move, str) 
     1619          || discarded_move_known(move, MAX_TACTICAL_POINTS, 
     1620                                  worm[str].discarded_attacks)) 
    16061621        continue; 
    16071622 
    16081623      /* No defenses are known at this time, so defend_code is always 0. */ 
     
    16121627        continue; 
    16131628#endif 
    16141629       
    1615       /* FIXME: Don't attack the same string more than once. 
    1616        * Play (move) and see if there is a defense. 
    1617        */ 
     1630      /* Play (move) and see if there is a defense. */ 
    16181631      if (trymove(move, color, "attack_callback", str)) { 
    16191632        int dcode; 
    16201633        if (!board[str]) 
     
    16371650                "Attack pattern %s+%d found attack on %1m at %1m with code %d\n", 
    16381651                pattern->name, ll, str, move, REVERSE_RESULT(dcode)); 
    16391652        } 
     1653        else 
     1654          movelist_change_discarded(move, MAX_TACTICAL_POINTS, 
     1655                                    worm[str].discarded_attacks); 
    16401656      } 
     1657      else 
     1658        movelist_change_discarded(move, MAX_TACTICAL_POINTS, 
     1659                                  worm[str].discarded_attacks); 
    16411660    } 
    16421661  } 
    16431662} 
     
    16881707      int str = worm[pos].origin; 
    16891708 
    16901709      if (worm[str].attack_codes[0] == 0 
    1691           || defense_move_known(move, str)) 
     1710          || defense_move_known(move, str) 
     1711          || discarded_move_known(move, MAX_TACTICAL_POINTS, 
     1712                                  worm[str].discarded_defenses)) 
    16921713        continue; 
    16931714       
    1694       /* FIXME: Don't try to defend the same string more than once. 
    1695        * FIXME: For all attacks on this string, we should test whether 
     1715      /* FIXME: For all attacks on this string, we should test whether 
    16961716       *        the proposed move happens to refute the attack. 
    16971717       * Play (move) and see if there is an attack. 
    16981718       */ 
     
    17071727                "Defense pattern %s+%d found defense of %1m at %1m with code %d\n", 
    17081728                pattern->name, ll, str, move, REVERSE_RESULT(acode)); 
    17091729        } 
     1730        else 
     1731          movelist_change_discarded(move, MAX_TACTICAL_POINTS, 
     1732                                    worm[str].discarded_defenses); 
    17101733      } 
     1734      else 
     1735        movelist_change_discarded(move, MAX_TACTICAL_POINTS, 
     1736                                  worm[str].discarded_defenses); 
    17111737    } 
    17121738  } 
    17131739} 
  • interface/gnugo.vcproj

    diff -N -r -u -X .ignore gnugo-copy/interface/gnugo.vcproj gnugo/interface/gnugo.vcproj
    old new  
    400400                                RelativePath=".\interface.h" 
    401401                                > 
    402402                        </File> 
     403                        <File 
     404                                RelativePath="..\engine\liberty.h" 
     405                                > 
     406                        </File> 
    403407                </Filter> 
    404408                <Filter 
    405409                        Name="Resource Files"