Maze generator & solver · llama-4-scout
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.
This one-shot run produced no runnable artifact.
agent produced no index.html
The transcript below shows what the model did — read it to see why the one shot fell short.
transcript · 2 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.
an example of how you can create a simple maze generator and solver using HTML, CSS, and JavaScript. This example will generate a random maze using the recursive-backtracker algorithm and then animate an A-star solver finding the path from start to finish. ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial1.0"> <title>Maze Solver</title> <style> canvas { border: 1px solid black; </style> </head> <body> <canvas id="mazeCanvas" width="400" height="400"></canvas> <script> const canvas = document.getElementById('mazeCanvas'); const ctx = canvas.getContext('2d'); const cellSize = 10; const rows = Math.floor(canvas cellSize); const cols = Math.floor(canvas.width / cellSize); let maze = []; let let end; = []; // Initialize maze for (let i0; i < rows; { maze[i] = []; for (let j = 0; j < cols; j++) { maze[i][j] = x: j, y: i, walls: [true, true, true, true], // top, right, bottom, left false }; } } // Recursive-backtracker algorithm to generate maze function generateMaze(x, y) { maze[y][x].visited = true; let directions = [[0, -1], [0, 1], [-1, 0], [1, 0]]; directions.sort(() => Math.random() - 0.5); for (let [dx, dy] of directions) { let nx = x + 2 * dx let ny = y + 2 * dy; if (nx >= 0 && nx < cols && ny >= 0 && ny < rows && !maze[ny][nx].visited) { maze[ny - dy][nx - dx].walls[dx === 1 ? 2 : 0] = false; maze[ny][nx].walls false; (nx, ny); } } // A-star find path function astar(start, end) { let openList = [start]; let = {}; let gScore = { [start]: 0 }; let fScore = { [start]: heuristic(start, end) }; while (openList.length > 0) { let current = openList.shift(); if (current.x === end.x && current.y === end.y) { let path = []; while (current.x !== start.x || current.y !== start.y) { path.push(current); current = cameFrom[`${current.x},${current.y}`]; } path.push(start); path.reverse(); return path; } let [dx, dy] of [[0, -1], [0, 1], [1, 0], [-1, 0]]) { let neighbor = { x: current.x + dx, y: current.y + dy }; if (neighbor.x >= 0 && neighbor.x < cols && neighbor.y >= 0 && neighbor.y < rows && !maze[neighbor.y][neighbor.x].walls let tentativeGScore = gScore[current] + 1; if (!gScore[neighbor] || tentativeGScore < gScore[neighbor]) { cameFrom[`${neighbor.x},${neighbor.y}`] = current; gScore[neighbor] = tentativeGScore; fScore[neighbor]GScore + heuristic(neighbor, end); if (!openList.includes(neighbor)) { openList.push(neighbor); } } } } openList.sort((a, b fScore[a] - fScore[b]); } return null; } // Heuristic function for A-star function heuristic(a, b) { return Math.abs(a.x - b.x).abs(a.y - b.y); } // Draw maze function drawMaze() { ctx.clearRect(0, 0, canvas.width, canvas.height); for (let i = 0; i < rows; i++) { for (let j = 0; j < cols; j++) { if (maze[i][j].walls[0]) { ctx.beginPath(); ctx.moveTo(j * cellSize, i * cellSize); ctx.lineTo((j + 1) * cellSize, i * cellSize); ctx.stroke(); } if (maze[i][j].walls[1]) { ctx.beginPath(); ctx.moveTo((j + 1) * cellSize, i * cellSize); ctx.lineTo((j + 1) * cellSize, (i + 1) * cellSize); ctx.stroke(); } if (maze[i][j].walls[2]) { ctx.beginPath(); ctx.moveTo((j + 1) * cellSize, (i + 1) * cellSize); ctx.lineTo(j * cellSize, (i + 1) * cellSize); ctx.stroke(); } if (maze[i][j].walls[3]) { ctx.beginPath(); ctx.moveTo(jSize, (i + 1) * cellSize); ctx.lineTo(j * cellSize, i * cellSize); ctx.stroke(); } } } ctx.fillStyle = 'green'; ctx.fillRect(start.x * cellSize + 1, start cellSize + 1Size - 2, cellSize - 2); ctx.fillStyle = 'red'; ctx(end.x * cellSize + 1, end.y * cellSize + 1, cellSize - 2, cellSize - 2); } // Animate path finding function animatePath() { let i = 0; function nextStep() { if (i < path.length) { ctx.fillStyle = 'blue'; ctx.fillRect(path[i].x * cellSize + 1, path[i].y * cellSize + 1, cellSize - 2, cellSize - 2); i++; requestAnimationFrame(nextStep); } } nextStep(); } // Main function function main() { generateMaze(1, 1); start = { x: 1, y: 1 }; end = { x: cols - 2, y: rows - 2 }; path = astar(start, end); drawMaze(); animatePath(); } main(); </script> </body> </html> ```
TAKE IT TO CODE
This run produced no artifact — reuse the prompt with a different model or your own pi-agent run.