# HG changeset patch # User Laman # Date 2017-12-14 14:11:07 # Node ID f9ab2070bd69d432829f1cb08bee296bbcfa8a9b # Parent 0cb3fbe06b5d87fe5a12a98a4d41f76f908311b3 Engine: more tests and fixes diff --git a/src/analyzer/__init__.py b/src/analyzer/__init__.py --- a/src/analyzer/__init__.py +++ b/src/analyzer/__init__.py @@ -1,8 +1,7 @@ import logging as log from .grid import Grid -from util import BLACK,WHITE,EMPTY -from go.core import exportBoard +from util import BLACK,WHITE,EMPTY, exportBoard class ImageAnalyzer: diff --git a/src/go/core.py b/src/go/core.py --- a/src/go/core.py +++ b/src/go/core.py @@ -15,9 +15,6 @@ class Go: self._hashes=[] self._record=GameRecord() - def listMoves(self,diff=[]): - return [] - ## Executes a move. # # Doesn't check for kos. Suicide not allowed. @@ -47,13 +44,15 @@ class Go: def undoMove(self,r,c,captures): assert self.board[r][c]==-1*self.toMove, "{0}!={1}".format(self.board[r][c],-1*self.toMove) - self.toMove*=-1 - self.board[r][c]=self.toMove + if len(captures)>0: self._helper.clear() - for (r,c) in captures: - self._helper.floodFill(EMPTY,r,c) - self._fill(-self.toMove) + for (ri,ci) in captures: + self._helper.floodFill(EMPTY,ri,ci) + self._fill(self.toMove) + + self.board[r][c]=EMPTY + self.toMove*=-1 self._hashes.pop() def transitionMove(self,board): @@ -79,11 +78,6 @@ class Go: self.board[r][c]=filling -def exportBoard(board): - substitutions={EMPTY:".", BLACK:"X", WHITE:"O"} - return "\n".join("".join(substitutions.get(x,"?") for x in row) for row in board) - - def isLegalPosition(board): boardSize=len(board) temp=[[None]*boardSize for x in range(boardSize)] diff --git a/src/go/engine.py b/src/go/engine.py --- a/src/go/engine.py +++ b/src/go/engine.py @@ -15,7 +15,7 @@ class SpecGo(core.Go): 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. + 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: @@ -23,7 +23,10 @@ class SpecGo(core.Go): 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) @@ -31,20 +34,17 @@ class SpecGo(core.Go): for (ri,ci) in self._helper.getContinuousArea(): res[colorKey].add((ri,ci)) res[1-colorKey].add((ri,ci)) - if ri>0: - res[colorKey].add((ri-1,ci)) - res[1-colorKey].add((ri-1,ci)) - if ri+10: - res[colorKey].add((ri,ci-1)) - res[1-colorKey].add((ri,ci-1)) - if ci+10: yield (r-1,c) + if r+10: yield (r,c-1) + if c+10 else None, g.board[r][c+1] if c+1