Changeset 66

Show
Ignore:
Timestamp:
02/16/04 22:43:32 (5 years ago)
Author:
ug
Message:

Miscellaneous C++ transcoding

Files:

Legend:

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

    r14 r66  
    3535 
    3636 
    37  
    38 class NLEntry { 
    39 public: 
    40   char* white; 
    41   char* black; 
    42   char* date; 
    43   char* filename; 
    44   char* result; 
    45   char signature[12]; 
    46  
    47   char* concat(); 
    48 }; 
    4937 
    5038 
     
    8573 
    8674      
    87 void process(char* dbpath, pair<char*, int> datap, int algos, PyObject* flist,  
     75void SGFDatabase::process(char* dbpath, pair<char*, int> datap, int algos, PyObject* flist,  
    8876             PyObject* messages, PyObject gamelist, 
    8977             int sloppySGF, int duplicateCheck, 
     
    124112    fileCtr++; 
    125113 
    126     // if self.stopAddDBVar.get() == 1: # FIXME?! 
     114    // if self.stopAddDBVar.get() == 1: // FIXME?! 
    127115    //     showinfo('Stop processing', 'Processing will be stopped after this database has been finished.\n') 
    128116    //     self.stopAddDBVar.set(2) 
     
    483471 
    484472 
    485 int validNamelist(vector<> namelist) { 
     473int SGFDatabase::validNamelist(vector<> namelist) { 
    486474  if (namelist[0][:-1]=='kombilo06' &&  typeof(namelist[1][:-1]) == int && 
    487475      filename, PB, PW, res, sig, date = split(namelist[2][:-1], '|%'))         FIXME 
     
    491479 
    492480 
    493     def loadDB(self, sgfpath=None, datapath=None, disabled=0): 
     481void SGFDatabase::loadDB(char* sgfpth, char* datapth aufpassen (eigtl tupel?), int disabled) { 
    494482 
    495483        if not datapath is None: self.datapath = datapath 
     
    524512 
    525513        return 1 
    526  
    527  
    528     def start(self): 
    529         """ Iterate through self.current. Continue with 'next()'. """ 
     514
     515 
     516 
     517int SGFDatabase::start() { 
    530518         
    531519        if len(self.current) and not self.disabled: 
     
    537525            self.results = [] 
    538526            return self.current[0] 
    539  
    540          
    541     def next(self): 
     527
     528         
     529int SGFDatabase::next() { 
    542530        self.currentIndexWithinCurrent += 1 
    543531        if self.currentIndexWithinCurrent >= len(self.current): 
     
    546534 
    547535        return self.current[self.currentIndexWithinCurrent] 
    548  
    549  
    550     def makeCurrentCandidate(self, matchList): 
     536
     537 
     538 
     539void SGFDatabase::makeCurrentCandidate(matchList) { 
    551540        self.newCurrent.append(self.current[self.currentIndexWithinCurrent]) 
    552541        self.matchlists.append(matchList) 
    553  
    554  
    555     def makeCurrentHit(self, results): 
     542
     543 
     544void SGFDatabase::makeCurrentHit(results) { 
    556545        win = self.getCurrentWinner() 
    557546        self.newCurrent.append(self.current[self.currentIndexWithinCurrent]) 
    558547        self.results.append(results) 
    559  
    560  
    561     def discardCurrent(self): 
    562         pass 
    563  
    564  
    565     def getCurrentMatchlist(self): 
     548
     549 
     550void SGFDatabase::discardCurrent() { 
     551
     552 
     553 
     554SGFDatabase::getCurrentMatchlist() { 
    566555        try:    return self.oldMatchlists[self.currentIndexWithinCurrent] 
    567556        except: return [] 
    568  
    569  
    570     def getCurrentWinner(self): 
     557
     558 
     559SGFDatabase::getCurrentWinner() { 
    571560        currentWithinDB = self.current[self.currentIndexWithinCurrent] 
    572561        return self.namelist[currentWithinDB][3] 
    573  
    574  
    575 class Pattern 
    576  
    577  
    578 bool Pattern::operator==(const &Pattern p) { 
    579         if self.sizeX != p.sizeX or self.sizeY != p.sizeY: return 1 
    580         if self.anchors != p.anchors: return 1 
    581         if self.moveOne != p.moveOne: return 1 
    582         for i in range(self.sizeX): 
    583             if self.initialData[i] != p.initialData[i]: return 1 
    584         if self.contList != p.contList: return 1 
    585         return 0
    586 } 
    587  
    588  
    589     def __repr__(self): 
    590         """ final position!!! (FIXME?)""" 
    591         return join(self.data, '') 
    592  
     562
     563 
     564 
     565// ----------- class Pattern ----------------------------------------------- 
     566 
     567int Pattern::operator==(const &Pattern p) { 
     568  if (sizeX != p.sizeX || sizeY != p.sizeY) return 0; 
     569  if (anchors != p.anchors) return 0; // tupel? FIXME 
     570  if (moveOne != p.moveOne) return 0; 
     571  for(int i=0; i < sizeX; i++) 
     572    if (initialData[i] != p.initialData[i]) return 0; 
     573  if (contList != p.contList) return 0; // aufpassen ... FIXME 
     574  return 1
     575} 
     576 
     577 
     578def Pattern::repr() { 
     579  // """ final position!!! (FIXME?)""" 
     580  return join(self.data, ''); 
     581
    593582 
    594583char Pattern::BW2XO(char c) { 
     
    598587} 
    599588  
    600          
     589 
    601590Pattern::Pattern(PyObject* anch, PyObject* initialDict, PyObject* contList, char mOne) { 
    602591  flip = 0; 
     
    616605        end = l[len(l)-1] 
    617606 
    618         self.sizeX = end[0] - start[0] + 1 
    619         self.sizeY = end[1] - start[1] + 1 
     607        sizeX = end[0] - start[0] + 1 
     608        sizeY = end[1] - start[1] + 1 
    620609 
    621610        self.initialData = [] 
     
    629618            initialDict[(x,y)]=BW2XO(co) 
    630619 
    631         self.data = [] # final position 
     620        self.data = []  
    632621        for i in range(self.sizeX): 
    633622            helpData = [] 
     
    638627        self.contList = [(x-start[0], y-start[1], self.BW2XO(co)) for x, y, co in contList] 
    639628         
    640         self.bits = [] # list of 4 bit-patterns 
     629        self.bits = [] 
    641630 
    642631        for i in range(2): 
     
    675664 
    676665    flips = [] 
    677     flips.append(lambda x,y, XX=18, YY=18: (x,y))                  # FIXME: different boardsize 
     666    flips.append(lambda x,y, XX=18, YY=18: (x,y))                  // FIXME: different boardsize 
    678667    flips.append(lambda x,y, XX=18, YY=18: (XX-x,y)) 
    679668    flips.append(lambda x,y, XX=18, YY=18: (x,YY-y)) 
     
    685674 
    686675 
    687 def PatternInvFlip(i): 
    688     return [0,1,2,3,4,6,5,7][i] 
    689  
     676int PatternInvFlip(i) { 
     677  if (i == 5) return 6; 
     678  if (i == 6) return 5; 
     679  return i; 
     680
    690681 
    691682PatternList::PatternList(Pattern p, int fColor, int nextMove) { 
     
    770761        for p in lCS: 
    771762            if not p in l: l.append(p) 
    772          
    773         # compute symmetries 
    774763         
    775764        symm = {} 
     
    798787        else: 
    799788            symm[-1] = PatternInvFlip(special) 
    800             # if there is a flip f such that color_swap(f(pattern)) == pattern, 
    801             # then this is stored as symm[-1] 
    802             # this is needed to get the continuation symmetries right when the 
    803             # color of the next move is fixed 
    804789 
    805790        self.symmetries = symm 
     
    818803 
    819804 
    820 PatternList::updateContinuations(self, index, x, y, co, Xint, Yint, 
     805PatternList::updateContinuations(index, x, y, co, Xint, Yint, 
    821806                            foundWhere, counter, 
    822807                            continuations, contLabels, contLabelsIndex, 
     
    872857                    if colorSwitch: numOfSwitched += 1 
    873858                else: 
    874                     return 0,0,0,0 # not a hit! 
     859                    return 0,0,0,0 
    875860            else: 
    876861                colorSwitch = cSymm 
     
    887872                contLabelsIndex += 1 
    888873            if cc == 'B': 
    889                 continuations[(xx,yy)] = {'B':1, 'W':0,       # B/W continuations at this point 
    890                                           'tB':0, 'tW':0,     # tenukis among the above 
    891                                           'wB':0,'lB':0,'wW':0,'lW':0, # B wins/losses among BW continuations 
     874                continuations[(xx,yy)] = {'B':1, 'W':0, 
     875                                          'tB':0, 'tW':0, 
     876                                          'wB':0,'lB':0,'wW':0,'lW':0, 
    892877                                          'N': text} 
    893878            else: 
     
    914899 
    915900 
    916 class hashTable: 
    917  
    918     def __init__(self, noOfGames, filename): 
     901// -------------- class hashTable ------------------------------------------------ 
     902 
     903 
     904hashTable(int noOfGames, char* filename) { 
    919905         self.data = array('l', [0]*(2*130*noOfGames)) 
    920906         self.currentCtr = -1 
    921907         self.dataIndex = 0 
    922908         self.filename = filename 
    923           
    924  
    925     def newCtr(self, ctr): 
     909
     910 
     911void hashtable::newCtr(ctr) { 
    926912        if ctr == self.currentCtr: 
    927913            while self.dataIndex > 0 and self.data[self.dataIndex-1] == ctr: 
     
    929915        self.currentCtr = ctr 
    930916        self.currentCtrL = [] 
    931  
     917
    932918          
    933     def append(self, i): 
     919void hashTable::append(int i) { 
    934920         
    935921        ctr = self.currentCtr 
     
    943929            self.dataIndex += 1 
    944930            self.currentCtrL.append(i) 
    945  
    946  
    947     def swap(self, l, r): 
     931
     932 
     933 
     934void hashTable::swap(int l, int r) { 
    948935        help1 = self.data[2*l] 
    949936        help2 = self.data[2*l+1] 
     
    952939        self.data[2*r] = help1 
    953940        self.data[2*r+1] = help2 
    954  
    955              
    956     def sort(self): 
     941
     942             
     943 
     944void hashTable::sort() { 
    957945 
    958946        l = 0 
     
    997985            else: 
    998986                l, r = stack.pop() 
    999  
    1000  
    1001     def sortedOutput(self, path): 
     987
     988 
     989 
     990hashTable::sortedOutput(char* path) { 
    1002991        self.sort() 
    1003992 
     
    1005994        data1X = array('B') 
    1006995 
    1007         currentCode = self.data[0] - 1  # != self.data[0] ! 
     996        currentCode = self.data[0] - 1 
    1008997        currentValues = [] 
    1009998         
     
    10321021        data1X.tofile(file) 
    10331022        file.close() 
    1034              
     1023
    10351024 
    10361025    hash_value = { 
     
    11581147        } 
    11591148         
    1160 # --------------------------------------------------------------------------------------- 
    1161  
    1162 def symmetrizeSig(s): 
     1149// --------------------------------------------------------------------------------------- 
     1150 
     1151char* symmetrizeSig(char* s) { 
    11631152 
    11641153    l = [] 
     
    11791168    m.sort() 
    11801169    return m[0] 
    1181  
    1182 # --------------------------------------------------------------------------------------- 
    1183  
    1184 class Algorithm: # virtual 
    1185  
    1186     def __init__(self, boardsize): pass 
    1187  
    1188     def initialize_process(self): 
     1170
     1171 
     1172 
     1173// --------------------------------------------------------------------------------------- 
     1174 
     1175class Algorithm: 
     1176 
     1177    def __init__(boardsize): pass 
     1178 
     1179    def initialize_process(): 
    11891180        """ Start of database. """ 
    11901181        pass 
    11911182 
    1192     def newgame_process(self): 
     1183    def newgame_process(): 
    11931184        """ New game. """ 
    11941185        pass 
    11951186     
    1196     def AB_process(self, x, y): pass 
    1197  
    1198     def AW_process(self, x, y): pass 
    1199  
    1200     def AE_process(self, x, y, removed): pass 
    1201  
    1202     def endOfNode_process(self): pass 
    1203  
    1204     def B_process(self, counter, x, y, cap): pass 
    1205  
    1206     def W_process(self, counter, x, y, cap): pass 
    1207  
    1208     def branchpoint_process(self): pass 
    1209  
    1210     def endOfVariation_process(self): pass 
    1211  
    1212     def endgame_process(self): pass 
    1213          
    1214     def finalize_process(self, datap): 
     1187    def AB_process(x, y): pass 
     1188 
     1189    def AW_process(x, y): pass 
     1190 
     1191    def AE_process(x, y, removed): pass 
     1192 
     1193    def endOfNode_process(): pass 
     1194 
     1195    def B_process(counter, x, y, cap): pass 
     1196 
     1197    def W_process(counter, x, y, cap): pass 
     1198 
     1199    def branchpoint_process(): pass 
     1200 
     1201    def endOfVariation_process(): pass 
     1202 
     1203    def endgame_process(): pass 
     1204         
     1205    def finalize_process(datap): 
    12151206        """ End of database. """ 
    12161207        pass 
    12171208 
    1218     filelist = [] # List of the names of the files written to disk by this algorithm. 
    1219  
    1220     # --------------------------------------------------------------- 
    1221  
    1222     def search(self, patternList, options, gamelist, matchlist): pass  
    1223  
    1224 # ------------------------------------------------------------------------------------------ 
    1225  
    1226 class Algo_finalpos(Algorithm): 
    1227  
    1228  
    1229  
    1230     def __init__(self, boardsize): 
    1231         pass 
    1232  
    1233     def initialize_process(self, l): 
    1234         """ Start of database. """ 
    1235         self.finalpos = array('B') 
    1236  
    1237     def newgame_process(self): 
    1238         """ New game. """ 
    1239         self.fp = array('B', [255] * 100)   # '20x20x2 bit-array', in the end 00 means: B, W at some time, 
    1240                                             #                                 01 = never B, but W ... 
    1241  
    1242     def AB_process(self, x, y): 
    1243         self.fp[y/2 + 10*(x/2)] &= ~(1 << (2*(x%2 + 2*(y%2)))) 
    1244  
    1245     def AW_process(self, x, y): 
    1246         self.fp[y/2 + 10*(x/2)] &= ~(1 << (2*(x%2 + 2*(y%2))+1)) 
    1247  
    1248     def AE_process(self, x, y, removed): 
    1249         pass 
    1250  
    1251     def endOfNode_process(self): 
    1252         pass 
    1253  
    1254     def B_process(self, x, y, cap): 
    1255         self.fp[y/2 + 10*(x/2)] &= ~(1 << (2*(x%2 + 2*(y%2)))) 
    1256  
    1257     def W_process(self, x, y, cap): 
    1258         self.fp[y/2 + 10*(x/2)] &= ~(1 << (2*(x%2 + 2*(y%2))+1)) 
    1259  
    1260     def branchpoint_process(self): 
    1261         pass 
    1262  
    1263     def endOfVariation_process(self): 
    1264         pass 
    1265  
    1266     def endgame_process(self): 
    1267         self.finalpos.extend(self.fp) 
    1268  
    1269     def finalize_process(self, datap): 
    1270         """ End of database. """ 
    1271  
    1272         file = open(os.path.join(datap[0], 'finalpos'+ datap[1] + '.db'), 'wb') 
    1273         self.finalpos.tofile(file) 
    1274         file.close() 
    1275  
    1276     filelist = ['finalpos'] 
    1277  
    1278     # --------------------------------------------------------------- 
    1279  
    1280     def duplicateCheck(self, sli, datapath=None): 
     1209    filelist = []  
     1210 
     1211    def search(patternList, options, gamelist, matchlist): pass  
     1212 
     1213 
     1214// ------------------------------------------------------------------------------------------ 
     1215 
     1216 
     1217Algo_finalpos(int bs) { 
     1218
     1219 
     1220 
     1221void Algo_finalpos::initialize_process(int l) { 
     1222  self.finalpos = array('B'); 
     1223
     1224 
     1225void Algo_finalpos::newgame_process() { 
     1226  self.fp = array('B', [255] * 100);   // '20x20x2 bit-array', in the end 00 means: B, W at some time, 
     1227                                       //                                 01 = never B, but W ... 
     1228
     1229 
     1230void Algo_finalpos::AB_process(int x, int y) { 
     1231  self.fp[y/2 + 10*(x/2)] &= ~(1 << (2*(x%2 + 2*(y%2)))); 
     1232
     1233 
     1234void Algo_finalpos::AW_process(int x, int y) { 
     1235  self.fp[y/2 + 10*(x/2)] &= ~(1 << (2*(x%2 + 2*(y%2))+1)); 
     1236
     1237 
     1238void Algo_finalpos::AE_process(int x, int y, removed) { 
     1239
     1240 
     1241void Algo_finalpos::endOfNode_process() { 
     1242
     1243 
     1244void Algo_finalpos::B_process(int x, int y, cap) { 
     1245  self.fp[y/2 + 10*(x/2)] &= ~(1 << (2*(x%2 + 2*(y%2)))); 
     1246
     1247 
     1248void Algo_finalpos::W_process(int x, int y, cap) { 
     1249  self.fp[y/2 + 10*(x/2)] &= ~(1 << (2*(x%2 + 2*(y%2))+1)); 
     1250
     1251 
     1252void Algo_finalpos::branchpoint_process() { 
     1253
     1254 
     1255void Algo_finalpos::endOfVariation_process() { 
     1256
     1257 
     1258void Algo_finalpos::endgame_process() { 
     1259  self.finalpos.extend(self.fp); 
     1260
     1261 
     1262void Algo_finalpos::finalize_process(datap) { 
     1263  file = open(os.path.join(datap[0], 'finalpos'+ datap[1] + '.db'), 'wb'); 
     1264  self.finalpos.tofile(file); 
     1265  file.close(); 
     1266 
     1267  filelist = ['finalpos']; 
     1268
     1269 
     1270 
     1271int Algo_finalpos::duplicateCheck(sli, datapath=None) { 
    12811272        if datapath is None: 
    12821273            if self.finalpos[sli*100:sli*100+100] == self.fp: return 1 
     
    12961287        if self.currentFP[sli*100:sli*100+100] == self.fp: return 1 
    12971288        else: return 0 
    1298  
    1299     # --------------------------------------------------------------- 
    1300  
    1301     def retrieve_db(self, datap): 
     1289
     1290 
     1291int Algo_finalpos::retrieve_db(datap) { 
    13021292        try: 
    13031293            self.finalpos = array('B') 
     
    13121302        except IOError: 
    13131303            return 0 
    1314  
    1315  
    1316     def search(self, patternList, options, db, progBar, progStart, progEnd): 
     1304
     1305 
     1306Algo_finalpos::search(patternList, options, db, progBar, progStart, progEnd) { 
    13171307 
    13181308        ctr = 0 
     
    13221312        counter = 0 
    13231313        if not self.retrieve_db(db.datapath): 
    1324             print 'error' # FIXME 
     1314         print 'error'// FIXME 
    13251315            return 
    13261316 
     
    13601350                            fpIndex += 10 - start - length 
    13611351                             
    1362                         if matches:                       # found candidate 
     1352                        if matches: 
    13631353                            matchList.append((N,(a0,a1))) 
    13641354 
     
    13681358 
    13691359            index = db.next() 
    1370  
     1360
    13711361 
    13721362// in x-coord: 
    1373 ENDOFNODE = 128 
    1374 BRANCHPOINT = 64          # these two flags ... 
    1375 ENDOFVARIATION = 32       # ... are not combined with move coordinates 
     1363const int ENDOFNODE = 128; 
     1364const int BRANCHPOINT = 64; 
     1365const int ENDOFVARIATION = 32; 
    13761366 
    13771367// in y-coord 
    1378 REMOVE = 128 
    1379 BLACK = 64 
    1380 WHITE = 32 
    1381  
    1382 class Algo_movelist(Algorithm): 
    1383  
    1384     def __init__(self, boardsize): 
    1385         pass 
    1386  
    1387  
    1388     def initialize_process(self, l): 
    1389         """ Start of database. """ 
    1390         self.mainlistArr = array('B')    # here we store all the move lists of the current database 
    1391         self.posTable = array('L')       # this is a table of pointers to the beginning of the 
    1392                                          # corresponding move list 
    1393         self.finalposC = array('B')      # here we store information about captures; this should be 
    1394                                           
    1395  
    1396     def newgame_process(self): 
    1397         """ New game. """ 
    1398         self.movelist = array('B') 
    1399         self.fpC = array('B', [0] * 50)     # '20x20 bit array', 0 = never captured, 1 = captured at some point 
    1400          
    1401  
    1402     def AB_process(self, x, y): 
    1403         self.movelist.append(x) 
    1404         self.movelist.append(y | BLACK) 
    1405          
    1406  
    1407     def AW_process(self, x, y): 
    1408         self.movelist.append(x) 
    1409         self.movelist.append(y | WHITE) 
    1410  
    1411  
    1412     def AE_process(self, x, y, removed): 
    1413         self.movelist.append(x) 
     1368const int REMOVE = 128; 
     1369const int BLACK = 64; 
     1370const int WHITE = 32; 
     1371 
     1372 
     1373  Algo_movelist(int bs) { 
     1374
     1375 
     1376void Algo_movelist:: initialize_process(l) { 
     1377 
     1378  self.mainlistArr = array('B');     
     1379  self.posTable = array('L');        
     1380                                     
     1381  self.finalposC = array('B');       
     1382}                                          
     1383 
     1384void Algo_movelist::newgame_process() { 
     1385 
     1386  self.movelist = array('B'); 
     1387  self.fpC = array('B', [0] * 50); 
     1388
     1389         
     1390void Algo_movelist::AB_process(int x, int y) { 
     1391  self.movelist.append(x); 
     1392  self.movelist.append(y | BLACK); 
     1393
     1394         
     1395 
     1396void Algo_movelist::AW_process(int x, int y) { 
     1397  self.movelist.append(x); 
     1398  self.movelist.append(y | WHITE); 
     1399
     1400 
     1401 
     1402void Algo_movelist::AE_process(int x, int y, removed) { 
     1403  self.movelist.append(x); 
    14141404        if removed == 'B': 
    14151405            self.movelist.append(y | REMOVE | BLACK) 
    14161406        elif removed == 'W': 
    14171407            self.movelist.append(y | REMOVE | WHITE) 
    1418         else: print 'oops' # FIXME 
    1419  
    1420  
    1421     def endOfNode_process(self): 
     1408                    else: print 'oops'  // FIXME 
     1409
     1410 
     1411void Algo_movelist::endOfNode_process() { 
    14221412        if self.movelist: 
    1423             if self.movelist[-2] & ENDOFNODE: # there has been a pass or something, so we append an extra node 
     1413            if self.movelist[-2] & ENDOFNODE: 
    14241414                self.movelist.append(ENDOFNODE) 
    14251415                self.movelist.append(0) 
    14261416            else: 
    14271417                self.movelist[-2] |= ENDOFNODE 
    1428  
    1429  
    1430     def B_process(self, x, y, cap): 
    1431         if not self.movelist:                  # the game starts here, so we put an ENDOFNODE here, 
    1432             self.movelist.append(ENDOFNODE)    # to make sure that the empty board can be found  
     1418
     1419 
     1420void Algo_movelist::B_process(int x, int y, cap) { 
     1421  if not self.movelist: 
     1422            self.movelist.append(ENDOFNODE) 
    14331423            self.movelist.append(0) 
    14341424 
     
    14401430            self.movelist.append(y | REMOVE | WHITE) 
    14411431            self.fpC[y/4 + 5*(x/2)] |= 1 << (x%2 + 2*(y%4)) 
    1442   
     1432
    14431433                 
    1444     def W_process(self, x, y, cap): 
     1434void Algo_movelist::W_process(int x, int y, cap) { 
    14451435        if not self.movelist: 
    14461436            self.movelist.append(ENDOFNODE) 
     
    14541444            self.movelist.append(y | REMOVE | BLACK) 
    14551445            self.fpC[y/4 + 5*(x/2)] |= 1 << (x%2 + 2*(y%4)) 
    1456  
    1457  
    1458     def branchpoint_process(self): 
     1446
     1447 
     1448void Algo_movelist::branchpoint_process() { 
    14591449        self.movelist.append(BRANCHPOINT) 
    14601450        self.movelist.append(0) 
    1461          
    1462  
    1463     def endOfVariation_process(self): 
    1464         self.movelist.append(ENDOFVARIATION) 
    1465         self.movelist.append(0) 
    1466  
    1467  
    1468     def endgame_process(self): 
    1469         self.posTable.append(len(self.mainlistArr)) 
    1470         self.mainlistArr.append(255)                  # FIXME: this delimiter shouldn't be needed 
    1471         self.mainlistArr.append(255) 
    1472         self.mainlistArr.extend(self.movelist) 
    1473  
    1474         self.finalposC.extend(self.fpC) 
    1475  
    1476  
    1477     def finalize_process(self, datap): 
    1478         """ End of database. """ 
     1451
     1452 
     1453void Algo_movelist::endOfVariation_process() { 
     1454  self.movelist.append(ENDOFVARIATION); 
     1455  self.movelist.append(0); 
     1456
     1457 
     1458void Algo_movelist::endgame_process() { 
     1459  self.posTable.append(len(self.mainlistArr)); 
     1460  self.mainlistArr.append(255); 
     1461  self.mainlistArr.append(255); 
     1462  self.mainlistArr.extend(self.movelist); 
     1463 
     1464  self.finalposC.extend(self.fpC) 
     1465
     1466 
     1467void Algo_movelist::finalize_process(datap) { 
    14791468         
    14801469        filelist = [(self.posTable, 'posTable'), (self.mainlistArr, 'lists'), 
     
    14841473            var.tofile(file) 
    14851474            file.close() 
    1486  
    1487  
    1488     filelist = ['posTable', 'lists', 'finalposC'] 
    1489  
    1490     # --------------------------------------------------------------- 
    1491  
    1492     def retrieve_db(self, datap): 
     1475
     1476 
     1477filelist = ['posTable', 'lists', 'finalposC'] 
     1478 
     1479 
     1480 
     1481void Algo_movelist::retrieve_db(datap) { 
    14931482        try: 
    14941483            self.posTable = array('L') 
     
    15061495        except IOError: 
    15071496            return 0 
    1508              
    1509  
    1510     def search(self, patternList, options, db,  
    1511                continuations, contLabelsIndex, contLabels, 
    1512                progBar, progStart, progEnd): 
     1497
     1498 
     1499void Algo_movelist::search(patternList, options, db,  
     1500                          continuations, contLabelsIndex, contLabels, 
     1501                           progBar, progStart, progEnd) { 
    15131502 
    15141503        numOfHits = 0 
     
    15231512 
    15241513        if not self.retrieve_db(db.datapath): 
    1525             print "error" # FIXME 
     1514         print "error" // FIXME 
    15261515            return 
    15271516             
     
    15531542            Yinterv = {} 
    15541543 
    1555             # initialize dictionaries 
    1556              
    15571544            for m in db.getCurrentMatchlist(): 
    15581545                d = {} 
     
    15661553 
    15671554                dicts[m] = d 
    1568                 dictsNO[m] = dNO # no of places that are currently not correct 
     1555                dictsNO[m] = dNO 
    15691556 
    15701557                contList[m] = [] 
     
    15751562                Xinterv[m] = (m[1][0], m[1][0] + patternList.get(m[0]).sizeX) 
    15761563                Yinterv[m] = (m[1][1], m[1][1] + patternList.get(m[0]).sizeY) 
    1577  
    1578             # go through the game 
    15791564 
    15801565            counter = 0 
     
    16151600                        if Xinterv[m][0] <= x < Xinterv[m][1] and Yinterv[m][0] <= y < Yinterv[m][1]: 
    16161601 
    1617                             if dicts[m].has_key('found'):   # so (x,y) is the continuation 
     1602                            if dicts[m].has_key('found'): 
    16181603                                hit, label, contLabelsIndex, switched =\ 
    16191604                                     patternList.updateContinuations(m[0], x, y, invco, 
     
    16281613                                    continue 
    16291614 
    1630                                 numOfSwitched += switched # FIXME: CHECK, was: patternList[m[0]].colorSwitch 
     1615                                        numOfSwitched += switched // FIXME: CHECK, was: patternList[m[0]].colorSwitch 
    16311616 
    16321617                                if switched and showColorSwap: 
    1633                                     # FIXME: CHECK,was: (patternList[m[0]].colorSwitch or colorSwitch) and showColorSwap: 
     1618                                 // FIXME: CHECK,was: (patternList[m[0]].colorSwitch or colorSwitch) and showColorSwap: 
    16341619                                    result.append((dicts[m]['found'], label + '-')) 
    16351620                                else: 
     
    16371622                                del dicts[m] 
    16381623                                del dictsNO[m] 
    1639                                 continue     # with for m in dicts.keys() 
     1624                                     continue     // with for m in dicts.keys() 
    16401625 
    16411626                            elif dicts[m].has_key('foundInitial'): 
     
    16551640                            if not dicts[m].has_key((x,y)): 
    16561641                                if not (self.finalposC[index*50 + y/4 + 5*(x/2)] & (1 << (x%2 + 2*(y%4)))): 
    1657                                                                   # this stone won't be captured later, 
    1658                                                                   # so this cannot become a match 
     1642 
    16591643                                    if not contListIndex[m]: 
    16601644                                        del dicts[m] 
     
    16871671                        co = 'O' 
    16881672                        invco = 'X' 
    1689                     else: print 'oops' # FIXME 
     1673                                else: print 'oops' // FIXME 
    16901674 
    16911675                    for m in dicts.keys(): 
     
    17351719                movelistIndex += 2 
    17361720 
    1737             # check for hits with no continuation: 
    1738                      
    17391721            if not patternList.nextMove: 
    17401722                for m in dicts.keys(): 
     
    17461728                            result.append((dicts[m]['found'], '')) 
    17471729 
    1748             # assemble results for this game, and return them to the SGFDatabase 
    1749  
    17501730            if result: 
    17511731                numOfHits = numOfHits + len(result) 
     
    17671747 
    17681748        return numOfHits, Bwins, Wwins, self.numOfSwitched 
    1769  
     1749
    17701750     
    1771 class Algo_hash(Algorithm): 
    1772  
    1773     def __init__(self, boardsize, poslist, filename): 
    1774         self.poslist = [[0,0] + p for p in poslist] # store num of stones and current 
    1775                                                     # hashcode in first two entries  
     1751 
     1752Algo_hash(boardsize, poslist, filename) { 
     1753        self.poslist = [[0,0] + p for p in poslist] 
    17761754        self.filename = filename 
    1777          
    1778  
    1779     def initialize_process(self, l): 
     1755
     1756 
     1757void Algo_hash::initialize_process(l) { 
    17801758        """ Start of database. """ 
    17811759        self.hash_global = hashTable(l, self.filename) 
    17821760        self.gameCtr = 0 
    1783  
    1784          
    1785     def newgame_process(self): 
    1786         """ New game. """ 
     1761
     1762         
     1763void Algo_hash::newgame_process() { 
    17871764 
    17881765        for p in self.poslist: 
     
    17921769        self.hash_global.newCtr(self.gameCtr) 
    17931770        self.branchpoints = [] 
    1794  
    1795  
    1796     def AB_process(self, x, y): 
     1771
     1772 
     1773void Algo_hash::AB_process(int x, int y) { 
    17971774        for p in self.poslist: 
    17981775            if p[2] <= x <= p[4] and p[3] <= y <= p[5]: 
    17991776                p[0] += 1 
    18001777                p[1] += hashTable.hash_value[(x,y)] 
    1801                  
    1802  
    1803     def AW_process(self, x, y): 
     1778
     1779 
     1780void Algo_hash::AW_process(int x, int y) { 
    18041781       for p in self.poslist: 
    18051782            if p[2] <= x <= p[4] and p[3] <= y <= p[5]: 
    18061783                p[0] += 1 
    18071784                p[1] -= hashTable.hash_value[(x,y)] 
    1808                      
    1809  
    1810     def AE_process(self, x, y, removed): 
     1785}                  
     1786 
     1787void Algo_hash::AE_process(int x, int y, removed) { 
    18111788        if removed == 'B': epsilon = -1 
    18121789        else: epsilon = 1 
     
    18161793                p[0] -= 1 
    18171794                p[1] += epsilon * hashTable.hash_value[(x,y)] 
    1818                      
    1819  
    1820     def endOfNode_process(self): 
     1795
     1796 
     1797void Algo_hash::endOfNode_process() { 
    18211798        for p in self.poslist: 
    18221799            if p[0] <= p[6]: self.hash_global.append(p[1]) 
    1823  
    1824  
    1825     def B_process(self, x, y, cap): 
     1800
     1801 
     1802void Algo_hash::B_process(int x, int y, cap) { 
    18261803        self.move_process(x, y, cap, 1) 
    1827  
    1828  
    1829     def W_process(self, x, y, cap): 
     1804
     1805 
     1806void Algo_hash::W_process(int x, int y, cap) { 
    18301807        self.move_process(x, y, cap, -1) 
    1831  
    1832  
    1833     def move_process(self, x, y, cap, epsilon): 
     1808
     1809 
     1810void Algo_hash::move_process(int x, int y, cap, epsilon) { 
    18341811        for p in self.poslist: 
    18351812            if p[2] <= x <= p[4] and p[3] <= y <= p[5]: 
     
    18421819                    p[0] -= 1 
    18431820                    p[1] += epsilon * hashTable.hash_value[c] 
    1844  
    1845  
    1846     def branchpoint_process(self): 
     1821
     1822 
     1823void Algo_hash::branchpoint_process() { 
    18471824        self.branchpoints.append(deepcopy(self.poslist)) 
    1848  
    1849  
    1850     def endOfVariation_process(self): 
     1825
     1826 
     1827void Algo_hash::endOfVariation_process() { 
    18511828        self.poslist = self.branchpoints.pop() 
    1852  
    1853  
    1854     def endgame_process(self): 
     1829
     1830 
     1831void Algo_hash::endgame_process() { 
    18551832        self.gameCtr += 1 
    1856  
     1833
    18571834  
    1858     def finalize_process(self, datap): 
     1835void Algo_hash::finalize_process(datap) { 
    18591836        """ End of database. """ 
    18601837         
    1861         self.hash_global.newCtr(self.gameCtr)  # in order to correct the hash table if the last game was 
    1862                                                # erroneous or a duplicate 
     1838        self.hash_global.newCtr(self.gameCtr) 
    18631839        self.hash_global.sortedOutput(datap) 
    1864  
    1865  
    1866     # filelist = ['hash', 'hashT'] 
    1867  
    1868     # --------------------------------------------------------------- 
    1869  
    1870     def compute_hashkey(self, pattern, type): 
     1840
     1841 
     1842          // filelist = ['hash', 'hashT'] 
     1843 
     1844 
     1845void Algo_hash::compute_hashkey(pattern, type) { 
    18711846 
    18721847        numOfStones = 0 
     
    18891864 
    18901865        return hashkey 
    1891      
    1892  
    1893     def retrieve_db(self, datap): 
     1866
     1867 
     1868void Algo_hash::retrieve_db(datap) { 
    18941869        try: 
    18951870            self.hashT = array('l') 
     
    19051880        except IOError: 
    19061881            return 0 
    1907  
    1908  
    1909     def search(self, patternList, options, db, progBar, progStart, progEnd): 
    1910  
    1911         """ 
    1912         FIXME: documentation 
    1913         """ 
     1882
     1883 
     1884void Algo_hash::search(patternList, options, db, progBar, progStart, progEnd) { 
    19141885 
    19151886        for i in range(patternList.size()): 
     
    19251896                            hk = self.compute_hashkey(pattern, p[2:]) 
    19261897 
    1927                             # If we get a hashkey, append it to pattern.hashkeys[(a0,a1)], 
    1928                             # we append this as a list because we will then be able to 
    1929                             # store start, index, end corresponding to that hash key in 
    1930                             # the table of hash keys in the same list 
    1931  
    19321898                            if not hk is None: pattern.hashkeys[(a0,a1)].append([hk]) 
    19331899                             
    1934                     if not pattern.hashkeys[(a0,a1)]: return          # we need to have a hashkey for 
    1935                                                                       # each anchor of each pattern, 
    1936                                                                       # otherwise this algorithm cannot be 
    1937                                                                       # applied, and we just return 
     1900                    if not pattern.hashkeys[(a0,a1)]: return 
    19381901         
    19391902        if not self.retrieve_db(db.datapath): 
    1940             print "error" # FIXME 
     1903         print "error" // FIXME 
    19411904            return 
    19421905         
     
    19491912                    for hk in range(len(pattern.hashkeys[(a0,a1)])): 
    19501913 
    1951                         # do a binary search for hashkey in self.hashT 
    19521914                        hashkey = pattern.hashkeys[(a0,a1)][hk][0] 
    19531915                        start = 0 
     
    19631925 
    19641926                                pattern.hashkeys[(a0,a1)][hk].extend([hash_start, 
    1965