from util import EMPTY,BLACK,WHITE from . import core def transitionSequence(state1, state2, diff, limit=0): return [] class SpecGo(core.Go): def __init__(self,boardSize=19): super().__init__(boardSize) def listRelevantMoves(self,diff): """There can be 3 different changes in the diff: additions, deletions and replacements. Additions can be taken as relevant right away. Deletions and replacements had to be captured, so we add their liberties. Also any non-missing stones of partially deleted (or replaced) groups had to be replayed, so add them too. Needs to handle snapback, throw-in. There's no end to what could be theoretically relevant, but such sequences are long and we will pretend they won't happen.""" res=(set(),set()) for d in diff: (r,c,action,color)=d colorKey=(1-color)>>1 # {-1,1}->{1,0} if action!="-" and (r,c) not in res[colorKey]: res[colorKey].add((r,c)) for (ri,ci) in self.listNeighbours(r,c): # in case a stone was played and captured. !! might want to add even more res[1-colorKey].add((ri,ci)) # this is rather sloppy but correct. the time will show if it is effective enough # just floodFill from the current intersection, add everything you find and also all the neighbours to be sure if action!="+" and (r,c) not in res[colorKey] and (r,c) not in res[1-colorKey]: self._helper.clear() self._helper.floodFill(color if action=="-" else 1-color, r, c) res[colorKey].union(self._helper.getContinuousArea()) for (ri,ci) in self._helper.getContinuousArea(): res[colorKey].add((ri,ci)) res[1-colorKey].add((ri,ci)) for (rj,cj) in self.listNeighbours(ri,ci): res[colorKey].add((rj,cj)) res[1-colorKey].add((rj,cj)) return res def listNeighbours(self,r,c): if r>0: yield (r-1,c) if r+10: yield (r,c-1) if c+1>1]: if g.board[r][c]!=EMPTY: continue neighbours=( g.board[r-1][c] if r>0 else None, g.board[r+1][c] if r+10 else None, g.board[r][c+1] if c+11: toMove=-1*g.toMove seq=self.dfs(state2,limit-1) if seq: seq.append((toMove,r,c)) return seq g.undoMove(r,c,captured) return False eng=Engine()