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


Python sgf_wrapper.replay_sgf方法代码示例

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


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

示例1: analyze_symmetries

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def analyze_symmetries(sgf_file, load_file):
    with open(sgf_file) as f:
        sgf_contents = f.read()
    iterator = sgf_wrapper.replay_sgf(sgf_contents)
    net = dual_net.DualNetwork(load_file)
    for i, pwc in enumerate(iterator):
        if i < 200:
            continue
        feats = features.extract_features(pwc.position)
        variants = [symmetries.apply_symmetry_feat(s, feats) for s in symmetries.SYMMETRIES]
        values = net.sess.run(
            net.inference_output['value_output'],
            feed_dict={net.inference_input['pos_tensor']: variants})
        mean = np.mean(values)
        stdev = np.std(values)
        all_vals = sorted(zip(values, symmetries.SYMMETRIES))

        print("{:3d} {:.3f} +/- {:.3f} min {:.3f} {} max {:.3f} {}".format(
            i, mean, stdev, *all_vals[0], *all_vals[-1])) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:21,代码来源:inspect_game.py

示例2: test_make_sgf

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def test_make_sgf(self):
    all_pwcs = list(replay_sgf(utils_test.BOARD_SIZE, NO_HANDICAP_SGF))
    second_last_position, last_move, _ = all_pwcs[-1]
    last_position = second_last_position.play_move(last_move)

    back_to_sgf = make_sgf(
        utils_test.BOARD_SIZE,
        last_position.recent,
        last_position.score(),
        komi=last_position.komi,
    )
    reconstructed_positions = list(replay_sgf(
        utils_test.BOARD_SIZE, back_to_sgf))
    second_last_position2, last_move2, _ = reconstructed_positions[-1]
    last_position2 = second_last_position2.play_move(last_move2)

    self.assertEqualPositions(last_position, last_position2) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:19,代码来源:sgf_wrapper_test.py

示例3: cmd_loadsgf

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def cmd_loadsgf(self, filename: str, movenum=0):
        try:
            with open(filename, 'r') as f:
                contents = f.read()
        except:
            raise ValueError("Unreadable file: " + filename)

        # Clear the board before replaying sgf
        # TODO: should this use the sgfs komi?
        self._player.initialize_game(go.Position())

        # This is kinda bad, because replay_sgf is already calling
        # 'play move' on its internal position objects, but we really
        # want to advance the engine along with us rather than try to
        # push in some finished Position object.
        for idx, p in enumerate(sgf_wrapper.replay_sgf(contents)):
            dbg("playing #", idx, p.next_move)
            self._player.play_move(p.next_move)
            if movenum and idx == movenum:
                break 
开发者ID:mlperf,项目名称:training,代码行数:22,代码来源:gtp_cmd_handlers.py

示例4: initialize_game

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

示例5: parse_sgf

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def parse_sgf(sgf_path):
  with open(sgf_path) as f:
    sgf_contents = f.read()

  collection = sgf.parse(sgf_contents)
  game = collection.children[0]
  props = game.root.properties
  assert int(sgf_prop(props.get('GM', ['1']))) == 1, "Not a Go SGF!"

  result = utils.parse_game_result(sgf_prop(props.get('RE')))

  positions, moves = zip(*[(p.position, p.next_move) for p in sgf_wrapper.replay_sgf(sgf_contents)])
  return positions, moves, result, props 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:15,代码来源:training_curve.py

示例6: predict_move

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def predict_move(filename, network, tries_per_move=1, readouts=1000):
  replay = []

  if filename not in REPLAY_CACHE:
    with open(filename) as f:
        text = f.read()
        for position_w_context in sgf_wrapper.replay_sgf(text):
          replay.append(position_w_context)
    REPLAY_CACHE[filename] = replay
  replay = REPLAY_CACHE[filename]


  black_net = network

  player = MCTSPlayer(
        black_net, verbosity=0, two_player_mode=True, num_parallel=4)

  tried = 0
  correct = 0
  move_ratings = []
  for position_w_context in replay:
      if position_w_context.next_move is None:
          continue

      num_correct = 0
      for i in range(tries_per_move):
        move, correct_move, is_correct = predict_position(position_w_context, player, readouts=readouts)
        if is_correct:
          num_correct += 1
      move_ratings.append(num_correct * 1.0 / tries_per_move)
      print('RATING: ', sum(move_ratings) / len(move_ratings))
  return move_ratings 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:34,代码来源:predict_games.py

示例7: cmd_loadsgf

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def cmd_loadsgf(self, arguments):
        args = arguments.split()
        if len(args) == 2:
            file_, movenum = args
            movenum = int(movenum)
            print("movenum =", movenum, file=sys.stderr)
        else:
            file_ = args[0]
            movenum = None

        try:
            with open(file_, 'r') as f:
                contents = f.read()
        except:
            raise ValueError("Unreadable file: " + file_)

        try:
            # This is kinda bad, because replay_sgf is already calling
            # 'play move' on its internal position objects, but we really
            # want to advance the engine along with us rather than try to
            # push in some finished Position object.
            for idx, p in enumerate(sgf_wrapper.replay_sgf(contents)):
                print("playing #", idx, p.next_move, file=sys.stderr)
                self._game.play_move(p.next_move)
                if movenum and idx == movenum:
                    break
        except:
            raise

# Should this class blatantly reach into the game_obj and frob its tree?  Sure!
# What are private members?  Python lets you do *anything!* 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:33,代码来源:gtp_extensions.py

示例8: test_make_sgf

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def test_make_sgf(self):
        all_pwcs = list(replay_sgf(NO_HANDICAP_SGF))
        second_last_position, last_move, _ = all_pwcs[-1]
        last_position = second_last_position.play_move(last_move)

        back_to_sgf = make_sgf(
            last_position.recent,
            last_position.score(),
            komi=last_position.komi,
        )
        reconstructed_positions = list(replay_sgf(back_to_sgf))
        second_last_position2, last_move2, _ = reconstructed_positions[-1]
        last_position2 = second_last_position2.play_move(last_move2)

        self.assertEqualPositions(last_position, last_position2) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:17,代码来源:test_sgf_wrapper.py

示例9: test_sgf_props

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def test_sgf_props(self):
        sgf_replayer = replay_sgf(CHINESE_HANDICAP_SGF)
        initial = next(sgf_replayer)
        self.assertEqual(initial.result, go.BLACK)
        self.assertEqual(initial.position.komi, 5.5) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:7,代码来源:test_sgf_wrapper.py

示例10: test_replay_position

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def test_replay_position(self):
        sgf_positions = list(sgf_wrapper.replay_sgf(NO_HANDICAP_SGF))
        initial = sgf_positions[0]
        self.assertEqual(initial.result, go.WHITE)

        final = sgf_positions[-1].position.play_move(
            sgf_positions[-1].next_move)

        # sanity check to ensure we're working with the right position
        final_board = test_utils.load_board('''
            .OXX.....
            O.OX.X...
            .OOX.....
            OOOOXXXXX
            XOXXOXOOO
            XOOXOO.O.
            XOXXXOOXO
            XXX.XOXXO
            X..XOO.O.
        ''')
        expected_final_position = go.Position(
            final_board,
            n=62,
            komi=6.5,
            caps=(3, 2),
            ko=None,
            recent=tuple(),
            to_play=go.BLACK
        )
        self.assertEqualPositions(expected_final_position, final)
        self.assertEqual(final.n, len(final.recent))

        replayed_positions = list(go.replay_position(final, 1))
        for sgf_pos, replay_pos in zip(sgf_positions, replayed_positions):
            self.assertEqualPositions(sgf_pos.position, replay_pos.position) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:37,代码来源:test_go.py

示例11: test_make_sgf

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def test_make_sgf(self):
        all_positions = list(replay_sgf(NO_HANDICAP_SGF))
        last_position, _, metadata = all_positions[-1]
        back_to_sgf = make_sgf(
            last_position.recent,
            last_position.score(),
            boardsize=metadata.board_size,
            komi=last_position.komi,
        )
        reconstructed_positions = list(replay_sgf(back_to_sgf))
        last_position2, _, _ = reconstructed_positions[-1]

        self.assertEqualPositions(last_position, last_position2) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:15,代码来源:test_sgf_wrapper.py

示例12: test_sgf_props

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def test_sgf_props(self):
        sgf_replayer = replay_sgf(CHINESE_HANDICAP_SGF)
        initial = next(sgf_replayer)
        self.assertEqual(initial.metadata.result, 'B+39.50')
        self.assertEqual(initial.metadata.board_size, 9)
        self.assertEqual(initial.position.komi, 5.5) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:8,代码来源:test_sgf_wrapper.py

示例13: test_replay_position

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def test_replay_position(self):
        sgf_positions = list(replay_sgf(NO_HANDICAP_SGF))
        initial = sgf_positions[0]
        self.assertEqual(initial.metadata.result, 'W+1.5')
        self.assertEqual(initial.metadata.board_size, 9)
        self.assertEqual(initial.position.komi, 6.5)

        final = sgf_positions[-1].position

        # sanity check to ensure we're working with the right position
        final_board = load_board('''
            .OXX.....
            O.OX.X...
            .OOX.....
            OOOOXXXXX
            XOXXOXOOO
            XOOXOO.O.
            XOXXXOOXO
            XXX.XOXXO
            X..XOO.O.
        ''')
        expected_final_position = go.Position(
            final_board,
            n=62,
            komi=6.5,
            caps=(3, 2),
            ko=None,
            recent=tuple(),
            to_play=go.BLACK
        )
        self.assertEqualPositions(expected_final_position, final)
        self.assertEqual(final.n, len(final.recent))

        replayed_positions = list(replay_position(final))
        for sgf_pos, replay_pos in zip(sgf_positions, replayed_positions):
            self.assertEqualPositions(sgf_pos.position, replay_pos.position) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:38,代码来源:test_sgf_wrapper.py

示例14: test_replay_position

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def test_replay_position(self):
    sgf_positions = list(sgf_wrapper.replay_sgf(
        utils_test.BOARD_SIZE, NO_HANDICAP_SGF))
    initial = sgf_positions[0]
    self.assertEqual(initial.result, go.WHITE)

    final = sgf_positions[-1].position.play_move(
        sgf_positions[-1].next_move)

    # sanity check to ensure we're working with the right position
    final_board = utils_test.load_board('''
        .OXX.....
        O.OX.X...
        .OOX.....
        OOOOXXXXX
        XOXXOXOOO
        XOOXOO.O.
        XOXXXOOXO
        XXX.XOXXO
        X..XOO.O.
      ''')
    expected_final_position = go.Position(
        utils_test.BOARD_SIZE,
        final_board,
        n=62,
        komi=6.5,
        caps=(3, 2),
        ko=None,
        recent=tuple(),
        to_play=go.BLACK
    )
    self.assertEqualPositions(expected_final_position, final)
    self.assertEqual(final.n, len(final.recent))

    replayed_positions = list(go.replay_position(
        utils_test.BOARD_SIZE, final, 1))
    for sgf_pos, replay_pos in zip(sgf_positions, replayed_positions):
      self.assertEqualPositions(sgf_pos.position, replay_pos.position) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:40,代码来源:go_test.py

示例15: cmd_loadsgf

# 需要导入模块: import sgf_wrapper [as 别名]
# 或者: from sgf_wrapper import replay_sgf [as 别名]
def cmd_loadsgf(self, arguments):
    args = arguments.split()
    if len(args) == 2:
      file_, movenum = args
      movenum = int(movenum)
      print('movenum =', movenum, file=sys.stderr)
    else:
      file_ = args[0]
      movenum = None

    try:
      with open(file_, 'r') as f:
        contents = f.read()
    except:
      raise ValueError('Unreadable file: ' + file_)

    try:
      # This is kinda bad, because replay_sgf is already calling
      # 'play move' on its internal position objects, but we really
      # want to advance the engine along with us rather than try to
      # push in some finished Position object.
      for idx, p in enumerate(sgf_wrapper.replay_sgf(contents)):
        print('playing #', idx, p.next_move, file=sys.stderr)
        self._game.play_move(p.next_move)
        if movenum and idx == movenum:
          break
    except:
      raise 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:30,代码来源:gtp_extensions.py


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