Ticket #145: persistent.c.patch

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

    RCS file: /sources/gnugo/gnugo/engine/persistent.c,v
    retrieving revision 1.40
    diff -u -r1.40 persistent.c
     
    224224verify_stored_board(Intersection p[BOARDMAX]) 
    225225{ 
    226226  int pos; 
    227   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    228     if (!ON_BOARD(pos)) 
     227  scan_board(pos, 
     228    if (p[pos] == GRAY) 
    229229      continue; 
    230     else if (p[pos] == GRAY) 
    231       continue; 
    232     else if ((p[pos] & 3) != board[pos]) 
     230    if ((p[pos] & 3) != board[pos]) 
    233231      return 0; 
    234232    else if (!(p[pos] & (HIGH_LIBERTY_BIT | HIGH_LIBERTY_BIT2))) 
    235233      continue; 
    236234    else if (((p[pos] & HIGH_LIBERTY_BIT) && countlib(pos) <= 4) 
    237235             || (p[pos] & HIGH_LIBERTY_BIT2 && countlib(pos) <= 3)) 
    238236      return 0; 
    239   } 
     237  ) 
    240238   
    241239  return 1; 
    242240} 
     
    645643    active[entry->move] = 1; 
    646644 
    647645  /* Add adjacent strings and empty. */ 
    648   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    649     if (!ON_BOARD(pos)) 
    650       continue; 
     646  scan_board(pos, 
    651647    if (active[pos] != 0)  
    652648      continue; 
    653649    if ((ON_BOARD(SOUTH(pos)) && active[SOUTH(pos)] == 1) 
     
    659655      else 
    660656        active[pos] = 2; 
    661657    } 
    662   } 
     658  ) 
    663659 
    664660  /* Remove invincible strings. No point adding their liberties and 
    665661   * neighbors. 
    666662   */ 
    667   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    668     if (!ON_BOARD(pos)) 
    669       continue; 
     663  scan_board(pos, 
    670664    if (IS_STONE(board[pos]) && worm[pos].invincible) 
    671665      active[pos] = 0; 
    672   } 
     666  ) 
    673667   
    674668  /* Expand empty to empty. */ 
    675   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     669  scan_board(pos, 
    676670    if (IS_STONE(board[pos]) || active[pos] != 0)  
    677671      continue; 
    678672    if ((board[SOUTH(pos)] == EMPTY && active[SOUTH(pos)] == 2) 
     
    680674        || (board[NORTH(pos)] == EMPTY && active[NORTH(pos)] == 2) 
    681675        || (board[EAST(pos)] == EMPTY && active[EAST(pos)] == 2)) 
    682676      active[pos] = 3; 
    683   } 
     677  ) 
    684678   
    685679  /* Add neighbors of active area so far. */ 
    686   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    687     if (!ON_BOARD(pos)) 
    688       continue; 
     680  scan_board(pos, 
    689681    if (active[pos] != 0)  
    690682      continue; 
    691683    if ((ON_BOARD(SOUTH(pos)) && active[SOUTH(pos)] > 0 
     
    697689        || (ON_BOARD(EAST(pos)) && active[EAST(pos)] > 0 
    698690            && active[EAST(pos)] < 4)) 
    699691      active[pos] = 4; 
    700   } 
     692  ) 
    701693 
    702694  /* Also add the previously played stones to the active area. */ 
    703695  for (r = 0; r < stackp; r++) 
    704696    active[entry->stack[r]] = 5; 
    705697 
    706   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    707     if (!ON_BOARD(pos)) 
    708       continue; 
     698  scan_board(pos, 
    709699    entry->board[pos] =  
    710700      active[pos] != 0 ? board[pos] : GRAY; 
    711   } 
     701  ) 
    712702} 
    713703 
    714704 
     
    870860 
    871861  /* Distance two expansion through empty intersections and own stones. */ 
    872862  for (k = 1; k < 3; k++) { 
    873     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    874       if (!ON_BOARD(pos) || board[pos] == other || active[pos] != 0)  
     863    scan_board(pos, 
     864      if (board[pos] == other || active[pos] != 0)  
    875865        continue; 
    876866      if ((ON_BOARD(SOUTH(pos)) && active[SOUTH(pos)] == k) 
    877867          || (ON_BOARD(WEST(pos)) && active[WEST(pos)] == k) 
     
    882872        else 
    883873          mark_string(pos, active, (signed char) (k + 1)); 
    884874      } 
    885     } 
     875        ) 
    886876  } 
    887877   
    888878  /* Adjacent opponent strings. */ 
    889   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     879  scan_board(pos, 
    890880    if (board[pos] != other || active[pos] != 0)  
    891881      continue; 
    892882    for (r = 0; r < 4; r++) { 
     
    895885        mark_string(pos, active, 1); 
    896886        break; 
    897887      } 
    898     } 
    899   } 
     888        } 
     889  ) 
    900890   
    901891  /* Liberties of adjacent opponent strings with less than five liberties + 
    902892   * liberties of low liberty neighbors of adjacent opponent strings 
    903893   * with less than five liberties. 
    904894   */ 
    905   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     895  scan_board(pos, 
    906896    if (board[pos] == other && active[pos] > 0 && countlib(pos) < 5) { 
    907897      int libs[4]; 
    908898      int liberties = findlib(pos, 4, libs); 
     
    930920        } 
    931921      } 
    932922    } 
    933   } 
     923  ) 
    934924   
    935925  /* Also add the previously played stones to the active area. */ 
    936926  for (r = 0; r < stackp; r++) 
    937927    active[entry->stack[r]] = 1; 
    938928 
    939   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     929  scan_board(pos, 
    940930    int value = board[pos]; 
    941     if (!ON_BOARD(pos)) 
    942       continue; 
     931 
    943932    if (!active[pos]) 
    944933      value = GRAY; 
    945934    else if (IS_STONE(board[pos]) && countlib(pos) > 4 && active[pos] > 0) 
    946935      value |= HIGH_LIBERTY_BIT; 
    947936     
    948937    entry->board[pos] = value; 
    949   } 
     938  ) 
    950939 
    951940} 
    952941 
     
    10181007 
    10191008  /* Distance two expansion through empty intersections and own stones. */ 
    10201009  for (k = 1; k < 3; k++) { 
    1021     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    1022       if (!ON_BOARD(pos) || board[pos] == other || active[pos] != 0)  
     1010    scan_board(pos, 
     1011      if (board[pos] == other || active[pos] != 0)  
    10231012        continue; 
    10241013      if ((ON_BOARD(SOUTH(pos)) && active[SOUTH(pos)] == k) 
    10251014          || (ON_BOARD(WEST(pos)) && active[WEST(pos)] == k) 
     
    10301019        else 
    10311020          mark_string(pos, active, (signed char) (k + 1)); 
    10321021      } 
    1033     } 
     1022        ) 
    10341023  } 
    10351024   
    10361025  /* Adjacent opponent strings. */ 
    1037   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1026  scan_board(pos, 
    10381027    if (board[pos] != other || active[pos] != 0)  
    10391028      continue; 
    10401029    for (r = 0; r < 4; r++) { 
     
    10461035        break; 
    10471036      } 
    10481037    } 
    1049   } 
     1038  ) 
    10501039   
    10511040  /* Liberties of adjacent opponent strings with less than four liberties + 
    10521041   * liberties of low liberty neighbors of adjacent opponent strings 
    10531042   * with less than five liberties. 
    10541043   */ 
    1055   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1044  scan_board(pos, 
    10561045    if (board[pos] == other && active[pos] > 0 && countlib(pos) < 4) { 
    10571046      int libs[4]; 
    10581047      int liberties = findlib(pos, 3, libs); 
     
    10801069        } 
    10811070      } 
    10821071    } 
    1083   } 
     1072  ) 
    10841073   
    1085   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1074  scan_board(pos, 
    10861075    Intersection value = board[pos]; 
    1087     if (!ON_BOARD(pos)) 
    1088       continue; 
     1076 
    10891077    if (!active[pos]) 
    10901078      value = GRAY; 
    10911079    else if (IS_STONE(board[pos]) && countlib(pos) > 3 && active[pos] > 0) 
    10921080      value |= HIGH_LIBERTY_BIT2; 
    10931081     
    10941082    entry->board[pos] = value; 
    1095   } 
     1083  ) 
    10961084} 
    10971085 
    10981086 
     
    11461134   * liberties and neighbors of low liberty neighbors of adjacent opponent 
    11471135   * strings with less than five liberties. 
    11481136   */ 
    1149   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    1150     if (ON_BOARD(pos) && goal[pos]) 
     1137  scan_board(pos, 
     1138    if (goal[pos]) 
    11511139      active[pos] = 1; 
     1140  ) 
    11521141 
    11531142  /* Distance four expansion through empty intersections and own stones. */ 
    11541143  for (k = 1; k < 5; k++) { 
    1155     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    1156       if (!ON_BOARD(pos) || board[pos] == other || active[pos] > 0)  
     1144    scan_board(pos, 
     1145      if (board[pos] == other || active[pos] > 0) 
    11571146        continue; 
    11581147      if ((ON_BOARD(SOUTH(pos)) && active[SOUTH(pos)] == k) 
    11591148          || (ON_BOARD(WEST(pos)) && active[WEST(pos)] == k) 
     
    11641153        else 
    11651154          mark_string(pos, active, (signed char) (k + 1)); 
    11661155      } 
    1167     } 
     1156        ) 
    11681157  } 
    11691158   
    11701159  /* Adjacent opponent strings. */ 
    1171   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1160  scan_board(pos, 
    11721161    if (board[pos] != other || active[pos] != 0)  
    11731162      continue; 
    11741163    for (r = 0; r < 4; r++) { 
     
    11781167        break; 
    11791168      } 
    11801169    } 
    1181   } 
     1170  ) 
    11821171   
    11831172  /* Liberties of adjacent opponent strings with less than five liberties + 
    11841173   * liberties of low liberty neighbors of adjacent opponent strings 
    11851174   * with less than five liberties. 
    11861175   */ 
    1187   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1176  scan_board(pos, 
    11881177    if (board[pos] == other && active[pos] > 0 && countlib(pos) < 5) { 
    11891178      int libs[4]; 
    11901179      int liberties = findlib(pos, 4, libs); 
     
    12121201        } 
    12131202      } 
    12141203    } 
    1215   } 
     1204  ) 
    12161205} 
    12171206 
    12181207static void 
     
    12321221 
    12331222  compute_active_owl_type_area(goal, goal_color, active); 
    12341223 
    1235   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1224  scan_board(pos, 
    12361225    int value = board[pos]; 
    1237     if (!ON_BOARD(pos)) 
    1238       continue; 
     1226 
    12391227    if (!active[pos]) 
    12401228      value = GRAY; 
    12411229    else if (IS_STONE(board[pos]) && countlib(pos) > 4 && active[pos] > 0) 
    12421230      value |= HIGH_LIBERTY_BIT; 
    12431231     
    12441232    entry->board[pos] = value; 
    1245   } 
     1233  ) 
    12461234} 
    12471235 
    12481236 
     
    12791267  signed char goal[BOARDMAX]; 
    12801268  int pos; 
    12811269 
    1282   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    1283     if (ON_BOARD(pos)) 
    1284       goal[pos] = goala[pos] || goalb[pos]; 
     1270  scan_board(pos, 
     1271    goal[pos] = goala[pos] || goalb[pos]; 
     1272  ) 
    12851273 
    12861274  store_persistent_cache(&semeai_cache, routine, 
    12871275                         apos, bpos, cpos, color, goal_hash, 
     
    13151303  compute_active_owl_type_area(goal, BLACK, active_b); 
    13161304  compute_active_owl_type_area(goal, WHITE, active_w); 
    13171305 
    1318   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1306  scan_board(pos, 
    13191307    int value = board[pos]; 
    1320     if (!ON_BOARD(pos)) 
    1321       continue; 
     1308 
    13221309    if (!active_b[pos] && !active_w[pos]) 
    13231310      value = GRAY; 
    13241311    else if (IS_STONE(board[pos]) && countlib(pos) > 4 
     
    13261313      value |= HIGH_LIBERTY_BIT; 
    13271314     
    13281315    entry->board[pos] = value; 
    1329   } 
     1316  ) 
    13301317} 
    13311318 
    13321319 
     
    13411328  int k; 
    13421329  if (!IS_STONE(board[dr])) 
    13431330    return; 
    1344   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1331  scan_board(pos, 
    13451332    if (board[pos] != EMPTY) 
    13461333      continue; 
    13471334    for (k = 0; k < 8; k++) { 
     
    13801367    if (k == 8 && active_board[pos] == EMPTY) { 
    13811368      values[pos] -= 0.5 * contribution; 
    13821369    } 
    1383   } 
     1370  ) 
    13841371} 
    13851372   
    13861373