Example #1
0
    def test_king_danger_5(self):
        """Check dangerous move.

        a king is one square down.
        """
        danger = king_danger(self.row, self.column, self.row, self.column + 1)
        self.assertTrue(danger)
Example #2
0
    def test_king_danger_3(self):
        """Check dangerous move.

        a king is one square to the right.
        """
        danger = king_danger(self.row, self.column, self.row + 1, self.column)
        self.assertTrue(danger)
Example #3
0
    def test_king_danger_1(self):
        """Check dangerous move.

        both pieces on the same square, one is king.
        """
        danger = king_danger(self.row, self.column, self.row, self.column)
        self.assertTrue(danger)
Example #4
0
    def test_king_danger_9(self):
        """Check dangerous move.

        a king is one square south-east.
        """
        danger = king_danger(self.row, self.column, self.row + 1,
                             self.column + 1)
        self.assertTrue(danger)
Example #5
0
    def test_king_danger_7(self):
        """Check dangerous move.

        a king is one square north-west.
        """
        danger = king_danger(self.row, self.column, self.row - 1,
                             self.column - 1)
        self.assertTrue(danger)
Example #6
0
    def is_threatened(cls, attacking_piece, attacking_row, attacking_column,
                      row, column):
        """Override ChessPiece is_threatened abstract class method."""
        if king_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
Example #7
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
Example #8
0
 def test_king_danger_10(self):
     """Check safe move."""
     danger = king_danger(self.row, self.column, self.row + 2, self.column)
     self.assertFalse(danger)