Changeset 175 for 06/devel

Show
Ignore:
Timestamp:
08/21/06 10:24:49 (2 years ago)
Author:
ug
Message:

Done some more work on pattern.cc; seems to work now.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/devel/aglPY.py

    r174 r175  
    554554        print "Build pattern list ..." 
    555555        patternList = PatternList(pattern, fixedColorVar, nextMoveVar, self.boardsize) 
    556         print "done" # FIXME 
     556        print "done, size:", patternList.size() # FIXME 
     557        for p in range(patternList.size()):  
     558            patternList.get(p).printPattern() 
     559            if patternList.get(p).colorSwitch: print 'CS' 
    557560 
    558561        if contLabels is None: 
     
    631634        if self.progBar: self.progBar.write('%1.1f seconds' % (time.time() - startTime)) 
    632635 
    633         return numOfHits, bw, ww, sw, continuations 
     636        return numOfHits, Bwins, Wwins, numSwitched, continuations 
    634637     
    635638 
  • 06/devel/algos.cc

    r174 r175  
    7979} 
    8080 
    81 void Algo_finalpos::B_process(int x, int y, cap) { 
     81void Algo_finalpos::B_process(int x, int y, PyObject* cap) { 
    8282  fp[y/2 + 10*(x/2)] &= ~(1 << (2*(x%2 + 2*(y%2)))); 
    8383} 
     
    100100 
    101101void Algo_finalpos::finalize_process(PyObject* datap) { 
    102        String fn = retrieve_datap0(datap) + "/finalpos" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
    103        ofstream file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
     102  String fn = retrieve_datap0(datap) + "/finalpos" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
     103  ofstream file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
    104104  file.write(finalpos, finalposSize); 
    105105  file.close(); 
     
    107107 
    108108 
    109 int Algo_finalpos::duplicateCheck(sli, datapath=None) { // FIXME None 
     109int Algo_finalpos::duplicateCheck(sli, datapath) { // FIXME argument types 
    110110  if (!strcmp(datapath, "")) { 
    111111    for(int i=0; i<100; i++) 
    112112      if (finalpos[sli*100+i] != fp[i]) 
    113                                return 0; 
     113        return 0; 
    114114    return 1; 
    115115  } 
    116    
    117   if (strcmp(currentDatap,datap)) { 
    118     delete [] currentDatap; 
    119     currentDatap = new char[strlen(datap)+1]; 
    120     strcpy(currentDatap, datap); 
    121  
    122     char* currentFP = new char[]; 
    123  
    124     try { 
    125       file = open(os.path.join(datap[0], 'finalpos'+datap[1]+'.db'), 'rb'); 
    126       while (1) { 
    127         try self.currentFP.fromfile(file, 1000000); 
    128         except EOFError break; 
    129       } 
    130       file.close(); 
    131     } 
    132     except return 0; 
    133   } 
    134    
    135   for(int i=0; i<100; i++) 
    136     if (currentFP[sli*100+i] != fp[i]) 
    137       return 0; 
    138   return 1;       
    139 
    140  
    141 int Algo_finalpos::retrieve_db(datap) { 
    142         String fn = retrieve_datap0(datap) + "/finalpos" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
    143         ifstream file (fn, ios::in|ios::binary|ios::ate); 
    144         if (file.is_open()) { 
    145                 ifstream::pos_type size = file.tellg(); 
    146                 delete [] finalpos; 
    147                 finalpos = new char[size]; 
    148                 file.seekg (0, ios::beg); 
    149                 file.read (memblock, size); 
    150                 file.close(); 
     116  return 0; // FIXME 
     117 
     118//   if (strcmp(currentDatap,datap)) { 
     119//     delete [] currentDatap; 
     120//     currentDatap = new char[strlen(datap)+1]; 
     121//     strcpy(currentDatap, datap); 
     122//  
     123//     char* currentFP = new char[]; 
     124//  
     125//     try { 
     126//       file = open(os.path.join(datap[0], 'finalpos'+datap[1]+'.db'), 'rb'); 
     127//       while (1) { 
     128//  try self.currentFP.fromfile(file, 1000000); 
     129//  except EOFError break; 
     130//       } 
     131//       file.close(); 
     132//     } 
     133//     except return 0; 
     134//   } 
     135//    
     136//   for(int i=0; i<100; i++) 
     137//     if (currentFP[sli*100+i] != fp[i]) 
     138//       return 0; 
     139//   return 1;    
     140
     141 
     142int Algo_finalpos::retrieve_db(PyObject* datap) { 
     143  String fn = retrieve_datap0(datap) + "/finalpos" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
     144  ifstream file (fn, ios::in|ios::binary|ios::ate); 
     145  if (file.is_open()) { 
     146    ifstream::pos_type size = file.tellg(); 
     147    delete [] finalpos; 
     148    finalpos = new char[size]; 
     149    file.seekg (0, ios::beg); 
     150    file.read (memblock, size); 
     151    file.close(); 
    151152    return 1; 
    152        
     153 
    153154  else cout << "Unable to open file"; 
    154155  return 0; 
     
    179180      Pattern pattern = patternList.get(N); 
    180181      for(int a0=pattern.left; a0 <= pattern.right; a0++) { 
    181        for(int a1 = pattern.top; a1 <= pattern.bottom; a1++) { 
    182          int matches = 1; 
     182  for(int a1 = pattern.top; a1 <= pattern.bottom; a1++) { 
     183    int matches = 1; 
    183184                                     
    184          int pIndex = 2*(a1%2) + (a0%2); 
    185          char* patternBits = pattern.bits[pIndex]; // FIXME? 
    186          int pbIndex = 0; 
     185    int pIndex = 2*(a1%2) + (a0%2); 
     186    char* patternBits = pattern.bits[pIndex]; // FIXME? 
     187    int pbIndex = 0; 
    187188          int fpIndex = index*100 + a1/2 + (a0/2)*10; 
    188189 
    189          for(int x=0; x<patternBits[0]; x++) { 
    190            char start = patternBits[pbIndex+1]; 
     190    for(int x=0; x<patternBits[0]; x++) { 
     191      char start = patternBits[pbIndex+1]; 
    191192            char length = patternBits[pbIndex+2]; 
    192            fpIndex += start; 
    193            pbIndex += 2; 
    194            for(int y=0; y<length; y++) { 
    195              pbIndex++; 
    196              if (patternBits[pbIndex] & finalpos[fpIndex]) { 
    197                matches = 0; 
    198                break; 
    199              } 
    200              fpIndex++; 
    201            } 
    202            if (!matches) break; 
    203            fpIndex += 10 - start - length; 
    204          }                 
    205          if (matches) matchList.append((N,(a0,a1))); // FIXME 
    206        
     193      fpIndex += start; 
     194      pbIndex += 2; 
     195      for(int y=0; y<length; y++) { 
     196        pbIndex++; 
     197        if (patternBits[pbIndex] & finalpos[fpIndex]) { 
     198    matches = 0; 
     199    break; 
     200        } 
     201        fpIndex++; 
     202      } 
     203      if (!matches) break; 
     204      fpIndex += 10 - start - length; 
     205    }                 
     206    if (matches) matchList.append((N,(a0,a1))); // FIXME 
     207 
    207208      } 
    208209    } 
     
    333334 
    334335void Algo_movelist::finalize_process(datap) { 
    335        String fn = retrieve_datap0(datap) + "/posTable" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
    336        ofstream file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
     336  String fn = retrieve_datap0(datap) + "/posTable" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
     337  ofstream file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
    337338  file.write(posTable, posTableSize); // FIXME: posTable is vector, posTableSize does not exist 
    338339  file.close(); 
    339          
    340        fn = datap0 + "/lists" + datap1 + ".db"; // FIXME: linux specific!? 
    341        file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
     340   
     341  fn = datap0 + "/lists" + datap1 + ".db"; // FIXME: linux specific!? 
     342  file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
    342343  file.write(mainlistArr, mainlistArrSize); // FIXME: mainlistArr is vector!, mainlistArrSize does not exist 
    343344  file.close(); 
    344          
    345        fn = datap0 + "/finalposC" + datap1 + ".db"; // FIXME: linux specific!? 
    346        file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
     345   
     346  fn = datap0 + "/finalposC" + datap1 + ".db"; // FIXME: linux specific!? 
     347  file(fn, ios::out|ios::trunc|ios::binary) // FIXME: careful with ios::trunc 
    347348  file.write(finalposC, finalposCSize); 
    348349  file.close(); 
     
    351352void Algo_movelist::retrieve_db(datap) { 
    352353 
    353        String fn = retrieve_datap0(datap) + "/finalposC" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
    354        ifstream file (fn, ios::in|ios::binary|ios::ate); 
    355        if (file.is_open()) { 
    356                ifstream::pos_type size = file.tellg(); 
    357                delete [] finalposC; 
    358                finalposC = new char[size]; 
    359                file.seekg (0, ios::beg); 
    360                file.read (memblock, size); 
    361                file.close(); 
    362        
     354  String fn = retrieve_datap0(datap) + "/finalposC" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
     355  ifstream file (fn, ios::in|ios::binary|ios::ate); 
     356  if (file.is_open()) { 
     357    ifstream::pos_type size = file.tellg(); 
     358    delete [] finalposC; 
     359    finalposC = new char[size]; 
     360    file.seekg (0, ios::beg); 
     361    file.read (memblock, size); 
     362    file.close(); 
     363 
    363364  else { 
    364                cout << "Unable to open file"; 
    365          return 0; 
    366        
    367        fn = retrieve_datap0(datap) + "/lists" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
    368        ifstream file (fn, ios::in|ios::binary|ios::ate); 
    369        if (file.is_open()) { 
    370                ifstream::pos_type size = file.tellg(); 
    371                delete [] mainlistArr; 
    372                mainlistArr = new char[size]; 
    373                file.seekg (0, ios::beg); 
    374                file.read (memblock, size); 
    375                file.close(); 
    376        
     365    cout << "Unable to open file"; 
     366    return 0; 
     367 
     368  fn = retrieve_datap0(datap) + "/lists" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
     369  ifstream file (fn, ios::in|ios::binary|ios::ate); 
     370  if (file.is_open()) { 
     371    ifstream::pos_type size = file.tellg(); 
     372    delete [] mainlistArr; 
     373    mainlistArr = new char[size]; 
     374    file.seekg (0, ios::beg); 
     375    file.read (memblock, size); 
     376    file.close(); 
     377 
    377378  else { 
    378                cout << "Unable to open file"; 
    379        return 0; 
    380        
    381        fn = retrieve_datap0(datap) + "/posTable" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
    382        ifstream file (fn, ios::in|ios::binary|ios::ate); 
    383        if (file.is_open()) { 
    384                ifstream::pos_type size = file.tellg(); 
    385                delete [] posTable; 
    386                posTable = new char[size]; // FIXME: not a char array??? 
    387                file.seekg (0, ios::beg); 
    388                file.read (memblock, size); 
    389                file.close(); 
     379    cout << "Unable to open file"; 
     380    return 0; 
     381 
     382  fn = retrieve_datap0(datap) + "/posTable" + retrieve_datap1(datap) + ".db"; // FIXME: linux specific!? 
     383  ifstream file (fn, ios::in|ios::binary|ios::ate); 
     384  if (file.is_open()) { 
     385    ifstream::pos_type size = file.tellg(); 
     386    delete [] posTable; 
     387    posTable = new char[size]; // FIXME: not a char array??? 
     388    file.seekg (0, ios::beg); 
     389    file.read (memblock, size); 
     390    file.close(); 
    390391    return 1; 
    391        
     392 
    392393  else { 
    393                cout << "Unable to open file"; 
    394          return 0; 
    395        
    396        return 0; 
     394    cout << "Unable to open file"; 
     395    return 0; 
     396 
     397  return 0; 
    397398} 
    398399 
     
    400401 
    401402void Algo_movelist::search(patternList, options, db,  
    402                           continuations, contLabelsIndex, contLabels, 
    403                           progBar, progStart, progEnd) { 
     403         continuations, contLabelsIndex, contLabels, 
     404         progBar, progStart, progEnd) { 
    404405 
    405406  int numOfHits = 0; 
     
    451452      Pattern p = patternList.get(m[0]); 
    452453      for(int i=0; i<p.sizeX; i++) { 
    453        for(int j=0; j<p.sizeY; j++) { 
    454          char p_ij = p.getInitial(i,j); 
    455          if (p_ij != '.') d[(i+m[1][0],j+m[1][1])] = p_ij; 
    456          if (p_ij == 'X' or p_ij == 'O') dNO++; 
    457        
     454  for(int j=0; j<p.sizeY; j++) { 
     455    char p_ij = p.getInitial(i,j); 
     456    if (p_ij != '.') d[(i+m[1][0],j+m[1][1])] = p_ij; 
     457    if (p_ij == 'X' or p_ij == 'O') dNO++; 
     458 
    458459      } 
    459460 
     
    463464      contList[m] = []; 
    464465      for (x, y, color in p.contList) 
    465        contList[m].append((x+m[1][0], y+m[1][1], color)); 
     466  contList[m].append((x+m[1][0], y+m[1][1], color)); 
    466467 
    467468      contListIndex[m] = 0; 
     
    475476 
    476477      if (mainlistArr[movelistIndex] & BRANCHPOINT) { 
    477        self.branchpoints.append((deepcopy(dicts), deepcopy(dictsNO), 
    478                                  deepcopy(contList), deepcopy(contListIndex), counter)); 
    479        movelistIndex += 2; 
    480        continue; 
     478  self.branchpoints.append((deepcopy(dicts), deepcopy(dictsNO), 
     479          deepcopy(contList), deepcopy(contListIndex), counter)); 
     480  movelistIndex += 2; 
     481  continue; 
    481482      } 
    482483      else if (mainlistArr[movelistIndex] & ENDOFVARIATION) { 
    483        if (!patternList.nextMove) { 
    484          for(m in dicts.keys()) 
    485            if (dicts[m].has_key('found')) { 
    486              Pattern p = patternList.get(m[0]); // FIXME: besser pointer uebergeben? 
    487              if (p.colorSwitch) numOfSwitched++; 
    488              if (p.colorSwitch && showColorSwap) 
    489                result.append((dicts[m]['found'], '-')); 
    490              else result.append((dicts[m]['found'], '')); 
    491            } 
    492        
    493        dicts, dictsNO, contList, contListIndex, counter = self.branchpoints.pop(); 
    494        movelistIndex += 2; 
    495        continue; 
     484  if (!patternList.nextMove) { 
     485    for(m in dicts.keys()) 
     486      if (dicts[m].has_key('found')) { 
     487        Pattern p = patternList.get(m[0]); // FIXME: besser pointer uebergeben? 
     488        if (p.colorSwitch) numOfSwitched++; 
     489        if (p.colorSwitch && showColorSwap) 
     490    result.append((dicts[m]['found'], '-')); 
     491        else result.append((dicts[m]['found'], '')); 
     492      } 
     493 
     494  dicts, dictsNO, contList, contListIndex, counter = self.branchpoints.pop(); 
     495  movelistIndex += 2; 
     496  continue; 
    496497      } 
    497498       
     
    505506 
    506507      if (!(mainlistArr[movelistIndex+1] & REMOVE) && (mainlistArr[movelistIndex+1] & (BLACK | WHITE))) { 
    507        if (mainlistArr[movelistIndex+1] & BLACK) { 
    508          co = 'X'; 
    509          invco = 'O'; 
    510        
    511        else { 
    512          co = 'O'; 
    513          invco = 'X'; 
    514        
    515  
    516        for(m in dicts.keys()) { 
    517          if (Xinterv[m][0] <= x && x < Xinterv[m][1] && Yinterv[m][0] <= y && y < Yinterv[m][1]) { 
    518            if (dicts[m].has_key('found')) { 
    519              hit, label, contLabelsIndex, switched = patternList.updateContinuations(m[0], x, y, invco, 
    520                                                                                      Xinterv[m], Yinterv[m], 
    521                                                                                      dicts[m]['found'], counter, 
    522                                                                                      continuations, contLabels, 
    523                                                                                      contLabelsIndex, 
    524                                                                                      db.getCurrentWinner()); 
    525              if (!hit) { 
    526                del dicts[m]; 
    527                del dictsNO[m]; 
    528                continue; 
    529              } 
    530               
    531              numOfSwitched += switched; // FIXME: CHECK, was: patternList[m[0]].colorSwitch 
    532  
    533              if (switched && showColorSwap) 
    534                // FIXME: CHECK,was: (patternList[m[0]].colorSwitch or colorSwitch) and showColorSwap: 
    535                result.append((dicts[m]['found'], label + '-')); 
    536              else result.append((dicts[m]['found'], label)); 
    537              del dicts[m]; 
    538              del dictsNO[m]; 
    539              continue;     // with for m in dicts.keys() 
    540            } 
    541            else if (dicts[m].has_key('foundInitial')) { 
    542              if ((x, y, co) == contList[m][contListIndex[m]]) { 
    543                contListIndex[m]++; 
    544                if (contListIndex[m] == len(contList[m])) { 
    545                  dicts[m]['found'] = counter; 
    546                  del dicts[m]['foundInitial']; 
    547                
    548              } 
    549              else { 
    550                if (dicts[m].has_key('dontRestore')) { 
    551                  del dicts[m]; 
    552                  continue; 
    553                
    554                else { 
    555                  contListIndex[m] = 0; 
    556                  del dicts[m]['foundInitial']; 
    557                
    558              } 
    559            } 
     508  if (mainlistArr[movelistIndex+1] & BLACK) { 
     509    co = 'X'; 
     510    invco = 'O'; 
     511 
     512  else { 
     513    co = 'O'; 
     514    invco = 'X'; 
     515 
     516 
     517  for(m in dicts.keys()) { 
     518    if (Xinterv[m][0] <= x && x < Xinterv[m][1] && Yinterv[m][0] <= y && y < Yinterv[m][1]) { 
     519      if (dicts[m].has_key('found')) { 
     520        hit, label, contLabelsIndex, switched = patternList.updateContinuations(m[0], x, y, invco, 
     521                          Xinterv[m], Yinterv[m], 
     522                          dicts[m]['found'], counter, 
     523                          continuations, contLabels, 
     524                          contLabelsIndex, 
     525                          db.getCurrentWinner()); 
     526        if (!hit) { 
     527    del dicts[m]; 
     528    del dictsNO[m]; 
     529    continue; 
     530        } 
     531         
     532        numOfSwitched += switched; // FIXME: CHECK, was: patternList[m[0]].colorSwitch 
     533 
     534        if (switched && showColorSwap) 
     535    // FIXME: CHECK,was: (patternList[m[0]].colorSwitch or colorSwitch) and showColorSwap: 
     536    result.append((dicts[m]['found'], label + '-')); 
     537        else result.append((dicts[m]['found'], label)); 
     538        del dicts[m]; 
     539        del dictsNO[m]; 
     540        continue;     // with for m in dicts.keys() 
     541      } 
     542      else if (dicts[m].has_key('foundInitial')) { 
     543        if ((x, y, co) == contList[m][contListIndex[m]]) { 
     544    contListIndex[m]++; 
     545    if (contListIndex[m] == len(contList[m])) { 
     546      dicts[m]['found'] = counter; 
     547      del dicts[m]['foundInitial']; 
     548   
     549        } 
     550        else { 
     551    if (dicts[m].has_key('dontRestore')) { 
     552      del dicts[m]; 
     553      continue; 
     554   
     555    else { 
     556      contListIndex[m] = 0; 
     557      del dicts[m]['foundInitial']; 
     558   
     559        } 
     560      } 
    560561                     
    561            if (!dicts[m].has_key((x,y))) { 
    562              if (!(self.finalposC[index*50 + y/4 + 5*(x/2)] & (1 << (x%2 + 2*(y%4))))) { 
    563  
    564                if (!contListIndex[m]) { 
    565                  del dicts[m]; 
    566                  continue; 
    567                
     562      if (!dicts[m].has_key((x,y))) { 
     563        if (!(self.finalposC[index*50 + y/4 + 5*(x/2)] & (1 << (x%2 + 2*(y%4))))) { 
     564 
     565    if (!contListIndex[m]) { 
     566      del dicts[m]; 
     567      continue; 
     568   
    568569                else dicts[m]['dontRestore'] = 1; 
    569              } 
    570              else { 
    571                dicts[m][(x,y)] = '.'; 
    572                dictsNO[m]++; 
    573              } 
    574            } 
    575            else if (dicts[m][(x,y)] == lower(invco)) { 
    576              if (!(self.finalposC[index*50 + y/4 + 5*(x/2)] & (1 << (x%2 + 2*(y%4))))) { 
    577                if (!contListIndex[m]) { 
    578                  del dicts[m]; 
    579                  continue; 
    580                
    581                else dicts[m]['dontRestore'] = 1; 
    582              } 
    583              else dictsNO[m]++; 
    584            } 
    585            else if (dicts[m][(x,y)] == co) { 
    586              del dicts[m][(x,y)]; 
    587              dictsNO[m]--; 
    588            } 
    589          } 
    590        
     570        } 
     571        else { 
     572    dicts[m][(x,y)] = '.'; 
     573    dictsNO[m]++; 
     574        } 
     575      } 
     576      else if (dicts[m][(x,y)] == lower(invco)) { 
     577        if (!(self.finalposC[index*50 + y/4 + 5*(x/2)] & (1 << (x%2 + 2*(y%4))))) { 
     578    if (!contListIndex[m]) { 
     579      del dicts[m]; 
     580      continue; 
     581   
     582    else dicts[m]['dontRestore'] = 1; 
     583        } 
     584        else dictsNO[m]++; 
     585      } 
     586      else if (dicts[m][(x,y)] == co) { 
     587        del dicts[m][(x,y)]; 
     588        dictsNO[m]--; 
     589      } 
     590    } 
     591 
    591592      } 
    592593      else if (mainlistArr[movelistIndex+1] & REMOVE) { 
    593        if (mainlistArr[movelistIndex+1] & BLACK) { 
    594          co = 'X'; 
    595          invco = 'O'; 
    596        
    597        else if mainlistArr[movelistIndex+1] & WHITE { 
    598          co = 'O'; 
    599          invco = 'X'; 
    600        
    601        else printf("oops\n"); // FIXME 
    602  
    603        for (m in dicts.keys()) { 
    604          if (!dicts[m].has_key('found')) { 
    605            if (Xinterv[m][0] <= x && x < Xinterv[m][1] && Yinterv[m][0] <= y && y < Yinterv[m][1]) { 
    606              if (dicts[m].has_key('foundInitial')) { 
    607                int ii = contListIndex[m]; 
    608                while (ii < len(contList[m]) && contList[m][ii][2] == '-' && 
    609                       (x != contList[m][ii][0] || y != contList[m][ii][1])) 
    610                  ii++; 
    611                if (ii < len(contList[m]) && contList[m][ii][2] == '-') { 
    612                  help = contList[m][ii]; 
    613                  contList[m][ii] = contList[m][contListIndex[m]]; 
    614                  contlist[contListIndex[m]] = help; 
    615  
    616                  contListIndex[m]++; 
    617                
    618                else { 
    619                  if (dicts[m].has_key('dontRestore')) { 
    620                    del dicts[m]; 
    621                    continue; 
    622                  } 
    623                  else { 
    624                    contListIndex[m] = 0; 
    625                    del dicts[m]['foundInitial']; 
    626                  } 
    627                
    628              } 
    629              if (!dicts[m].has_key((x,y))) { 
    630                dicts[m][(x,y)] = co; 
    631                dictsNO[m]++; 
    632              } 
    633              else if (dicts[m][(x,y)] == lower(invco)) { 
    634                dictsNO[m]--; 
    635              } 
    636              else if (dicts[m][(x,y)] == '.') { 
    637                del dicts[m][(x,y)]; 
    638                dictsNO[m]--; 
    639              } 
    640            } 
    641          } 
    642        
     594  if (mainlistArr[movelistIndex+1] & BLACK) { 
     595    co = 'X'; 
     596    invco = 'O'; 
     597 
     598  else if mainlistArr[movelistIndex+1] & WHITE { 
     599    co = 'O'; 
     600    invco = 'X'; 
     601 
     602  else printf("oops\n"); // FIXME 
     603 
     604  for (m in dicts.keys()) { 
     605    if (!dicts[m].has_key('found')) { 
     606      if (Xinterv[m][0] <= x && x < Xinterv[m][1] && Yinterv[m][0] <= y && y < Yinterv[m][1]) { 
     607        if (dicts[m].has_key('foundInitial')) { 
     608    int ii = contListIndex[m]; 
     609    while (ii < len(contList[m]) && contList[m][ii][2] == '-' && 
     610           (x != contList[m][ii][0] || y != contList[m][ii][1])) 
     611      ii++; 
     612    if (ii < len(contList[m]) && contList[m][ii][2] == '-') { 
     613      help = contList[m][ii]; 
     614      contList[m][ii] = contList[m][contListIndex[m]]; 
     615      contlist[contListIndex[m]] = help; 
     616 
     617      contListIndex[m]++; 
     618   
     619    else { 
     620      if (dicts[m].has_key('dontRestore')) { 
     621        del dicts[m]; 
     622        continue; 
     623      } 
     624      else { 
     625        contListIndex[m] = 0; 
     626        del dicts[m]['foundInitial']; 
     627      } 
     628   
     629        } 
     630        if (!dicts[m].has_key((x,y))) { 
     631    dicts[m][(x,y)] = co; 
     632    dictsNO[m]++; 
     633        } 
     634        else if (dicts[m][(x,y)] == lower(invco)) { 
     635    dictsNO[m]--; 
     636        } 
     637        else if (dicts[m][(x,y)] == '.') { 
     638    del dicts[m][(x,y)]; 
     639    dictsNO[m]--; 
     640        } 
     641      } 
     642    } 
     643 
    643644      } 
    644645 
    645646      if (endOfNode) { 
    646        for (m in dicts.keys()) { 
    647          if (!dictsNO[m] && !dicts[m].has_key('found') && !dicts[m].has_key('foundInitial')) 
    648            if (contListIndex[m] == len(contList[m])) dicts[m]['found'] = counter; 
    649            else dicts[m]['foundInitial'] = counter; 
    650        
    651          
    652        counter++; 
     647  for (m in dicts.keys()) { 
     648    if (!dictsNO[m] && !dicts[m].has_key('found') && !dicts[m].has_key('foundInitial')) 
     649      if (contListIndex[m] == len(contList[m])) dicts[m]['found'] = counter; 
     650      else dicts[m]['foundInitial'] = counter; 
     651 
     652   
     653  counter++; 
    653654      } 
    654655                     
     
    659660    if (!patternList.nextMove) { 
    660661      for (m in dicts.keys()) { 
    661        Pattern p = patternList.get(m[0]); 
    662        if (dicts[m].has_key('found')) { 
    663          if (p.colorSwitch) numOfSwitched++; 
    664          if (p.colorSwitch && showColorSwap) result.append((dicts[m]['found'], '-')); 
    665          else result.append((dicts[m]['found'], '')); 
    666        
     662  Pattern p = patternList.get(m[0]); 
     663  if (dicts[m].has_key('found')) { 
     664    if (p.colorSwitch) numOfSwitched++; 
     665    if (p.colorSwitch && showColorSwap) result.append((dicts[m]['found'], '-')); 
     666    else result.append((dicts[m]['found'], '')); 
     667 
    667668      } 
    668669    } 
     
    673674             
    674675      if (db.getCurrentWinner() == 'B') { 
    675        Bwins += len(result) - numOfSwitched; 
    676        Wwins += Wwins + numOfSwitched; 
     676  Bwins += len(result) - numOfSwitched; 
     677  Wwins += Wwins + numOfSwitched; 
    677678      } 
    678679      else if (db.getCurrentWinner() == 'W') { 
    679        Bwins += numOfSwitched; 
    680        Wwins += len(result) - numOfSwitched; 
     680  Bwins += numOfSwitched; 
     681  Wwins += len(result) - numOfSwitched; 
    681682      } 
    682683      result.sort(); 
     
    771772//     for(p in self.poslist)  
    772773//       if (p[2] <= c[0] && c[0] <= p[4] && p[3] <= c[1] && c[1] <= p[5]) { 
    773 //     p[0] -= 1; 
    774 //     p[1] += epsilon * hashTable.hash_value[c]; 
     774// p[0] -= 1; 
     775// p[1] += epsilon * hashTable.hash_value[c]; 
    775776//       } 
    776777//   } 
     
    805806//     for(int j=b0; j<b1+1; j++) { 
    806807//       if (pattern.data[i-pattern.anchors[0][0]][j-pattern.anchors[0][1]] in ['x', 'o', '*']) 
    807 //     return NOT_HASHABLE; 
     808// return NOT_HASHABLE; 
    808809//       else if (pattern.data[i-pattern.anchors[0][0]][j-pattern.anchors[0][1]] == 'X') { 
    809 //     hashkey += hashTable.hash_value[(i,j)]; 
    810 //     numOfStones += 1; 
     810// hashkey += hashTable.hash_value[(i,j)]; 
     811// numOfStones += 1; 
    811812//       } 
    812813//       else if (pattern.data[i-pattern.anchors[0][0]][j-pattern.anchors[0][1]] == 'O') { 
    813 //     hashkey -= hashTable.hash_value[(i,j)]; 
    814 //     numOfStones += 1; 
     814// hashkey -= hashTable.hash_value[(i,j)]; 
     815// numOfStones += 1; 
    815816//       } 
    816817//     } 
     
    821822//  
    822823// int Algo_hash::retrieve_db(PyObject* datap) { 
    823 //     String fn = ... filename ...; // FIXME 
    824 //     ifstream file (fn, ios::in|ios::binary|ios::ate); 
    825 //     if (file.is_open()) { 
    826 //             ifstream::pos_type size = file.tellg(); 
    827 //             delete [] hash; 
    828 //             hash = new char[size]; // FIXME: not a char array? 
    829 //             file.seekg (0, ios::beg); 
    830 //             file.read (memblock, size); 
    831 //             file.close(); 
    832 //    
     824// String fn = ... filename ...; // FIXME 
     825// ifstream file (fn, ios::in|ios::binary|ios::ate); 
     826// if (file.is_open()) { 
     827//    ifstream::pos_type size = file.tellg(); 
     828//    delete [] hash; 
     829//    hash = new char[size]; // FIXME: not a char array? 
     830//    file.seekg (0, ios::beg); 
     831//    file.read (memblock, size); 
     832//    file.close(); 
     833//
    833834//   else { 
    834 //             cout << "Unable to open file"; 
    835 //       return 0; 
    836 //    
    837 //     String fn = ... filename + "T" ...; // FIXME 
    838 //     ifstream file (fn, ios::in|ios::binary|ios::ate); 
    839 //     if (file.is_open()) { 
    840 //             ifstream::pos_type size = file.tellg(); 
    841 //             delete [] hashT; 
    842 //             hashT = new char[size]; 
    843 //             file.seekg (0, ios::beg); 
    844 //             file.read (memblock, size); 
    845 //             file.close(); 
    846 //    
     835//    cout << "Unable to open file"; 
     836//   return 0; 
     837//
     838// String fn = ... filename + "T" ...; // FIXME 
     839// ifstream file (fn, ios::in|ios::binary|ios::ate); 
     840// if (file.is_open()) { 
     841//    ifstream::pos_type size = file.tellg(); 
     842//    delete [] hashT; 
     843//    hashT = new char[size]; 
     844//    file.seekg (0, ios::beg); 
     845//    file.read (memblock, size); 
     846//    file.close(); 
     847//
    847848//   else { 
    848 //             cout << "Unable to open file"; 
    849 //       return 0; 
    850 //    
     849//    cout << "Unable to open file"; 
     850//   return 0; 
     851//
    851852//   return 0; 
    852853// } 
     
    859860//     for(int a0=pattern.left; a0<=pattern.right; a0++) { 
    860861//       for(int a1=pattern.top; a1<=pattern.bottom; a1++) { 
    861 //     pattern_hashkeys[(a0,a1)] = []; 
    862 //     for(p in self.poslist) { 
    863 //       if (a0 <= p[2] && a0+pattern.sizeX >= p[4] a1 <= p[3] && a1+pattern.sizeY >= p[5]) { 
    864 //         hk = self.compute_hashkey(pattern, p[2:]); 
    865 //  
    866 //         if (hk != NOT_HASHABLE) pattern.hashkeys[(a0,a1)].append([hk]); 
    867 //       } 
    868 //    
    869 //     if (!pattern.hashkeys[(a0,a1)]) return; 
     862// pattern_hashkeys[(a0,a1)] = []; 
     863// for(p in self.poslist) { 
     864//   if (a0 <= p[2] && a0+pattern.sizeX >= p[4] a1 <= p[3] && a1+pattern.sizeY >= p[5]) { 
     865//     hk = self.compute_hashkey(pattern, p[2:]); 
     866//  
     867//     if (hk != NOT_HASHABLE) pattern.hashkeys[(a0,a1)].append([hk]); 
     868//   } 
     869//
     870// if (!pattern.hashkeys[(a0,a1)]) return; 
    870871//       } 
    871872//     } 
     
    883884//       for(int a1=pattern.top; a1<=pattern.bottom; a1++) { 
    884885//              
    885 //     for(int hk=0; hk<len(pattern.hashkeys[(a0,a1)]); hk++) { 
    886 //  
    887 //       int hashkey = pattern.hashkeys[(a0,a1)][hk][0]; 
    888 //       int start = 0; 
    889 //       int end = len(self.hashT)/2; 
     886// for(int hk=0; hk<len(pattern.hashkeys[(a0,a1)]); hk++) { 
     887//  
     888//   int hashkey = pattern.hashkeys[(a0,a1)][hk][0]; 
     889//   int start = 0; 
     890//   int end = len(self.hashT)/2; 
    890891//                    
    891 //       int hash_start; 
    892 //       int hash_end; 
    893 //  
    894 //       while (start < end) { 
    895 //         int help = self.hashT[2*((start+end)/2)]; 
    896 //         if (help == hashkey) { 
    897 //           hash_start = self.hashT[2*((start+end)/2)+1]; 
    898 //           if (2*((start+end)/2)+3 >= len(self.hashT)) hash_end = len(hash); 
    899 //           else hash_end = self.hashT[2*((start+end)/2)+3]; 
    900 //  
    901 //           pattern.hashkeys[(a0,a1)][hk].extend([hash_start, hash_start, hash_end]); 
    902 //           break; 
    903 //         } 
    904 //         else if (help > hashkey) end = (start+end)/2; 
    905 //         else if (help < hashkey) start = (start+end)/2 + 1; 
    906 //       } 
    907 //    
     892//   int hash_start; 
     893//   int hash_end; 
     894//  
     895//   while (start < end) { 
     896//     int help = self.hashT[2*((start+end)/2)]; 
     897//     if (help == hashkey) { 
     898//       hash_start = self.hashT[2*((start+end)/2)+1]; 
     899//       if (2*((start+end)/2)+3 >= len(self.hashT)) hash_end = len(hash); 
     900//       else hash_end = self.hashT[2*((start+end)/2)+3]; 
     901//  
     902//       pattern.hashkeys[(a0,a1)][hk].extend([hash_start, hash_start, hash_end]); 
     903//       break; 
     904//     } 
     905//     else if (help > hashkey) end = (start+end)/2; 
     906//     else if (help < hashkey) start = (start+end)/2 + 1; 
     907//   } 
     908//
    908909//       } 
    909910//     } 
     
    922923//       Pattern pattern = patternList.get(N); 
    923924//       for(int a0=pattern.left; a0<=pattern.right; a0++) { 
    924 //     for(int a1=pattern.top; a1<=pattern.bottom; a1++) { 
    925 //       int matchPossible = 1; 
    926 //       for(int hk=0; hk<len(pattern.hashkeys[(a0,a1)]); hk++) { 
    927 //         l = pattern.hashkeys[(a0,a1)][hk]; 
    928 //         if (len(l) == 1) { 
    929 //           matchPossible = 0; 
    930 //           break; 
    931 //         } 
     925// for(int a1=pattern.top; a1<=pattern.bottom; a1++) { 
     926//   int matchPossible = 1; 
     927//   for(int hk=0; hk<len(pattern.hashkeys[(a0,a1)]); hk++) { 
     928//     l = pattern.hashkeys[(a0,a1)][hk]; 
     929//     if (len(l) == 1) { 
     930//       matchPossible = 0; 
     931//       break; 
     932//     } 
    932933//                              
    933 //         while (l[2]+1 < l[3] && index > 256*hash[l[2]] + hash[l[2]+1]) 
    934 //           l[2] += 2; 
     934//     while (l[2]+1 < l[3] && index > 256*hash[l[2]] + hash[l[2]+1]) 
     935//       l[2] += 2; 
    935936//                      
    936 //         if (index < 256*hash[l[2]] + hash[l[2]+1]) { 
    937 //           matchPossible = 0; 
    938 //           break; 
    939 //         } 
    940 //       } 
    941 //  
    942 //       if (matchPossible) { 
    943 //         l[2] += 2; 
    944 //         matchList.append((N, (a0, a1))); 
    945 //       } 
    946 //    
     937//     if (index < 256*hash[l[2]] + hash[l[2]+1]) { 
     938//       matchPossible = 0; 
     939//       break; 
     940//     } 
     941//   } 
     942//  
     943//   if (matchPossible) { 
     944//     l[2] += 2; 
     945//     matchList.append((N, (a0, a1))); 
     946//   } 
     947//
    947948//       } 
    948949//     } 
     
    10141015//  
    10151016//     newUInt.append(max(self.data[current1][0], uinterv.data[current2low][0]), 
    1016 //                min(self.data[current1][1], uinterv.data[current2low][1])); 
     1017//       min(self.data[current1][1], uinterv.data[current2low][1])); 
    10171018//  
    10181019//     for(int c=current2low+1; c < current2high; c++) 
     
    11021103//     for(int y=0; y < boardsize; y++) { 
    11031104//       if (!moves[self.boardsize*x+y]->size()) 
    1104 //     movesArr.push_back(0); 
     1105// movesArr.push_back(0); 
    11051106//       else if (moves[self.boardsize*x+y]->size() == 1) { 
    1106 //     long d = (*moves[self.boardsize*x+y])[0]; 
    1107 //     self.movesArr.append(d); 
     1107// long d = (*moves[self.boardsize*x+y])[0]; 
     1108// self.movesArr.append(d); 
    11081109//       } 
    11091110//       else { 
    1110 //     vector<int>* mvs = moves[self.boardsize*x+y]; 
    1111 //     long d = moveIntsArr.size() | FLAG_POINTER; 
    1112 //  
    1113 //     vector<long> Blist; 
    1114 //     vector<long> Wlist; 
    1115 //     vector<long> Elist; 
    1116 //  
    1117 //     Elist.push_back(0); 
    1118 //  
    1119 //     int moveIndex = 0; 
    1120 //     while (moveIndex < mvs.size()) { 
    1121 //       if (mvs[moveIndex] & FLAG_BLACK) { 
    1122 //         d = d | FLAG_BLACK; 
    1123 //         Blist.push_back(mvs[moveIndex] & ~FLAG_BLACK); 
    1124 //         Elist.push_back(mvs[moveIndex] & ~FLAG_BLACK); 
    1125 //         if (moveIndex + 1 < mvs->size()) { 
    1126 //           Blist.push_back(mvs[moveIndex+1] & ~(FLAG_BLACK|FLAG_WHITE|FLAG_REMOVE)); 
    1127 //           Elist.push_back(mvs[moveIndex+1] & ~(FLAG_BLACK|FLAG_WHITE|FLAG_REMOVE)); 
    1128 //         } 
    1129 //         else Blist.push_back(MAXNOMOVES); 
    1130 //       } 
    1131 //       if (mvs[moveIndex] & FLAG_WHITE) { 
    1132 //         d = d | FLAG_WHITE; 
    1133 //         Wlist.push_back(mvs[moveIndex] & ~FLAG_WHITE); 
    1134 //         Elist.push_back(mvs[moveIndex] & ~FLAG_WHITE); 
    1135 //         if (moveIndex + 1 < mvs->size()) { 
    1136 //           Wlist.push_back(mvs[moveIndex+1] & ~(FLAG_BLACK|FLAG_WHITE|FLAG_REMOVE)); 
    1137 //           Elist.push_back(mvs[moveIndex+1] & ~(FLAG_BLACK|FLAG_WHITE|FLAG_REMOVE)); 
    1138 //         } 
    1139 //         else Wlist.append(MAXNOMOVES); 
    1140 //       } 
    1141 //       moveIndex += 2; 
    1142 //    
     1111// vector<int>* mvs = moves[self.boardsize*x+y]; 
     1112// long d = moveIntsArr.size() | FLAG_POINTER; 
     1113//  
     1114// vector<long> Blist; 
     1115// vector<long> Wlist; 
     1116// vector<long> Elist; 
     1117//  
     1118// Elist.push_back(0); 
     1119//  
     1120// int moveIndex = 0; 
     1121// while (moveIndex < mvs.size()) { 
     1122//   if (mvs[moveIndex] & FLAG_BLACK) { 
     1123//     d = d | FLAG_BLACK; 
     1124//     Blist.push_back(mvs[moveIndex] & ~FLAG_BLACK); 
     1125//     Elist.push_back(mvs[moveIndex] & ~FLAG_BLACK); 
     1126//     if (moveIndex + 1 < mvs->size()) { 
     1127//       Blist.push_back(mvs[moveIndex+1] & ~(FLAG_BLACK|FLAG_WHITE|FLAG_REMOVE)); 
     1128//       Elist.push_back(mvs[moveIndex+1] & ~(FLAG_BLACK|FLAG_WHITE|F