minor fixed

This commit is contained in:
rtz19970824 2017-11-28 15:10:41 +08:00
parent 336a3d0020
commit 56012c8de9

View File

@ -8,7 +8,6 @@
import utils import utils
import copy import copy
''' '''
(1, 1) is considered as the upper left corner of the board, (1, 1) is considered as the upper left corner of the board,
(size, 1) is the lower left (size, 1) is the lower left
@ -16,11 +15,11 @@ import copy
DELTA = [[1, 0], [-1, 0], [0, -1], [0, 1]] DELTA = [[1, 0], [-1, 0], [0, -1], [0, 1]]
class Executor: class Executor:
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.game = kwargs['game'] self.game = kwargs['game']
def _bfs(self, vertex, color, block, status, alive_break): def _bfs(self, vertex, color, block, status, alive_break):
block.append(vertex) block.append(vertex)
status[self.game._flatten(vertex)] = True status[self.game._flatten(vertex)] = True
@ -42,7 +41,6 @@ class Executor:
return False, block return False, block
return True, block return True, block
def _is_qi(self, color, vertex): def _is_qi(self, color, vertex):
nei = self._neighbor(vertex) nei = self._neighbor(vertex)
for n in nei: for n in nei:
@ -66,7 +64,6 @@ class Executor:
self.game.board[self.game._flatten(vertex)] = utils.EMPTY self.game.board[self.game._flatten(vertex)] = utils.EMPTY
return True return True
def _check_global_isomorphous(self, color, vertex): def _check_global_isomorphous(self, color, vertex):
##backup ##backup
_board = copy.copy(self.game.board) _board = copy.copy(self.game.board)
@ -80,14 +77,12 @@ class Executor:
self.game.board = _board self.game.board = _board
return res return res
def _in_board(self, vertex): def _in_board(self, vertex):
x, y = vertex x, y = vertex
if x < 1 or x > self.game.size: return False if x < 1 or x > self.game.size: return False
if y < 1 or y > self.game.size: return False if y < 1 or y > self.game.size: return False
return True return True
def _neighbor(self, vertex): def _neighbor(self, vertex):
x, y = vertex x, y = vertex
nei = [] nei = []
@ -107,7 +102,6 @@ class Executor:
for b in block: for b in block:
self.game.board[self.game._flatten(b)] = utils.EMPTY self.game.board[self.game._flatten(b)] = utils.EMPTY
def is_valid(self, color, vertex): def is_valid(self, color, vertex):
### in board ### in board
if not self._in_board(vertex): if not self._in_board(vertex):
@ -121,7 +115,6 @@ class Executor:
if not self._is_qi(color, vertex): if not self._is_qi(color, vertex):
return False return False
if self._check_global_isomorphous(color, vertex): if self._check_global_isomorphous(color, vertex):
return False return False
@ -149,7 +142,6 @@ class Game:
x, y = vertex x, y = vertex
return (y - 1) * self.size + (x - 1) return (y - 1) * self.size + (x - 1)
def clear(self): def clear(self):
self.board = [utils.EMPTY] * (self.size * self.size) self.board = [utils.EMPTY] * (self.size * self.size)
@ -160,7 +152,6 @@ class Game:
def set_komi(self, k): def set_komi(self, k):
self.komi = k self.komi = k
def check_valid(self, vertex): def check_valid(self, vertex):
return True return True
@ -170,34 +161,27 @@ class Game:
res = self.executor.do_move(color, vertex) res = self.executor.do_move(color, vertex)
return res return res
def gen_move(self, color): def gen_move(self, color):
# move = self.strategy.gen_move(color) # move = self.strategy.gen_move(color)
# return move # return move
return utils.PASS return utils.PASS
def status2symbol(self, s): def status2symbol(self, s):
pool = {utils.WHITE: '#', utils.EMPTY: '.', utils.BLACK: '*', utils.FILL: 'F', utils.UNKNOWN: '?'} pool = {utils.WHITE: '#', utils.EMPTY: '.', utils.BLACK: '*', utils.FILL: 'F', utils.UNKNOWN: '?'}
return pool[s] return pool[s]
def show_board(self): def show_board(self):
row = [i for i in range(1, 20)] row = [i for i in range(1, 20)]
col = ' abcdefghijklmnopqrstuvwxyz' col = ' abcdefghijklmnopqrstuvwxyz'
for i in range(self.size): for i in range(self.size):
print(row[i], end = ' ') print(row[i])
if row[i] < 10: if row[i] < 10:
print(' ', end = '') print(' ')
for j in range(self.size): for j in range(self.size):
print(self.status2symbol(self.board[self._flatten((j+1,i+1))]), end=' ') print(self.status2symbol(self.board[self._flatten((j + 1, i + 1))]))
print('\n') print('\n')
print(' ', end = '') print(' ')
for j in range(self.size + 1): for j in range(self.size + 1):
print(col[j], end = ' ') print(col[j])
print('\n') print('\n')