Changeset 128

Show
Ignore:
Timestamp:
03/26/04 17:59:58 (5 years ago)
Author:
ug
Message:

Jump to match in variations

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/devel/aglPY.py

    r119 r128  
    2323from searchPY import * 
    2424from patternPY import * 
     25from algosPY import Hit 
    2526 
    2627class abstractGameList: 
     
    4950    getFilename          returns complete filename, and gameNumber (since there may be more than one 
    5051                         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                          
    5355    getString            returns the string which represents the corresponding game in the list of 
    5456                         games as displayed in the Listbox; the format basically is: 
     
    177179        DBindex, indexWithinCurrent = self.getIndex(index) 
    178180        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] 
    185184 
    186185     
     
    617616            trans = maketrans(join(t, ''), join(contLabels[:contLabelsIndex], '')) 
    618617            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, '|%') 
    622622 
    623623        self.updateGameIndex() 
  • 06/devel/algosPY.py

    r126 r128  
    3333 
    3434 
     35 
     36class 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 
    3555class Algorithm: # virtual 
    3656    """ 
    37     This class is a prototype for search algorithms to Kombilo. 
     57    This class is a prototype for search algorithms for Kombilo. 
    3858 
    3959    Two parts: 
     
    505525        else: showColorSwap = 1 
    506526 
     527        searchInVariations = 1 # FIXME 
     528 
    507529        if not self.retrieve_db(db.datapath): 
    508530            print "error" # FIXME 
     
    563585            # go through the game 
    564586 
    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 
    567595             
    568596            while movelistIndex < endMovelist and (counter <= self.movelimit or self.branchpoints): 
     
    571599                    whereAreWeCopy = copy(whereAreWe) 
    572600                    if movelistIndex < self.posTable[index]+4 or not movelist[movelistIndex-2] & ENDOFVARIATION: 
     601                        whereAreWe[-1] -= 1 
    573602                        whereAreWeCopy.extend([0,0]) 
    574603                    self.branchpoints.append((deepcopy(dicts), deepcopy(dictsNO), 
     
    583612                                if patternList.get(m[0]).colorSwitch: numOfSwitched += 1 
    584613                                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'], '-')) 
    587617                                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'], '')) 
    590621                    dicts, dictsNO, contList, contListIndex, counter, whereAreWe = self.branchpoints.pop() 
    591622                     
     
    630661                                if switched and showColorSwap: 
    631662                                    # 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+'-')) 
    634666                                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)) 
    637670                                del dicts[m] 
    638671                                del dictsNO[m] 
     
    748781                        if patternList.get(m[0]).colorSwitch: numOfSwitched += 1 
    749782                        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'], '-')) 
    752787                        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'], '')) 
    755792 
    756793            # assemble results for this game, and return them to the SGFDatabase 
     
    768805 
    769806                result.sort() 
    770                 db.makeCurrentHit(join([str(x[0])+x[1] for x in result], ', ')
     807                db.makeCurrentHit(result
    771808            else: 
    772809                db.discardCurrent() 
  • 06/devel/kombilo.py

    r120 r128  
    19411941            # but that would be too slow 
    19421942            # 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) 
    19441945        cursorSn = [self.cursor, self.cursor.currentGame, self.cursor.currentN.pathToNode()] 
    19451946 
     
    22492250            self.gamelist.DBlist[`self.boardsize`][i].current = g[i] 
    22502251            self.gamelist.DBlist[`self.boardsize`][i].results = [''] * len(g[i]) 
     2252            # FIXME results 
    22512253             
    22522254        self.noMatches = 0 
     
    22922294            for i in range(len(r)): 
    22932295                self.gamelist.DBlist[`self.boardsize`][i].results = split(r[i], '|%') 
    2294  
     2296                # FIXME results 
    22952297            self.continuations = c 
    22962298         
     
    28532855 
    28542856    def openViewer_external(self, filename, gameNumber, moveno): 
     2857 
     2858        # FIXME: moveno is not an int now, but a list (whereAreWe format) 
     2859 
    28552860        if self.options.altViewerVar1.get(): 
    28562861                 
     
    29302935        if self.options.jumpToMatchVar.get(): 
    29312936            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]): 
    29342940                        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 
    29432945            except: 
    29442946                showwarning('Error', 'SGF error') 
  • 06/devel/searchPY.py

    r126 r128  
    569569 
    570570    def makeCurrentHit(self, results): 
     571        """ results is list of Hit's (see algosPY.py) """ 
    571572        win = self.getCurrentWinner() 
    572573        self.newCurrent.append(self.current[self.currentIndexWithinCurrent]) 
    573574        self.results.append(results) 
     575        print 'mch', results[0].moveno() 
    574576 
    575577