Exemplo n.º 1
0
 def _registration(self, arg):
     LOGGER.error("engine registration not supported")
Exemplo n.º 2
0
 def _copyprotection(self, arg):
     LOGGER.error("engine copyprotection not supported")
Exemplo n.º 3
0
 def _registration(self, arg):
     LOGGER.error("engine registration not supported")
Exemplo n.º 4
0
    def position(self, board, async_callback=None):
        """
        Set up a given position.

        Instead of just the final FEN, the initial FEN and all moves leading
        up to the position will be sent, so that the engine can detect
        repetitions.

        If the position is from a new game, it is recommended to use the
        *ucinewgame* command before the *position* command.

        :param board: A *chess.Board*.

        :return: Nothing

        :raises: :exc:`~chess.uci.EngineStateException` if the engine is still
            calculating.
        """
        # Check UCI_Variant
        uci_variant = type(board).uci_variant
        if uci_variant == "chess" and self.uci_variant is None:
            pass
        elif uci_variant != self.uci_variant:
            LOGGER.error("current UCI_Variant (%s) does not match position (%s)", self.uci_variant, uci_variant)

        # Raise if this is called while the engine is still calculating.
        with self.state_changed:
            if not self.idle:
                raise EngineStateException("position command while engine is busy")

        builder = []
        builder.append("position")

        # Take back moves to obtain the FEN at the latest pawn move or
        # capture. Later giving the moves explicitly allows for transposition
        # detection.
        switchyard = collections.deque()
        while board.move_stack:
            move = board.pop()
            switchyard.append(move)

            if board.is_irreversible(move):
                break

        # Validate castling rights.
        if not self.uci_chess960 and board.chess960:
            if board.has_chess960_castling_rights():
                LOGGER.error("not in UCI_Chess960 mode but position has non-standard castling rights")

                # Just send the final FEN without transpositions in hopes
                # that this will work.
                while switchyard:
                    board.push(switchyard.pop())

        # Send starting position.
        if uci_variant == "chess" and board.fen() == chess.STARTING_FEN:
            builder.append("startpos")
        else:
            builder.append("fen")
            builder.append(board.shredder_fen() if self.uci_chess960 else board.fen())

        # Send moves.
        if switchyard:
            builder.append("moves")

            while switchyard:
                move = switchyard.pop()
                builder.append(board.uci(move, chess960=self.uci_chess960))
                board.push(move)

        self.board = board.copy(stack=False)

        def command():
            with self.semaphore:
                self.send_line(" ".join(builder))

                if self.terminated.is_set():
                    raise EngineTerminatedException()

        return self._queue_command(command, async_callback)
Exemplo n.º 5
0
 def _copyprotection(self, arg):
     LOGGER.error("engine copyprotection not supported")