Example #1
0
def test_stalemate_check(self):
    self.game.reset_board()
    # Remove all of blacks pieces.
    for x_coordinate in range(chessapi.constants.BOARD_WIDTH):
        for y_coordinate in (6, 7):
            self.game.set_piece_at_position((x_coordinate, y_coordinate), None)
    # Place a black king in the corner.
    self.game.pieces.append(chessapi.King((7, 7), chessapi.BLACK, self.game))
    # Put it in a stalemate with white rooks.
    self.game.pieces.append(chessapi.Rook((6, 5), chessapi.WHITE, self.game))
    self.game.pieces.append(chessapi.Rook((5, 6), chessapi.WHITE, self.game))
    self.assertTrue(self.game.is_in_stalemate(chessapi.BLACK))
Example #2
0
 def test_initialisation(self):
     """
     Makes sure that basic initialisation of the pieces does not raise any
     errors.
     """
     chessapi.Pawn(
         chessapi.DiscreteVector(0, 0), chessapi.WHITE,
         chessapi.Game(chessapi.Player(chessapi.WHITE),
                       chessapi.Player(chessapi.BLACK)))
     chessapi.Rook(
         chessapi.DiscreteVector(0, 0), chessapi.BLACK,
         chessapi.Game(chessapi.Player(chessapi.WHITE),
                       chessapi.Player(chessapi.BLACK)))
     chessapi.Knight(
         chessapi.DiscreteVector(0, 0), chessapi.WHITE,
         chessapi.Game(chessapi.Player(chessapi.WHITE),
                       chessapi.Player(chessapi.BLACK)))
     chessapi.Bishop(
         chessapi.DiscreteVector(0, 0), chessapi.BLACK,
         chessapi.Game(chessapi.Player(chessapi.WHITE),
                       chessapi.Player(chessapi.BLACK)))
     chessapi.Queen(
         chessapi.DiscreteVector(0, 0), chessapi.WHITE,
         chessapi.Game(chessapi.Player(chessapi.WHITE),
                       chessapi.Player(chessapi.BLACK)))
     chessapi.King(
         chessapi.DiscreteVector(0, 0), chessapi.BLACK,
         chessapi.Game(chessapi.Player(chessapi.WHITE),
                       chessapi.Player(chessapi.BLACK)))
Example #3
0
def test_black_in_check_check(self):
    # Same as above except with a black king and a white rook.
    self.game.reset_board()
    self.game.set_piece_at_position((4, 6),
                                    chessapi.Rook((4, 6), chessapi.WHITE,
                                                  self.game))
    self.assertTrue(self.game.is_in_check(chessapi.BLACK))
Example #4
0
def test_white_in_check_check(self):
    self.game.reset_board()
    # Replace the pawn in front of the white king with a black rook.
    self.game.set_piece_at_position((4, 1),
                                    chessapi.Rook((4, 1), chessapi.BLACK,
                                                  self.game))
    # Assert that white is now in check.
    self.assertTrue(self.game.is_in_check(chessapi.WHITE))
Example #5
0
def test_black_in_checkmate_check(self):
    # Same as above, but for the opposite colours.
    self.game.reset_board()
    self.game.set_piece_at_position((4, 6), None)
    self.game.set_piece_at_position((6, 7), None)
    self.game.set_piece_at_position((5, 7),
                                    chessapi.Pawn((5, 7), chessapi.BLACK,
                                                  self.game))
    self.game.set_piece_at_position((3, 7),
                                    chessapi.Pawn((3, 7), chessapi.BLACK,
                                                  self.game))
    self.game.pieces.append(chessapi.Rook((4, 3), chessapi.WHITE, self.game))
    self.assertTrue(self.game.is_in_checkmate(chessapi.BLACK))
Example #6
0
def test_white_in_checkmate_check(self):
    self.game.reset_board()
    # Remove the pawn in front of the white king.
    self.game.set_piece_at_position((4, 1), None)
    # Remove the white king's knight.
    self.game.set_piece_at_position((6, 0), None)
    # Replace the bishop and the queen with pawns
    self.game.set_piece_at_position((5, 0),
                                    chessapi.Pawn((5, 0), chessapi.WHITE,
                                                  self.game))
    self.game.set_piece_at_position((3, 0),
                                    chessapi.Pawn((3, 0), chessapi.WHITE,
                                                  self.game))
    # Add a black rook, putting the white king in checkmate.
    self.game.pieces.append(chessapi.Rook((4, 3), chessapi.BLACK, self.game))
    self.assertTrue(self.game.is_in_checkmate(chessapi.WHITE))