示例#1
0
    def test_knight_danger_1(self):
        """Check dangerous move.

        a knight is on the end of an L-shaped distance.
        """
        danger = knight_danger(self.row, self.column, self.row + 1,
                               self.column - 2)
        self.assertTrue(danger)
示例#2
0
    def is_threatened(cls, attacking_piece, attacking_row, attacking_column,
                      row,
                      column):
        """Override ChessPiece is_threatened abstract class method."""
        if knight_danger(attacking_row, attacking_column, row, column):
            return True

        if cls._check_common_threats(attacking_piece, attacking_row,
                                     attacking_column, row, column):
            return True
        return False
示例#3
0
    def is_threatened(cls, attacking_piece, attacking_row, attacking_column,
                      row,
                      column):
        """Override ChessPiece is_threatened abstract class method."""
        if diagonals_danger(attacking_row, attacking_column, row, column) or \
                row_or_column_danger(attacking_row, attacking_column, row,
                                     column):
            return True

        # Queen can only be threatened by a knight, as an optimization,
        # let it check for knight attacks only.
        if attacking_piece.piece_type == PieceType.Knight and knight_danger(
                attacking_row, attacking_column, row, column):
            return True

        return False
示例#4
0
    def _check_common_threats(cls, attacking_piece, attacking_row,
                              attacking_column, row,
                              column):
        """Check for threats from already allocated pieces.

        Arguments:
        attacking_piece -- A class that extends ChessPiece
        attacking_row -- the row at which the attacking piece is located.
        attacking_column -- the column at which the attacking piece is
        located.
        row -- the row at which the current piece is located.
        column -- the column at which the current piece is located.
        """
        if attacking_piece.piece_type == PieceType.Rook and \
                row_or_column_danger(attacking_row, attacking_column, row,
                                     column):
            return True

        elif attacking_piece.piece_type == PieceType.Queen and \
                (diagonals_danger(attacking_row, attacking_column, row,
                                  column) or row_or_column_danger(
                    attacking_row, attacking_column, row, column)):
            return True

        elif attacking_piece.piece_type == PieceType.Bishop and \
                diagonals_danger(attacking_row, attacking_column, row,
                                 column):
            return True

        elif attacking_piece.piece_type == PieceType.Knight and knight_danger(
                attacking_row, attacking_column, row, column):
            return True

        elif attacking_piece.piece_type == PieceType.King and king_danger(
                attacking_row, attacking_column, row, column):
            return True

        return False
示例#5
0
 def test_knight_danger_8(self):
     """Check safe move."""
     danger = knight_danger(self.row, self.column, self.row - 1,
                            self.column - 1)
     self.assertFalse(danger)