Esempio n. 1
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))
Esempio n. 2
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))
Esempio n. 3
0
def test_cant_move_into_check(self):
    self.game.reset_board()
    # Remove the pawn in front of the black king.
    self.game.set_piece_at_position((4, 6), None)
    # Place a white pawn in a position to attack the empty square now in
    # front of the black king.
    self.game.pieces.append(chessapi.Pawn((3, 5), chessapi.WHITE, self.game))
    # Assert that the black king has no possible moves.
    self.assertEqual(
        self.game.piece_at_position((4, 7)).get_current_moves(), [])
Esempio n. 4
0
def test_taking(self):
    self.game.reset_board()
    # Place a white pawn in a position to take a black pawn.
    self.game.set_piece_at_position((0, 5),
                                    chessapi.Pawn((0, 5), chessapi.WHITE,
                                                  self.game))
    # Take the black pawn.
    self.game.move((0, 5), (1, 6), self.player_1)
    # Assert that their is now a white piece at that position.
    self.assertEqual(
        self.game.piece_at_position((1, 6)).colour, chessapi.WHITE)