本文整理汇总了Python中go.EMPTY属性的典型用法代码示例。如果您正苦于以下问题:Python go.EMPTY属性的具体用法?Python go.EMPTY怎么用?Python go.EMPTY使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类go
的用法示例。
在下文中一共展示了go.EMPTY属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_board
# 需要导入模块: import go [as 别名]
# 或者: from go import EMPTY [as 别名]
def load_board(string):
reverse_map = {
'X': go.BLACK,
'O': go.WHITE,
'.': go.EMPTY,
'#': go.FILL,
'*': go.KO,
'?': go.UNKNOWN
}
string = re.sub(r'[^XO\.#]+', '', string)
assert len(string) == go.N ** 2, "Board to load didn't have right dimensions"
board = np.zeros([go.N, go.N], dtype=np.int8)
for i, char in enumerate(string):
np.ravel(board)[i] = reverse_map[char]
return board
示例2: test_is_move_suicidal
# 需要导入模块: import go [as 别名]
# 或者: from go import EMPTY [as 别名]
def test_is_move_suicidal(self):
board = load_board('''
...O.O...
....O....
XO.....O.
OXO...OXO
O.XO.OX.O
OXO...OOX
XO.......
......XXO
.....XOO.
''')
position = Position(
board=board,
to_play=BLACK,
)
suicidal_moves = pc_set('E9 H5')
nonsuicidal_moves = pc_set('B5 J1 A9')
for move in suicidal_moves:
assert(position.board[move] == go.EMPTY) #sanity check my coordinate input
self.assertTrue(position.is_move_suicidal(move), str(move))
for move in nonsuicidal_moves:
assert(position.board[move] == go.EMPTY) #sanity check my coordinate input
self.assertFalse(position.is_move_suicidal(move), str(move))
示例3: load_board
# 需要导入模块: import go [as 别名]
# 或者: from go import EMPTY [as 别名]
def load_board(string):
reverse_map = {
'X': go.BLACK,
'O': go.WHITE,
'.': go.EMPTY,
'#': go.FILL,
'*': go.KO,
'?': go.UNKNOWN
}
string = re.sub(r'[^XO\.#]+', '', string)
if len(string) != BOARD_SIZE ** 2:
raise ValueError("Board to load didn't have right dimensions")
board = np.zeros([BOARD_SIZE, BOARD_SIZE], dtype=np.int8)
for ii, char in enumerate(string):
np.ravel(board)[ii] = reverse_map[char]
return board
示例4: stone_color_feature
# 需要导入模块: import go [as 别名]
# 或者: from go import EMPTY [as 别名]
def stone_color_feature(position):
board = position.board
features = np.zeros([go.N, go.N, 3], dtype=np.uint8)
if position.to_play == go.BLACK:
features[board == go.BLACK, 0] = 1
features[board == go.WHITE, 1] = 1
else:
features[board == go.WHITE, 0] = 1
features[board == go.BLACK, 1] = 1
features[board == go.EMPTY, 2] = 1
return features
示例5: test_is_move_suicidal
# 需要导入模块: import go [as 别名]
# 或者: from go import EMPTY [as 别名]
def test_is_move_suicidal(self):
board = test_utils.load_board('''
...O.O...
....O....
XO.....O.
OXO...OXO
O.XO.OX.O
OXO...OOX
XO.......
......XXO
.....XOO.
''')
position = Position(
board=board,
to_play=BLACK,
)
suicidal_moves = coords_from_kgs_set('E9 H5')
nonsuicidal_moves = coords_from_kgs_set('B5 J1 A9')
for move in suicidal_moves:
# sanity check my coordinate input
assert(position.board[move] == go.EMPTY)
self.assertTrue(position.is_move_suicidal(move), str(move))
for move in nonsuicidal_moves:
# sanity check my coordinate input
assert(position.board[move] == go.EMPTY)
self.assertFalse(position.is_move_suicidal(move), str(move))
示例6: test_is_move_suicidal
# 需要导入模块: import go [as 别名]
# 或者: from go import EMPTY [as 别名]
def test_is_move_suicidal(self):
board = utils_test.load_board('''
...O.O...
....O....
XO.....O.
OXO...OXO
O.XO.OX.O
OXO...OOX
XO.......
......XXO
.....XOO.
''')
position = Position(
utils_test.BOARD_SIZE,
board=board,
to_play=BLACK,
)
suicidal_moves = coords_from_kgs_set('E9 H5')
nonsuicidal_moves = coords_from_kgs_set('B5 J1 A9')
for move in suicidal_moves:
# sanity check my coordinate input
assert position.board[move] == go.EMPTY
self.assertTrue(position.is_move_suicidal(move), str(move))
for move in nonsuicidal_moves:
# sanity check my coordinate input
assert position.board[move] == go.EMPTY
self.assertFalse(position.is_move_suicidal(move), str(move))
示例7: parse_board
# 需要导入模块: import go [as 别名]
# 或者: from go import EMPTY [as 别名]
def parse_board(example):
"""Parses a go board from a TF example.
Args:
example: a ParsedExample.
Returns:
A go.Position parsed from the input example.
"""
to_play_feature = example.features[0, 0, FLAGS.to_play_feature]
to_play = go.BLACK if to_play_feature else go.WHITE
other = go.WHITE if to_play_feature else go.BLACK
board = np.zeros([go.N, go.N], dtype=np.int8)
for row in range(go.N):
for col in range(go.N):
f = example.features[row, col]
if f[0]:
board[row, col] = to_play
elif f[1]:
board[row, col] = other
else:
board[row, col] = go.EMPTY
return go.Position(board=board, to_play=to_play)
示例8: format_pi
# 需要导入模块: import go [as 别名]
# 或者: from go import EMPTY [as 别名]
def format_pi(pi, stone, mean, mx, picked):
# Start of the ANSI color code for this point: gray if this point was picked
# as the next move, black otherwise.
col = '\x1b[48;5;8;' if picked else '\x1b[0;'
GREEN = '32m'
BRIGHT_YELLOW = '33;1m'
BRIGHT_WHITE = '37;1m'
BLUE = '34m'
RED = '31m'
NORMAL = '\x1b[0m'
if stone != go.EMPTY:
return '\x1b[0;31m %s %s' % ('X' if stone == go.BLACK else 'O', NORMAL)
if pi < 1:
s = ('%.3f' % pi)[1:]
else:
s = '%.2f' % pi
if s == '.000':
col += BLUE
elif pi < mean:
col += GREEN
elif pi < mx:
col += BRIGHT_YELLOW
else:
col += BRIGHT_WHITE
s = '%s%s%s' % (col, s, NORMAL)
return s
示例9: print_example
# 需要导入模块: import go [as 别名]
# 或者: from go import EMPTY [as 别名]
def print_example(examples, i):
example = examples[i]
p = parse_board(example)
print('\nExample %d of %d, %s to play, winner is %s' % (
i + 1, len(examples), 'Black' if p.to_play == 1 else 'White',
'Black' if example.value > 0 else 'White'))
if example.n != -1:
print('N:%d Q:%.3f picked:%s' % (
example.n, example.q, coords.to_gtp(coords.from_flat(example.c))))
board_lines = str(p).split('\n')[:-2]
mean = np.mean(example.pi[example.pi > 0])
mx = np.max(example.pi)
pi_lines = ['PI']
for row in range(go.N):
pi = []
for col in range(go.N):
stone = p.board[row, col]
idx = row * go.N + col
if example.c != -1:
picked = example.c == row * go.N + col
else:
picked = False
pi.append(format_pi(example.pi[idx], stone, mean, mx, picked))
pi_lines.append(' '.join(pi))
pi_lines.append(format_pi(example.pi[-1], go.EMPTY, mean, mx,
example.c == go.N * go.N))
for b, p in zip(board_lines, pi_lines):
print('%s | %s' % (b, p))
示例10: test_is_move_suicidal
# 需要导入模块: import go [as 别名]
# 或者: from go import EMPTY [as 别名]
def test_is_move_suicidal(self):
board = test_utils.load_board('''
...O.O...
....O....
XO.....O.
OXO...OXO
O.XO.OX.O
OXO...OOX
XO.......
......XXO
.....XOO.
''')
position = Position(
board=board,
to_play=BLACK,
)
suicidal_moves = coords_from_gtp_set('E9 H5')
nonsuicidal_moves = coords_from_gtp_set('B5 J1 A9')
for move in suicidal_moves:
# sanity check my coordinate input
self.assertEqual(position.board[move], go.EMPTY)
self.assertTrue(position.is_move_suicidal(move), str(move))
for move in nonsuicidal_moves:
# sanity check my coordinate input
self.assertEqual(position.board[move], go.EMPTY)
self.assertFalse(position.is_move_suicidal(move), str(move))