oneshotlm
Compare all models on this prompt →

Maze generator & solver · grok-4.20

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 · 4 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
The task is: "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."
First, the task is to generate a single self-contained index.html file with CSS and JS.

I need to implement:

- Recursive Backtracker for maze generation.

- Display on canvas.

- Animate A* or BFS pathfinding from start to finish.

Make it interactive with buttons.

Choose BFS for simplicity, as A* needs priority queue and heuristic.

But task says A* or BFS, so I'll do BFS with animation.

Grid: 20x20 cells to fit nicely.

Cell size: 20px, canvas 500x500.

Start: (0,0), End: (19,19)

For maze: walls are 1px thick lines.

Cells are squares with walls between.

Standard way: draw horizontal and vertical lines.

For generation: use iterative stack.

For animation: use requestAnimationFrame to step through generation or solving.

I'll have a button to generate and animate generation, then solve.

To keep simple: button "Generate", button "Solve with BFS" which animates the search.

For code: keep it in one script tag.

Confidence: I'm familiar with this, so high confidence \confidence{70}

Now, I need to generate the actual HTML/JS code as the answer.

The user says "Generate a random maze..." but in context it's to produce the code for the app.

The human message is the task description, so the answer is the index.html code.

Yes.

I need to write the code.

Let me outline the code structure:

<!DOCTYPE html>

<html>

<head>

<title>Maze Solver</title>

<style>

body { background: # 000; color: #fff; font-family: Arial; }

#controls { text-align: center; padding: 10px; }

canvas { border: 1px solid #fff; background: #111; display: block; margin: 0 auto; }

</style>

</head>

<body>

<div id="controls">

<button id="generate">Generate Maze</button>

<button id="solve">Solve with BFS</button>

<slider id="speed">Speed: <input type="range" min="1" max="50" value="10"></slider>

</div>

<canvas id="mazeCanvas" width="500" height="500"></canvas>

<div id="status">Ready</div>

<script>

// JS code here

const COLS = 20;

const ROWS = 20;

const CELL_SIZE = 20;

const CANVAS_SIZE = COLS * CELL_SIZE;

const canvas = document.getElementBy id('mazeCanvas');

const ctx = canvas.getContext('2d');

canvas.width = CANVAS_SIZE;

canvas.height = CANVAS_SIZE;

let grid = [];

let stack = [];

let current;

let delay = 10; // default

let isAnimating = false;

let animationSteps = [];

let currentStep = 0;

let start, goal;

let cameFrom = new Map();

let openSet = new Set();

let closedSet = new Set();

let status = document.getElementById('status');

const generateBtn = document.getElementById('generate');

const solveBtn = document.getElementById('solve ');

const speedSlider = document.querySelector('input[type="range"]');

speedSlider.addEventListener('change', (e) => {

  delay = parseInt(e.target.value);

});

generateBtn.addEventListener('click', generateMaze);

solveBtn.addEventListener('click', solveMaze);

function init() {

  generateMaze();

}

function generateMaze() {

  status.innerText = 'Generating...';

  grid = [];

  for (let y = 0; y < ROWS; y++) {

    grid[y] = [];

    for (let x = 0; x < COLS; x++) {

 grid[y][x] = {

        x, y,

        walls: {top: true, right: true, bottom: true, left: true},

        visited: false

      };

    }

  }

  start = grid[0][0];

  goal = grid[ROWS-1][COLS- 1];

  stack = [];

  current = grid[0][0];

  current.visited = true;

  stack.push(current);

  animationSteps = [];

  currentStep = 0;

  isAnimating = true;

  animateGeneration();

}

function animateGeneration() {

  if (currentStep >= animationSteps.length || !isAnimating) return;

  // add step logic

  // for simplicity, run the whole gen in loop but with delay

  // better to make the backtracker step by step

  // let's redefine

}

This is getting long, I need to write full code.

Since the response should be the code, and confidence.

I will write a complete code in my mind.

To save time, I'll assume I write it.

The final answer is the HTML code.

Let's try to write it. 

Since this is text, I need to produce it.

The task is to generate the maze, but no, the user is giving the task to me to do, but in context it's to produce the app code.

Looking back: "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."

But then -- and the task is that.

But since it's a coding task, the answer is the code.

But the system says "Your team's answer should report a confidence"

So, the answer is the index.html content.

I will craft a complete one.

Let me try to write a simplified version.

Simplified: generate instant, solve with animation by revealing.

Code:

<! DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Maze Solver</title>

<style>

body { margin: 0; background: #000; color: #fff; font-family: Arial, sans-serif; }

#controls { text-align: center; padding:  10px; }

button, input { margin: 5px; padding: 5px 10px; }

canvas { display: block; margin: 0 auto; border: 2px solid #fff; }

#status { text-align: center; padding: 10px; }

</style >

</head>

<body onload="init()">

<div id="controls">

<button id="newMaze">New Maze</button>

<button id="solve">Solve BFS</button>

<label>Speed: <input type="range" id="speed" min="1" max="50" value="10"></label>

 </div>

<canvas id="canvas" width="500" height="500"></canvas>

<div id="status">Ready</div>

<script>

const COLS = 20;

const ROWS = 20;

const CELL_SIZE = 20;

const canvas = document.getElementById('canvas');

const ctx = canvas.getContext('2d');

canvas.width = COLS * CELL_SIZE;

canvas.height = ROWS * CELL_SIZE;

let grid = [];

let start, goal;

let delay = 10;

let isSolving = false;

let path = [];

let exploredOrder = [];

let cameFrom = {};

let status = document.getElementById('status');

document.getElementById('newMaze').addEventListener('click', generateMaze);

document.getElementById('solve').addEventListener('click', solveMaze);

document.getElementById('speed').
write index.html (22811 bytes)
toolResult

Successfully wrote 22811 bytes to index.html

assistant
thinking
The task is complete. I have generated a single self-contained index.html file with a random maze using the recursive backtracker algorithm, displayed on a canvas. It includes buttons to generate a ne...

The file `index.html` has been created. Open it in a browser to play with the interactive maze (recursive backtracker generation + animated A*/BFS solver). Use the controls or keys (R=new maze, S=A*, B=BFS, C=clear).

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

modelgrok-4.20
vendorxAI · Grok
harnesspi-agent
generated2026-08-01

EVALUATION

4/5 working

Maze generates via recursive backtracker and A* solver animates path with explored/path colors; only WASD triggered solving, not clicks or arrows.

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 motion28.8%
on click0.0%
on drag0.0%
on wheel0.0%
on enter + space0.0%
on arrow keys0.0%
on w/a/s/d10.0%
frame spread57.6 / 255
console errors1
js errors none

METRICS

runtime68.6s
tokens in4.9k
tokens out13k
cached3.1k
cost / run$0.0389