Changeset 230

Show
Ignore:
Timestamp:
03/02/07 00:27:09 (1 year ago)
Author:
ug
Message:

Fixed continuation statistics for Algo_hash_full.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo/cpptest.cpp

    r229 r230  
    6767  // Pattern p(2,3,4,6, 19, 3, 3, ".X.XXXXOX", vector<MoveNC>());  
    6868   
    69   Pattern p(CORNER_NW_PATTERN,19,8,8,"...................X......X.......XO......OO...................."); 
     69  // Pattern p(CORNER_NW_PATTERN,19,8,8,"...................X......X.......XO......OO...................."); 
    7070  // Pattern p(CORNER_NW_PATTERN,19,7,7,".................X.....X......XO.....OO.........."); 
    7171  // Pattern p(CORNER_NW_PATTERN,19,7,7,".......................X........................."); 
    7272 
    7373  // gl.gisearch("pw = 'Hane Naoki'"); 
    74   // Pattern p(CENTER_PATTERN, 19, 3, 5, ".X..OX.OX.OXOXO"); 
     74  Pattern p(CENTER_PATTERN, 19, 3, 5, ".X..OX.OX.OXOXO"); 
    7575  // vector<MoveNC> contList; 
    7676  // contList.push_back(MoveNC(6,15,'X')); 
     
    8080  // Pattern p(FULLBOARD_PATTERN, 19, 19, 19, "..O.O....X...XXXXX.OOXO....OXO.XXOOOXOXXXXOO.OOXO.OXO..O..X.X..OOX,X.XO.O.....XOOOXOXX..XO......X.XOXXX..XXXO........XOX..XXOOXO.OOO.....OOXOXOO.O...XX...X..OXXOO.XOX........O..OX.,..X..X.....X...OX...X..........O....XXXO...XO...X...OOOXOOXX...X....O..OX.O..OX..........OXX....OX..OO..O.OOOOX..O.OX..XX..OOXXXOX.XOOX..X....XXXXXOX...OX.......X.O.XO............."); 
    8181 
     82  // Pattern p(FULLBOARD_PATTERN,19,19,19,"........................................................................O......................................................................................................................................................................................................................X........................................................................."); 
     83 
    8284  // -------------------- set up search options ---------------------------------- 
    8385  SearchOptions so; 
     86  // so.trustHashFull = true; 
    8487  // SearchOptions so(0,0,50); // use move limit 
    8588  // so.searchInVariations = false; 
     
    9093 
    9194  // ------------------- print some information about current list of games ------------ 
    92   printf("num games: %d, num hits: %d=%d\n", gl.size(), gl.numHits(), gl.num_hits); 
     95  printf("num games: %d, num hits: %d\n", gl.size(), gl.numHits()); 
    9396  // vector<string> res = gl.currentEntriesAsStrings(); 
    9497  // for(vector<string>::iterator it = res.begin(); it != res.end(); it++) 
     
    110113  printf("num hits: %d, num switched: %d, B wins: %d, W wins: %d\n", gl.num_hits, gl.num_switched, gl.Bwins, gl.Wwins); 
    111114 
    112   printf("Continuation | Black ( B wins / W wins ) | White (B wins / W wins) |\n"); 
     115  printf("Continuation | Black      ( B wins / W wins ) | White      (B wins / W wins) |\n"); 
    113116  for(int y=0; y<p.sizeY; y++) { 
    114117    for(int x=0; x<p.sizeX; x++) { 
    115118      if (gl.lookupLabel(x,y) != '.') { 
    116119        Continuation cont = gl.lookupContinuation(x,y); 
    117         printf("      %c      |   %3d (    %3d /    %3d ) |   %3d (   %3d /    %3d) | %1.1f /  %1.1f \n", 
    118             gl.lookupLabel(x,y), cont.B, cont.wB, cont.lB, cont.W, cont.wW, cont.lW,  
     120        printf("      %c      |   %3d[%3d] (    %3d /    %3d ) |   %3d[%3d] (   %3d /    %3d) | %1.1f /  %1.1f \n", 
     121            gl.lookupLabel(x,y), cont.B, cont.tB, cont.wB, cont.lB, cont.W, cont.tW, cont.wW, cont.lW,  
    119122            cont.wW*100.0/cont.W, cont.wB*100.0/cont.B); 
    120123      } 
  • 06/libkombilo/search.cpp

    r229 r230  
    722722  yy = symmetries[index].getY(x,y); 
    723723  cSymm = symmetries[index].getCS(x,y); 
    724   if (co == 'X') { 
     724  if (co == 'X' || co == 'B') { 
    725725    if (cSymm) cc = 'W'; else cc = 'B'; 
    726726  } else { 
     
    23132313 
    23142314int Algo_hash_full::search(PatternList& patternList, GameList& gl, SearchOptions& options, sqlite3* db) { 
     2315  // printf("enter algo_hash_full::search\n"); 
     2316  int numOfHits = 0; 
     2317  int self_numOfSwitched = 0; 
     2318  int Bwins = 0; 
     2319  int Wwins = 0; 
     2320 
    23152321  int hash_result = -1; // -1 = failure; 0 = ok, but have to check w/ Algo_movelist, 1 = ok, produced final result 
    23162322  int plS = patternList.size(); 
     
    23362342 
    23372343      if (hash_result) { 
     2344        gl.setCurrentFromIndex(index); 
     2345        int numOfSwitched = 0; 
    23382346        vector<Hit* >* hits = new vector<Hit* >; 
    23392347        while ((*resultIT)->gameid == index) { 
     
    23462354            label = patternList.updateContinuations((*resultIT)->orientation,  
    23472355                                                    (*resultIT)->cont->x, (*resultIT)->cont->y, (*resultIT)->cont->color, 
    2348                                                     false, gl.getCurrentWinner()); 
     2356                                                    false, // tenuki impossible with full board pattern 
     2357                                                    gl.getCurrentWinner()); 
    23492358            if (label) { 
    23502359              hits->push_back(new Hit((*resultIT)->emn, label)); 
    23512360              (*resultIT)->emn = 0; 
     2361              numOfSwitched += label[2]; 
    23522362            } 
    23532363          } else { 
     
    23562366            label[1] = 0; 
    23572367            label[2] = patternList.data[(*resultIT)->orientation].colorSwitch; 
     2368            numOfSwitched += label[2]; 
    23582369            hits->push_back(new Hit((*resultIT)->emn, label)); 
    23592370            (*resultIT)->emn = 0; 
     
    23622373          if (resultIT == results->end()) break; 
    23632374        } 
    2364         if (hits->size()) gl.makeIndexHit(index, hits); 
    2365         else delete hits; 
     2375        if (hits->size()) { 
     2376          numOfHits += hits->size(); 
     2377          self_numOfSwitched += numOfSwitched; 
     2378          if (gl.getCurrentWinner() == 'B') { 
     2379            Bwins += hits->size() - numOfSwitched; 
     2380            Wwins += numOfSwitched; 
     2381          } else if (gl.getCurrentWinner() == 'W') { 
     2382            Bwins += numOfSwitched; 
     2383            Wwins += hits->size() - numOfSwitched; 
     2384          } 
     2385          gl.makeCurrentHit(hits); 
     2386        } else delete hits; 
    23662387      } else { // produce Candidate list, check using another algorithm 
    23672388        vector<Candidate* >* candidates = new vector<Candidate* >; 
     
    23792400    gl.end_sorted(); 
    23802401  } 
    2381   return 0; 
     2402  gl.num_hits = numOfHits; 
     2403  gl.num_switched = self_numOfSwitched; 
     2404  gl.Bwins = Bwins; 
     2405  gl.Wwins = Wwins; 
     2406  return hash_result; 
    23822407} 
    23832408 
     
    37363761  sort(gle->hits->begin(), gle->hits->end(), Hit::cmp_pts); 
    37373762  currentList->push_back((*oldList)[current]); 
     3763} 
     3764 
     3765void GameList::setCurrentFromIndex(int index) { 
     3766  int start = current; 
     3767  int end = oldList->size(); 
     3768  int m = start; 
     3769  while (start < end) { 
     3770    m = (end+start)/2; 
     3771    if (index == (*oldList)[m].first) { 
     3772      break; 
     3773    } else { 
     3774      if (index < (*oldList)[m].first) end = m; 
     3775      else start = m+1; 
     3776    } 
     3777  } 
     3778  current = m; 
    37383779} 
    37393780 
  • 06/libkombilo/search.h

    r229 r230  
    658658    void makeIndexCandidate(int index, std::vector<Candidate* > *candidates); 
    659659    void makeIndexHit(int index, std::vector<Hit* > *hits); 
     660    void setCurrentFromIndex(int index); 
    660661 
    661662  private: