Snake · gpt-oss-20b
Build a playable Snake game on a canvas with arrow-key controls, a growing tail, food, score, and a game-over and restart state.
transcript · 4 messages
Build a playable Snake game on a canvas with arrow-key controls, a growing tail, food, score, and a game-over and restart state.
thinking
We need to write single-page web app index.html. Must create file with HTML, CSS, JS. Use canvas, arrow key controls. Game logic: snake moves in grid, grows on eating food. Detect collision with walls or self -> game over. Score increments. Provide restart button after game over.
We'll write file using write function.
Let's craft index.html content.
Design:
- <canvas id="gameCanvas" width="400" height="400"></canvas>
- <div id="score">Score: 0</div>
- <div id="gameOver" style="display:none;">Game Over! <button id="restartBtn">Restart</button></div>
JS: use window.onload to init.
Set grid size, e.g., cellSize 20, so grid 20x20.
Snake array of positions: [{x, y}]. Initial length 3.
Direction: {dx, dy}, default right.
Set interval to update every 100ms.
Keydown event to change direction if not opposite.
Generate food at random empty cell.
Move snake: add new head = {x+dx, y+dy}. If new head collides with walls or self: game over.
If new head equals food: increase score, generate new food; don't pop tail.
Else: pop tail.
Render: clear canvas, fill each cell of snake with color, food with red.
Game over: clear interval, show gameOver div, hide canvas? Keep canvas.
Restart: reset state, hide gameOver, start interval.
Also allow pressing space or similar.
Implement as all in one file.
Let's prepare content string.
We'll write using write tool.
index.html (3514 bytes)Successfully wrote 3514 bytes to index.html
The `index.html` file has been created in the current directory. It contains a self‑contained Snake game with arrow‑key controls, growing tail, food, score tracking, and a game‑over/restart interface. You can open this file in a web browser to play the game.
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
Stuck on Game Over screen with static snake and food, no response to any input including restart clicks.
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.