Changeset 128
- Timestamp:
- 03/26/04 17:59:58 (5 years ago)
- Files:
-
- 06/devel/aglPY.py (modified) (4 diffs)
- 06/devel/algosPY.py (modified) (8 diffs)
- 06/devel/kombilo.py (modified) (5 diffs)
- 06/devel/searchPY.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/devel/aglPY.py
r119 r128 23 23 from searchPY import * 24 24 from patternPY import * 25 from algosPY import Hit 25 26 26 27 class abstractGameList: … … 49 50 getFilename returns complete filename, and gameNumber (since there may be more than one 50 51 game stored in the SGF file) 51 getMoveno returns move number as given by the first entry in 52 the corresponding 'results' string (this is used to 'jump to match') 52 getMoveno returns position of first hit as given in 53 the corresponding 'results' list (this is used to 'jump to match') 54 53 55 getString returns the string which represents the corresponding game in the list of 54 56 games as displayed in the Listbox; the format basically is: … … 177 179 DBindex, indexWithinCurrent = self.getIndex(index) 178 180 try: 179 s = self.DBlist[`self.boardsize`][DBindex].results[indexWithinCurrent] 180 i = 0 181 while i<len(s) and s[i] in digits: i += 1 182 moveno = int(s[:i]) 183 except: moveno = 0 184 return moveno 181 h = self.DBlist[`self.boardsize`][DBindex].results[indexWithinCurrent][0] 182 return h.moveno() 183 except IndexError: return [0] 185 184 186 185 … … 617 616 trans = maketrans(join(t, ''), join(contLabels[:contLabelsIndex], '')) 618 617 for db in self.DBlist[`self.boardsize`]: 619 s1 = join(db.results, '|%') 620 s2 = translate(s1, trans) 621 db.results = split(s2, '|%') 618 pass # FIXME ... results is now list of Hit's 619 # s1 = join(db.results, '|%') 620 # s2 = translate(s1, trans) 621 # db.results = split(s2, '|%') 622 622 623 623 self.updateGameIndex() 06/devel/algosPY.py
r126 r128 33 33 34 34 35 36 class Hit: 37 def __init__(self, counter, labelStr, where=None): 38 self.counter = counter 39 self.labelStr = labelStr 40 self.where = where 41 42 def moveno(self): 43 if self.where: 44 print self.where 45 return self.where 46 else: 47 print 'no where' 48 if labelStr[-1]=='-': 49 return [int(labelstr[:-1])] 50 else: 51 return [int(labelStr)] 52 53 54 35 55 class Algorithm: # virtual 36 56 """ 37 This class is a prototype for search algorithms toKombilo.57 This class is a prototype for search algorithms for Kombilo. 38 58 39 59 Two parts: … … 505 525 else: showColorSwap = 1 506 526 527 searchInVariations = 1 # FIXME 528 507 529 if not self.retrieve_db(db.datapath): 508 530 print "error" # FIXME … … 563 585 # go through the game 564 586 565 counter = 0 566 whereAreWe = [0] 587 counter = 0 # counts at which move in the game we are 588 whereAreWe = [0] # records the exact position in the game tree 589 # format: list [n1, m1, n2, m2, n3 ..., ni], where 590 # the current position can be reached by 591 # going forward n1 times, then choosing the m1st variation, 592 # then going forward n2 times, then choosing the m2nd variation, 593 # etc. 594 # we have counter == sum_j nj 567 595 568 596 while movelistIndex < endMovelist and (counter <= self.movelimit or self.branchpoints): … … 571 599 whereAreWeCopy = copy(whereAreWe) 572 600 if movelistIndex < self.posTable[index]+4 or not movelist[movelistIndex-2] & ENDOFVARIATION: 601 whereAreWe[-1] -= 1 573 602 whereAreWeCopy.extend([0,0]) 574 603 self.branchpoints.append((deepcopy(dicts), deepcopy(dictsNO), … … 583 612 if patternList.get(m[0]).colorSwitch: numOfSwitched += 1 584 613 if patternList.get(m[0]).colorSwitch and showColorSwap: 585 result.append((dicts[m]['found'], '-')) 586 print whereAreWe 614 if searchInVariations: 615 result.append(Hit(dicts[m]['found'], '-', copy(whereAreWe))) 616 else: result.append(Hit(dicts[m]['found'], '-')) 587 617 else: 588 result.append((dicts[m]['found'], '')) 589 print whereAreWe 618 if searchInVariations: 619 result.append(Hit(dicts[m]['found'], '', copy(whereAreWe))) 620 else: result.append(Hit(dicts[m]['found'], '')) 590 621 dicts, dictsNO, contList, contListIndex, counter, whereAreWe = self.branchpoints.pop() 591 622 … … 630 661 if switched and showColorSwap: 631 662 # FIXME: CHECK,was: (patternList[m[0]].colorSwitch or colorSwitch) and showColorSwap: 632 result.append((dicts[m]['found'], label + '-')) 633 print whereAreWe 663 if searchInVariations: 664 result.append(Hit(dicts[m]['found'], label+'-', copy(whereAreWe))) 665 else: result.append(Hit(dicts[m]['found'], label+'-')) 634 666 else: 635 result.append((dicts[m]['found'], label)) 636 print whereAreWe 667 if searchInVariations: 668 result.append(Hit(dicts[m]['found'], label, copy(whereAreWe))) 669 else: result.append(Hit(dicts[m]['found'], label)) 637 670 del dicts[m] 638 671 del dictsNO[m] … … 748 781 if patternList.get(m[0]).colorSwitch: numOfSwitched += 1 749 782 if patternList.get(m[0]).colorSwitch and showColorSwap: 750 result.append((dicts[m]['found'], '-')) 751 print whereAreWe 783 if searchInVariations: 784 result.append(Hit(dicts[m]['found'], '-', copy(whereAreWe))) 785 else: 786 result.append(Hit(dicts[m]['found'], '-')) 752 787 else: 753 result.append((dicts[m]['found'], '')) 754 print whereAreWe 788 if searchInVariations: 789 result.append(Hit(dicts[m]['found'], '', copy(whereAreWe))) 790 else: 791 result.append(Hit(dicts[m]['found'], '')) 755 792 756 793 # assemble results for this game, and return them to the SGFDatabase … … 768 805 769 806 result.sort() 770 db.makeCurrentHit( join([str(x[0])+x[1] for x in result], ', '))807 db.makeCurrentHit(result) 771 808 else: 772 809 db.discardCurrent() 06/devel/kombilo.py
r120 r128 1941 1941 # but that would be too slow 1942 1942 # and it should work this way too. 1943 results = [join(l.results, '|%') for l in self.gamelist.DBlist[`self.boardsize`]] 1943 # results = [join(l.results, '|%') for l in self.gamelist.DBlist[`self.boardsize`]] 1944 # FIXME results (is now list of Hit's) 1944 1945 cursorSn = [self.cursor, self.cursor.currentGame, self.cursor.currentN.pathToNode()] 1945 1946 … … 2249 2250 self.gamelist.DBlist[`self.boardsize`][i].current = g[i] 2250 2251 self.gamelist.DBlist[`self.boardsize`][i].results = [''] * len(g[i]) 2252 # FIXME results 2251 2253 2252 2254 self.noMatches = 0 … … 2292 2294 for i in range(len(r)): 2293 2295 self.gamelist.DBlist[`self.boardsize`][i].results = split(r[i], '|%') 2294 2296 # FIXME results 2295 2297 self.continuations = c 2296 2298 … … 2853 2855 2854 2856 def openViewer_external(self, filename, gameNumber, moveno): 2857 2858 # FIXME: moveno is not an int now, but a list (whereAreWe format) 2859 2855 2860 if self.options.altViewerVar1.get(): 2856 2861 … … 2930 2935 if self.options.jumpToMatchVar.get(): 2931 2936 try: 2932 if moveno: 2933 while not (self.cursor.currentNode().has_key('B') or self.cursor.currentNode().has_key('W')): 2937 movenoIndex = 0 2938 while movenoIndex < len(moveno): 2939 for i in range(moveno[movenoIndex]): 2934 2940 self.next(0,0) 2935 i=1 2936 while i < moveno: 2937 if self.cursor.atEnd(): 2938 break 2939 2940 if self.cursor.currentNode().has_key('B') or self.cursor.currentNode().has_key('W'): 2941 i += 1 2942 self.next(0,0) 2941 movenoIndex += 1 2942 if movenoIndex < len(moveno): 2943 self.next(moveno[movenoIndex],0) 2944 movenoIndex += 1 2943 2945 except: 2944 2946 showwarning('Error', 'SGF error') 06/devel/searchPY.py
r126 r128 569 569 570 570 def makeCurrentHit(self, results): 571 """ results is list of Hit's (see algosPY.py) """ 571 572 win = self.getCurrentWinner() 572 573 self.newCurrent.append(self.current[self.currentIndexWithinCurrent]) 573 574 self.results.append(results) 575 print 'mch', results[0].moveno() 574 576 575 577
