Changeset 169

Show
Ignore:
Timestamp:
08/04/05 21:52:22 (3 years ago)
Author:
ug
Message:

Misc. changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/devel/search.cc

    r83 r169  
    2222 
    2323// -------------------------------------------------------------------------- 
    24  
    25 // class stdout_message: 
    26 //     def __init__(self): pass 
    27 //     def insert(self, dummy, text): print text 
    28  
    29  
    30 // class no_message: 
    31 //     def __init__(self): pass 
    32 //     def insert(self, dummy, text): pass 
    33  
    34 // ------------------------------------------------------------------------- 
    35  
    36  
    3724 
    3825 
     
    6956  else filename = s + '.sgf'; 
    7057 
    71   return strip(os.path.join(self.sgfpath, filename)), gameNumber; 
     58XXX  return strip(os.path.join(self.sgfpath, filename)), gameNumber; 
    7259} 
    7360 
    7461      
    75 void SGFDatabase::process(char* dbpath, pair<char*, int> datap, int algos, PyObject* flist,  
     62void SGFDatabase::process(char* dbpath, pair<char*, int> datap, int Algos, PyObject* flist,  
    7663             PyObject* messages, PyObject gamelist, 
    7764             int sloppySGF, int duplicateCheck, 
     
    8067  int currentTime = time(0); 
    8168  if (progBar) progBar.clear(); 
    82   messages.insert('end', 'Processing ' + dbpath + ' ...\n'); 
     69XXX  messages.insert('end', 'Processing ' + dbpath + ' ...\n'); 
    8370 
    8471  vector<Algorithm> algolist; 
    8572  algos |= 1; // add Algo_finalpos 
    86   foreach(int i = 0; i < NUM_OF_ALGOS; i++) 
     73  for(int i = 0; i < NUM_OF_ALGOS; i++) 
    8774    if (algos & ALGOS[i]) 
    8875      algolist.push_back(ALL_ALGOS[i](boardsize)); 
    8976 
    90   vector<char*> namelist; 
    91   namelist.push_back("kombilo06"); 
    92   namelist.push_back(itao(algos)); 
     77  vector<char*> Namelist; 
     78  Namelist.push_back("kombilo06"); 
     79  Namelist.push_back(itao(algos)); 
    9380 
    9481  vector<char*> siglist; 
     
    9784 
    9885  vector<char*> filelist; 
    99   // ... build filelist from flist 
     86XXX  // ... build filelist from flist 
    10087  filelist.sort(); 
    10188 
     
    10794  int fileCtr = 0; // counts files which are processed 
    10895         
    109   for(f in filelist) { 
    110     if (progBar && fileCtr % 10 == 0) 
    111       progBar.redraw(fileCtr*1.0/total); 
     96XXX  for(f in filelist) { 
     97XXX    if (progBar && fileCtr % 10 == 0) 
     98XXX      progBar.redraw(fileCtr*1.0/total); 
    11299    fileCtr++; 
    113100 
     
    117104 
    118105    if (find(f, '|%') != -1 || find(f, '[') != -1) { 
    119       messages.insert('end', 'Invalid characters in filename ' + f + ', skipped.\n'); 
     106XXX      messages.insert('end', 'Invalid characters in filename ' + f + ', skipped.\n'); 
    120107      continue; 
    121108    } 
    122109 
    123110    try { 
    124       file = open(f); 
    125       s = file.read(); 
    126       file.close(); 
     111XXX      file = open(f); 
     112XXX      s = file.read(); 
     113XXX      file.close(); 
    127114    } 
    128115    catch(IOError) { 
    129       messages.insert('end', 'I/O Error: Cannot read file ' + f + ', skipped.\n'); 
     116XXX      messages.insert('end', 'I/O Error: Cannot read file ' + f + ', skipped.\n'); 
    130117      continue; 
    131118    } 
     
    135122    } 
    136123    catch { 
    137       messages.insert('end', 'Error in SGF file '+f+': Skipped.\n'); 
     124XXX      messages.insert('end', 'Error in SGF file '+f+': Skipped.\n'); 
    138125      continue; 
    139126    } 
     
    142129    if (cursor.root.numChildren > 1) { 
    143130      collection = 1; 
    144       messages.insert('end', 'Warning: ' + f + ' is a collection;' +\ 
    145                     ' for performance reasons it would be better to' + \ 
    146                     ' split it into files with single game records.\n'); 
     131XXX      messages.insert('end', 'Warning: ' + f + ' is a collection;' +\ 
     132XXX                 ' for performance reasons it would be better to' + \ 
     133XXX                 ' split it into files with single game records.\n'); 
    147134    } 
    148135    if (!cursor.root.numChildren) { 
    149       messages.insert('end', 'File '+f+' does not contain a game record. Skipped.\n'); 
     136XXX      messages.insert('end', 'File '+f+' does not contain a game record. Skipped.\n'); 
    150137      continue; 
    151138    } 
    152139 
    153     for(indexColl in range(cursor.root.numChildren)) { 
     140    for(int indexColl=0; indexColl < cursor.root.numChildren; indexColl++) { 
    154141      char* iColl; 
    155       if (collection) iColl = '[' + `indexColl` + ']'; 
    156       else iColl = ''; 
     142XXX      if (collection) iColl = '[' + `indexColl` + ']'; 
     143XXX      else iColl = ''; 
    157144 
    158145      try 
    159       cursor.game(indexColl); 
    160       catch SGFError { 
    161       messages.insert('end', 'SGF Error in game ' + iColl + ' of file ' + f + ', skipped.\n'); 
    162         continue; 
     146XXX                           cursor.game(indexColl); 
     147XXX     catch SGFError { 
     148XXX                           messages.insert('end', 'SGF Error in game ' + iColl + ' of file ' + f + ', skipped.\n'); 
     149                               continue; 
    163150      } 
    164151                 
    165       try { 
    166         if (cursor.currentNode().has_key('SZ') && strip(cursor.currentNode()['SZ'][0]) != `self.boardsize`) 
    167           messages.insert('end', 'SGF file '+ f + iColl +\ 
    168                           ' does not contain a %sx%s game. Skipped.\n' \ 
    169                           % (`self.boardsize`, `self.boardsize`)); 
    170         continue; 
    171              
    172         char playerB[]; 
    173         char playerW[]; 
    174         char result; 
    175         char date[11]; 
    176  
    177         if (cursor.currentNode().has_key('PB')) { 
    178           playerB = replace(cursor.currentNode()['PB'][0], '|%', ' '); 
    179           playerB = replace(playerB, '\r', ' '); 
    180           playerB = replace(playerB, '\n', ' '); 
     152    try { 
     153                        if (cursor.currentNode().has_key('SZ') && strip(cursor.currentNode()['SZ'][0]) != `self.boardsize`) 
     154                                messages.insert('end', 'SGF file '+ f + iColl +\ 
     155                                                ' does not contain a %sx%s game. Skipped.\n' \ 
     156                                                % (`self.boardsize`, `self.boardsize`)); 
     157                        continue; 
     158 
     159                        char playerB[]; 
     160                        char playerW[]; 
     161                        char result; 
     162                        char date[11]; 
     163 
     164                        if (cursor.currentNode().has_key('PB')) { 
     165                                playerB = replace(cursor.currentNode()['PB'][0], '|%', ' '); 
     166                                playerB = replace(playerB, '\r', ' '); 
     167                                playerB = replace(playerB, '\n', ' '); 
     168                        } 
     169                        else playerB = '?'; 
     170 
     171                        if (cursor.currentNode().has_key('PW')) { 
     172                                playerW = replace(cursor.currentNode()['PW'][0], '|%', ' '); 
     173                                playerW = replace(playerW, '\r', ' '); 
     174                                playerW = replace(playerW, '\n', ' '); 
     175                        } 
     176                        else playerW = '?'; 
     177 
     178                        if (cursor.currentNode().has_key('RE') && strip(cursor.currentNode()['RE'][0])) 
     179                                result = strip(cursor.currentNode()['RE'][0])[0]; 
     180                        else result = '-'; 
     181 
     182                        if (cursor.currentNode().has_key('DT') && cursor.currentNode()['DT'][0]) { 
     183                                date_str = cursor.currentNode()['DT'][0]; 
     184 
     185                                m = re.search('(^|[^\d])(\d\d\d\d-\d\d-\d\d)($|[^\d])', date_str); 
     186 
     187                                try  
     188                                        date = m.group(2); 
     189                                catch (AttributeError, ValueError) { 
     190                                        m = re.search('(^|[^\d])(\d\d\d\d-\d\d)($|[^\d])', date_str); 
     191                                        try 
     192                                                date = m.group(2); 
     193                                        catch (AttributeError, ValueError) { 
     194                                                m = re.search('(^|[^\d])(\d\d\d\d)($|[^\d])', date_str); 
     195                                                try 
     196                                                        date = m.group(2); 
     197                                                catch (AttributeError, ValueError) 
     198                                                        date = ''; 
     199                                                // else FIXME 
     200                                                // date = '' 
     201                                        } 
     202                                } 
     203                        } 
     204 
     205                        char signature1[]; 
     206                        char signature2[]; 
     207                } 
     208                catch { 
     209                        messages.insert('end', 'SGF Error in root node of game ' + iColl + \ 
     210                                        ', file ' + f + ', skipped.\n'); 
     211                        continue; 
     212                } 
     213 
     214                int counter = -1; 
     215 
     216                try { 
     217 
     218                        for(algo in algolist) algo.newgame_process(); 
     219 
     220                        b = abstractBoard(); 
     221                        vector<> branchpoints; 
     222 
     223                        while(1) { 
     224                                counter++; 
     225 
     226                                try { 
     227                                        if (cursor.currentNode().has_key('B') || cursor.currentNode().has_key('W')) { 
     228                                                if (cursor.currentNode().has_key('B')) co = 'B'; 
     229                                                else co = 'W'; 
     230 
     231                                                char* p = cursor.currentNode()[co][0]; 
     232                                                if (strlen(p) != 2) 
     233                                                        if (!strlen(p)) { 
     234                                                                messages.insert('end', 'SGF Error in file ' + f + '\n'); 
     235                                                                break; 
     236                                                        } 
     237                                                assert len(p) == 2; 
     238 
     239                                                int x = p[0] - oa; 
     240                                                int y = p[1] - oa; 
     241 
     242                                                if (0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize) { 
     243                                                        if (!b.play((x, y), co)) { 
     244                                                                messages.insert('end', 'Illegal move in file ' + f \ 
     245                                                                                + ' (' + `counter+1` + ')\n'); 
     246                                                                break; 
     247                                                        } 
     248                                                } 
     249                                                else 
     250                                                        if (x != 19 || y != 19) { 
     251                                                                messages.insert('end', 'Invalid move in file '+f+ 
     252                                                                                ' (' + `counter+1` + ')\n'); 
     253                                                                break; 
     254                                                        } 
     255 
     256                                                assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; 
     257 
     258                                                if (b.undostack.size())  
     259                                                        captures = b.undostack[len(b.undostack)-1][2]; 
     260                                                else assert 0; // FIXME? 
     261 
     262                                                if (counter+1 in [20, 40, 60]) signature1 = signature1 + chr(x + oa) + chr(y + oa); 
     263                                                if (counter+1 in [31, 51, 71]) signature2 = signature2 + chr(x + oa) + chr(y + oa); 
     264 
     265                                                for(algo in algolist) 
     266                                                        if (co == 'B') algo.B_process(x, y, captures); 
     267                                                        else algo.W_process(x, y, captures); 
     268                                        } 
     269                                        else { 
     270                                                if (cursor.currentNode().has_key('AB')) 
     271                                                        for (p in cursor.currentNode()['AB']) { 
     272                                                                if (strlen(p) != 2) continue; 
     273                                                                int x = ord(p[0])-oa; 
     274                                                                int y = ord(p[1])-oa; 
     275                                                                if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) 
     276                                                                        messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); 
     277 
     278                                                                assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; 
     279                                                                b.play((x, y), 'black'); 
     280                                                                for(algo in algolist) algo.AB_process(x, y); 
     281                                                        } 
     282 
     283                                                if (cursor.currentNode().has_key('AW')) 
     284                                                        for (p in cursor.currentNode()['AW']) { 
     285                                                                if (strlen(p) != 2) continue; 
     286                                                                int x = ord(p[0])-oa; 
     287                                                                int y = ord(p[1])-oa; 
     288                                                                if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) 
     289                                                                        messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); 
     290 
     291                                                                assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; 
     292                                                                b.play((x, y), 'white'); 
     293                                                                for (algo in algolist) algo.AW_process(x, y); 
     294                                                        } 
     295 
     296                                                if (cursor.currentNode().has_key('AE')) 
     297                                                        for(p in cursor.currentNode()['AE']) { 
     298                                                                if (strlen(p) != 2) continue; 
     299                                                                int x = ord(p[0])-oa;  
     300                                                                int y = ord(p[1])-oa; 
     301                                                                if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) 
     302                                                                        messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); 
     303 
     304                                                                assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; 
     305                                                                assert b.status.has_key((x,y)); 
     306 
     307                                                                if (b.status[(x,y)] == 'black') removed = 'B'; 
     308                                                                elif (b.status[(x,y)] == 'white') removed = 'W'; 
     309                                                                b.remove((x, y)); 
     310                                                                for(algo in algolist) algo.AE_process(x, y, removed); 
     311                                                        } 
     312                                        } 
     313                                } 
     314                                catch AssertionError 
     315                                        pass; 
     316 
     317                                for(algo in algolist) algo.endOfNode_process(); 
     318 
     319                                if (processVariations && cursor.noChildren() > 1) { 
     320                                        for (algo in algolist) algo.branchpoint_process(); 
     321                                        self.branchpoints.append((cursor.currentN, b.copy(), 0)); 
     322                                } 
     323 
     324                                if (!cursor.atEnd()) cursor.next(); 
     325                                else if (self.branchpoints) { 
     326                                        for (algo in algolist) algo.endOfVariation_process(); 
     327 
     328                                        cursor.currentN, b, whichVar = self.branchpoints.pop(); 
     329                                        if (whichVar+2 < cursor.noChildren()) { 
     330                                                for (algo in algolist) algo.branchpoint_process(); 
     331                                                self.branchpoints.append((cursor.currentN, b.copy(), whichVar+1)); 
     332                                        } 
     333                                        cursor.next(whichVar+1); 
     334                                } 
     335                                else break; 
     336                        } 
     337                } 
     338 
     339                catch SGFError { 
     340                        messages.insert('end', 'File ' + f +iColl + ': SGF error in node ' + `counter+3` + '.\n'); 
     341                } 
     342                catch (*) { 
     343                        messages.insert('end', 'File ' + f + iColl + ': Error in node ' + `counter+3` + '.\n'); 
     344                } 
     345 
     346                try { 
     347XXX                     while (strlen(signature1) < 6) signature1 += "??"; 
     348XXX                     while (strlen(signature2) < 6) signature2 += "??"; 
     349XXX                     signature = signature1 + signature2; 
     350                        signature = symmetrizeSig(signature); 
     351 
     352//                      if (duplicateCheck && (counter > 20 || (counter > 5 && strictDuplicateCheck))) { 
     353//                              duplist = []; 
     354//                              for (sli in range(len(siglist)))  
     355//                                      if (siglist[sli] == signature && 
     356//                                                      (not strictDuplicateCheck || algolist[0].duplicateCheck(sli))) 
     357//                                              duplist.append(split(Namelist[sli], '|%')[0]); 
     358//  
     359//                              if (gamelist)  { // FIXME 
     360//                                      for (db in gamelist.DBlist[bsize]) { 
     361//                                              if (db.disabled) continue; 
     362//                                              for (i in range(len(db.namelist))) { 
     363//                                                      g = db.namelist[i]; 
     364//                                                      if (signature == g[4]) 
     365//                                                              if (!strictDuplicateCheck) 
     366//                                                                      duplist.append(os.path.join(db.sgfpath, g[0])); 
     367//                                                              else 
     368//                                                                      if (algolist[0].duplicateCheck(i, db.datapath)) 
     369//                                                                              duplist.append(os.path.join(db.sgfpath, g[0])); 
     370//                                              } 
     371//                                      } 
     372//                              } 
     373//  
     374//                              if (strictDuplicateCheck) 
     375//                                      char* dupText = " is the same as "; 
     376//                              else 
     377//                                      char* dupText = " is probably the same as "; // do we have to delete this? FIXME 
     378//  
     379//                              if (duplist.size()) { 
     380//                                      ff = join(duplist, ', '); 
     381//                                      if (duplicateCheck == 1) 
     382//                                              messages.insert('end', 'Duplicate: ' + os.path.split(f)[1] +iColl+ dupText + ff + '.\n'); 
     383//                                      else if (duplicateCheck == 3) { 
     384//                                              messages.insert('end', 'Duplicate: '+os.path.split(f)[1]+iColl+\ 
     385//                                                              dupText + ff + ', omitted.\n'); 
     386//                                              continue; 
     387//                                      } 
     388//                                      else if (duplicateCheck == 2) { 
     389//                                              if (askyesno('Duplicate', 'File ' +os.path.split(f)[1]+iColl\ 
     390//                                                                      + ' is the same as ' + ff + '. Include it?')) 
     391//                                                      messages.insert('end', 'Duplicate: ' + os.path.split(f)[1]+iColl\ 
     392//                                                                      + dupText + ff + '\n'); 
     393//                                              else { 
     394//                                                      messages.insert('end', 'Duplicate: ' + os.path.split(f)[1]\ 
     395//                                                                      + dupText + ff + ', omitted.\n'); 
     396//                                                      continue; 
     397//                                              } 
     398//                                      } 
     399//                              } 
     400//                      } 
     401 
     402                        siglist.append(signature); 
     403                } 
     404 
     405XXX             catch (*) { 
     406XXX                     messages.insert('end', 'File ' + f +iColl + ': Error computing the Dyer signature.\n'); 
     407                        signature = "????????????"; 
     408                } 
     409 
     410                for (algo in algolist) algo.endgame_process(); 
     411 
     412                if (os.path.split(f)[1][-4:] == '.sgf') filenameDB = os.path.split(f)[1][:-4]; 
     413                else if (os.path.split(f)[1][-4:] == '.mgt') filenameDB = os.path.split(f)[1][:-2];  
     414                else filenameDB = os.path.split(f)[1] + '.'; 
     415 
     416                Namelist.append(filenameDB + iColl + '|%' + playerB + '|%' + playerW + '|%' \ 
     417                                + result + '|%' + signature + '|%' + date); 
     418 
     419                gameCtr++; 
     420                } 
     421
     422 
     423if (gameCtr) { 
     424        try { 
     425                for (algo in algolist) algo.finalize_process(datap); 
    181426        } 
    182         else playerB = '?'; 
    183  
    184         if (cursor.currentNode().has_key('PW')) { 
    185           playerW = replace(cursor.currentNode()['PW'][0], '|%', ' '); 
    186           playerW = replace(playerW, '\r', ' '); 
    187           playerW = replace(playerW, '\n', ' '); 
     427        catch IOError { 
     428                messages.insert("end", "I/O Error: Could not write database files (Directory write-protected?).\n"); 
     429                return; 
    188430        } 
    189         else playerW = '?'; 
    190  
    191         if (cursor.currentNode().has_key('RE') && strip(cursor.currentNode()['RE'][0])) 
    192           result = strip(cursor.currentNode()['RE'][0])[0]; 
    193         else result = '-'; 
    194  
    195         if (cursor.currentNode().has_key('DT') && cursor.currentNode()['DT'][0]) { 
    196           date_str = cursor.currentNode()['DT'][0]; 
    197                          
    198           m = re.search('(^|[^\d])(\d\d\d\d-\d\d-\d\d)($|[^\d])', date_str); 
    199                      
    200           try  
    201             date = m.group(2); 
    202           catch (AttributeError, ValueError) { 
    203             m = re.search('(^|[^\d])(\d\d\d\d-\d\d)($|[^\d])', date_str); 
    204             try 
    205               date = m.group(2); 
    206             catch (AttributeError, ValueError) { 
    207               m = re.search('(^|[^\d])(\d\d\d\d)($|[^\d])', date_str); 
    208               try 
    209                 date = m.group(2); 
    210               catch (AttributeError, ValueError) 
    211                 date = ''; 
    212               // else FIXME 
    213               // date = '' 
    214             } 
    215           } 
     431 
     432        try { 
     433XXX             file = open(os.path.join(datap[0], "namelist" + datap[1] + ".db"), "w"); 
     434XXX             for (s in Namelist) 
     435XXX                     file.write(s+'\n'); 
     436XXX             file.close(); 
    216437        } 
    217  
    218         char signature1[]; 
    219         char signature2[]; 
    220       } 
    221       catch { 
    222         messages.insert('end', 'SGF Error in root node of game ' + iColl + \ 
    223                         ', file ' + f + ', skipped.\n'); 
    224         continue; 
    225       } 
    226  
    227       int counter = -1; 
    228  
    229       try { 
    230  
    231         for(algo in algolist) algo.newgame_process(); 
    232  
    233         b = abstractBoard(); 
    234         vector<> branchpoints; 
    235                      
    236         while(1) { 
    237           counter++; 
    238  
    239           try { 
    240             if (cursor.currentNode().has_key('B') || cursor.currentNode().has_key('W')) { 
    241               if (cursor.currentNode().has_key('B')) co = 'B'; 
    242               else co = 'W'; 
    243                              
    244               char* p = cursor.currentNode()[co][0]; 
    245               if (strlen(p) != 2) 
    246                 if (!strlen(p)) { 
    247                   messages.insert('end', 'SGF Error in file ' + f + '\n'); 
    248                   break; 
    249                 } 
    250               assert len(p) == 2; 
    251  
    252               int x = p[0] - oa; 
    253               int y = p[1] - oa; 
    254                      
    255               if (0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize) { 
    256                 if (!b.play((x, y), co)) { 
    257                   messages.insert('end', 'Illegal move in file ' + f \ 
    258                                   + ' (' + `counter+1` + ')\n'); 
    259                   break; 
    260                 } 
    261               } 
    262               else 
    263                 if (x != 19 || y != 19) { 
    264                   messages.insert('end', 'Invalid move in file '+f+ 
    265                                   ' (' + `counter+1` + ')\n'); 
    266                   break; 
    267                 } 
    268                    
    269               assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; 
    270                        
    271               if (b.undostack.size())  
    272                 captures = b.undostack[len(b.undostack)-1][2]; 
    273               else assert 0; // FIXME? 
    274  
    275               if (counter+1 in [20, 40, 60]) signature1 = signature1 + chr(x + oa) + chr(y + oa); 
    276               if (counter+1 in [31, 51, 71]) signature2 = signature2 + chr(x + oa) + chr(y + oa); 
    277                              
    278               for(algo in algolist) 
    279                 if (co == 'B') algo.B_process(x, y, captures); 
    280                 else algo.W_process(x, y, captures); 
    281             } 
    282             else { 
    283               if (cursor.currentNode().has_key('AB')) 
    284                 for (p in cursor.currentNode()['AB']) { 
    285                   if (strlen(p) != 2) continue; 
    286                   int x = ord(p[0])-oa; 
    287                   int y = ord(p[1])-oa; 
    288                   if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) 
    289                     messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); 
    290  
    291                   assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; 
    292                   b.play((x, y), 'black'); 
    293                   for(algo in algolist) algo.AB_process(x, y); 
    294                 } 
    295                      
    296               if (cursor.currentNode().has_key('AW')) 
    297                 for (p in cursor.currentNode()['AW']) { 
    298                   if (strlen(p) != 2) continue; 
    299                   int x = ord(p[0])-oa; 
    300                   int y = ord(p[1])-oa; 
    301                   if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) 
    302                     messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); 
    303  
    304                   assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; 
    305                   b.play((x, y), 'white'); 
    306                   for (algo in algolist) algo.AW_process(x, y); 
    307                 } 
    308                
    309               if (cursor.currentNode().has_key('AE')) 
    310                 for(p in cursor.currentNode()['AE']) { 
    311                   if (strlen(p) != 2) continue; 
    312                   int x = ord(p[0])-oa;  
    313                   int y = ord(p[1])-oa; 
    314                   if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) 
    315                     messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); 
    316  
    317                   assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; 
    318                   assert b.status.has_key((x,y)); 
    319  
    320                   if (b.status[(x,y)] == 'black') removed = 'B'; 
    321                   elif (b.status[(x,y)] == 'white') removed = 'W'; 
    322                   b.remove((x, y)); 
    323                   for(algo in algolist) algo.AE_process(x, y, removed); 
    324                 } 
    325             } 
    326           } 
    327           catch AssertionError 
    328             pass; 
    329                          
    330           for(algo in algolist) algo.endOfNode_process(); 
    331  
    332           if (processVariations && cursor.noChildren() > 1) { 
    333             for (algo in algolist) algo.branchpoint_process(); 
    334             self.branchpoints.append((cursor.currentN, b.copy(), 0)); 
    335           } 
    336  
    337           if (!cursor.atEnd()) cursor.next(); 
    338           else if (self.branchpoints) { 
    339             for (algo in algolist) algo.endOfVariation_process(); 
    340              
    341             cursor.currentN, b, whichVar = self.branchpoints.pop(); 
    342             if (whichVar+2 < cursor.noChildren()) { 
    343               for (algo in algolist) algo.branchpoint_process(); 
    344               self.branchpoints.append((cursor.currentN, b.copy(), whichVar+1)); 
    345             } 
    346             cursor.next(whichVar+1); 
    347           } 
    348           else break; 
    349         } 
    350       } 
    351  
    352       catch SGFError { 
    353         messages.insert('end', 'File ' + f +iColl + ': SGF error in node ' + `counter+3` + '.\n'); 
    354       } 
    355       catch (*) { 
    356         messages.insert('end', 'File ' + f + iColl + ': Error in node ' + `counter+3` + '.\n'); 
    357       } 
    358            
    359       try { 
    360         while (strlen(signature1) < 6) signature1 += '??'; 
    361         while (strlen(signature2) < 6) signature2 += '??'; 
    362         signature = signature1 + signature2; 
    363         signature = symmetrizeSig(signature); 
    364                                  
    365         if (duplicateCheck && (counter > 20 || (counter > 5 && strictDuplicateCheck))) { 
    366           duplist = []; 
    367           for (sli in range(len(siglist)))  
    368             if (siglist[sli] == signature && 
    369                 (not strictDuplicateCheck || algolist[0].duplicateCheck(sli))) 
    370               duplist.append(split(namelist[sli], '|%')[0]); 
    371            
    372           if (gamelist)  { // FIXME 
    373             for (db in gamelist.DBlist[bsize]) { 
    374               if (db.disabled) continue; 
    375               for (i in range(len(db.namelist))) { 
    376                 g = db.namelist[i]; 
    377                 if (signature == g[4]) 
    378                   if (!strictDuplicateCheck) 
    379                     duplist.append(os.path.join(db.sgfpath, g[0])); 
    380                   else 
    381                     if (algolist[0].duplicateCheck(i, db.datapath)) 
    382                       duplist.append(os.path.join(db.sgfpath, g[0])); 
    383               } 
    384             } 
    385           } 
    386  
    387           if (strictDuplicateCheck) 
    388             char* dupText = " is the same as "; 
    389           else 
    390             char* dupText = " is probably the same as "; // do we have to delete this? FIXME 
    391  
    392           if (duplist.size()) { 
    393             ff = join(duplist, ', '); 
    394             if (duplicateCheck == 1) 
    395               messages.insert('end', 'Duplicate: ' + os.path.split(f)[1] +iColl+ dupText + ff + '.\n'); 
    396             else if (duplicateCheck == 3) { 
    397               messages.insert('end', 'Duplicate: '+os.path.split(f)[1]+iColl+\ 
    398                               dupText + ff + ', omitted.\n'); 
    399               continue; 
    400             } 
    401             else if (duplicateCheck == 2) { 
    402               if (askyesno('Duplicate', 'File ' +os.path.split(f)[1]+iColl\ 
    403                            + ' is the same as ' + ff + '. Include it?')) 
    404                 messages.insert('end', 'Duplicate: ' + os.path.split(f)[1]+iColl\ 
    405                                 + dupText + ff + '\n'); 
    406               else { 
    407                 messages.insert('end', 'Duplicate: ' + os.path.split(f)[1]\ 
    408                                 + dupText + ff + ', omitted.\n'); 
    409                 continue; 
    410               } 
    411             } 
    412           } 
    413         } 
    414          
    415         siglist.append(signature); 
    416       } 
    417  
    418       catch (*) { 
    419         messages.insert('end', 'File ' + f +iColl + ': Error computing the Dyer signature.\n'); 
    420         signature = '????????????'; 
    421       } 
    422  
    423       for (algo in algolist) algo.endgame_process(); 
    424           
    425       if (os.path.split(f)[1][-4:] == '.sgf') filenameDB = os.path.split(f)[1][:-4]; 
    426       else if (os.path.split(f)[1][-4:] == '.mgt') filenameDB = os.path.split(f)[1][:-2];  
    427       else filenameDB = os.path.split(f)[1] + '.'; 
    428                  
    429       namelist.append(filenameDB + iColl + '|%' + playerB + '|%' + playerW + '|%' \ 
    430                       + result + '|%' + signature + '|%' + date); 
    431  
    432       gameCtr++; 
    433     } 
    434   } 
    435  
    436   if (gameCtr) { 
    437     try { 
    438       for (algo in algolist) algo.finalize_process(datap); 
    439     } 
    440     catch IOError { 
    441       messages.insert('end', 'I/O Error: Could not write database files (Directory write-protected?).\n'); 
    442       return; 
    443     } 
    444          
    445     try { 
    446       file = open(os.path.join(datap[0], 'namelist' + datap[1] + '.db'), 'w'); 
    447       for (s in namelist) 
    448         file.write(s+'\n'); 
    449       file.close(); 
    450     } 
    451     catch IOError  
    452       messages.insert('end', 'I/O Error: Could not write namelist.db file.\n'); 
    453  
    454     if (progBar) { 
    455       progBar.redraw(1); 
    456       progBar.write('%1.1f seconds' % (time.time() - currentTime)); 
    457     } 
    458       
    459     messages.insert('end', '%1.1f seconds' % (time.time() - currentTime)); 
    460     messages.insert('end', '... finished.\n'); 
    461  
    462     datapath = datap; 
    463     sgfpath = dbpath; 
    464     algos = algos; // FIXME (algos, algos; auch namelist) 
    465     namelist = [split(x[:-1], '|%') for x in namelist[2:]]; 
    466     disabled = 0; 
    467     current = array('L', range(len(namelist)-2)); 
    468     results = []; 
    469   } 
     438        catch IOError  
     439XXX             messages.insert('end', 'I/O Error: Could not write namelist.db file.\n'); 
     440 
     441        // if (progBar) { 
     442        //      progBar.redraw(1); 
     443        //      progBar.write('%1.1f seconds' % (time.time() - currentTime)); 
     444        // } 
     445 
     446XXX     messages.insert('end', '%1.1f seconds' % (time.time() - currentTime)); 
     447XXX     messages.insert('end', '... finished.\n'); 
     448 
     449        datapath = datap; 
     450        sgfpath = dbpath; 
     451        algos = Algos; 
     452XXX     namelist = [split(x[:-1], '|%') for x in Namelist[2:]]; 
     453        disabled = 0; 
     454XXX     current = array('L', range(len(namelist)-2)); 
     455        results = []; 
     456
    470457} 
    471458 
  • 06/devel/searchPY.py

    r161 r169  
    4848    def insert(self, dummy, text): print text 
    4949 
    50  
    5150class no_message: 
    5251    def __init__(self): pass 
     
    5554# ------------------------------------------------------------------------- 
    5655 
    57  
     56class dummy_progbar: 
     57    def __init__(self): 
     58        pass 
     59 
     60    def clear(self): 
     61        pass 
     62 
     63    def redraw(self, x): 
     64        print x 
     65 
     66    def write(self, text): 
     67        pass 
     68 
     69# ------------------------------------------------------------------------- 
     70     
    5871class SGFDatabase: 
    5972 
    6073    def __init__(self, boardsize, progBar): 
    6174        self.boardsize = boardsize 
    62         self.progBar = progBar 
     75        if not progBar is None: self.progBar = progBar 
     76        else: self.progBar = dummy_progbar() 
    6377        self.datapath = ('', '') 
    6478        self.sgfpath = ''