當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。