diff --git a/GTP/.game.py.swp b/GTP/.game.py.swp deleted file mode 100644 index 4ad0ba6..0000000 Binary files a/GTP/.game.py.swp and /dev/null differ diff --git a/GTP/.test.py.swp b/GTP/.test.py.swp index 71ca4b4..b635af1 100644 Binary files a/GTP/.test.py.swp and b/GTP/.test.py.swp differ diff --git a/GTP/game.py b/GTP/game.py index c5d58fa..7f1b4c6 100644 --- a/GTP/game.py +++ b/GTP/game.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # vim:fenc=utf-8 # $File: game.py -# $Date: Tue Nov 28 01:1540 2017 +0800 +# $Date: Tue Nov 28 14:4726 2017 +0800 # $Author: renyong15 © # @@ -43,8 +43,43 @@ class Executor: return True,block - def _check_qi(self, vertex): - pass + def _is_qi(self, color, vertex): + nei = self._neighbor(vertex) + for n in nei: + if self.game.board[self.game._flatten(n)] == utils.EMPTY: + return True + + self.game.board[self.game._flatten(vertex)] = color + for n in nei: + if self.game.board[self.game._flatten(n)] == utils.another_color(color): + can_kill,block = self._find_block(n) + if can_kill: + self.game.board[self.game._flatten(vertex)] = utils.EMPTY + return True + + ### can not suicide + can_kill,block = self._find_block(vertex) + if can_kill: + self.game.board[self.game._flatten(vertex)] = utils.EMPTY + return False + + self.game.board[self.game._flatten(vertex)] = utils.EMPTY + return True + + + def _check_global_isomorphous(self, color, vertex): + ##backup + _board = copy.copy(self.game.board) + self.game.board[self.game._flatten(vertex)] = color + self._process_board(color, vertex) + if self.game.board in self.game.history: + res = True + else: + res = False + + self.game.board = _board + return res + def _in_board(self, vertex): x, y = vertex @@ -74,16 +109,30 @@ class Executor: def is_valid(self, color, vertex): + ### in board if not self._in_board(vertex): return False + + ### already have stone + if not self.game.board[self.game._flatten(vertex)] == utils.EMPTY: + return False + + ### check if it is qi + if not self._is_qi(color, vertex): + return False + + + if self._check_global_isomorphous(color, vertex): + return False + return True def do_move(self, color, vertex): if not self.is_valid(color, vertex): return False - self.game.history.append(copy.copy(self.game.board)) self.game.board[self.game._flatten(vertex)] = color self._process_board(color,vertex) + self.game.history.append(copy.copy(self.game.board)) return True diff --git a/GTP/test.py b/GTP/test.py index 0574ce0..0b8d4df 100644 --- a/GTP/test.py +++ b/GTP/test.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # vim:fenc=utf-8 # $File: test.py -# $Date: Tue Nov 28 01:0627 2017 +0800 +# $Date: Tue Nov 28 14:4717 2017 +0800 # $Author: renyong15 © # @@ -44,11 +44,11 @@ print(res) res = e.run_cmd('8 genmove BLACK') print(res) -g.show_board() +#g.show_board() print(g.check_valid((10, 9))) print(g.executor._neighbor((1,1))) print(g.do_move(utils.WHITE, (4, 6))) -g.show_board() +#g.show_board() res = e.run_cmd('play BLACK L10') @@ -88,7 +88,7 @@ print(res) res = e.run_cmd('play BLACK N12') print(res) -g.show_board() +#g.show_board() res = e.run_cmd('play BLACK P16') res = e.run_cmd('play BLACK P17') @@ -97,7 +97,6 @@ res = e.run_cmd('play BLACK P19') res = e.run_cmd('play BLACK Q16') res = e.run_cmd('play BLACK R16') res = e.run_cmd('play BLACK S16') -res = e.run_cmd('play BLACK S19') res = e.run_cmd('play WHITE S18') res = e.run_cmd('play WHITE S17') @@ -106,12 +105,37 @@ res = e.run_cmd('play WHITE Q18') res = e.run_cmd('play WHITE Q17') res = e.run_cmd('play WHITE R18') res = e.run_cmd('play WHITE R17') +res = e.run_cmd('play BLACK S19') print(res) -g.show_board() +#g.show_board() res = e.run_cmd('play WHITE R19') g.show_board() res = e.run_cmd('play BLACK S19') +print(res) g.show_board() +res = e.run_cmd('play BLACK S19') +print(res) + + +res = e.run_cmd('play BLACK E17') +res = e.run_cmd('play BLACK F16') +res = e.run_cmd('play BLACK F18') +res = e.run_cmd('play BLACK G17') +res = e.run_cmd('play WHITE G16') +res = e.run_cmd('play WHITE G18') +res = e.run_cmd('play WHITE H17') +g.show_board() + +res = e.run_cmd('play WHITE F17') +g.show_board() + +res = e.run_cmd('play BLACK G17') +print(res) +g.show_board() + +res = e.run_cmd('play BLACK G19') +res = e.run_cmd('play BLACK G17') +g.show_board()