el siguiente codigo es correcto pero si le puedes añadir mas dificultad a la hora de presentar el lberinto y resolverlo estaria bien:"import tkinter as tk
import random
import time

class MazeApp:
    def __init__(self, master):
        self.master = master
        self.master.title("Generador y Resolver Laberinto - Algoritmo de Prim")
        self.canvas = tk.Canvas(master, width=525, height=525)
        self.canvas.pack()

        self.rows = 21  # Debe ser impar
        self.columns = 21  # Debbe ser impar
        self.cell_size = 25
        self.grid = None
        self.start = (1, 1)
        self.end = (self.rows - 2, self.columns - 2)
        self.solution_path = []

        self.create_maze()
        self.draw_maze()

        self.solve_button = tk.Button(master, text="Resolver Laberinto", command=self.solve_maze)
        self.solve_button.pack(side='left')

        self.reset_button = tk.Button(master, text="Generar Nuevo Laberinto", command=self.reset_maze)
        self.reset_button.pack(side='right')

    def create_maze(self):
        # Inicializar todas las celdas como muros
        self.grid = [[1 for _ in range(self.columns)] for _ in range(self.rows)]
        self.grid[self.start[0]][self.start[1]] = 0

        # Lista de paredes
        walls = []
        self._add_walls(self.start[0], self.start[1], walls)

        while walls:
            # Seleccionar una pared al azar
            wall = walls.pop(random.randint(0, len(walls) - 1))
            r, c, direction = wall

            nr, nc = r + direction[0], c + direction[1]
            if 0 < nr < self.rows -1 and 0 < nc < self.columns -1:
                if self.grid[nr][nc] == 1:
                    # Marcar el camino
                    self.grid[nr][nc] = 0
                    self.grid[r + direction[0]//2][c + direction[1]//2] = 0
                    self._add_walls(nr, nc, walls)

    def _add_walls(self, r, c, walls):
        directions = [(0, 2), (2, 0), (0, -2), (-2, 0)]
        for dr, dc in directions:
            nr, nc = r + dr, c + dc
            if 0 < nr < self.rows -1 and 0 < nc < self.columns -1:
                if self.grid[nr][nc] == 1:
                    walls.append((r, c, (dr, dc)))

    def draw_maze(self):
        self.canvas.delete("all")
        for r in range(self.rows):
            for c in range(self.columns):
                color = "black" if self.grid[r][c] == 1 else "white"
                self.canvas.create_rectangle(c * self.cell_size, r * self.cell_size,
                                             (c + 1) * self.cell_size,
                                             (r + 1) * self.cell_size, fill=color, outline='gray')

        # Inicio
        self.canvas.create_rectangle(self.start[1] * self.cell_size, self.start[0] * self.cell_size,
                                     (self.start[1] + 1) * self.cell_size,
                                     (self.start[0] + 1) * self.cell_size, fill="green")

        # Fin
        self.canvas.create_rectangle(self.end[1] * self.cell_size, self.end[0] * self.cell_size,
                                     (self.end[1] + 1) * self.cell_size,
                                     (self.end[0] + 1) * self.cell_size, fill="red")

    def solve_maze(self):
        self.solution_path = []
        visited = set()
        if self._solve_dfs(self.start[0], self.start[1], visited):
            self.animate_solution()
        else:
            print("No hay solución para el laberinto.")

    def _solve_dfs(self, r, c, visited):
        if (r, c) == self.end:
            self.solution_path.append((r, c))
            return True

        if (r < 0 or r >= self.rows or
            c < 0 or c >= self.columns or
            self.grid[r][c] == 1 or
            (r, c) in visited):
            return False

        visited.add((r, c))
        self.solution_path.append((r, c))

        # Explorar en cada dirección
        for dr, dc in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            if self._solve_dfs(r + dr, c + dc, visited):
                return True

        self.solution_path.pop()
        return False

    def animate_solution(self):
        for r, c in self.solution_path:
            if (r, c) != self.start and (r, c) != self.end:
                self.canvas.create_rectangle(c * self.cell_size, r * self.cell_size,
                                             (c + 1) * self.cell_size,
                                             (r + 1) * self.cell_size, fill="blue")
                self.master.update()
                time.sleep(0.02)

    def reset_maze(self):
        self.solution_path = []
        self.create_maze()
        self.draw_maze()

if __name__ == "__main__":
    root = tk.Tk()
    app = MazeApp(root)
    root.mainloop()"