Ticket #145: owl.c.patch

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

    RCS file: /sources/gnugo/gnugo/engine/owl.c,v
    retrieving revision 1.251
    diff -u -r1.251 owl.c
     
    453453  sgf_dumptree = NULL; 
    454454  if (verbose > 0) 
    455455    verbose--; 
    456   for (str = BOARDMIN; str < BOARDMAX; str++)  
    457     if (ON_BOARD(str) && ms[str] && worm[str].origin == str) { 
     456  scan_board(str, 
     457    if (ms[str] && worm[str].origin == str) { 
    458458      int adj; 
    459459      int adjs[MAXCHAIN]; 
    460460      int k; 
     
    493493        semeai_worms[s_worms++] = str; 
    494494        DEBUG(DEBUG_SEMEAI, "semeai worm: %1m\n", str); 
    495495      } 
    496     } 
     496        } 
     497  ) 
    497498  verbose = save_verbose; 
    498499  sgf_dumptree = save_sgf_dumptree; 
    499500 
     
    981982  if (!you_look_alive 
    982983      && !safe_outside_liberty_found && moves[0].value < 110) { 
    983984    int pos; 
    984     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    985       if (!ON_BOARD(pos)) 
    986         continue; 
     985    scan_board(pos, 
    987986       
    988987      if (board[pos] == EMPTY && !mw[pos]) { 
    989988        if (liberty_of_goal(pos, owlb)) { 
     
    10101009          } 
    10111010        } 
    10121011      } 
    1013     } 
     1012        ) 
    10141013  } 
    10151014 
    10161015  /* Add the best liberty filling move available. We first want to 
     
    15161515  /* Never try to fill opponent's eyes which contain our dragon.  This 
    15171516   * is nothing else than suicide. 
    15181517   */ 
    1519   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    1520     if (ON_BOARD(pos) && owla->goal[pos]) 
     1518  scan_board(pos, 
     1519    if (owla->goal[pos]) 
    15211520      mw[owlb->my_eye[pos].origin] = 0; 
    1522   } 
     1521  ) 
    15231522 
    1524   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1523  scan_board(pos, 
    15251524    if (board[pos] == EMPTY) { 
    15261525      int origin = owlb->my_eye[pos].origin; 
    15271526 
     
    15461545          return pos; 
    15471546      } 
    15481547    } 
    1549   } 
     1548  ) 
    15501549 
    15511550  return NO_MOVE; 
    15521551} 
     
    15731572  ASSERT1(board[move] == EMPTY, move); 
    15741573  verbose = 0; 
    15751574  if (safe_move(move, color)) { 
    1576     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1575    scan_board(pos, 
    15771576      if (IS_STONE(board[pos]) 
    15781577          && pos == find_origin(pos)) { 
    15791578        if (owla->goal[pos]) 
     
    15811580        if (owlb->goal[pos]) 
    15821581          net += 100*countlib(pos);        
    15831582      } 
    1584     } 
     1583        ) 
    15851584    if (!trymove(move, color, NULL, 0)) { 
    15861585      verbose = save_verbose; 
    15871586      return 0; 
    15881587    } 
    1589     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     1588    scan_board(pos, 
    15901589      if (IS_STONE(board[pos]) 
    15911590          && pos == find_origin(pos)) { 
    15921591        if (owla->goal[pos] 
     
    15951594        if (owlb->goal[pos]) 
    15961595          net -= 100*countlib(pos); 
    15971596      } 
    1598     } 
     1597        ) 
    15991598 
    16001599    increase_depth_values(); 
    16011600    for (k = 0; k < s_worms; k++) { 
     
    23602359           */ 
    23612360           
    23622361          if (board[target] == EMPTY) { 
    2363             for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     2362            scan_board(pos, 
    23642363              if (IS_STONE(board[pos]) && owl->goal[pos] == 1) { 
    23652364                origin = find_origin(pos); 
    23662365                break; 
    23672366              } 
    2368             } 
     2367                ) 
    23692368             
    23702369            if (origin == NO_MOVE 
    23712370                || do_owl_attack(origin, NULL, NULL, owl, 0)) { 
     
    26552654 
    26562655        /* If the goal is small, try a tactical defense. */ 
    26572656 
    2658         for (k = BOARDMIN; k < BOARDMAX; k++) 
    2659           if (ON_BOARD(k)) 
    2660             goalcount += owl->goal[k]; 
     2657        scan_board(k, 
     2658          goalcount += owl->goal[k]; 
     2659        ) 
    26612660 
    26622661        if (goalcount < 5) { 
    26632662 
     
    30873086  owl_find_relevant_eyespaces(owl, mw, mz); 
    30883087 
    30893088  /* Reset halfeye data. Set topological eye value to something big. */ 
    3090   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    3091     if (ON_BOARD(pos)) { 
    3092       owl->half_eye[pos].type = 0; 
    3093       owl->half_eye[pos].value = 10.0; 
    3094     } 
    3095   } 
     3089  scan_board(pos, 
     3090    owl->half_eye[pos].type = 0; 
     3091    owl->half_eye[pos].value = 10.0; 
     3092  ) 
    30963093   
    30973094  /* Find topological half eyes and false eyes. */ 
    30983095  find_half_and_false_eyes(color, eye, owl->half_eye, mw); 
     
    31063103   
    31073104  set_eyevalue(probable_eyes, 0, 0, 0, 0); 
    31083105 
    3109   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    3110     if (ON_BOARD(pos) && mw[pos] > 1) { 
     3106  scan_board(pos, 
     3107    if (mw[pos] > 1) { 
    31113108      int value = 0; 
    31123109      const char *reason = ""; 
    31133110      compute_eyes_pessimistic(pos, &eyevalue, &pessimistic_min, 
     
    31323129       * that the pessimistic min is 0. 
    31333130       */ 
    31343131      if (pessimistic_min > 0) { 
    3135         for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { 
    3136           if (ON_BOARD(pos2) 
    3137               && eye[pos2].origin == pos 
     3132        scan_board(pos2, 
     3133          if (eye[pos2].origin == pos 
    31383134              && owl->inessential[pos2]) { 
    31393135            pessimistic_min = 0; 
    31403136            break; 
    31413137          } 
    3142         } 
     3138        ) 
    31433139      } 
    31443140#endif 
    31453141 
     
    32633259      } 
    32643260      num_eyes++; 
    32653261    } 
    3266   } 
     3262  ) 
    32673263 
    32683264  /* Sniff each lunch for nutritional value. The assumption is that 
    32693265   * capturing the lunch is gote, therefore the number of half eyes 
     
    34113407 
    34123408  memset(mw, 0, BOARDMAX * sizeof(mw[0])); 
    34133409  memset(mz, 0, BOARDMAX * sizeof(mz[0])); 
    3414   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     3410  scan_board(pos, 
    34153411    if (board[pos] == owl->color) { 
    34163412      for (k = 0; k < 8; k++) { 
    34173413        int pos2 = pos + delta[k]; 
     
    34253421        } 
    34263422      } 
    34273423    } 
    3428   } 
     3424  ) 
    34293425} 
    34303426 
    34313427/* Case 1. 
     
    40374033   * and calculate initial chain values (as if all patterns passed 
    40384034   * constraint validation). 
    40394035   */ 
    4040   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     4036  scan_board(pos, 
    40414037    if (list->first_pattern_index[pos] != -1) { 
    40424038      struct matched_pattern_data *pattern_data 
    40434039        = &list->pattern_list[list->first_pattern_index[pos]]; 
     
    40454041      pattern_data->value = valuate_combinable_pattern_chain(list, pos); 
    40464042      list->pattern_heap[list->heap_num_patterns++] = pattern_data; 
    40474043    } 
    4048   } 
     4044  ) 
    40494045 
    40504046  if (list->heap_num_patterns > 0) 
    40514047    pattern_list_build_heap(list); 
     
    45794575  ASSERT1(bpos == NO_MOVE || board[bpos] == color, bpos); 
    45804576 
    45814577  if (new_dragons == NULL) { 
    4582     for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    4583       if (ON_BOARD(pos)) { 
    4584         if (is_same_dragon(pos, apos) || is_same_dragon(pos, bpos)) 
    4585           owl->goal[pos] = 1; 
    4586         else 
    4587           owl->goal[pos] = 0; 
    4588       } 
     4578    scan_board(pos, 
     4579          if (is_same_dragon(pos, apos) || is_same_dragon(pos, bpos)) 
     4580            owl->goal[pos] = 1; 
     4581          else 
     4582            owl->goal[pos] = 0; 
     4583        ) 
    45894584  } 
    45904585  else { 
    4591     for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    4592       if (ON_BOARD(pos)) { 
    4593         if (IS_STONE(board[pos]) 
    4594             && (new_dragons[pos] == new_dragons[apos] 
    4595                 || new_dragons[pos] == new_dragons[bpos])) 
    4596           owl->goal[pos] = 1; 
    4597         else 
    4598           owl->goal[pos] = 0; 
    4599       } 
     4586    scan_board(pos, 
     4587          if (IS_STONE(board[pos]) 
     4588              && (new_dragons[pos] == new_dragons[apos] 
     4589                  || new_dragons[pos] == new_dragons[bpos])) 
     4590            owl->goal[pos] = 1; 
     4591          else 
     4592            owl->goal[pos] = 0; 
     4593        ) 
    46004594  } 
    46014595 
    46024596  memcpy(owl->cumulative_goal, owl->goal, sizeof(owl->goal)); 
     
    46174611   
    46184612  ASSERT1(bpos == NO_MOVE || board[bpos] == color, bpos); 
    46194613 
    4620   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    4621     if (ON_BOARD(pos)) { 
     4614  scan_board(pos, 
    46224615      if (is_same_worm(pos, apos) || is_same_worm(pos, bpos)) 
    46234616        owl->goal[pos] = 1; 
    46244617      else 
    46254618        owl->goal[pos] = 0; 
    4626     } 
     4619  ) 
    46274620 
    46284621  owl->color = color; 
    46294622} 
     
    46454638  memset(owl->neighbors, 0, sizeof(owl->neighbors)); 
    46464639 
    46474640  /* Find all friendly neighbors of the dragon in goal. */ 
    4648   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     4641  scan_board(pos, 
    46494642    if (board[pos] == color && owl->goal[pos]) { 
    46504643      for (k = 0; k < 4; k++) { 
    46514644        if (board[pos + delta[k]] == EMPTY 
     
    46644657          mark_string(pos2, owl->neighbors, 1); 
    46654658      } 
    46664659    } 
    4667   } 
     4660  ) 
    46684661 
    46694662  /* First find all boundary strings (including those adjacent not to 
    46704663   * the goal dragon, but one of its neighbors). 
    46714664   */ 
    4672   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
     4665  scan_board(pos, 
    46734666    if (board[pos] == other && !owl->boundary[pos]) { 
    46744667      for (k = 0; k < 8; k++) 
    46754668        if (ON_BOARD(pos + delta[k]) 
     
    46774670          mark_string(pos, owl->boundary, 1); 
    46784671          break; 
    46794672        } 
    4680     } 
     4673        } 
     4674  ) 
    46814675 
    46824676  /* Upgrade the mark of a boundary string if it adjoins a safe 
    46834677   * friendly dragon. 
    46844678   */ 
    4685   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
     4679  scan_board(pos, 
    46864680    if (owl->boundary[pos] == 1) { 
    46874681      for (k = 0; k < 8; k++) { 
    46884682        int pos2 = pos + delta[k]; 
     
    46954689          break; 
    46964690        } 
    46974691      } 
    4698     } 
     4692        } 
     4693  ) 
    46994694   
    47004695  /* During the owl reading, stones farther away may become parts of 
    47014696   * the boundary. We mark those strings neighboring some other 
    47024697   * friendly dragon with boundary value 2 right away, since we have 
    47034698   * no mechanism for detecting this later. 
    47044699   */ 
    4705   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
     4700  scan_board(pos, 
    47064701    if (board[pos] == other && owl->boundary[pos] == 0) { 
    47074702      /* If a lunch has been amalgamated into a larger dragon, we 
    47084703       * have to back out now. 
     
    47294724          break; 
    47304725        } 
    47314726      } 
    4732     } 
     4727        } 
     4728  ) 
    47334729} 
    47344730 
    47354731/* Add the stone just played to the goal dragon if same_dragon is 
     
    49814977    /* Now put each goal string to the component to which it has the 
    49824978     * smallest distance. 
    49834979     */ 
    4984     for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     4980    scan_board(pos, 
    49854981      int closest_dist = HUGE_CONNECTION_DISTANCE; 
    49864982      int closest_component = -1; 
    49874983      if (board[pos] != color || !goal[pos]) 
     
    49994995        mark_string(pos, component2, closest_component); 
    50004996        component_size[closest_component] += countstones(pos); 
    50014997      } 
    5002     } 
     4998        ) 
    50034999 
    50045000    /* Now find the biggest_component. */ 
    50055001    { 
     
    50135009    } 
    50145010 
    50155011    /* Now delete everything except the biggest component from the goal. */ 
    5016     for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
     5012    scan_board(pos, 
    50175013      if (component2[pos] != biggest_component) 
    5018         goal[pos] = 0; 
     5014            goal[pos] = 0; 
     5015        ) 
     5016 
    50195017    if (debug & DEBUG_SPLIT_OWL) { 
    50205018      gprintf("Split dragon. Biggest component is %d (of %d).\n", 
    50215019              biggest_component, num_components); 
     
    50655063goaldump(const signed char goal[BOARDMAX]) 
    50665064{ 
    50675065  int pos; 
    5068   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    5069     if (ON_BOARD(pos) && goal[pos]) 
     5066  scan_board(pos, 
     5067    if (goal[pos]) 
    50705068      gprintf("%o%1m (%d)  ", pos, (int) goal[pos]); 
     5069  ) 
    50715070  gprintf("\n"); 
    50725071} 
    50735072 
     
    50755074componentdump(const signed char component[BOARDMAX]) 
    50765075{ 
    50775076  int pos; 
    5078   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    5079     if (ON_BOARD(pos) && component[pos] != -1) 
     5077  scan_board(pos, 
     5078    if (component[pos] != -1) 
    50805079      gprintf("%o%1m (%d)  ", pos, (int) component[pos]); 
     5080  ) 
    50815081  gprintf("\n"); 
    50825082} 
    50835083 
     
    51335133{ 
    51345134  int pos; 
    51355135 
    5136   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     5136  scan_board(pos, 
    51375137    if (!IS_STONE(board[pos]) 
    51385138        || dragon[pos].origin != pos) 
    51395139      continue; 
     
    53165316            "owl: %1m might defend the uncertain dragon at %1m at move %d\n", 
    53175317            DRAGON2(pos).owl_attack_point, pos, movenum+1); 
    53185318    } 
    5319   } 
     5319  ) 
    53205320} 
    53215321 
    53225322/* Use the owl code to determine whether the move at (move) makes 
     
    57325732  memset(owl->inessential, 0, sizeof(owl->inessential)); 
    57335733   
    57345734  memset(already_checked, 0, sizeof(already_checked)); 
    5735   for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
     5735  scan_board(pos, 
    57365736    if (board[pos] == color && owl->goal[pos]) { 
    57375737      /* Loop over the eight neighbors. */ 
    57385738      for (k = 0; k < 8; k++) { 
     
    58705870        } 
    58715871      } 
    58725872    } 
    5873   } 
     5873  ) 
    58745874 
    58755875  owl->lunches_are_current = 1; 
    58765876  sgf_dumptree = save_sgf_dumptree; 
     
    64486448select_new_goal_origin(int origin, struct local_owl_data *owl) 
    64496449{ 
    64506450  int pos; 
    6451   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
     6451  scan_board(pos, 
    64526452    if (board[pos] == owl->color && owl->goal[pos] == 1) 
    64536453      return find_origin(pos); 
     6454  ) 
    64546455 
    64556456  return origin; 
    64566457} 
     
    65276528              compute_escape_influence(owl->color, safe_stones, owl->goal, NULL, 
    65286529                                       escape_values); 
    65296530 
    6530               for (pos2 = BOARDMIN; pos2 < BOARDMAX; pos2++) { 
    6531                 if (ON_BOARD(pos2)) 
    6532                   dragon[pos2] = is_same_dragon(pos2, pos); 
    6533               } 
     6531              scan_board(pos2, 
     6532                    dragon[pos2] = is_same_dragon(pos2, pos); 
     6533                  ) 
    65346534 
    65356535              if (dragon_escape(dragon, owl->color, escape_values) > 5) 
    65366536                owl->escape_values[pos] = 4; 
     
    67316731  signed char modified_escape[BOARDMAX]; 
    67326732  int pos; 
    67336733  memcpy(modified_escape, owl->escape_values, sizeof(modified_escape)); 
    6734   for (pos = BOARDMIN; pos < BOARDMAX; pos++) 
    6735     if (ON_BOARD(pos) && owl->cumulative_goal[pos]) 
     6734  scan_board(pos, 
     6735    if (owl->cumulative_goal[pos]) 
    67366736      modified_escape[pos] = 0; 
     6737  ) 
    67376738  return dragon_escape(owl->goal, owl->color, modified_escape); 
    67386739} 
    67396740 
     
    68636864  for (k = 0; k < MAX_GOAL_WORMS; k++) 
    68646865    goal_worm[k] = NO_MOVE; 
    68656866 
    6866   for (pos = BOARDMIN; pos < BOARDMAX && w < MAX_GOAL_WORMS; pos++) { 
    6867     if (ON_BOARD(pos) 
    6868         && board[pos] 
     6867  scan_board(pos, 
     6868    if (w >= MAX_GOAL_WORMS) 
     6869          break; 
     6870    if (board[pos] 
    68696871        && owl->goal[pos] == 1) { 
    68706872      int origin = find_origin(pos); 
    68716873      for (k = 0; k < w; k++) 
     
    68746876      if (k == w) 
    68756877        goal_worm[w++] = pos; 
    68766878    } 
    6877   } 
     6879  ) 
    68786880 
    68796881  /* experimental: let's try to fill up the array with other neighboring 
    68806882   * opponent worms 
     
    68876889      if (DRAGON(d).color != owl->color) 
    68886890        continue; 
    68896891 
    6890       for (ii = BOARDMIN; ii < BOARDMAX && w < MAX_GOAL_WORMS; ii++) 
    6891         if (ON_BOARD(ii) && board[ii] && worm[ii].origin == ii 
     6892          scan_board(ii, 
     6893            if (w >= MAX_GOAL_WORMS) 
     6894                  break; 
     6895            if (board[ii] && worm[ii].origin == ii 
    68926896            && worm[ii].size >= 3 && dragon[ii].id == d) 
    6893           goal_worm[w++] = ii; 
    6894     } 
     6897              goal_worm[w++] = ii; 
     6898          ) 
     6899        } 
    68956900  } 
    68966901 
    68976902  return w; 
     
    69466951  for (k = 0; k < MAX_WORMS; k++) 
    69476952    goal_worm[k] = NO_MOVE; 
    69486953 
    6949   for (pos = BOARDMIN; pos < BOARDMAX && worms < MAX_WORMS; pos++) 
    6950     if (ON_BOARD(pos) 
    6951         && board[pos] 
     6954  scan_board(pos, 
     6955    if (worms >= MAX_WORMS) 
     6956      break; 
     6957    if (board[pos] 
    69526958        && (owl->goal)[pos]) { 
    69536959      int origin = find_origin(pos); 
    69546960      if (pos == origin) { 
     
    69576963        } 
    69586964        goal_worm[worms++] = pos; 
    69596965      } 
    6960     } 
     6966        } 
     6967  ) 
    69616968  return worms; 
    69626969} 
    69636970#endif