def get_sgf_move_probs(sgf_game, policy, player):
    with open(sgf_game, "r") as f:
        sgf_game = f.read()

    def get_single_prob(move, move_probs):
        for (mv, prob) in move_probs:
            if move == mv:
                return prob
        return 0

    return [(move, get_single_prob(move, policy.eval_state(state)))
            for (state, move, pl) in sgf_iter_states(sgf_game) if pl == player]
Ejemplo n.º 2
0
	def convert_game(self, file_name, bd_size):
		"""Read the given SGF file into an iterable of (input,output) pairs
		for neural network training

		Each input is a GameState converted into one-hot neural net features
		Each output is an action as an (x,y) pair (passes are skipped)

		If this game's size does not match bd_size, a SizeMismatchError is raised
		"""

		with open(file_name, 'r') as file_object:
			state_action_iterator = sgf_iter_states(file_object.read(), include_end=False)

		for (state, move, player) in state_action_iterator:
			if state.size != bd_size:
				raise SizeMismatchError()
			if move != go.PASS_MOVE:
				nn_input = self.feature_processor.state_to_tensor(state)
				yield (nn_input, move)
    def __init__(self, policy, sgf_game):

        with open(sgf_game, "r") as f:
            sgf_game = f.read()
        self.moves = [move for (_, move, _) in sgf_iter_states(sgf_game)]
        self.policy = policy