Ejemplo n.º 1
0
    def lookup(self, board: Board) -> Optional[Board]:
        board_id = board.get_normalized_id()
        openings = self.data["openings"]

        if board_id not in openings:
            return None

        return Board.from_id(openings[board_id]["best_child"])
Ejemplo n.º 2
0
    def _get_openings(
            self, color: int, board: Board,
            prefix: List[Tuple[Board, int]]) -> List[List[Tuple[Board, int]]]:

        assert board.turn == color

        try:
            best_child_id: str = self.data["openings"][
                board.get_normalized_id()]["best_child"]
        except KeyError:
            return [prefix]

        best_child = board.denormalize_child(Board.from_id(best_child_id))
        assert best_child in board.get_children()
        assert best_child.turn == opponent(color)
        best_move = board.get_move(best_child)

        openings = []

        for grand_child in best_child.get_children():
            openings += self._get_openings(color, grand_child,
                                           prefix + [(board, best_move)])

        return openings
Ejemplo n.º 3
0
 def upsert(self, board: Board, best_child: Board) -> None:
     board_id = board.get_normalized_id()
     best_child_id = best_child.get_normalized_id()
     self.data["openings"][board_id] = {"best_child": best_child_id}