Ticket #145: optics.c.patch

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

    RCS file: /sources/gnugo/gnugo/engine/optics.c,v
    retrieving revision 1.105
    diff -u -r1.105 optics.c
     
    118118    memset(w_eye, 0, BOARDMAX * sizeof(w_eye[0])); 
    119119 
    120120  /* Initialize eye data and compute the lively array. */ 
    121   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    122     if (ON_BOARD(pos)) 
    123       lively[pos] = is_lively(owl_call, pos); 
     121  scan_board(pos, 
     122    lively[pos] = is_lively(owl_call, pos); 
     123  ) 
    124124 
    125125  /* Compute the domains of influence of each color. */ 
    126126  compute_primary_domains(BLACK, black_domain, lively, false_margins, 1); 
     
    130130   * each eye shape. 
    131131   */ 
    132132 
    133   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    134     if (!ON_BOARD(pos)) 
    135       continue; 
     133  scan_board(pos, 
    136134     
    137135    if (board[pos] == EMPTY || !lively[pos]) { 
    138136      if (black_domain[pos] == 0 && white_domain[pos] == 0) { 
     
    191189        } 
    192190      } 
    193191    } 
    194   } 
     192  ) 
    195193   
    196194  /* The eye spaces are all found. Now we need to find the origins. */ 
    197195  partition_eyespaces(b_eye, BLACK); 
     
    207205  if (!eye) 
    208206    return; 
    209207 
    210   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    211     if (ON_BOARD(pos)) 
    212       eye[pos].origin = NO_MOVE; 
     208  scan_board(pos, 
     209    eye[pos].origin = NO_MOVE; 
     210  ) 
     211 
     212  scan_board(pos, 
    213213 
    214   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    215     if (!ON_BOARD(pos)) 
    216       continue; 
    217214    if (eye[pos].origin == NO_MOVE && eye[pos].color == color) { 
    218215      int esize = 0; 
    219216      int msize = 0; 
     
    222219      eye[pos].esize = esize; 
    223220      eye[pos].msize = msize; 
    224221    } 
    225   } 
     222  ) 
    226223 
    227224  /* Now we count the number of neighbors and marginal neighbors 
    228225   * of each vertex. 
     
    302299   *    (Cases (1) and (2) above.) 
    303300   * 2. Fill influence[] and threshold[] arrays with initial values. 
    304301   */ 
    305   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    306     if (!ON_BOARD(pos)) 
    307       continue; 
     302  scan_board(pos, 
    308303    
    309304    if (lively[pos]) { 
    310305      if (board[pos] == color) { 
     
    356351    } 
    357352    else if (is_edge_vertex(pos)) 
    358353      influence[pos]--; 
    359   } 
     354  ) 
    360355   
    361356  /* Now we loop over the board until no more vertices can be added to 
    362357   * the domain through case (3) above. 
     
    410405  int pos; 
    411406  int k; 
    412407 
    413   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    414     if (!ON_BOARD(pos) || eyedata[pos].origin == NO_MOVE)  
     408  scan_board(pos, 
     409    if (eyedata[pos].origin == NO_MOVE)  
    415410      continue; 
    416411 
    417412    eyedata[pos].esize = eyedata[eyedata[pos].origin].esize; 
     
    427422          eyedata[pos].marginal_neighbors++; 
    428423      } 
    429424    } 
    430   } 
     425  ) 
    431426} 
    432427 
    433428 
     
    565560{ 
    566561  int pos; 
    567562 
    568   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    569     if (ON_BOARD(pos) && eye[pos].origin == origin) { 
     563  scan_board(pos, 
     564    if (eye[pos].origin == origin) { 
    570565      eye[pos].color         = eye[origin].color; 
    571566      eye[pos].esize         = eye[origin].esize; 
    572567      eye[pos].msize         = eye[origin].msize; 
    573568      eye[pos].origin        = eye[origin].origin; 
    574569      eye[pos].value         = eye[origin].value; 
    575570    } 
     571  ) 
    576572} 
    577573 
    578574 
     
    591587 
    592588  memset(mx, 0, sizeof(mx)); 
    593589  DEBUG(DEBUG_MISCELLANEOUS, "find_eye_dragons: %1m %C\n", origin, eye_color); 
    594   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     590  scan_board(pos, 
    595591    if (board[pos] == eye_color 
    596592        && mx[dragon[pos].origin] == 0 
    597593        && ((ON_BOARD(SOUTH(pos)) 
     
    613609        dragons[num_dragons] = dragon[pos].origin; 
    614610      num_dragons++; 
    615611    } 
    616   } 
     612  ) 
    617613   
    618614  return num_dragons; 
    619615} 
     
    634630  gprintf("Eyespace at %1m: color=%C, esize=%d, msize=%d\n", 
    635631          pos, eye[pos].color, eye[pos].esize, eye[pos].msize); 
    636632   
    637   for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { 
    638     if (!ON_BOARD(pos2)) 
    639       continue; 
     633  scan_board(pos2, 
    640634     
    641635    if (eye[pos2].origin != pos)  
    642636      continue; 
     
    663657    } 
    664658    else 
    665659      gprintf("%1m\n", pos2); 
    666   } 
     660  ) 
    667661  gprintf("\n"); 
    668662   
    669663  /* Determine the size of the eye. */ 
     
    789783 
    790784  memset(chainlinks, 0, BOARDMAX); 
    791785 
    792   for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { 
     786  scan_board(pos2, 
    793787    int k; 
    794788 
    795     if (!ON_BOARD(pos2) || eye[pos2].origin != pos) 
     789    if (eye[pos2].origin != pos) 
    796790      continue; 
    797791 
    798792    if (eye[pos2].marginal || is_halfeye(heye, pos2)) { 
     
    819813      else if (!ON_BOARD(neighbor)) 
    820814        bulk_score += 2; 
    821815    } 
    822   } 
     816  ) 
    823817 
    824818  /* This is a measure based on the simplified assumption that both 
    825819   * players only cares about playing the marginal eye spaces. It is 
     
    891885    int best_defense_point = NO_MOVE; 
    892886    float score = 0.0; 
    893887     
    894     for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { 
    895       if (ON_BOARD(pos2) && eye[pos2].origin == pos) { 
     888    scan_board(pos2, 
     889      if (eye[pos2].origin == pos) { 
    896890        float this_score = 0.0; 
    897891        int this_attack_point = NO_MOVE; 
    898892        int this_defense_point = NO_MOVE; 
     
    922916          score = this_score; 
    923917        } 
    924918      } 
    925     } 
     919        ) 
    926920     
    927921    if (score > 0.0) { 
    928922      if (defense_point) 
    929923        *defense_point = best_defense_point; 
    930924      if (attack_point) 
    931925        *attack_point = best_attack_point; 
    932     } 
     926        } 
    933927  } 
    934928 
    935929  if (defense_point && *defense_point != NO_MOVE) { 
     
    10481042    return 0; 
    10491043 
    10501044  /* Find ko half eyes and "combination" half eyes if any. */ 
    1051   for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { 
    1052     if (ON_BOARD(pos2) 
    1053         && eye[pos2].origin == pos 
     1045  scan_board(pos2, 
     1046    if (eye[pos2].origin == pos 
    10541047        && heye[pos2].type == HALF_EYE) { 
    10551048      if (combination_halfeye == NO_MOVE) { 
    10561049        int apos = NO_MOVE; 
     
    10821075        ko_halfeye = pos2; 
    10831076      } 
    10841077    } 
    1085   } 
     1078  ) 
    10861079 
    10871080  /* In case we have a "combination" half eye, turn it into a proper eye 
    10881081   * vertex for a while and see what happens. 
     
    12301223    return 0; 
    12311224 
    12321225  /* Create list of eye vertices */ 
    1233   for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { 
    1234     if (!ON_BOARD(pos2)) 
    1235       continue; 
     1226  scan_board(pos2, 
    12361227    if (eye[pos2].origin == pos) { 
    12371228      vpos[eye_size] = pos2; 
    12381229      marginal[eye_size] = eye[pos2].marginal; 
     
    12711262       
    12721263      eye_size++; 
    12731264    } 
    1274   } 
     1265  ) 
    12751266   
    12761267  /* We attempt to construct a map from the graph to the eyespace 
    12771268   * preserving the adjacency structure. If this can be done, we've 
     
    16861677  int pos; 
    16871678  float sum; 
    16881679   
    1689   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1680  scan_board(pos, 
    16901681    /* skip eyespaces which owl doesn't want to be searched */ 
    1691     if (!ON_BOARD(pos) || (find_mask && find_mask[eye[pos].origin] <= 1)) 
     1682    if (find_mask && find_mask[eye[pos].origin] <= 1) 
    16921683      continue; 
    16931684     
    16941685    /* skip every vertex which can't be a false or half eye */ 
     
    17141705      ASSERT1(heye[pos].num_defenses > 0, pos); 
    17151706      ASSERT_ON_BOARD1(heye[pos].defense_point[0]); 
    17161707    } 
    1717   } 
     1708  ) 
    17181709} 
    17191710 
    17201711 
     
    23862377  } 
    23872378 
    23882379  /* Play white stones surrounding the eyespace, including diagonals. */ 
    2389   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    2390     if (!ON_BOARD(pos) || mx[pos] == 1) 
     2380  scan_board(pos, 
     2381    if (mx[pos] == 1) 
    23912382      continue; 
    23922383    for (k = 0; k < 8; k++) { 
    23932384      if (ON_BOARD(pos + delta[k]) && mx[pos + delta[k]] == 1) { 
     
    23962387        break; 
    23972388      } 
    23982389    } 
    2399   } 
     2390  ) 
    24002391 
    24012392  /* Play black stones surrounding the white group, but leaving all 
    24022393   * liberties empty. 
    24032394   */ 
    2404   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     2395  scan_board(pos, 
    24052396    if (mx[pos] == 1 || board[pos] != EMPTY || liberty_of_string(pos, str)) 
    24062397      continue; 
    24072398    for (k = 0; k < 8; k++) { 
     
    24112402        break; 
    24122403      } 
    24132404    } 
    2414   } 
     2405  ) 
    24152406 
    24162407  /* Show the board if verbose is on. Then turn off traces so we don't 
    24172408   * get any from make_worms(), make_dragons(), or the owl reading. 
     
    35153506  /* Mark the eyespace in the mx array. We construct the position in 
    35163507   * the mx array and copy it to the actual board later. 
    35173508   */ 
    3518   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    3519     if (ON_BOARD(pos)) 
    3520       mx[pos] = WHITE; 
     3509  scan_board(pos, 
     3510    mx[pos] = WHITE; 
     3511  ) 
    35213512 
    35223513  /* Find out the size of the eye graph pattern so that we can center 
    35233514   * it properly. 
     
    36323623 
    36333624  /* Copy the mx array over to the board. */ 
    36343625  clear_board(); 
    3635   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    3636     if (ON_BOARD(pos)) { 
     3626  scan_board(pos, 
    36373627      if (mx[pos] == WHITE) 
    36383628        add_stone(pos, WHITE); 
    36393629      else if (mx[pos] == BLACK) 
    36403630        add_stone(pos, BLACK); 
    3641     } 
     3631  ) 
    36423632 
    36433633  if (verbose) 
    36443634    showboard(0); 
     
    36463636  /* If there are any isolated O stones, those should also be added to 
    36473637   * the playable vertices. 
    36483638   */ 
    3649   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
     3639  scan_board(pos, 
    36503640    if (board[pos] == WHITE && !same_string(pos, POS(1, 0))) { 
    36513641      vertices[num_vertices] = vertices[num_vertices - 1]; 
    36523642      vertices[num_vertices - 1] = vertices[num_vertices - 2]; 
    36533643      vertices[num_vertices - 2] = vertices[num_vertices - 3]; 
    36543644      vertices[num_vertices - 3] = pos; 
    36553645      num_vertices++; 
    3656     } 
     3646        } 
     3647  ) 
    36573648 
    36583649  if (verbose) { 
    36593650    int k;