Files
@ 11ce21596826
Branch filter:
Location: Diana/src/go.py - annotation
11ce21596826
1.0 KiB
text/x-python
py files moved to src
11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 11ce21596826 | class Go:
# 1: B, 0: _, -1: W
# resp. jakákoli čísla s opačnými znaménky
board=[[0]*19 for i in range(19)]
def __init__(self): self.board=[[0]*19 for i in range(19)]
def move(self,color,y,x):
if self.board[x][y]!=0: return False
self.board[x][y]=color
for i,j in ((-1,0),(1,0),(0,-1),(0,1)):
self.temp=[[False]*19 for i in range(19)]
if not self._floodFill(-color,x+i,y+j): self._remove()
self.temp=[[False]*19 for i in range(19)]
if not self._floodFill(color,x,y):
self.board[x][y]=0
return False
return True
def _floodFill(self,color,x,y):
if x<0 or x>18 or y<0 or y>18: return False
if self.temp[x][y]: return False
if self.board[x][y]==0: return True
if self.board[x][y]!=color: return False
self.temp[x][y]=True
return self._floodFill(color,x-1,y) or self._floodFill(color,x+1,y) or self._floodFill(color,x,y-1) or self._floodFill(color,x,y+1)
def _remove(self):
for i in range(19):
for j in range(19):
if self.temp[i][j]: self.board[i][j]=0
|