Maze generator & solver · gpt-oss-20b
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.
transcript · 4 messages
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.
thinking
We need to create index.html with canvas all in one file. Should generate maze via recursive backtracker, draw it. Then animate BFS/ A* solving. Should be single page app. Implement generating grid, maze representation, rendering. Use canvas 800x600. Maze cells, walls. We'll use cell size variable. Implement random maze generation recursively using stack. Then solver: BFS or A*. Use BFS for simpler; animate step by step. Show start and end. Use color for walls,bfs frontier, visited, path. Render updates each frame. Should run completely offline. Use JS. Complexity: implement as single script. Also include CSS minimal style. Let's design index.html skeleton. Add canvas element and maybe buttons: generate maze, solve, reset. But not required but beneficial. Let's write code. Implementation plan: CSS: center canvas. JS: constants: cols, rows based on canvas width/height and cellSize. Maze: array of Cell objects: y,x, walls [top,right,bottom,left], visited. generateMaze: recursive backtracker: choose start cell, stack, while stack not empty pop. Use algorithm: while unvisited cells remain: current cell mark visited, pick random unvisited neighbor, remove wall between, push current onto stack, move to neighbor, else if no neighbors, pop stack. Animation: rendering entire maze each frame, grid lines. After generation, set start cell top-left(0,0) and end cell bottom-right(cols-1,rows-1). Solver: BFS: queue, visited set, cameFrom map. Animate: to animate solving, we use BFS but we step through when iterating over queue. We track frontier and visited. Simplest: use setInterval or requestAnimationFrame to process nodes in queue. During each step, process one node: expand, record visited, add neighbors. For each neighbor, record cameFrom. When reaching end, reconstruct path by backtracking from end to start using cameFrom. Rendering: color visited cells, frontier in distinct color, path when found. When path found, stop solver. Edge: We'll treat cells as rectangular. Edges drawn as lines per wall. Implement functions: drawMaze(), drawCell(x,y,color?). Let's produce code. Need to embed CSS and JS within index.html. We'll write script using ES6. Tweak to run in browser: use global variables. Implementation details: - Could set cell size 20, canvas 400x400 for 20x20 grid. - Use random() to choose neighbor. - Provide a reset button to re-generate. Provide solve button. - Provide animation speed adjustable but fixed 50 ms. Will embed all JS inside <script> after DOMContentLoaded. I'll produce final index.html file. Let's write now.
index.html (5970 bytes)Successfully wrote 5970 bytes to index.html
thinking
We need to confirm if the file was created. Provide final message. Probably okay.
The **`index.html`** file has been created in the current directory. It contains a self‑contained web app that: * Generates a maze using the recursive‑backtracker algorithm on a canvas. * Animates a BFS solver discovering the path from the start (top‑left) to the finish (bottom‑right). * Includes controls to generate, solve, and reset the maze.
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
EVALUATION
Maze renders with start/end markers but no solving animation ever appears; requires clicking a specific 'Solve' button not triggered by generic inputs.
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.