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


Python utils.parse_game_result方法代码示例

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


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

示例1: parse_sgf

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

示例2: test_parse_game_result

# 需要导入模块: import utils [as 别名]
# 或者: from utils import parse_game_result [as 别名]
def test_parse_game_result(self):
        self.assertEqual(utils.parse_game_result('B+3.5'), go.BLACK)
        self.assertEqual(utils.parse_game_result('W+T'), go.WHITE)
        self.assertEqual(utils.parse_game_result('Void'), 0) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:6,代码来源:test_utils.py

示例3: replay_sgf

# 需要导入模块: import utils [as 别名]
# 或者: from utils import parse_game_result [as 别名]
def replay_sgf(sgf_contents):
    '''
    Wrapper for sgf files, returning go.PositionWithContext instances.

    It does NOT return the very final position, as there is no follow up.
    To get the final position, call pwc.position.play_move(pwc.next_move)
    on the last PositionWithContext returned.

    Example usage:
    with open(filename) as f:
        for position_w_context in replay_sgf(f.read()):
            print(position_w_context.position)
    '''
    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!"

    komi = 0
    if props.get('KM') != None:
        komi = float(sgf_prop(props.get('KM')))
    result = utils.parse_game_result(sgf_prop(props.get('RE')))
    assert result is not None

    pos = Position(komi=komi)
    current_node = game.root
    while pos is not None and current_node.next is not None:
        pos = handle_node(pos, current_node)
        maybe_correct_next(pos, current_node.next)
        next_move = get_next_move(current_node)
        yield PositionWithContext(pos, next_move, result)
        current_node = current_node.next 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:34,代码来源:sgf_wrapper.py

示例4: test_parse_game_result

# 需要导入模块: import utils [as 别名]
# 或者: from utils import parse_game_result [as 别名]
def test_parse_game_result(self):
        self.assertEqual(utils.parse_game_result('B+3.5'), go.BLACK)
        self.assertEqual(utils.parse_game_result('W+T'), go.WHITE)
        self.assertEqual(utils.parse_game_result('Void'), None) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:6,代码来源:test_utils.py

示例5: get_winrate

# 需要导入模块: import utils [as 别名]
# 或者: from utils import parse_game_result [as 别名]
def get_winrate(final_positions):
    black_win = [utils.parse_game_result(pos.result()) == go.BLACK
                 for pos in final_positions]
    return sum(black_win) / len(black_win) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:6,代码来源:selfplay.py

示例6: extract_moves

# 需要导入模块: import utils [as 别名]
# 或者: from utils import parse_game_result [as 别名]
def extract_moves(final_positions):
    winning_moves = []
    losing_moves = []
    for final_position in final_positions:
        positions_w_context = utils.take_n(
            strategies.POLICY_CUTOFF_DEPTH,
            sgf_wrapper.replay_position(final_position))
        winner = utils.parse_game_result(final_position.result())
        for pwc in positions_w_context:
            if pwc.position.to_play == winner:
                winning_moves.append(pwc)
            else:
                losing_moves.append(pwc)
    return (load_data_sets.DataSet.from_positions_w_context(winning_moves),
            load_data_sets.DataSet.from_positions_w_context(losing_moves)) 
开发者ID:llSourcell,项目名称:alphago_demo,代码行数:17,代码来源:selfplay.py

示例7: test_parse_game_result

# 需要导入模块: import utils [as 别名]
# 或者: from utils import parse_game_result [as 别名]
def test_parse_game_result(self):
    self.assertEqual(utils.parse_game_result('B+3.5'), go.BLACK)
    self.assertEqual(utils.parse_game_result('W+T'), go.WHITE)
    self.assertEqual(utils.parse_game_result('Void'), 0) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:6,代码来源:utils_test.py

示例8: replay_sgf

# 需要导入模块: import utils [as 别名]
# 或者: from utils import parse_game_result [as 别名]
def replay_sgf(board_size, sgf_contents):
  """Wrapper for sgf files.

  It does NOT return the very final position, as there is no follow up.
  To get the final position, call pwc.position.play_move(pwc.next_move)
  on the last PositionWithContext returned.
  Example usage:
  with open(filename) as f:
    for position_w_context in replay_sgf(f.read()):
      print(position_w_context.position)

  Args:
    board_size: the go board size.
    sgf_contents: the content in sgf.

  Yields:
    The go.PositionWithContext instances.
  """
  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!'

  komi = 0
  if props.get('KM') is not None:
    komi = float(sgf_prop(props.get('KM')))
  result = utils.parse_game_result(sgf_prop(props.get('RE')))

  pos = Position(board_size, komi=komi)
  current_node = game.root
  while pos is not None and current_node.next is not None:
    pos = handle_node(board_size, pos, current_node)
    maybe_correct_next(pos, current_node.next)
    next_move = get_next_move(current_node)
    yield PositionWithContext(pos, next_move, result)
    current_node = current_node.next 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:38,代码来源:sgf_wrapper.py

示例9: extract_game_data

# 需要导入模块: import utils [as 别名]
# 或者: from utils import parse_game_result [as 别名]
def extract_game_data(gcs_path, root_node):
    props = root_node.properties
    komi = float(sgf_wrapper.sgf_prop(props.get('KM')))
    result = sgf_wrapper.sgf_prop(props.get('RE', ''))
    board_size = int(sgf_wrapper.sgf_prop(props.get('SZ')))
    value = utils.parse_game_result(result)
    was_resign = '+R' in result

    filename = os.path.basename(gcs_path)
    filename_no_ext, _ = os.path.splitext(filename)
    # BigQuery's TIMESTAMP() takes in unix millis.
    completion_millis = 1000 * int(filename_no_ext.split('-')[0])
    worker_id = filename_no_ext.split('-')[-1]
    model_num = shipname.detect_model_num(props.get('PW')[0])
    sgf_url = gcs_path
    first_comment_node_lines = root_node.next.properties['C'][0].split('\n')
    # in-place edit to comment node so that first move's comment looks
    # the same as all the other moves.
    root_node.next.properties['C'][0] = '\n'.join(first_comment_node_lines[1:])
    resign_threshold = float(first_comment_node_lines[0].split()[-1])

    return {
        'worker_id': worker_id,
        'completed_time': completion_millis,
        'board_size': board_size,
        'model_num': model_num,
        'result_str': result,
        'value': value,
        'was_resign': was_resign,
        'sgf_url': sgf_url,
        'resign_threshold': resign_threshold,
    } 
开发者ID:mlperf,项目名称:training,代码行数:34,代码来源:prepare_bigquery.py

示例10: test_parse_game_result

# 需要导入模块: import utils [as 别名]
# 或者: from utils import parse_game_result [as 别名]
def test_parse_game_result(self):
        self.assertEqual(go.BLACK, utils.parse_game_result('B+3.5'))
        self.assertEqual(go.WHITE, utils.parse_game_result('W+T'))
        self.assertEqual(0, utils.parse_game_result('Void')) 
开发者ID:mlperf,项目名称:training,代码行数:6,代码来源:test_utils.py

示例11: replay_sgf

# 需要导入模块: import utils [as 别名]
# 或者: from utils import parse_game_result [as 别名]
def replay_sgf(sgf_contents):
    """Wrapper for sgf files, returning go.PositionWithContext instances.

    It does NOT return the very final position, as there is no follow up.
    To get the final position, call pwc.position.play_move(pwc.next_move)
    on the last PositionWithContext returned.

    Example usage:
    with open(filename) as f:
        for position_w_context in replay_sgf(f.read()):
            print(position_w_context.position)
    """
    root_node = get_sgf_root_node(sgf_contents)
    props = root_node.properties
    assert int(sgf_prop(props.get('GM', ['1']))) == 1, "Not a Go SGF!"

    komi = 0
    if props.get('KM') is not None:
        komi = float(sgf_prop(props.get('KM')))
    result = utils.parse_game_result(sgf_prop(props.get('RE', '')))

    pos = Position(komi=komi)
    current_node = root_node
    while pos is not None and current_node.next is not None:
        pos = handle_node(pos, current_node)
        maybe_correct_next(pos, current_node.next)
        next_move = get_next_move(current_node)
        yield PositionWithContext(pos, next_move, result)
        current_node = current_node.next 
开发者ID:mlperf,项目名称:training,代码行数:31,代码来源:sgf_wrapper.py


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