Changeset 161

Show
Ignore:
Timestamp:
09/15/04 21:39:06 (4 years ago)
Author:
ug
Message:

Changes to board-snapshot/restore

Location:
06/devel
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • 06/devel/abstractBoardPY.py

    r152 r161  
    2626from copy import deepcopy 
    2727 
    28  
    2928class abstractBoard: 
    3029    """ This class administrates a go board. 
     
    4746        self.undostack = [] 
    4847        self.boardsize = boardsize 
    49  
    5048 
    5149    def getStatus(self, x, y): 
     
    6260        ab.undostack = deepcopy(ab.undostack) 
    6361        return ab 
     62 
     63    def restore(self, data): 
     64        self.boardsize = ab.boardsize 
     65        self.status = ab.status 
     66        self.undostack = ab.undostack 
    6467 
    6568    def len_cap_last(self): 
  • 06/devel/board.py

    r152 r161  
    3232try: 
    3333    from abstractBoard import * 
     34    print 'OK' 
    3435except ImportError: 
     36    print 'oops' # FIXME 
    3537    from abstractBoardPY import * 
    3638 
     
    176178 
    177179 
    178     def resize(self, event = None): 
     180    def resize(self, event = None, force = 0): 
    179181        """ This is called when the window containing the board is resized. """ 
    180182 
    181         if not self.resizable: return 
     183        if not self.resizable and not force: return 
    182184 
    183185        self.noChanges = 1 
     
    209211        self.noChanges = 0 
    210212 
     213 
     214    def snapshot(self): 
     215        handle = abstractBoard.snapshot(self) 
     216        self.snapshots[handle].extend([self.currentColor, deepcopy(self.stones), deepcopy(self.marks), deepcopy(self.labels)]) 
     217        return handle 
     218 
     219    def restore(self, handle): 
     220        abstractBoard.restore(self, handle) 
     221        self.currentColor = self.snapshots[handle][2] 
     222        self.stones = self.snapshots[handle][3] 
     223        self.marks = self.snapshots[handle][4] 
     224        self.labels = self.snapshots[handle][5] 
     225        self.resize(None, 1) 
    211226 
    212227    def play(self, pos, color=None): 
  • 06/devel/kombilo.py

    r160 r161  
    9292    """ 
    9393    Board with support for wildcards and selection 
    94     of search-relevant region. Furthermore, snapshot returns a dictionary which 
    95     describes the current board position. It can then be restored with restore. 
     94    of search-relevant region. 
    9695    """ 
    9796     
     
    115114 
    116115 
    117     def resize(self, event = None): 
     116    def resize(self, event = None, force=0): 
    118117        """ Resize the board. Take care of wildcards and selection here. """ 
    119118         
    120         Board.resize(self, event) 
     119        Board.resize(self, event, force) 
    121120        for x,y in self.wildcards.keys(): 
    122121            x1, x2, y1, y2 = self.getPixelCoord((x,y),1) 
     
    291290 
    292291    def snapshot(self): 
    293         """ Return a dictionary which contains the data of all the objects 
    294             currently displayed on the board, which are not stored in the SGF file. 
    295             This means, at the moment: wildcards, and selection. """ 
    296          
    297         data = {} 
    298         data['wildcards'] = copy(self.wildcards) 
    299         data['selection'] = self.selection 
    300         return data 
    301  
    302  
    303     def restore(self, d): 
    304         """ Restore the data from a 'snapshot' dictionary. """ 
    305          
    306         for pos in d['wildcards'].keys(): 
    307             color = d['wildcards'][pos][1] 
    308             x1, x2, y1, y2 = self.getPixelCoord(pos,1) 
    309             self.wildcards[pos] = (self.create_oval(x1+4, x2+4, y1-4, y2-4, fill = color, 
    310                                                     tags=('wildcard','non-bg')), color) 
    311  
    312         if d['selection'] != ((0,0), (self.boardsize-1, self.boardsize-1)) and d['selection'][1] != (-1,-1): 
    313             self.setSelection(d['selection'][0], d['selection'][1]) 
     292        handle = Board.snapshot(self)  
     293        self.snapshots[handle].extend([copy(self.wildcards), self.selection]) 
     294        return handle 
     295 
     296    def restore(self, handle): 
     297        self.wildcards = self.snapshots[handle][6] 
     298        self.selection = self.snapshots[handle][7] 
     299        Board.restore(self, handle) # This does a self.resize(), which takes care of wildcards and selection in our case 
    314300 
    315301# --------------------------------------------------------------------------------------- 
     
    977963 
    978964         
    979     def append(self, s, data = None): 
    980          
    981         if not data: return 
    982  
     965    def append(self, s): 
    983966        if self.mster.options.maxLengthSearchesStack.get() and\ 
    984967           len(self.data) >= self.mster.options.maxLengthSearchesStack.get(): 
     
    999982        b.unbind('<Shift-1>', b.bounds1) 
    1000983         
    1001         for key in data[0].keys(): 
    1002             print data[0][key] 
    1003             p = b.getPixelCoord(key) 
    1004             b.status[key] = data[0][key] 
    1005             b.stones[key] = b.create_oval(p, fill=data[0][key], tags='non-bg') 
    1006         for key in data[1].keys(): 
    1007             print key, 
    1008             color = data[1][key][1] 
    1009             print color 
    1010             x1, x2, y1, y2 = b.getPixelCoord(key,1) 
    1011             b.wildcards[key] = (b.create_oval(x1, x2, y1, y2, fill = color, 
    1012                                               outline='', tags=('wildcard','non-bg')), color) 
    1013             print b.wildcards[key] 
    1014         if data[2] != ((0,0), (self.mster.boardsize-1, self.mster.boardsize-1)) and data[2][1] != (-1,-1): 
    1015             b.setSelection(data[2][0], data[2][1]) 
     984#         for key in data[0].keys(): 
     985#             print data[0][key] 
     986#             p = b.getPixelCoord(key) 
     987#             b.status[key] = data[0][key] 
     988#             b.stones[key] = b.create_oval(p, fill=data[0][key], tags='non-bg') 
     989#         for key in data[1].keys(): 
     990#             print key, 
     991#             color = data[1][key][1] 
     992#             print color 
     993#             x1, x2, y1, y2 = b.getPixelCoord(key,1) 
     994#             b.wildcards[key] = (b.create_oval(x1, x2, y1, y2, fill = color, 
     995#                                               outline='', tags=('wildcard','non-bg')), color) 
     996            # print b.wildcards[key] 
     997#         if data[2] != ((0,0), (self.mster.boardsize-1, self.mster.boardsize-1)) and data[2][1] != (-1,-1): 
     998#             b.setSelection(data[2][0], data[2][1]) 
    1016999 
    10171000        b.tkraise('non-bg') 
     
    10201003        self.prevSF.reposition() 
    10211004        self.data.append([s, b, 0]) 
    1022         if data: self.select(len(self.data)-1) 
     1005        self.select(len(self.data)-1) 
    10231006 
    10241007         
     
    18411824 
    18421825        boardData = self.board.snapshot() 
    1843         boardData2 = (None, None, None) # FIXME, was (copy(self.board.status), copy(self.board.wildcards), self.board.selection) 
    18441826 
    18451827        self.progBar.clear() 
     
    19401922        games = [l.current for l in self.gamelist.DBlist[`self.boardsize`]] 
    19411923            # This should really be copy (resp. deepcopy), 
    1942             # but that would be too slow 
     1924            # but that would be too slow (FIXME: test this again; also test join/split?!) 
    19431925            # and it should work this way too. 
    1944         # results = [join(l.results, '|%') for l in self.gamelist.DBlist[`self.boardsize`]] 
    1945         # FIXME results (is now list of Hit's) 
    1946         # cursorSn = [self.cursor, self.cursor.currentGame, self.cursor.currentN.pathToNode()] 
    1947         # see FIXME above (boardData = ...) 
    1948         # self.prevSearches.append([boardData, games, results, copy(self.continuations), 
    1949         #                       self.noMatches, self.noSwitched, self.Bwins, self.Wwins, 
    1950         #                       self.modeVar.get(), self.fixedColorVar.get(), self.fixedAnchorVar.get(), 
    1951         #                       self.moveLimit.get(), self.nextMoveVar.get(), cursorSn], boardData2) 
     1926        results = [l.results for l in self.gamelist.DBlist[`self.boardsize`]] 
     1927            # FIXME not sure whether this works 
     1928 
     1929        cursorSn = [self.cursor, self.cursor.currentGame, self.cursor.currentN.pathToNode()] 
     1930        self.prevSearches.append([boardData, games, results, copy(self.continuations), 
     1931                              self.noMatches, self.noSwitched, self.Bwins, self.Wwins, 
     1932                              self.modeVar.get(), self.fixedColorVar.get(), self.fixedAnchorVar.get(), 
     1933                              self.moveLimit.get(), self.nextMoveVar.get(), cursorSn]) 
    19521934 
    19531935        self.configButtons(NORMAL) 
     
    22382220                 
    22392221        try: 
    2240             d, g, r, c, nm, ns, bw, ww, mv, fc, fa, ml, nextM, cu = prev 
     2222            handle, g, r, c, nm, ns, bw, ww, mv, fc, fa, ml, nextM, cu = prev 
    22412223        except: 
    22422224            self.reset() 
     
    22562238        self.Wwins = 0 
    22572239         
    2258         if d: 
     2240        if not handle is None: 
    22592241            if cu: 
    22602242                found = 0 
     
    22782260                    self.cursor.seeCurrent() 
    22792261                     
    2280                     self.board.restore(d) 
     2262                    self.board.restore(handle) 
    22812263             
    22822264                    self.sel = self.board.selection      # used in self.showCont()                     
    2283                     self.capVar.set('Cap - B: ' + str(self.capB) + ', W: ' + str(self.capW)) 
     2265                    self.capVar.set('Cap - B: ' + str(self.capB) + ', W: ' + str(self.capW)) # FIXME wo kommen die her? ist das so ok? 
    22842266                else: 
    22852267                    showwarning('Error', 'SGF File not found') 
  • 06/devel/searchPY.py

    r160 r161  
    367367                        elif self.branchpoints: 
    368368                            for algo in algolist: algo.endOfVariation_process() 
    369                             print 'eov process' 
     369                            # print 'eov process' 
    370370                            cursor.currentN, b, whichVar = self.branchpoints.pop() 
    371371                            if whichVar+2 < cursor.noChildren():