Ticket #163: semeai.diff

File semeai.diff, 6.9 KB (added by draqo, 5 years ago)
  • engine/owl.c

    diff -N -r -u -X .ignore gnugo-copy/engine/owl.c gnugo/engine/owl.c
    old new  
    670670  struct eyevalue probable_eyes_a; 
    671671  struct eyevalue probable_eyes_b; 
    672672  struct eyevalue dummy_eyes; 
     673  int I_have_more_eyes; 
    673674   
    674675  SETUP_TRACE_INFO2("do_owl_analyze_semeai", apos, bpos); 
    675676 
     
    804805  if (!owl_phase) { 
    805806    set_eyevalue(&probable_eyes_a, 0, 0, 0, 0); 
    806807    set_eyevalue(&probable_eyes_b, 0, 0, 0, 0); 
     808    I_have_more_eyes = 0; 
    807809  } 
    808810  else { 
    809811    /* First the vital moves. These include moves to attack or 
     
    893895                                     shape_defensive_moves, 1, owla)) 
    894896          break; 
    895897    } 
     898    else 
     899      shape_defensive_moves[0].pos = 0; 
     900 
    896901    owl_shapes(&shape_offensive_patterns, shape_offensive_moves, color, owlb,  
    897902               &owl_attackpat_db); 
    898903    for (k = 0; k < MAX_MOVES-1; k++) 
    899904      if (!get_next_move_from_list(&shape_offensive_patterns, color, 
    900905                                   shape_offensive_moves, 1, owla)) 
    901906        break; 
    902      
     907 
     908    /* Filter out moves, which fills our eye (and not split it). */ 
     909    if (eyemax_a == 1) { 
     910      int n; 
     911      struct owl_move_data *checked_moves; 
     912 
     913      for (n = 1; n <= 5; n++) { 
     914        switch (n) { 
     915        case 1: 
     916          checked_moves = moves; 
     917          break; 
     918        case 2: 
     919          checked_moves = vital_defensive_moves; 
     920          break; 
     921        case 3: 
     922          checked_moves = vital_offensive_moves; 
     923          break; 
     924        case 4: 
     925          checked_moves = shape_defensive_moves; 
     926          break; 
     927        case 5: 
     928          checked_moves = shape_offensive_moves; 
     929          break; 
     930        } 
     931 
     932        for (k = 0; k < MAX_MOVES; k++) { 
     933          if (checked_moves[k].pos <= 0) 
     934            break; 
     935          else { 
     936            struct eye_data *eye = &owla->my_eye[checked_moves[k].pos]; 
     937 
     938            /* If esize==1 this eye must not be a real eye (at least one 
     939             * worm is capturable, otherwise this move would not be 
     940             * proposed). 
     941             */ 
     942            if (eye->color == color && eye->msize == 0 && eye->neighbors <= 1 
     943                && eye->esize != 1 
     944                && owla->half_eye[checked_moves[k].pos].type != HALF_EYE 
     945                && !has_neighbor(checked_moves[k].pos, OTHER_COLOR(color))) 
     946              checked_moves[k].value = 0; 
     947          } 
     948        } 
     949      } 
     950    } 
     951 
    903952    /* Now we review the moves already considered, while collecting 
    904953     * them into a single list.  
    905954     */ 
     
    9541003      include_semeai_worms_in_eyespace = 0; 
    9551004    } 
    9561005 
     1006    if (eyemin_a == eyemax_a) 
     1007      /* We have stable number of eyes, so we can try to reduce 
     1008       * opponent eyes. */ 
     1009      I_have_more_eyes = (eyemin_a > min_eyes(&probable_eyes_b)); 
     1010    else { 
     1011      if (min_eyes(&probable_eyes_a) == max_eyes(&probable_eyes_a)) 
     1012        /* If we can't increase our number of eyes, we try to reduce 
     1013         * opponent eyes. */ 
     1014        I_have_more_eyes = (max_eyes(&probable_eyes_a) > min_eyes(&probable_eyes_b)); 
     1015      else 
     1016        /* If we can increase our number of eyes, we do it and let 
     1017         * opponent to increase his. */ 
     1018        I_have_more_eyes = (max_eyes(&probable_eyes_a) > max_eyes(&probable_eyes_b)); 
     1019    } 
     1020 
    9571021    if (get_level() < 8) { 
    9581022      /* If no owl moves were found on two consecutive moves, 
    9591023       * turn off the owl phase. 
     
    9771041   
    9781042  /* Now we look for a move to fill a liberty. This is only 
    9791043   * interesting if the opponent doesn't already have two eyes. 
     1044   * If we have more eyes, always check for a backfilling move. 
    9801045   */ 
    9811046  if (!you_look_alive 
    982       && !safe_outside_liberty_found && moves[0].value < 110) { 
     1047      && !safe_outside_liberty_found 
     1048      && (moves[0].value < 110 || I_have_more_eyes)) { 
    9831049    int pos; 
    9841050    for (pos = BOARDMIN; pos < BOARDMAX; pos++) { 
    9851051      if (!ON_BOARD(pos)) 
    986         continue; 
     1052        continue; 
    9871053       
    9881054      if (board[pos] == EMPTY && !mw[pos]) { 
    9891055        if (liberty_of_goal(pos, owlb)) { 
     
    9951061              break; 
    9961062            } 
    9971063            else if (backfill_outside_liberty.pos == NO_MOVE) 
    998               backfill_outside_liberty.pos = find_semeai_backfilling_move(bpos, 
    999                                                                           pos); 
     1064              backfill_outside_liberty.pos = 
     1065                find_semeai_backfilling_move(bpos, pos); 
    10001066          } 
    10011067          else { 
    10021068            /* common liberty */ 
     
    10051071              common_liberty.pos = pos; 
    10061072            } 
    10071073            else if (backfill_common_liberty.pos == NO_MOVE) 
    1008               backfill_common_liberty.pos = find_semeai_backfilling_move(bpos, 
    1009                                                                         pos); 
     1074              backfill_common_liberty.pos = 
     1075                find_semeai_backfilling_move(bpos, pos); 
    10101076          } 
    10111077        } 
    10121078      } 
     
    10931159    if (mpos == NO_MOVE) 
    10941160      break; 
    10951161 
     1162    if (moves[k].value == 0) 
     1163      continue; 
     1164 
    10961165    /* Do not try too many moves. */ 
    10971166    if (tested_moves > 2 
    10981167        || (stackp > semeai_branch_depth2 && tested_moves > 1) 
     
    12811350  gg_assert(this_resulta != NULL && this_resultb != NULL); 
    12821351  *this_resulta = 0; 
    12831352  *this_resultb = 0; 
    1284   if (!komaster_trymove(move, color, move_name, apos, &ko_move, ko_allowed)) 
     1353 
     1354  if (!komaster_trymove(move, color, move_name, apos, &ko_move, ko_allowed)) { 
     1355    /* Move was not allowed because of komaster. We want to check, if this 
     1356     * situation is double ko and when it is, we won semeai. 
     1357     */ 
     1358    int libs[MAX_LIBERTIES]; 
     1359    int n; 
     1360    int nlib; 
     1361    int sworm; 
     1362    int worm_color; 
     1363 
     1364    for (sworm = 0; sworm < s_worms; sworm++) { 
     1365      worm_color = board[semeai_worms[sworm]]; 
     1366      if (worm_color == color && *this_resulta == 0) { 
     1367        /* We only check up to MAX_LIBERTIES, due to performance reasons. When we 
     1368         * have more liberties we have some outside liberties to fill and these 
     1369         * moves will be tried later (and double ko situation will be found). 
     1370         */ 
     1371        nlib = findlib(semeai_worms[sworm], MAX_LIBERTIES, libs); 
     1372        if (nlib > MAX_LIBERTIES) 
     1373          return 0; 
     1374 
     1375        for (n = 0; n < nlib; n++) 
     1376          if (is_ko(libs[n], OTHER_COLOR(color), NULL)) { 
     1377            /* Our dragon has double ko, but we have to check if opponent dragon 
     1378             * doesn't have outside liberties or double ko. 
     1379             */ 
     1380            *this_resulta = WIN; 
     1381            *this_resultb = WIN; 
     1382          } 
     1383      } 
     1384      else if (worm_color == OTHER_COLOR(color)) { 
     1385        nlib = findlib(semeai_worms[sworm], 2, libs); 
     1386        if (nlib > 2) 
     1387          /* In double ko situation the opponent can have only 
     1388           * a single eye and a ko outside liberty to be sure that we 
     1389           * will always win double ko. */ 
     1390          return 0; 
     1391      } 
     1392    } 
     1393 
     1394    if (*this_resulta == WIN) 
     1395      return 1; 
     1396 
    12851397    return 0; 
     1398  } 
    12861399   
    12871400  semeai_add_sgf_comment(move_value, owl_phase); 
    12881401  TRACE("Trying %C %1m. Current stack: ", color, move); 
     
    14511564    if (move == NO_MOVE) 
    14521565      break; 
    14531566 
     1567    if (owl_moves[k].value == 0) 
     1568      continue; 
     1569 
    14541570    /* Does the move fill a liberty in the semeai? */ 
    14551571    if (liberty_of_goal(move, owlb) 
    14561572        && safe_move(move, color)) { 
  • patterns/conn.db

    diff -N -r -u -X .ignore gnugo-copy/patterns/conn.db gnugo/patterns/conn.db
    old new  
    611611Bc 
    612612dA 
    613613 
    614 ;(attack(A) || attack(B)) && !oplay_disconnect(c,d) 
     614;lib(c)<=1 || lib(d)<=1 || xplay_defend_both(A,B) ? 0 : (amalgamate(c,d), 0) 
    615615 
    616616 
    617617Pattern CC506