Example #1
0
    def play(self, color, x, y, update_tree=True):
        index = coord2index(x, y)

        if update_tree:
            self.tree.play(index)

        self.board, self.player = make_play(x, y, self.board)
        self.move += 1
        return self.board, self.player
Example #2
0
    def play(self, color, x, y, update_tree=True):
        index = coord2index(x, y)
        if update_tree:
            if self.mcts_tree and index in self.mcts_tree['subtree']:
                self.mcts_tree = self.mcts_tree['subtree'][index]
                self.mcts_tree['parent'] = None  # Cut the tree
            else:
                self.mcts_tree = None

        self.board, self.player = make_play(x, y, self.board, color)
        self.move += 1
        return self.board, self.player
Example #3
0
    def play_game_kgs(self, game_file):
        with open(game_file, "rb") as f:
            game = sgf.Sgf_game.from_bytes(f.read())
        winner = game.get_winner()
        board_size = game.get_size()
        root_node = game.get_root()
        b_player = root_node.get("PB")
        w_player = root_node.get("PW")

        SIZE = conf['SIZE']
        if board_size != SIZE:
            print("GAME SIZE IS NOT EXPECTED ", board_size)
            return

        board, _ = game_init()
        moves = []
        try:
            handicap = root_node.get("AB")  # Get handicap
            if len(handicap) > 0:
                board = self.setupHandicap(board, handicap)
        except:
            pass

        for move_n, node in enumerate(game.get_main_sequence()):
            player, move = node.get_move()
            if player is None:
                continue
            if move is None:
                index = -1
                move = (board_size, board_size)  #pass move
            else:
                index = coord2index(move[0], move[1])
            policy_target = np.zeros(board_size * board_size + 1, dtype=float)
            policy_target[index] = 1.0
            value = -1.0
            if winner == player:
                value = 1.0

            move_data = {
                'board': np.copy(board),
                'policy': policy_target,
                'value': value,
                'move': (move[0], move[1]),
                'move_n': move_n,
                'player': player
            }
            moves.append(move_data)
            board, _ = make_play(move[0],
                                 move[1],
                                 board,
                                 color=(1 if player == "b" else -1))

        return moves