rewrite _is_qi in a more understandable way
This commit is contained in:
parent
14da3200ff
commit
6a410384bb
@ -41,37 +41,27 @@ class GoEnv:
|
|||||||
has_liberty = True
|
has_liberty = True
|
||||||
return has_liberty, chain
|
return has_liberty, chain
|
||||||
|
|
||||||
def _bfs(self, vertex, color, block, status):
|
def _is_suicide(self, color, vertex):
|
||||||
block.append(vertex)
|
### assume that we already take this move
|
||||||
status[self._flatten(vertex)] = True
|
|
||||||
nei = self._neighbor(vertex)
|
|
||||||
for n in nei:
|
|
||||||
if not status[self._flatten(n)]:
|
|
||||||
if self.board[self._flatten(n)] == color:
|
|
||||||
self._bfs(n, color, block, status)
|
|
||||||
|
|
||||||
def _is_qi(self, color, vertex):
|
|
||||||
nei = self._neighbor(vertex)
|
|
||||||
for n in nei:
|
|
||||||
if self.board[self._flatten(n)] == utils.EMPTY:
|
|
||||||
return True
|
|
||||||
|
|
||||||
self.board[self._flatten(vertex)] = color
|
self.board[self._flatten(vertex)] = color
|
||||||
for n in nei:
|
|
||||||
if self.board[self._flatten(n)] == utils.another_color(color):
|
|
||||||
has_liberty, group = self._find_group(n)
|
|
||||||
if not has_liberty:
|
|
||||||
self.board[self._flatten(vertex)] = utils.EMPTY
|
|
||||||
return True
|
|
||||||
|
|
||||||
### avoid suicide
|
|
||||||
has_liberty, group = self._find_group(vertex)
|
has_liberty, group = self._find_group(vertex)
|
||||||
if not has_liberty:
|
if has_liberty:
|
||||||
|
### this group still has liberty after this move, not suicide
|
||||||
self.board[self._flatten(vertex)] = utils.EMPTY
|
self.board[self._flatten(vertex)] = utils.EMPTY
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
self.board[self._flatten(vertex)] = utils.EMPTY
|
### liberty is zero
|
||||||
return True
|
for n in self._neighbor(vertex):
|
||||||
|
if self.board[self._flatten(n)] == utils.another_color(color):
|
||||||
|
opponent_liberty, group = self._find_group(n)
|
||||||
|
# this move is able to take opponent's stone, not suicide
|
||||||
|
if not opponent_liberty:
|
||||||
|
self.board[self._flatten(vertex)] = utils.EMPTY
|
||||||
|
return False
|
||||||
|
# not a take, suicide
|
||||||
|
self.board[self._flatten(vertex)] = utils.EMPTY
|
||||||
|
return True
|
||||||
|
|
||||||
def _check_global_isomorphous(self, color, vertex):
|
def _check_global_isomorphous(self, color, vertex):
|
||||||
##backup
|
##backup
|
||||||
@ -174,8 +164,8 @@ class GoEnv:
|
|||||||
# print(vertex)
|
# print(vertex)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
### check if it is qi
|
### check if it is suicide
|
||||||
if not self._is_qi(color, vertex):
|
if self._is_suicide(color, vertex):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
### forbid global isomorphous
|
### forbid global isomorphous
|
||||||
|
Loading…
x
Reference in New Issue
Block a user