Example #1
0
    def test_filter_checks(self):
        """Assure that all moves that lead to check for the player are
        appropriately filtered out of the move list."""
        board, white, black = create_board_and_players()
        pawn_pos_white = [5, 3]  # f5
        pawn_white = Pawn(white, pawn_pos_white)
        pawn_white.first_move = False
        board.add_to_board(pawn_white)

        king_pos_white = [7, 3]  # h5
        king_white = King(white, king_pos_white)
        board.add_to_board(king_white)

        pawn_moves = pawn_white.get_legal_moves(board, False)
        filtered_pawn_moves = pawn_white.filter_checks(pawn_moves, board)
        self.assertEqual(pawn_moves, filtered_pawn_moves)

        rook_pos_black = [1, 3]  # a1
        rook_black = Rook(black, rook_pos_black)
        board.add_to_board(rook_black)

        pawn_moves = pawn_white.get_legal_moves(board, False)
        filtered_pawn_moves = pawn_white.filter_checks(pawn_moves, board)
        self.assertEqual(len(filtered_pawn_moves), 0)