pgn_read/core/game.py
def is_position_checkmate(self):
        """Return True if the side to move is checkmated."""
        piece_placement_data = self._piece_placement_data.copy()
        pieces_on_board = self._pieces_on_board
        side_to_move_king = SIDE_TO_MOVE_KING[self._active_color]
        king_square = pieces_on_board[side_to_move_king][0].square.name
        escape_squares = KING_MOVES[king_square]

        # Be sure to put king back!
        del self._piece_placement_data[king_square]

        # Can king avoid check by moving?
        # Test all possible destination squares without putting king on them.
        for s in escape_squares:
            if s not in piece_placement_data:
                if not self.is_square_attacked_by_other_side(s):
                    self._piece_placement_data[
                        king_square] = piece_placement_data[king_square]
                    return False
            elif PIECE_TO_KING[piece_placement_data[s].name
                               ] != side_to_move_king:
                if not self.is_square_attacked_by_other_side(s):
                    self._piece_placement_data[
                        king_square] = piece_placement_data[king_square]
                    return False

        # Put king back.
        self._piece_placement_data[
            king_square] = piece_placement_data[king_square]

        # Can side to move block the check?
        attack_lines = self.get_attacks_on_square_by_other_side(king_square)
        if len(attack_lines) > 1:
            return True
        elif len(attack_lines) == 0:
            return False
        if self.legal_move_to_square_exists(
            attack_lines[0], PGN_CAPTURE_MOVE, king_square):
            return False
        ptp = POINT_TO_POINT.get((attack_lines[0], king_square))
        if ptp is not None:
            for s in ptp[2][ptp[0]:ptp[1]]:
                if self.legal_move_to_square_exists(s, '', king_square):
                    return False
            return True
        ptp = KNIGHT_MOVES.get(attack_lines[0])
        if ptp is not None:
            for s in ptp:
                if self.legal_move_to_square_exists(s, '', king_square):
                    return False
            return True
        return False
Return True if the side to move is checkmated.
Return True if the side to move is checkmated.
Return True if the side to move is checkmated .
def is_position_checkmate(self):
        piece_placement_data = self._piece_placement_data.copy()
        pieces_on_board = self._pieces_on_board
        side_to_move_king = SIDE_TO_MOVE_KING[self._active_color]
        king_square = pieces_on_board[side_to_move_king][0].square.name
        escape_squares = KING_MOVES[king_square]
        del self._piece_placement_data[king_square]
        for s in escape_squares:
            if s not in piece_placement_data:
                if not self.is_square_attacked_by_other_side(s):
                    self._piece_placement_data[
                        king_square] = piece_placement_data[king_square]
                    return False
            elif PIECE_TO_KING[piece_placement_data[s].name
                               ] != side_to_move_king:
                if not self.is_square_attacked_by_other_side(s):
                    self._piece_placement_data[
                        king_square] = piece_placement_data[king_square]
                    return False
        self._piece_placement_data[
            king_square] = piece_placement_data[king_square]
        attack_lines = self.get_attacks_on_square_by_other_side(king_square)
        if len(attack_lines) > 1:
            return True
        elif len(attack_lines) == 0:
            return False
        if self.legal_move_to_square_exists(
            attack_lines[0], PGN_CAPTURE_MOVE, king_square):
            return False
        ptp = POINT_TO_POINT.get((attack_lines[0], king_square))
        if ptp is not None:
            for s in ptp[2][ptp[0]:ptp[1]]:
                if self.legal_move_to_square_exists(s, '', king_square):
                    return False
            return True
        ptp = KNIGHT_MOVES.get(attack_lines[0])
        if ptp is not None:
            for s in ptp:
                if self.legal_move_to_square_exists(s, '', king_square):
                    return False
            return True
        return False
def is_position_checkmate ( self ) : piece_placement_data = self . _piece_placement_data . copy ( ) pieces_on_board = self . _pieces_on_board side_to_move_king = SIDE_TO_MOVE_KING [ self . _active_color ] king_square = pieces_on_board [ side_to_move_king ] [ 0 ] . square . name escape_squares = KING_MOVES [ king_square ] del self . _piece_placement_data [ king_square ] for s in escape_squares : if s not in piece_placement_data : if not self . is_square_attacked_by_other_side ( s ) : self . _piece_placement_data [ king_square ] = piece_placement_data [ king_square ] return False elif PIECE_TO_KING [ piece_placement_data [ s ] . name ] != side_to_move_king : if not self . is_square_attacked_by_other_side ( s ) : self . _piece_placement_data [ king_square ] = piece_placement_data [ king_square ] return False self . _piece_placement_data [ king_square ] = piece_placement_data [ king_square ] attack_lines = self . get_attacks_on_square_by_other_side ( king_square ) if len ( attack_lines ) > 1 : return True elif len ( attack_lines ) == 0 : return False if self . legal_move_to_square_exists ( attack_lines [ 0 ] , PGN_CAPTURE_MOVE , king_square ) : return False ptp = POINT_TO_POINT . get ( ( attack_lines [ 0 ] , king_square ) ) if ptp is not None : for s in ptp [ 2 ] [ ptp [ 0 ] : ptp [ 1 ] ] : if self . legal_move_to_square_exists ( s , '' , king_square ) : return False return True ptp = KNIGHT_MOVES . get ( attack_lines [ 0 ] ) if ptp is not None : for s in ptp : if self . legal_move_to_square_exists ( s , '' , king_square ) : return False return True return False
Return True if the side to move is checkmated.
Return True if the side to move is checkmated .
"""Return True if the side to move is checkmated.""" # Be sure to put king back! # Can king avoid check by moving? # Test all possible destination squares without putting king on them. # Put king back. # Can side to move block the check?
self