oneshotlm
Compare all models on this prompt →

Maze generator & solver · gpt-5.1-codex-mini

Generate a random maze with the recursive-backtracker algorithm on a canvas, then animate an A-star or BFS solver finding the path from start to finish.

⛨ sandboxed Open in new tab ↗
transcript · 8 messages
user

Generate a random maze with the recursive-backtracker algorithm on a canvas, then animate an A-star or BFS solver finding the path from start to finish.

assistant
thinking
**Planning maze generation**

I need to create a single-page web app that implements maze generation using the recursive backtracker algorithm. I want to include animations for rendering paths, possibly using A* or BFS for pathfinding. It’s important to have clear instructions on how to apply these concepts. I should also think about what to inspect during the development process. Let's make a list of the key steps I need to take to get started!
bash {"command":"pwd"}
toolResult

/tmp/ws

assistant
thinking
**Checking file structure**

I'm thinking I need a single file, index.html. To do that, I should inspect the repository. I want to make sure I understand its structure and locate the right files. Once I check, I’ll know if I can create or modify the index.html file as needed. It’s essential to have everything organized correctly, so I can proceed smoothly with my task! Let's see what the repo has in store for me.
bash {"command":"ls"}
toolResult

(no output)

assistant
thinking
**Planning maze generation**

I want to create a single file, index.html, for maze generation and animation using a canvas. There’s no need for external files, which simplifies things. The plan is to generate a random maze through recursive backtracking and animate the solver using BFS or A*. I think 20x20 cells could work for the maze grid, and I'll ensure to include a start and finish at opposite corners. I've sketched out the needed HTML structure, CSS, and JavaScript functions all within one file, which should be neat!**Implementing maze animation**

I'm working on recursive backtracking, starting at (0,0) to mark cells as visited. As long as the stack isn’t empty, I’ll look for unvisited neighbors, remove walls, and push to the stack when found. After generating the maze, I’ll implement BFS to find the path. I plan to animate the exploration, potentially using requestAnimationFrame to highlight each step on the grid. Maybe I’ll have a small UI for a button to regenerate the maze, ensuring a new random maze each time the page loads! Looking forward to it!**Setting up the maze script**

Inside the script, I'll set constants for columns and rows and define the canvas size based on those values. I need to create a grid and implement functions like `setupGrid`, `carveMaze`, and `drawMaze`. For the solver, I’ll set up a queue starting with the initial cell and track visited nodes. The animation for BFS will be crucial. I’m considering using `setTimeout` or `requestAnimationFrame` to control the animation steps without causing endless loops. Just need to ensure the timing is right!**Structuring the BFS animation**

I need to set up an exploration queue and a visited set for my BFS animation. The function `animateBFS` will process cells from the queue, and if the target is reached, it will reconstruct and draw the path. To avoid issues with `setTimeout` stacking, I’ll make sure to call `drawMaze` efficiently to visualize walls and visited cells. I'm considering a `Cell` class to store row, column, walls, and the visited status, while maintaining a clear structure for removing walls and defining direction mappings. This will help keep everything organized!**Designing the maze generator**

I'm creating the `carveMaze` function that starts from the first cell, marking it as visited and using a stack to manage exploration. If there are unvisited neighbors, I'll randomly choose one, remove the walls between, and continue; otherwise, I'll backtrack. After generating the maze, I plan to reset the visited status so it can be reused later for BFS. My maze will have a structure where cells store their walls and a separate visited state for pathfinding. I'll also implement the `drawMaze` function for visualization, highlighting visited cells and paths effectively!**Structuring the maze generation and solving process**

I'm defining a `generateAndSolve` function that initializes the maze grid, carves the maze, and visualizes it. In `startSolver`, I’ll manage an animation loop that employs `setTimeout` for stepping through the BFS process. I need to ensure that when regenerating the maze, earlier animations are canceled using a global variable `solverTimer`. I'll create helper functions like `getAvailableNeighbors` and use structured helper functions for drawing, while keeping track of start and goal cells globally. I'll also ensure the interface provides feedback with the status text and has a button to generate a new maze!**Finalizing the maze generation script**

I'm putting together the final script to manage the maze generation and solving. I'm ensuring to set up the global variables for the grid, start cell, goal cell, and the solver timer. The `createGrid` function will establish the grid setup, and `carveMaze` will handle the maze carving process.

I'll implement the `drawMaze` function to visualize the maze with specified colors for paths and visited cells, ensuring the start and goal cells stand out. The `getAvailableNeighbors` will help during BFS, and I'll create a `resetCellMarks` function to prepare for solving. I also need to refine color settings for clarity in visual representation. Lastly, I plan to manage animations and status updates effectively to inform users about the maze's generation and solving progress.**Refining the maze algorithm**

I'm organizing my script to effectively manage the maze generation and solving process. I'm going to use a `Map` to handle parent-child relationships in path reconstruction. The `reconstructPath` function will build a path from the end cell back to the start.

I'll ensure that any previously scheduled timeouts are cleared when generating a new maze to prevent unnecessary execution. The drawing order in the `drawMaze` function will prioritize path highlights while keeping the start and goal colors distinct. I'll structure the fill colors carefully to avoid overwriting important visual indicators. Finally, I want to ensure my event listeners are properly set up for regeneration.**Finalizing maze generation and solving**

I’m refining various parts of my maze generation and solving functions. I'll lighten the path color for clarity and ensure my sets for visited, frontier, and paths default to empty to avoid errors. I'll update the status to indicate whether a path is found and handle potential animations later.

In the `createGrid` function, I’ll ensure that the grid is initialized properly. While carving the maze, I’ll confirm that I manage which cells are marked as visited or unvisited effectively. In the `drawMaze` function, I need to maintain a clear color coding for the start and goal cells to ensure they are distinguishable even when the path is found. Additionally, I want to prevent overlapping timeouts and efficiently handle solver restarts.**Crafting the maze web app**

I'm considering adding a small delay to let users appreciate the maze before starting the solver. I'll immediately call `startSolver()` after drawing the maze to keep the experience smooth. To enhance the user experience, I plan to highlight the status text nicely in CSS, and I'll ensure the regeneration button works correctly.

For the CSS, I want a gradient background that centers everything neatly. The canvas dimensions should be responsive, so I’ll limit its maximum width while ensuring the pixelated rendering looks sharp. I’ll implement a mechanism to manage solver activity and a way to prevent execution issues. This will help ensure a seamless transition when the maze regenerates, keeping previous animations from interfering. Finally, I’ll ensure that all the code fits nicely into a single self-contained HTML file.**Finalizing the maze script**

I'm working on wrapping everything in an IIFE (Immediately Invoked Function Expression) to keep the scope clean. Inside, I’ll set up the canvas, context, and status elements. 

I also need to define the regeneration button (`regenBtn`) before the script runs, ensuring it works properly. Additionally, I’ll make sure the solver timer and active states are managed right.

The goal is to allow a seamless user experience with the maze generation, making it nice and smooth when users click to regenerate. Let’s finalize that file!
write index.html (10089 bytes)
toolResult

Successfully wrote 10089 bytes to index.html

assistant

Generated a fully self-contained single-page app in `index.html` that draws a recursive backtracker maze on a canvas and animates a BFS solver exploring the maze toward the goal.

TAKE IT TO CODE

A single self-contained HTML file — copy it and open in any browser, or reuse the prompt with your own pi-agent run.

RUN

modelgpt-5.1-codex-mini
vendorOpenAI
harnesspi-agent
generated2026-08-01

EVALUATION

4/5 working

Maze generates and BFS solver animates exploring then highlighting the solution path; keyboard had no additional effect but click/drag/wheel progressed the solve.

Vision grade · anthropic/claude-sonnet-5

MEASUREMENTS

Raw readings from the capture, not a verdict — the grade above is the only judgement. Percentages are how much of the screen changed; the measure under-reports sparse motion on a dark background.

idle motion0.7%
on click6.8%
on drag6.2%
on wheel17.6%
on enter + space23.0%
on arrow keys0.0%
on w/a/s/d0.0%
frame spread63.2 / 255
console errors0
js errors none

METRICS

runtime98.0s
tokens in7.8k
tokens out13k
cached4.4k
cost / run$0.0263