예제 #1
0
def replay_position(position, extract_move_probs=False):
    '''
    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) and (position.n == len(position.recent_move_prob))),\
        "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, move_prob in zip(position.recent,
                                      position.recent_move_prob):
        color, next_move = player_move
        try:
            tmp = pos.play_move(next_move, color=color)
            if extract_move_probs:
                yield PositionWithContext(pos, move_prob, metadata)
            else:
                yield PositionWithContext(pos, next_move, metadata)
            pos = tmp
        except:
            break
    '''
예제 #2
0
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)