add some error message for better debugging
This commit is contained in:
parent
e58df65301
commit
c217aa165d
@ -61,8 +61,7 @@ class Game:
|
|||||||
del self.board[:]
|
del self.board[:]
|
||||||
self.board = [utils.EMPTY] * (self.size ** 2)
|
self.board = [utils.EMPTY] * (self.size ** 2)
|
||||||
del self.history[:]
|
del self.history[:]
|
||||||
del self.history_set
|
self.history_set.clear()
|
||||||
self.history_set = set()
|
|
||||||
if self.name == "reversi":
|
if self.name == "reversi":
|
||||||
self.board = self.game_engine.get_board()
|
self.board = self.game_engine.get_board()
|
||||||
for _ in range(self.history_length):
|
for _ in range(self.history_length):
|
||||||
|
@ -157,21 +157,33 @@ class Go:
|
|||||||
vertex = self._deflatten(action)
|
vertex = self._deflatten(action)
|
||||||
return vertex
|
return vertex
|
||||||
|
|
||||||
def _rule_check(self, history_hashtable, current_board, color, vertex):
|
def _rule_check(self, history_hashtable, current_board, color, vertex, is_thinking=True):
|
||||||
### in board
|
### in board
|
||||||
if not self._in_board(vertex):
|
if not self._in_board(vertex):
|
||||||
|
if not is_thinking:
|
||||||
|
raise ValueError("Target point not in board, Current Board: {}, color: {}, vertex : {}".format(current_board, color, vertex))
|
||||||
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
### already have stone
|
### already have stone
|
||||||
if not current_board[self._flatten(vertex)] == utils.EMPTY:
|
if not current_board[self._flatten(vertex)] == utils.EMPTY:
|
||||||
|
if not is_thinking:
|
||||||
|
raise ValueError("Target point already has a stone, Current Board: {}, color: {}, vertex : {}".format(current_board, color, vertex))
|
||||||
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
### check if it is suicide
|
### check if it is suicide
|
||||||
if self._is_suicide(current_board, color, vertex):
|
if self._is_suicide(current_board, color, vertex):
|
||||||
|
if not is_thinking:
|
||||||
|
raise ValueError("Target point causes suicide, Current Board: {}, color: {}, vertex : {}".format(current_board, color, vertex))
|
||||||
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
### forbid global isomorphous
|
### forbid global isomorphous
|
||||||
if self._check_global_isomorphous(history_hashtable, current_board, color, vertex):
|
if self._check_global_isomorphous(history_hashtable, current_board, color, vertex):
|
||||||
|
if not is_thinking:
|
||||||
|
raise ValueError("Target point causes global isomorphous, Current Board: {}, color: {}, vertex : {}".format(current_board, color, vertex))
|
||||||
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -231,9 +243,8 @@ class Go:
|
|||||||
return tuple(state[0][-1])
|
return tuple(state[0][-1])
|
||||||
|
|
||||||
def executor_do_move(self, history, history_set, latest_boards, current_board, color, vertex):
|
def executor_do_move(self, history, history_set, latest_boards, current_board, color, vertex):
|
||||||
if not self._rule_check(history_set, current_board, color, vertex):
|
if not self._rule_check(history_set, current_board, color, vertex, is_thinking=False):
|
||||||
print(current_board)
|
# raise ValueError("!!! We have more than four ko at the same time !!!")
|
||||||
raise ValueError("!!! We have more than four ko at the same time !!!")
|
|
||||||
return False
|
return False
|
||||||
current_board[self._flatten(vertex)] = color
|
current_board[self._flatten(vertex)] = color
|
||||||
self._process_board(current_board, color, vertex)
|
self._process_board(current_board, color, vertex)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user