Changeset 66
- Timestamp:
- 02/16/04 22:43:32 (5 years ago)
- Files:
-
- 06/devel/search.cc (modified) (75 diffs)
- 06/devel/search.h (modified) (1 diff)
- 06/devel/search.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/devel/search.cc
r14 r66 35 35 36 36 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 };49 37 50 38 … … 85 73 86 74 87 void process(char* dbpath, pair<char*, int> datap, int algos, PyObject* flist,75 void SGFDatabase::process(char* dbpath, pair<char*, int> datap, int algos, PyObject* flist, 88 76 PyObject* messages, PyObject gamelist, 89 77 int sloppySGF, int duplicateCheck, … … 124 112 fileCtr++; 125 113 126 // if self.stopAddDBVar.get() == 1: #FIXME?!114 // if self.stopAddDBVar.get() == 1: // FIXME?! 127 115 // showinfo('Stop processing', 'Processing will be stopped after this database has been finished.\n') 128 116 // self.stopAddDBVar.set(2) … … 483 471 484 472 485 int validNamelist(vector<> namelist) {473 int SGFDatabase::validNamelist(vector<> namelist) { 486 474 if (namelist[0][:-1]=='kombilo06' && typeof(namelist[1][:-1]) == int && 487 475 filename, PB, PW, res, sig, date = split(namelist[2][:-1], '|%')) FIXME … … 491 479 492 480 493 def loadDB(self, sgfpath=None, datapath=None, disabled=0): 481 void SGFDatabase::loadDB(char* sgfpth, char* datapth aufpassen (eigtl tupel?), int disabled) { 494 482 495 483 if not datapath is None: self.datapath = datapath … … 524 512 525 513 return 1 526 527 528 def start(self): 529 """ Iterate through self.current. Continue with 'next()'. """ 514 } 515 516 517 int SGFDatabase::start() { 530 518 531 519 if len(self.current) and not self.disabled: … … 537 525 self.results = [] 538 526 return self.current[0] 539 540 541 def next(self): 527 } 528 529 int SGFDatabase::next() { 542 530 self.currentIndexWithinCurrent += 1 543 531 if self.currentIndexWithinCurrent >= len(self.current): … … 546 534 547 535 return self.current[self.currentIndexWithinCurrent] 548 549 550 def makeCurrentCandidate(self, matchList): 536 } 537 538 539 void SGFDatabase::makeCurrentCandidate(matchList) { 551 540 self.newCurrent.append(self.current[self.currentIndexWithinCurrent]) 552 541 self.matchlists.append(matchList) 553 554 555 def makeCurrentHit(self, results): 542 } 543 544 void SGFDatabase::makeCurrentHit(results) { 556 545 win = self.getCurrentWinner() 557 546 self.newCurrent.append(self.current[self.currentIndexWithinCurrent]) 558 547 self.results.append(results) 559 560 561 def discardCurrent(self): 562 pass 563 564 565 def getCurrentMatchlist(self): 548 } 549 550 void SGFDatabase::discardCurrent() { 551 } 552 553 554 SGFDatabase::getCurrentMatchlist() { 566 555 try: return self.oldMatchlists[self.currentIndexWithinCurrent] 567 556 except: return [] 568 569 570 def getCurrentWinner(self): 557 } 558 559 SGFDatabase::getCurrentWinner() { 571 560 currentWithinDB = self.current[self.currentIndexWithinCurrent] 572 561 return self.namelist[currentWithinDB][3] 573 574 575 class Pattern 576 577 578 boolPattern::operator==(const &Pattern p) {579 if self.sizeX != p.sizeX or self.sizeY != p.sizeY: return 1580 if self.anchors != p.anchors: return 1581 if self.moveOne != p.moveOne: return 1582 for i in range(self.sizeX):583 if self.initialData[i] != p.initialData[i]: return 1584 if self.contList != p.contList: return 1585 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 567 int 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 578 def Pattern::repr() { 579 // """ final position!!! (FIXME?)""" 580 return join(self.data, ''); 581 } 593 582 594 583 char Pattern::BW2XO(char c) { … … 598 587 } 599 588 600 589 601 590 Pattern::Pattern(PyObject* anch, PyObject* initialDict, PyObject* contList, char mOne) { 602 591 flip = 0; … … 616 605 end = l[len(l)-1] 617 606 618 s elf.sizeX = end[0] - start[0] + 1619 s elf.sizeY = end[1] - start[1] + 1607 sizeX = end[0] - start[0] + 1 608 sizeY = end[1] - start[1] + 1 620 609 621 610 self.initialData = [] … … 629 618 initialDict[(x,y)]=BW2XO(co) 630 619 631 self.data = [] # final position620 self.data = [] 632 621 for i in range(self.sizeX): 633 622 helpData = [] … … 638 627 self.contList = [(x-start[0], y-start[1], self.BW2XO(co)) for x, y, co in contList] 639 628 640 self.bits = [] # list of 4 bit-patterns629 self.bits = [] 641 630 642 631 for i in range(2): … … 675 664 676 665 flips = [] 677 flips.append(lambda x,y, XX=18, YY=18: (x,y)) #FIXME: different boardsize666 flips.append(lambda x,y, XX=18, YY=18: (x,y)) // FIXME: different boardsize 678 667 flips.append(lambda x,y, XX=18, YY=18: (XX-x,y)) 679 668 flips.append(lambda x,y, XX=18, YY=18: (x,YY-y)) … … 685 674 686 675 687 def PatternInvFlip(i): 688 return [0,1,2,3,4,6,5,7][i] 689 676 int PatternInvFlip(i) { 677 if (i == 5) return 6; 678 if (i == 6) return 5; 679 return i; 680 } 690 681 691 682 PatternList::PatternList(Pattern p, int fColor, int nextMove) { … … 770 761 for p in lCS: 771 762 if not p in l: l.append(p) 772 773 # compute symmetries774 763 775 764 symm = {} … … 798 787 else: 799 788 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 the803 # color of the next move is fixed804 789 805 790 self.symmetries = symm … … 818 803 819 804 820 PatternList::updateContinuations( self,index, x, y, co, Xint, Yint,805 PatternList::updateContinuations(index, x, y, co, Xint, Yint, 821 806 foundWhere, counter, 822 807 continuations, contLabels, contLabelsIndex, … … 872 857 if colorSwitch: numOfSwitched += 1 873 858 else: 874 return 0,0,0,0 # not a hit!859 return 0,0,0,0 875 860 else: 876 861 colorSwitch = cSymm … … 887 872 contLabelsIndex += 1 888 873 if cc == 'B': 889 continuations[(xx,yy)] = {'B':1, 'W':0, # B/W continuations at this point890 'tB':0, 'tW':0, # tenukis among the above891 'wB':0,'lB':0,'wW':0,'lW':0, # B wins/losses among BW continuations874 continuations[(xx,yy)] = {'B':1, 'W':0, 875 'tB':0, 'tW':0, 876 'wB':0,'lB':0,'wW':0,'lW':0, 892 877 'N': text} 893 878 else: … … 914 899 915 900 916 class hashTable: 917 918 def __init__(self, noOfGames, filename): 901 // -------------- class hashTable ------------------------------------------------ 902 903 904 hashTable(int noOfGames, char* filename) { 919 905 self.data = array('l', [0]*(2*130*noOfGames)) 920 906 self.currentCtr = -1 921 907 self.dataIndex = 0 922 908 self.filename = filename 923 924 925 def newCtr(self, ctr): 909 } 910 911 void hashtable::newCtr(ctr) { 926 912 if ctr == self.currentCtr: 927 913 while self.dataIndex > 0 and self.data[self.dataIndex-1] == ctr: … … 929 915 self.currentCtr = ctr 930 916 self.currentCtrL = [] 931 917 } 932 918 933 def append(self, i): 919 void hashTable::append(int i) { 934 920 935 921 ctr = self.currentCtr … … 943 929 self.dataIndex += 1 944 930 self.currentCtrL.append(i) 945 946 947 def swap(self, l, r): 931 } 932 933 934 void hashTable::swap(int l, int r) { 948 935 help1 = self.data[2*l] 949 936 help2 = self.data[2*l+1] … … 952 939 self.data[2*r] = help1 953 940 self.data[2*r+1] = help2 954 955 956 def sort(self): 941 } 942 943 944 void hashTable::sort() { 957 945 958 946 l = 0 … … 997 985 else: 998 986 l, r = stack.pop() 999 1000 1001 def sortedOutput(self, path): 987 } 988 989 990 hashTable::sortedOutput(char* path) { 1002 991 self.sort() 1003 992 … … 1005 994 data1X = array('B') 1006 995 1007 currentCode = self.data[0] - 1 # != self.data[0] !996 currentCode = self.data[0] - 1 1008 997 currentValues = [] 1009 998 … … 1032 1021 data1X.tofile(file) 1033 1022 file.close() 1034 1023 } 1035 1024 1036 1025 hash_value = { … … 1158 1147 } 1159 1148 1160 #---------------------------------------------------------------------------------------1161 1162 def symmetrizeSig(s): 1149 // --------------------------------------------------------------------------------------- 1150 1151 char* symmetrizeSig(char* s) { 1163 1152 1164 1153 l = [] … … 1179 1168 m.sort() 1180 1169 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 1175 class Algorithm: 1176 1177 def __init__(boardsize): pass 1178 1179 def initialize_process(): 1189 1180 """ Start of database. """ 1190 1181 pass 1191 1182 1192 def newgame_process( self):1183 def newgame_process(): 1193 1184 """ New game. """ 1194 1185 pass 1195 1186 1196 def AB_process( self,x, y): pass1197 1198 def AW_process( self,x, y): pass1199 1200 def AE_process( self,x, y, removed): pass1201 1202 def endOfNode_process( self): pass1203 1204 def B_process( self,counter, x, y, cap): pass1205 1206 def W_process( self,counter, x, y, cap): pass1207 1208 def branchpoint_process( self): pass1209 1210 def endOfVariation_process( self): pass1211 1212 def endgame_process( self): pass1213 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): 1215 1206 """ End of database. """ 1216 1207 pass 1217 1208 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 pass1232 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 1217 Algo_finalpos(int bs) { 1218 } 1219 1220 1221 void Algo_finalpos::initialize_process(int l) { 1222 self.finalpos = array('B'); 1223 } 1224 1225 void 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 1230 void 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 1234 void 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 1238 void Algo_finalpos::AE_process(int x, int y, removed) { 1239 } 1240 1241 void Algo_finalpos::endOfNode_process() { 1242 } 1243 1244 void 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 1248 void 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 1252 void Algo_finalpos::branchpoint_process() { 1253 } 1254 1255 void Algo_finalpos::endOfVariation_process() { 1256 } 1257 1258 void Algo_finalpos::endgame_process() { 1259 self.finalpos.extend(self.fp); 1260 } 1261 1262 void 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 1271 int Algo_finalpos::duplicateCheck(sli, datapath=None) { 1281 1272 if datapath is None: 1282 1273 if self.finalpos[sli*100:sli*100+100] == self.fp: return 1 … … 1296 1287 if self.currentFP[sli*100:sli*100+100] == self.fp: return 1 1297 1288 else: return 0 1298 1299 # --------------------------------------------------------------- 1300 1301 def retrieve_db(self, datap): 1289 } 1290 1291 int Algo_finalpos::retrieve_db(datap) { 1302 1292 try: 1303 1293 self.finalpos = array('B') … … 1312 1302 except IOError: 1313 1303 return 0 1314 1315 1316 def search(self, patternList, options, db, progBar, progStart, progEnd): 1304 } 1305 1306 Algo_finalpos::search(patternList, options, db, progBar, progStart, progEnd) { 1317 1307 1318 1308 ctr = 0 … … 1322 1312 counter = 0 1323 1313 if not self.retrieve_db(db.datapath): 1324 print 'error' #FIXME1314 print 'error'// FIXME 1325 1315 return 1326 1316 … … 1360 1350 fpIndex += 10 - start - length 1361 1351 1362 if matches: # found candidate1352 if matches: 1363 1353 matchList.append((N,(a0,a1))) 1364 1354 … … 1368 1358 1369 1359 index = db.next() 1370 1360 } 1371 1361 1372 1362 // in x-coord: 1373 ENDOFNODE = 128 1374 BRANCHPOINT = 64 # these two flags ... 1375 ENDOFVARIATION = 32 # ... are not combined with move coordinates 1363 const int ENDOFNODE = 128; 1364 const int BRANCHPOINT = 64; 1365 const int ENDOFVARIATION = 32; 1376 1366 1377 1367 // 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 database1391 self.posTable = array('L') # this is a table of pointers to the beginning of the1392 # 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 point1400 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)1368 const int REMOVE = 128; 1369 const int BLACK = 64; 1370 const int WHITE = 32; 1371 1372 1373 Algo_movelist(int bs) { 1374 } 1375 1376 void Algo_movelist:: initialize_process(l) { 1377 1378 self.mainlistArr = array('B'); 1379 self.posTable = array('L'); 1380 1381 self.finalposC = array('B'); 1382 } 1383 1384 void Algo_movelist::newgame_process() { 1385 1386 self.movelist = array('B'); 1387 self.fpC = array('B', [0] * 50); 1388 } 1389 1390 void Algo_movelist::AB_process(int x, int y) { 1391 self.movelist.append(x); 1392 self.movelist.append(y | BLACK); 1393 } 1394 1395 1396 void Algo_movelist::AW_process(int x, int y) { 1397 self.movelist.append(x); 1398 self.movelist.append(y | WHITE); 1399 } 1400 1401 1402 void Algo_movelist::AE_process(int x, int y, removed) { 1403 self.movelist.append(x); 1414 1404 if removed == 'B': 1415 1405 self.movelist.append(y | REMOVE | BLACK) 1416 1406 elif removed == 'W': 1417 1407 self.movelist.append(y | REMOVE | WHITE) 1418 else: print 'oops' #FIXME1419 1420 1421 def endOfNode_process(self): 1408 else: print 'oops' // FIXME 1409 } 1410 1411 void Algo_movelist::endOfNode_process() { 1422 1412 if self.movelist: 1423 if self.movelist[-2] & ENDOFNODE: # there has been a pass or something, so we append an extra node1413 if self.movelist[-2] & ENDOFNODE: 1424 1414 self.movelist.append(ENDOFNODE) 1425 1415 self.movelist.append(0) 1426 1416 else: 1427 1417 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 found1418 } 1419 1420 void Algo_movelist::B_process(int x, int y, cap) { 1421 if not self.movelist: 1422 self.movelist.append(ENDOFNODE) 1433 1423 self.movelist.append(0) 1434 1424 … … 1440 1430 self.movelist.append(y | REMOVE | WHITE) 1441 1431 self.fpC[y/4 + 5*(x/2)] |= 1 << (x%2 + 2*(y%4)) 1442 1432 } 1443 1433 1444 def W_process(self, x, y, cap): 1434 void Algo_movelist::W_process(int x, int y, cap) { 1445 1435 if not self.movelist: 1446 1436 self.movelist.append(ENDOFNODE) … … 1454 1444 self.movelist.append(y | REMOVE | BLACK) 1455 1445 self.fpC[y/4 + 5*(x/2)] |= 1 << (x%2 + 2*(y%4)) 1456 1457 1458 def branchpoint_process(self): 1446 } 1447 1448 void Algo_movelist::branchpoint_process() { 1459 1449 self.movelist.append(BRANCHPOINT) 1460 1450 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 1453 void Algo_movelist::endOfVariation_process() { 1454 self.movelist.append(ENDOFVARIATION); 1455 self.movelist.append(0); 1456 } 1457 1458 void 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 1467 void Algo_movelist::finalize_process(datap) { 1479 1468 1480 1469 filelist = [(self.posTable, 'posTable'), (self.mainlistArr, 'lists'), … … 1484 1473 var.tofile(file) 1485 1474 file.close() 1486 1487 1488 filelist = ['posTable', 'lists', 'finalposC']1489 1490 # --------------------------------------------------------------- 1491 1492 def retrieve_db(self, datap): 1475 } 1476 1477 filelist = ['posTable', 'lists', 'finalposC'] 1478 1479 1480 1481 void Algo_movelist::retrieve_db(datap) { 1493 1482 try: 1494 1483 self.posTable = array('L') … … 1506 1495 except IOError: 1507 1496 return 0 1508 1509 1510 def search(self,patternList, options, db,1511 continuations, contLabelsIndex, contLabels,1512 progBar, progStart, progEnd): 1497 } 1498 1499 void Algo_movelist::search(patternList, options, db, 1500 continuations, contLabelsIndex, contLabels, 1501 progBar, progStart, progEnd) { 1513 1502 1514 1503 numOfHits = 0 … … 1523 1512 1524 1513 if not self.retrieve_db(db.datapath): 1525 print "error" #FIXME1514 print "error" // FIXME 1526 1515 return 1527 1516 … … 1553 1542 Yinterv = {} 1554 1543 1555 # initialize dictionaries1556 1557 1544 for m in db.getCurrentMatchlist(): 1558 1545 d = {} … … 1566 1553 1567 1554 dicts[m] = d 1568 dictsNO[m] = dNO # no of places that are currently not correct1555 dictsNO[m] = dNO 1569 1556 1570 1557 contList[m] = [] … … 1575 1562 Xinterv[m] = (m[1][0], m[1][0] + patternList.get(m[0]).sizeX) 1576 1563 Yinterv[m] = (m[1][1], m[1][1] + patternList.get(m[0]).sizeY) 1577 1578 # go through the game1579 1564 1580 1565 counter = 0 … … 1615 1600 if Xinterv[m][0] <= x < Xinterv[m][1] and Yinterv[m][0] <= y < Yinterv[m][1]: 1616 1601 1617 if dicts[m].has_key('found'): # so (x,y) is the continuation1602 if dicts[m].has_key('found'): 1618 1603 hit, label, contLabelsIndex, switched =\ 1619 1604 patternList.updateContinuations(m[0], x, y, invco, … … 1628 1613 continue 1629 1614 1630 numOfSwitched += switched #FIXME: CHECK, was: patternList[m[0]].colorSwitch1615 numOfSwitched += switched // FIXME: CHECK, was: patternList[m[0]].colorSwitch 1631 1616 1632 1617 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: 1634 1619 result.append((dicts[m]['found'], label + '-')) 1635 1620 else: … … 1637 1622 del dicts[m] 1638 1623 del dictsNO[m] 1639 continue #with for m in dicts.keys()1624 continue // with for m in dicts.keys() 1640 1625 1641 1626 elif dicts[m].has_key('foundInitial'): … … 1655 1640 if not dicts[m].has_key((x,y)): 1656 1641 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 1659 1643 if not contListIndex[m]: 1660 1644 del dicts[m] … … 1687 1671 co = 'O' 1688 1672 invco = 'X' 1689 else: print 'oops' #FIXME1673 else: print 'oops' // FIXME 1690 1674 1691 1675 for m in dicts.keys(): … … 1735 1719 movelistIndex += 2 1736 1720 1737 # check for hits with no continuation:1738 1739 1721 if not patternList.nextMove: 1740 1722 for m in dicts.keys(): … … 1746 1728 result.append((dicts[m]['found'], '')) 1747 1729 1748 # assemble results for this game, and return them to the SGFDatabase1749 1750 1730 if result: 1751 1731 numOfHits = numOfHits + len(result) … … 1767 1747 1768 1748 return numOfHits, Bwins, Wwins, self.numOfSwitched 1769 1749 } 1770 1750 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 1752 Algo_hash(boardsize, poslist, filename) { 1753 self.poslist = [[0,0] + p for p in poslist] 1776 1754 self.filename = filename 1777 1778 1779 def initialize_process(self, l): 1755 } 1756 1757 void Algo_hash::initialize_process(l) { 1780 1758 """ Start of database. """ 1781 1759 self.hash_global = hashTable(l, self.filename) 1782 1760 self.gameCtr = 0 1783 1784 1785 def newgame_process(self): 1786 """ New game. """ 1761 } 1762 1763 void Algo_hash::newgame_process() { 1787 1764 1788 1765 for p in self.poslist: … … 1792 1769 self.hash_global.newCtr(self.gameCtr) 1793 1770 self.branchpoints = [] 1794 1795 1796 def AB_process(self, x, y): 1771 } 1772 1773 void Algo_hash::AB_process(int x, int y) { 1797 1774 for p in self.poslist: 1798 1775 if p[2] <= x <= p[4] and p[3] <= y <= p[5]: 1799 1776 p[0] += 1 1800 1777 p[1] += hashTable.hash_value[(x,y)] 1801 1802 1803 def AW_process(self, x, y): 1778 } 1779 1780 void Algo_hash::AW_process(int x, int y) { 1804 1781 for p in self.poslist: 1805 1782 if p[2] <= x <= p[4] and p[3] <= y <= p[5]: 1806 1783 p[0] += 1 1807 1784 p[1] -= hashTable.hash_value[(x,y)] 1808 1809 1810 def AE_process(self, x, y, removed): 1785 } 1786 1787 void Algo_hash::AE_process(int x, int y, removed) { 1811 1788 if removed == 'B': epsilon = -1 1812 1789 else: epsilon = 1 … … 1816 1793 p[0] -= 1 1817 1794 p[1] += epsilon * hashTable.hash_value[(x,y)] 1818 1819 1820 def endOfNode_process(self): 1795 } 1796 1797 void Algo_hash::endOfNode_process() { 1821 1798 for p in self.poslist: 1822 1799 if p[0] <= p[6]: self.hash_global.append(p[1]) 1823 1824 1825 def B_process(self, x, y, cap): 1800 } 1801 1802 void Algo_hash::B_process(int x, int y, cap) { 1826 1803 self.move_process(x, y, cap, 1) 1827 1828 1829 def W_process(self, x, y, cap): 1804 } 1805 1806 void Algo_hash::W_process(int x, int y, cap) { 1830 1807 self.move_process(x, y, cap, -1) 1831 1832 1833 def move_process(self, x, y, cap, epsilon): 1808 } 1809 1810 void Algo_hash::move_process(int x, int y, cap, epsilon) { 1834 1811 for p in self.poslist: 1835 1812 if p[2] <= x <= p[4] and p[3] <= y <= p[5]: … … 1842 1819 p[0] -= 1 1843 1820 p[1] += epsilon * hashTable.hash_value[c] 1844 1845 1846 def branchpoint_process(self): 1821 } 1822 1823 void Algo_hash::branchpoint_process() { 1847 1824 self.branchpoints.append(deepcopy(self.poslist)) 1848 1849 1850 def endOfVariation_process(self): 1825 } 1826 1827 void Algo_hash::endOfVariation_process() { 1851 1828 self.poslist = self.branchpoints.pop() 1852 1853 1854 def endgame_process(self): 1829 } 1830 1831 void Algo_hash::endgame_process() { 1855 1832 self.gameCtr += 1 1856 1833 } 1857 1834 1858 def finalize_process(self, datap): 1835 void Algo_hash::finalize_process(datap) { 1859 1836 """ End of database. """ 1860 1837 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) 1863 1839 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 1845 void Algo_hash::compute_hashkey(pattern, type) { 1871 1846 1872 1847 numOfStones = 0 … … 1889 1864 1890 1865 return hashkey 1891 1892 1893 def retrieve_db(self, datap): 1866 } 1867 1868 void Algo_hash::retrieve_db(datap) { 1894 1869 try: 1895 1870 self.hashT = array('l') … … 1905 1880 except IOError: 1906 1881 return 0 1907 1908 1909 def search(self, patternList, options, db, progBar, progStart, progEnd): 1910 1911 """ 1912 FIXME: documentation 1913 """ 1882 } 1883 1884 void Algo_hash::search(patternList, options, db, progBar, progStart, progEnd) { 1914 1885 1915 1886 for i in range(patternList.size()): … … 1925 1896 hk = self.compute_hashkey(pattern, p[2:]) 1926 1897 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 to1929 # store start, index, end corresponding to that hash key in1930 # the table of hash keys in the same list1931 1932 1898 if not hk is None: pattern.hashkeys[(a0,a1)].append([hk]) 1933 1899 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 1938 1901 1939 1902 if not self.retrieve_db(db.datapath): 1940 print "error" #FIXME1903 print "error" // FIXME 1941 1904 return 1942 1905 … … 1949 1912 for hk in range(len(pattern.hashkeys[(a0,a1)])): 1950 1913 1951 # do a binary search for hashkey in self.hashT1952 1914 hashkey = pattern.hashkeys[(a0,a1)][hk][0] 1953 1915 start = 0 … … 1963 1925 1964 1926 pattern.hashkeys[(a0,a1)][hk].extend([hash_start, 1965
