本文整理汇总了Python中go.LibertyTracker.from_board方法的典型用法代码示例。如果您正苦于以下问题:Python LibertyTracker.from_board方法的具体用法?Python LibertyTracker.from_board怎么用?Python LibertyTracker.from_board使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go.LibertyTracker
的用法示例。
在下文中一共展示了LibertyTracker.from_board方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_place_stone_opposite_color
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_place_stone_opposite_color(self):
board = test_utils.load_board('X........' + EMPTY_ROW * 8)
lib_tracker = LibertyTracker.from_board(board)
lib_tracker.add_stone(WHITE, coords.from_kgs('B9'))
self.assertEqual(len(lib_tracker.groups), 2)
self.assertNotEqual(
lib_tracker.group_index[coords.from_kgs('A9')], go.MISSING_GROUP_ID)
self.assertNotEqual(
lib_tracker.group_index[coords.from_kgs('B9')], go.MISSING_GROUP_ID)
self.assertEqual(lib_tracker.liberty_cache[coords.from_kgs('A9')], 1)
self.assertEqual(lib_tracker.liberty_cache[coords.from_kgs('B9')], 2)
black_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
'A9')]]
white_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
'B9')]]
self.assertEqual(black_group.stones, coords_from_kgs_set('A9'))
self.assertEqual(black_group.liberties, coords_from_kgs_set('A8'))
self.assertEqual(black_group.color, BLACK)
self.assertEqual(white_group.stones, coords_from_kgs_set('B9'))
self.assertEqual(white_group.liberties, coords_from_kgs_set('C9 B8'))
self.assertEqual(white_group.color, WHITE)
示例2: test_merge_multiple_groups
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_merge_multiple_groups(self):
board = test_utils.load_board('''
.X.......
X.X......
.X.......
''' + EMPTY_ROW * 6)
lib_tracker = LibertyTracker.from_board(board)
lib_tracker.add_stone(BLACK, coords.from_kgs('B8'))
self.assertEqual(len(lib_tracker.groups), 1)
self.assertNotEqual(
lib_tracker.group_index[coords.from_kgs('B8')], go.MISSING_GROUP_ID)
sole_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
'B8')]]
self.assertEqual(sole_group.stones,
coords_from_kgs_set('B9 A8 B8 C8 B7'))
self.assertEqual(sole_group.liberties,
coords_from_kgs_set('A9 C9 D8 A7 C7 B6'))
self.assertEqual(sole_group.color, BLACK)
liberty_cache = lib_tracker.liberty_cache
for stone in sole_group.stones:
self.assertEqual(liberty_cache[stone], 6, str(stone))
示例3: test_same_friendly_group_neighboring_twice
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_same_friendly_group_neighboring_twice(self):
board = test_utils.load_board('''
XX.......
X........
''' + EMPTY_ROW * 7)
lib_tracker = LibertyTracker.from_board(board)
captured = lib_tracker.add_stone(BLACK, coords.from_kgs('B8'))
self.assertEqual(len(lib_tracker.groups), 1)
sole_group_id = lib_tracker.group_index[coords.from_kgs('A9')]
sole_group = lib_tracker.groups[sole_group_id]
self.assertEqual(sole_group.stones,
coords_from_kgs_set('A9 B9 A8 B8'))
self.assertEqual(sole_group.liberties,
coords_from_kgs_set('C9 C8 A7 B7'))
self.assertEqual(captured, set())
示例4: test_same_opponent_group_neighboring_twice
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_same_opponent_group_neighboring_twice(self):
board = test_utils.load_board('''
XX.......
X........
''' + EMPTY_ROW * 7)
lib_tracker = LibertyTracker.from_board(board)
captured = lib_tracker.add_stone(WHITE, coords.from_kgs('B8'))
self.assertEqual(len(lib_tracker.groups), 2)
black_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
'A9')]]
self.assertEqual(black_group.stones, coords_from_kgs_set('A9 B9 A8'))
self.assertEqual(black_group.liberties, coords_from_kgs_set('C9 A7'))
white_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
'B8')]]
self.assertEqual(white_group.stones, coords_from_kgs_set('B8'))
self.assertEqual(white_group.liberties, coords_from_kgs_set('C8 B7'))
self.assertEqual(captured, set())
示例5: test_place_stone_opposite_color
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_place_stone_opposite_color(self):
board = load_board('X........' + EMPTY_ROW * 8)
lib_tracker = LibertyTracker.from_board(board)
lib_tracker.add_stone(WHITE, pc('B9'))
self.assertEqual(len(lib_tracker.groups), 2)
self.assertNotEqual(lib_tracker.group_index[pc('A9')], go.MISSING_GROUP_ID)
self.assertNotEqual(lib_tracker.group_index[pc('B9')], go.MISSING_GROUP_ID)
self.assertEqual(lib_tracker.liberty_cache[pc('A9')], 1)
self.assertEqual(lib_tracker.liberty_cache[pc('B9')], 2)
black_group = lib_tracker.groups[lib_tracker.group_index[pc('A9')]]
white_group = lib_tracker.groups[lib_tracker.group_index[pc('B9')]]
self.assertEqual(black_group.stones, pc_set('A9'))
self.assertEqual(black_group.liberties, pc_set('A8'))
self.assertEqual(black_group.color, BLACK)
self.assertEqual(white_group.stones, pc_set('B9'))
self.assertEqual(white_group.liberties, pc_set('C9 B8'))
self.assertEqual(white_group.color, WHITE)
示例6: test_merge_multiple_groups
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_merge_multiple_groups(self):
board = load_board('''
.X.......
X.X......
.X.......
''' + EMPTY_ROW * 6)
lib_tracker = LibertyTracker.from_board(board)
lib_tracker.add_stone(BLACK, pc('B8'))
self.assertEqual(len(lib_tracker.groups), 1)
self.assertNotEqual(lib_tracker.group_index[pc('B8')], go.MISSING_GROUP_ID)
sole_group = lib_tracker.groups[lib_tracker.group_index[pc('B8')]]
self.assertEqual(sole_group.stones, pc_set('B9 A8 B8 C8 B7'))
self.assertEqual(sole_group.liberties, pc_set('A9 C9 D8 A7 C7 B6'))
self.assertEqual(sole_group.color, BLACK)
liberty_cache = lib_tracker.liberty_cache
for stone in sole_group.stones:
self.assertEqual(liberty_cache[stone], 6, str(stone))
示例7: test_capture_multiple_groups
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_capture_multiple_groups(self):
board = load_board('''
.OX......
OXX......
XX.......
''' + EMPTY_ROW * 6)
lib_tracker = LibertyTracker.from_board(board)
captured = lib_tracker.add_stone(BLACK, pc('A9'))
self.assertEqual(len(lib_tracker.groups), 2)
self.assertEqual(captured, pc_set('B9 A8'))
corner_stone = lib_tracker.groups[lib_tracker.group_index[pc('A9')]]
self.assertEqual(corner_stone.stones, pc_set('A9'))
self.assertEqual(corner_stone.liberties, pc_set('B9 A8'))
surrounding_stones = lib_tracker.groups[lib_tracker.group_index[pc('C9')]]
self.assertEqual(surrounding_stones.stones, pc_set('C9 B8 C8 A7 B7'))
self.assertEqual(surrounding_stones.liberties, pc_set('B9 D9 A8 D8 C7 A6 B6'))
liberty_cache = lib_tracker.liberty_cache
for stone in corner_stone.stones:
self.assertEqual(liberty_cache[stone], 2, str(stone))
for stone in surrounding_stones.stones:
self.assertEqual(liberty_cache[stone], 7, str(stone))
示例8: test_same_opponent_group_neighboring_twice
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_same_opponent_group_neighboring_twice(self):
board = load_board('''
XX.......
X........
''' + EMPTY_ROW * 7)
lib_tracker = LibertyTracker.from_board(board)
captured = lib_tracker.add_stone(WHITE, pc('B8'))
self.assertEqual(len(lib_tracker.groups), 2)
black_group = lib_tracker.groups[lib_tracker.group_index[pc('A9')]]
self.assertEqual(black_group.stones, pc_set('A9 B9 A8'))
self.assertEqual(black_group.liberties, pc_set('C9 A7'))
white_group = lib_tracker.groups[lib_tracker.group_index[pc('B8')]]
self.assertEqual(white_group.stones, pc_set('B8'))
self.assertEqual(white_group.liberties, pc_set('C8 B7'))
self.assertEqual(captured, set())
示例9: test_place_stone
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_place_stone(self):
board = utils_test.load_board('X........' + EMPTY_ROW * 8)
lib_tracker = LibertyTracker.from_board(utils_test.BOARD_SIZE, board)
lib_tracker.add_stone(BLACK, coords.from_kgs(utils_test.BOARD_SIZE, 'B9'))
self.assertEqual(len(lib_tracker.groups), 1)
self.assertNotEqual(
lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'A9')], go.MISSING_GROUP_ID)
self.assertEqual(lib_tracker.liberty_cache[coords.from_kgs(
utils_test.BOARD_SIZE, 'A9')], 3)
self.assertEqual(lib_tracker.liberty_cache[coords.from_kgs(
utils_test.BOARD_SIZE, 'B9')], 3)
sole_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'A9')]]
self.assertEqual(sole_group.stones, coords_from_kgs_set('A9 B9'))
self.assertEqual(sole_group.liberties,
coords_from_kgs_set('C9 A8 B8'))
self.assertEqual(sole_group.color, BLACK)
示例10: test_place_stone_opposite_color
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_place_stone_opposite_color(self):
board = utils_test.load_board('X........' + EMPTY_ROW * 8)
lib_tracker = LibertyTracker.from_board(utils_test.BOARD_SIZE, board)
lib_tracker.add_stone(WHITE, coords.from_kgs(utils_test.BOARD_SIZE, 'B9'))
self.assertEqual(len(lib_tracker.groups), 2)
self.assertNotEqual(
lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'A9')], go.MISSING_GROUP_ID)
self.assertNotEqual(
lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'B9')], go.MISSING_GROUP_ID)
self.assertEqual(lib_tracker.liberty_cache[coords.from_kgs(
utils_test.BOARD_SIZE, 'A9')], 1)
self.assertEqual(lib_tracker.liberty_cache[coords.from_kgs(
utils_test.BOARD_SIZE, 'B9')], 2)
black_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'A9')]]
white_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'B9')]]
self.assertEqual(black_group.stones, coords_from_kgs_set('A9'))
self.assertEqual(black_group.liberties, coords_from_kgs_set('A8'))
self.assertEqual(black_group.color, BLACK)
self.assertEqual(white_group.stones, coords_from_kgs_set('B9'))
self.assertEqual(white_group.liberties, coords_from_kgs_set('C9 B8'))
self.assertEqual(white_group.color, WHITE)
示例11: test_merge_multiple_groups
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_merge_multiple_groups(self):
board = utils_test.load_board('''
.X.......
X.X......
.X.......
''' + EMPTY_ROW * 6)
lib_tracker = LibertyTracker.from_board(utils_test.BOARD_SIZE, board)
lib_tracker.add_stone(BLACK, coords.from_kgs(utils_test.BOARD_SIZE, 'B8'))
self.assertEqual(len(lib_tracker.groups), 1)
self.assertNotEqual(
lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'B8')], go.MISSING_GROUP_ID)
sole_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'B8')]]
self.assertEqual(sole_group.stones,
coords_from_kgs_set('B9 A8 B8 C8 B7'))
self.assertEqual(sole_group.liberties,
coords_from_kgs_set('A9 C9 D8 A7 C7 B6'))
self.assertEqual(sole_group.color, BLACK)
liberty_cache = lib_tracker.liberty_cache
for stone in sole_group.stones:
self.assertEqual(liberty_cache[stone], 6, str(stone))
示例12: test_same_friendly_group_neighboring_twice
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_same_friendly_group_neighboring_twice(self):
board = utils_test.load_board('''
XX.......
X........
''' + EMPTY_ROW * 7)
lib_tracker = LibertyTracker.from_board(utils_test.BOARD_SIZE, board)
captured = lib_tracker.add_stone(BLACK, coords.from_kgs(
utils_test.BOARD_SIZE, 'B8'))
self.assertEqual(len(lib_tracker.groups), 1)
sole_group_id = lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'A9')]
sole_group = lib_tracker.groups[sole_group_id]
self.assertEqual(sole_group.stones,
coords_from_kgs_set('A9 B9 A8 B8'))
self.assertEqual(sole_group.liberties,
coords_from_kgs_set('C9 C8 A7 B7'))
self.assertEqual(captured, set())
示例13: test_same_opponent_group_neighboring_twice
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_same_opponent_group_neighboring_twice(self):
board = utils_test.load_board('''
XX.......
X........
''' + EMPTY_ROW * 7)
lib_tracker = LibertyTracker.from_board(utils_test.BOARD_SIZE, board)
captured = lib_tracker.add_stone(WHITE, coords.from_kgs(
utils_test.BOARD_SIZE, 'B8'))
self.assertEqual(len(lib_tracker.groups), 2)
black_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'A9')]]
self.assertEqual(black_group.stones, coords_from_kgs_set('A9 B9 A8'))
self.assertEqual(black_group.liberties, coords_from_kgs_set('C9 A7'))
white_group = lib_tracker.groups[lib_tracker.group_index[coords.from_kgs(
utils_test.BOARD_SIZE, 'B8')]]
self.assertEqual(white_group.stones, coords_from_kgs_set('B8'))
self.assertEqual(white_group.liberties, coords_from_kgs_set('C8 B7'))
self.assertEqual(captured, set())
示例14: test_place_stone_opposite_color
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_place_stone_opposite_color(self):
board = test_utils.load_board('X........' + EMPTY_ROW * 8)
lib_tracker = LibertyTracker.from_board(board)
lib_tracker.add_stone(WHITE, coords.from_gtp('B9'))
self.assertEqual(len(lib_tracker.groups), 2)
self.assertNotEqual(
lib_tracker.group_index[coords.from_gtp('A9')], go.MISSING_GROUP_ID)
self.assertNotEqual(
lib_tracker.group_index[coords.from_gtp('B9')], go.MISSING_GROUP_ID)
self.assertEqual(lib_tracker.liberty_cache[coords.from_gtp('A9')], 1)
self.assertEqual(lib_tracker.liberty_cache[coords.from_gtp('B9')], 2)
black_group = lib_tracker.groups[lib_tracker.group_index[coords.from_gtp(
'A9')]]
white_group = lib_tracker.groups[lib_tracker.group_index[coords.from_gtp(
'B9')]]
self.assertEqual(black_group.stones, coords_from_gtp_set('A9'))
self.assertEqual(black_group.liberties, coords_from_gtp_set('A8'))
self.assertEqual(black_group.color, BLACK)
self.assertEqual(white_group.stones, coords_from_gtp_set('B9'))
self.assertEqual(white_group.liberties, coords_from_gtp_set('C9 B8'))
self.assertEqual(white_group.color, WHITE)
示例15: test_merge_multiple_groups
# 需要导入模块: from go import LibertyTracker [as 别名]
# 或者: from go.LibertyTracker import from_board [as 别名]
def test_merge_multiple_groups(self):
board = test_utils.load_board('''
.X.......
X.X......
.X.......
''' + EMPTY_ROW * 6)
lib_tracker = LibertyTracker.from_board(board)
lib_tracker.add_stone(BLACK, coords.from_gtp('B8'))
self.assertEqual(len(lib_tracker.groups), 1)
self.assertNotEqual(
lib_tracker.group_index[coords.from_gtp('B8')], go.MISSING_GROUP_ID)
sole_group = lib_tracker.groups[lib_tracker.group_index[coords.from_gtp(
'B8')]]
self.assertEqual(sole_group.stones,
coords_from_gtp_set('B9 A8 B8 C8 B7'))
self.assertEqual(sole_group.liberties,
coords_from_gtp_set('A9 C9 D8 A7 C7 B6'))
self.assertEqual(sole_group.color, BLACK)
liberty_cache = lib_tracker.liberty_cache
for stone in sole_group.stones:
self.assertEqual(liberty_cache[stone], 6, str(stone))