当前位置: 首页>>代码示例>>Python>>正文


Python go.Position方法代码示例

本文整理汇总了Python中go.Position方法的典型用法代码示例。如果您正苦于以下问题:Python go.Position方法的具体用法?Python go.Position怎么用?Python go.Position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在go的用法示例。


在下文中一共展示了go.Position方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_long_game_tree_search

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_long_game_tree_search(self):
        player = MCTSPlayerMixin(DummyNet())
        endgame = go.Position(
            board=TT_FTW_BOARD,
            n=MAX_DEPTH-2,
            komi=2.5,
            ko=None,
            recent=(go.PlayerMove(go.BLACK, (0, 1)),
                    go.PlayerMove(go.WHITE, (0, 8))),
            to_play=go.BLACK
        )
        player.initialize_game(endgame)

        # Test that an almost complete game
        for i in range(10):
            player.tree_search(num_parallel=8)
        self.assertNoPendingVirtualLosses(player.root)
        self.assertGreater(player.root.Q, 0) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:20,代码来源:test_strategies.py

示例2: test_only_check_game_end_once

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_only_check_game_end_once(self):
        # When presented with a situation where the last move was a pass,
        # and we have to decide whether to pass, it should be the first thing
        # we check, but not more than that.

        white_passed_pos = go.Position(
        ).play_move((3, 3)  # b plays
                    ).play_move((3, 4)  # w plays
                                ).play_move((4, 3)  # b plays
                                            ).pass_move()  # w passes - if B passes too, B would lose by komi.

        player = MCTSPlayerMixin(DummyNet())
        player.initialize_game(white_passed_pos)
        # initialize the root
        player.tree_search()
        # explore a child - should be a pass move.
        player.tree_search()
        pass_move = go.N * go.N
        self.assertEqual(player.root.children[pass_move].N, 1)
        self.assertEqual(player.root.child_N[pass_move], 1)
        player.tree_search()
        # check that we didn't visit the pass node any more times.
        self.assertEqual(player.root.child_N[pass_move], 1) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:25,代码来源:test_strategies.py

示例3: test_flipturn

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_flipturn(self):
        start_position = Position(
            board=TEST_BOARD,
            n=0,
            komi=6.5,
            caps=(1, 2),
            ko=coords.from_kgs('A1'),
            recent=tuple(),
            to_play=BLACK,
        )
        expected_position = Position(
            board=TEST_BOARD,
            n=0,
            komi=6.5,
            caps=(1, 2),
            ko=None,
            recent=tuple(),
            to_play=WHITE,
        )
        flip_position = start_position.flip_playerturn()
        self.assertEqualPositions(flip_position, expected_position) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:23,代码来源:test_go.py

示例4: test_make_dataset_from_sgf

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_make_dataset_from_sgf(self):
        with tempfile.NamedTemporaryFile() as sgf_file, \
                tempfile.NamedTemporaryFile() as record_file:
            sgf_file.write(TEST_SGF.encode('utf8'))
            sgf_file.seek(0)
            preprocessing.make_dataset_from_sgf(
                sgf_file.name, record_file.name)
            recovered_data = self.extract_data(record_file.name)
        start_pos = go.Position()
        first_move = coords.from_sgf('fd')
        next_pos = start_pos.play_move(first_move)
        second_move = coords.from_sgf('cf')
        expected_data = [
            (
                features.extract_features(start_pos),
                preprocessing._one_hot(coords.to_flat(first_move)),
                -1
            ), (
                features.extract_features(next_pos),
                preprocessing._one_hot(coords.to_flat(second_move)),
                -1
            )]
        self.assertEqualData(expected_data, recovered_data) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:25,代码来源:test_preprocessing.py

示例5: test_passing

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_passing(self):
        start_position = Position(
            board=TEST_BOARD,
            n=0,
            komi=6.5,
            caps=(1, 2),
            ko=coords.from_kgs('A1'),
            recent=tuple(),
            to_play=BLACK,
        )
        expected_position = Position(
            board=TEST_BOARD,
            n=1,
            komi=6.5,
            caps=(1, 2),
            ko=None,
            recent=(PlayerMove(BLACK, None),),
            to_play=WHITE,
        )
        pass_position = start_position.pass_move()
        self.assertEqualPositions(pass_position, expected_position) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:23,代码来源:test_go.py

示例6: test_is_move_reasonable

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_is_move_reasonable(self):
        board = load_board('''
            .XXOOOXXX
            X.XO.OX.X
            XXXOOOXX.
            ...XXX..X
            XXXX.....
            OOOX....O
            X.OXX.OO.
            .XO.X.O.O
            XXO.X.OO.
        ''')
        position = Position(
            board=board,
            to_play=BLACK,
        )
        reasonable_moves = pc_set('E8 B3')
        unreasonable_moves = pc_set('A9 B8 H8 J7 A2 J3 H2 J1')
        for move in reasonable_moves:
            self.assertTrue(is_move_reasonable(position, move), str(move))
        for move in unreasonable_moves:
            self.assertFalse(is_move_reasonable(position, move), str(move)) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:24,代码来源:test_strategies.py

示例7: test_passing

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_passing(self):
        start_position = Position(
            board=TEST_BOARD,
            n=0,
            komi=6.5,
            caps=(1, 2),
            ko=pc('A1'),
            recent=tuple(),
            to_play=BLACK,
        )
        expected_position = Position(
            board=TEST_BOARD,
            n=1,
            komi=6.5,
            caps=(1, 2),
            ko=None,
            recent=(PlayerMove(BLACK, None),),
            to_play=WHITE,
        )
        pass_position = start_position.pass_move()
        self.assertEqualPositions(pass_position, expected_position) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:23,代码来源:test_go.py

示例8: test_flipturn

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_flipturn(self):
        start_position = Position(
            board=TEST_BOARD,
            n=0,
            komi=6.5,
            caps=(1, 2),
            ko=pc('A1'),
            recent=tuple(),
            to_play=BLACK,
        )
        expected_position = Position(
            board=TEST_BOARD,
            n=0,
            komi=6.5,
            caps=(1, 2),
            ko=None,
            recent=tuple(),
            to_play=WHITE,
        )
        flip_position = start_position.flip_playerturn()
        self.assertEqualPositions(flip_position, expected_position) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:23,代码来源:test_go.py

示例9: test_is_move_suicidal

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [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)) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:26,代码来源:test_go.py

示例10: replay_position

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def replay_position(position):
    '''
    Wrapper for a go.Position which replays its history.
    Assumes an empty start position! (i.e. no handicap, and history must be exhaustive.)

    for position_w_context in replay_position(position):
        print(position_w_context.position)
    '''
    assert position.n == len(position.recent), "Position history is incomplete"
    metadata = GameMetadata(
        result=position.result(),
        handicap=0,
        board_size=position.board.shape[0]
    )
    go.set_board_size(metadata.board_size)

    pos = Position(komi=position.komi)
    for player_move in position.recent:
        color, next_move = player_move
        yield PositionWithContext(pos, next_move, metadata)
        pos = pos.play_move(next_move, color=color)
    # return the original position, with unknown next move
    yield PositionWithContext(pos, None, metadata) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:25,代码来源:sgf_wrapper.py

示例11: test_passing

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_passing(self):
    start_position = Position(
        utils_test.BOARD_SIZE,
        board=TEST_BOARD,
        n=0,
        komi=6.5,
        caps=(1, 2),
        ko=coords.from_kgs(utils_test.BOARD_SIZE, 'A1'),
        recent=tuple(),
        to_play=BLACK,
    )
    expected_position = Position(
        utils_test.BOARD_SIZE,
        board=TEST_BOARD,
        n=1,
        komi=6.5,
        caps=(1, 2),
        ko=None,
        recent=(PlayerMove(BLACK, None),),
        to_play=WHITE,
    )
    pass_position = start_position.pass_move()
    self.assertEqualPositions(pass_position, expected_position) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:25,代码来源:go_test.py

示例12: test_flipturn

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_flipturn(self):
    start_position = Position(
        utils_test.BOARD_SIZE,
        board=TEST_BOARD,
        n=0,
        komi=6.5,
        caps=(1, 2),
        ko=coords.from_kgs(utils_test.BOARD_SIZE, 'A1'),
        recent=tuple(),
        to_play=BLACK,
    )
    expected_position = Position(
        utils_test.BOARD_SIZE,
        board=TEST_BOARD,
        n=0,
        komi=6.5,
        caps=(1, 2),
        ko=None,
        recent=tuple(),
        to_play=WHITE,
    )
    flip_position = start_position.flip_playerturn()
    self.assertEqualPositions(flip_position, expected_position) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:25,代码来源:go_test.py

示例13: test_long_game_tree_search

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_long_game_tree_search(self):
    player = MCTSPlayerMixin(utils_test.BOARD_SIZE, DummyNet())
    endgame = go.Position(
        utils_test.BOARD_SIZE,
        board=TT_FTW_BOARD,
        n=MAX_DEPTH-2,
        komi=2.5,
        ko=None,
        recent=(go.PlayerMove(go.BLACK, (0, 1)),
                go.PlayerMove(go.WHITE, (0, 8))),
        to_play=go.BLACK
    )
    player.initialize_game(endgame)

    # Test that an almost complete game
    for i in range(10):
      player.tree_search(num_parallel=8)
    self.assertNoPendingVirtualLosses(player.root)
    self.assertGreater(player.root.Q, 0) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:21,代码来源:strategies_test.py

示例14: test_action_flipping

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def test_action_flipping(self):
    np.random.seed(1)
    probs = np.array([.02] * (
        utils_test.BOARD_SIZE * utils_test.BOARD_SIZE + 1))
    probs += np.random.random(
        [utils_test.BOARD_SIZE * utils_test.BOARD_SIZE + 1]) * 0.001
    black_root = MCTSNode(
        utils_test.BOARD_SIZE, go.Position(utils_test.BOARD_SIZE))
    white_root = MCTSNode(utils_test.BOARD_SIZE, go.Position(
        utils_test.BOARD_SIZE, to_play=go.WHITE))
    black_root.select_leaf().incorporate_results(probs, 0, black_root)
    white_root.select_leaf().incorporate_results(probs, 0, white_root)
    # No matter who is to play, when we know nothing else, the priors
    # should be respected, and the same move should be picked
    black_leaf = black_root.select_leaf()
    white_leaf = white_root.select_leaf()
    self.assertEqual(black_leaf.fmove, white_leaf.fmove)
    self.assertEqualNPArray(
        black_root.child_action_score, white_root.child_action_score) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:21,代码来源:mcts_test.py

示例15: clear

# 需要导入模块: import go [as 别名]
# 或者: from go import Position [as 别名]
def clear(self):
        if self.position and len(self.position.recent) > 1:
            try:
                sgf = self.to_sgf()
                with open(datetime.datetime.now().strftime("%Y-%m-%d-%H:%M.sgf"), 'w') as f:
                    f.write(sgf)
            except NotImplementedError:
                pass
            except:
                print("Error saving sgf", file=sys.stderr, flush=True)
        self.position = go.Position(komi=self.komi)
        self.initialize_game(self.position) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:14,代码来源:gtp_wrapper.py


注:本文中的go.Position方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。