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


Python strategies.MCTSPlayerMixin方法代码示例

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


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

示例1: test_long_game_tree_search

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [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 strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [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_extract_data_normal_end

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def test_extract_data_normal_end(self):
        player = MCTSPlayerMixin(DummyNet())
        player.initialize_game()
        player.tree_search()
        player.play_move(None)
        player.tree_search()
        player.play_move(None)
        self.assertTrue(player.root.is_done())
        player.set_result(player.root.position.result(), was_resign=False)

        data = list(player.extract_data())
        self.assertEqual(len(data), 2)
        position, pi, result = data[0]
        # White wins by komi
        self.assertEqual(result, go.WHITE)
        self.assertEqual(player.result_string, "W+{}".format(player.root.position.komi)) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:18,代码来源:test_strategies.py

示例4: test_extract_data_resign_end

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def test_extract_data_resign_end(self):
        player = MCTSPlayerMixin(DummyNet())
        player.initialize_game()
        player.tree_search()
        player.play_move((0, 0))
        player.tree_search()
        player.play_move(None)
        player.tree_search()
        # Black is winning on the board
        self.assertEqual(player.root.position.result(), go.BLACK)
        # But if Black resigns
        player.set_result(go.WHITE, was_resign=True)

        data = list(player.extract_data())
        position, pi, result = data[0]
        # Result should say White is the winner
        self.assertEqual(result, go.WHITE)
        self.assertEqual(player.result_string, "W+R") 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:20,代码来源:test_strategies.py

示例5: test_long_game_tree_search

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [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

示例6: test_extract_data_normal_end

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def test_extract_data_normal_end(self):
    player = MCTSPlayerMixin(utils_test.BOARD_SIZE, DummyNet())
    player.initialize_game()
    player.tree_search()
    player.play_move(None)
    player.tree_search()
    player.play_move(None)
    self.assertTrue(player.root.is_done())
    player.set_result(player.root.position.result(), was_resign=False)

    data = list(player.extract_data())
    self.assertEqual(len(data), 2)
    position, pi, result = data[0]
    # White wins by komi
    self.assertEqual(result, go.WHITE)
    self.assertEqual(player.result_string, 'W+{}'.format(
        player.root.position.komi)) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:19,代码来源:strategies_test.py

示例7: test_extract_data_resign_end

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def test_extract_data_resign_end(self):
    player = MCTSPlayerMixin(utils_test.BOARD_SIZE, DummyNet())
    player.initialize_game()
    player.tree_search()
    player.play_move((0, 0))
    player.tree_search()
    player.play_move(None)
    player.tree_search()
    # Black is winning on the board
    self.assertEqual(player.root.position.result(), go.BLACK)
    # But if Black resigns
    player.set_result(go.WHITE, was_resign=True)

    data = list(player.extract_data())
    position, pi, result = data[0]
    # Result should say White is the winner
    self.assertEqual(result, go.WHITE)
    self.assertEqual(player.result_string, 'W+R') 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:20,代码来源:strategies_test.py

示例8: initialize_game

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def initialize_game(sgf_file, load_file, move=1):
    with open(sgf_file) as f:
        sgf_contents = f.read()
    iterator = sgf_wrapper.replay_sgf(sgf_contents)
    for i in range(move):
        position_w_context = next(iterator)
    player = strategies.MCTSPlayerMixin(dual_net.DualNetwork(load_file))
    player.initialize_game(position_w_context.position)
    return player 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:11,代码来源:inspect_game.py

示例9: initialize_basic_player

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def initialize_basic_player():
    player = MCTSPlayerMixin(DummyNet())
    player.initialize_game()
    first_node = player.root.select_leaf()
    first_node.incorporate_results(
        *player.network.run(player.root.position), up_to=player.root)
    return player 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:9,代码来源:test_strategies.py

示例10: initialize_almost_done_player

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def initialize_almost_done_player():
    probs = np.array([.001] * (go.N * go.N + 1))
    probs[2:5] = 0.2  # some legal moves along the top.
    probs[-1] = 0.2  # passing is also ok
    net = DummyNet(fake_priors=probs)
    player = MCTSPlayerMixin(net)
    # root position is white to play with no history == white passed.
    player.initialize_game(SEND_TWO_RETURN_ONE)
    return player 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:11,代码来源:test_strategies.py

示例11: test_cold_start_parallel_tree_search

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def test_cold_start_parallel_tree_search(self):
        # Test that parallel tree search doesn't trip on an empty tree
        player = MCTSPlayerMixin(DummyNet(fake_value=0.17))
        player.initialize_game()
        self.assertEqual(player.root.N, 0)
        self.assertFalse(player.root.is_expanded)
        player.tree_search(num_parallel=4)
        self.assertNoPendingVirtualLosses(player.root)
        # Even though the root gets selected 4 times by tree search, its
        # final visit count should just be 1.
        self.assertEqual(player.root.N, 1)
        # 0.085 = average(0, 0.17), since 0 is the prior on the root.
        self.assertAlmostEqual(player.root.Q, 0.085) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:15,代码来源:test_strategies.py

示例12: test_tree_search_failsafe

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def test_tree_search_failsafe(self):
        # Test that the failsafe works correctly. It can trigger if the MCTS
        # repeatedly visits a finished game state.
        probs = np.array([.001] * (go.N * go.N + 1))
        probs[-1] = 1  # Make the dummy net always want to pass
        player = MCTSPlayerMixin(DummyNet(fake_priors=probs))
        pass_position = go.Position().pass_move()
        player.initialize_game(pass_position)
        player.tree_search(num_parallel=1)
        self.assertNoPendingVirtualLosses(player.root) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:12,代码来源:test_strategies.py

示例13: initialize_basic_player

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def initialize_basic_player():
  player = MCTSPlayerMixin(utils_test.BOARD_SIZE, DummyNet())
  player.initialize_game()
  first_node = player.root.select_leaf()
  first_node.incorporate_results(
      *player.network.run(player.root.position), up_to=player.root)
  return player 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:9,代码来源:strategies_test.py

示例14: initialize_almost_done_player

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def initialize_almost_done_player():
  probs = np.array([.001] * (utils_test.BOARD_SIZE * utils_test.BOARD_SIZE + 1))
  probs[2:5] = 0.2  # some legal moves along the top.
  probs[-1] = 0.2  # passing is also ok
  net = DummyNet(fake_priors=probs)
  player = MCTSPlayerMixin(utils_test.BOARD_SIZE, net)
  # root position is white to play with no history == white passed.
  player.initialize_game(SEND_TWO_RETURN_ONE)
  return player 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:11,代码来源:strategies_test.py

示例15: test_cold_start_parallel_tree_search

# 需要导入模块: import strategies [as 别名]
# 或者: from strategies import MCTSPlayerMixin [as 别名]
def test_cold_start_parallel_tree_search(self):
    # Test that parallel tree search doesn't trip on an empty tree
    player = MCTSPlayerMixin(utils_test.BOARD_SIZE, DummyNet(fake_value=0.17))
    player.initialize_game()
    self.assertEqual(player.root.N, 0)
    self.assertFalse(player.root.is_expanded)
    player.tree_search(num_parallel=4)
    self.assertNoPendingVirtualLosses(player.root)
    # Even though the root gets selected 4 times by tree search, its
    # final visit count should just be 1.
    self.assertEqual(player.root.N, 1)
    # 0.085 = average(0, 0.17), since 0 is the prior on the root.
    self.assertAlmostEqual(player.root.Q, 0.085) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:15,代码来源:strategies_test.py


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