Files
@ daac513eadcc
Branch filter:
Location: Diana/go.py - annotation
daac513eadcc
1.1 KiB
text/x-python
another random commit
3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 3ce489491296 | 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
|