Changeset 175 for 06/devel/algos.cc

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:
1 modified

Legend:

Unmodified
Added
Removed
  • 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