Gemini 3.1 Flash Lite
by GoogleReasoningClean
Running live in a sandboxed frame. Click inside it before using the keyboard.
How it went
- Total time
- 4.7 s
- Cost
- $0.0028
- Output tokens
- 1,766
- Spent thinking
- 0 tokens
- Speed
- 416.9 tok/s
- Console errors
- 0
- First token after
- 428 ms
- First visible text after
- 428 ms
- Prompt tokens
- 507
- Code size
- 5.0 KB
- Finish reason
- stop
- Served by
- Model id
google/gemini-3.1-flash-lite- Reasoning sent
{"effort":"minimal"}- Max output
- 65,536 tokens
- Generated
- Nov 12, 2026
What it was asked
The prompt
Build a polished Snake game in a single HTML file using vanilla JavaScript and a <canvas>. Requirements: - A grid of at least 20×20 cells, centered on the page. - Arrow keys and WASD control the snake. Quick successive key presses must both be honored, but the snake can never reverse onto itself. - Eating food adds 10 points and grows the snake by one cell; new food never spawns on the snake. - Game over when the snake hits a wall or itself, with an overlay showing the score; Space or Enter restarts, P pauses. - Visual polish: smooth movement, a snake with a distinct head and eyes facing its direction, and a small particle burst when eating. - Display the current score and the best score of the session.
System prompt, sent with every prompt
You are generating a self-contained web demo. It will be rendered automatically in a sandboxed iframe and compared side by side with the output of other AI models given the exact same task. Output rules: - Reply with exactly ONE fenced code block containing the complete file: ```html (or ```svg when the task asks for an SVG). No text before or after the code block. - Everything must be inline: CSS in <style>, JavaScript in <script>. No external files, images, fonts or network requests, except the CDN URLs explicitly allowed by the task. - Do not use localStorage, sessionStorage, cookies, IndexedDB, alert(), confirm(), prompt() or window.open(): they are blocked in the sandbox and will throw. - The page must look right in a 1280×800 viewport and adapt gracefully down to 375px wide. No horizontal scrollbar. - Something meaningful must be visible on first paint: a screenshot is taken automatically about 3 seconds after load, without any interaction. - Everything that makes the demo interesting must be visible within the first seconds: nothing hidden behind a high score, a later level or a long play session. - Games must start in a self-playing demo mode (a simple AI plays) behind a "Click or press a key to start" message, so the game can be judged in action without playing. - The iframe only receives keyboard events after the user clicks it: if the demo uses the keyboard, display a clear "Click or press a key to start" message. - The code must run with zero errors in the console of the latest Chrome.
Code run-1.html · 142 lines
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Polished Snake</title>
<style>
body { margin: 0; background: #1a1a1a; display: flex; justify-content: center; align-items: center; height: 100vh; font-family: 'Segoe UI', Tahoma, sans-serif; color: white; overflow: hidden; }
#game-container { position: relative; }
canvas { background: #222; border: 4px solid #444; box-shadow: 0 0 20px rgba(0,0,0,0.5); }
#ui { position: absolute; top: 10px; left: 10px; pointer-events: none; }
#overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; background: rgba(0,0,0,0.7); }
h1 { margin: 0; color: #4CAF50; }
.hidden { display: none !important; }
</style>
</head>
<body>
<div id="game-container">
<div id="ui">
<div>Score: <span id="score">0</span></div>
<div>Best: <span id="best">0</span></div>
</div>
<canvas id="canvas" width="400" height="400"></canvas>
<div id="overlay">
<h1 id="msg">SNAKE</h1>
<p id="submsg">Click or press any key to start</p>
</div>
</div>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const scoreEl = document.getElementById('score');
const bestEl = document.getElementById('best');
const overlay = document.getElementById('overlay');
const msg = document.getElementById('msg');
const submsg = document.getElementById('submsg');
const gridSize = 20;
const tileCount = 20;
let snake = [{x: 10, y: 10}];
let food = {x: 15, y: 10};
let dx = 1, dy = 0;
let nextDx = 1, nextDy = 0;
let score = 0, best = 0;
let particles = [];
let gameActive = false, paused = false, started = false;
function reset() {
snake = [{x: 10, y: 10}, {x: 9, y: 10}];
dx = 1; dy = 0;
nextDx = 1; nextDy = 0;
score = 0;
scoreEl.innerText = score;
gameActive = true;
overlay.classList.add('hidden');
}
function spawnFood() {
let valid = false;
while (!valid) {
food = { x: Math.floor(Math.random() * tileCount), y: Math.floor(Math.random() * tileCount) };
valid = !snake.some(s => s.x === food.x && s.y === food.y);
}
}
window.addEventListener('keydown', e => {
if (!started) { started = true; reset(); return; }
if (e.key === 'p' || e.key === 'P') paused = !paused;
if (e.key === ' ' || e.key === 'Enter') if (!gameActive) reset();
const keyMap = { ArrowUp: [0, -1], w: [0, -1], ArrowDown: [0, 1], s: [0, 1], ArrowLeft: [-1, 0], a: [-1, 0], ArrowRight: [1, 0], d: [1, 0] };
if (keyMap[e.key]) {
const [ndx, ndy] = keyMap[e.key];
if (ndx !== -dx && ndy !== -dy) { nextDx = ndx; nextDy = ndy; }
}
});
function draw() {
ctx.fillStyle = '#222';
ctx.fillRect(0, 0, canvas.width, canvas.height);
if (!gameActive) return;
// Snake
snake.forEach((s, i) => {
ctx.fillStyle = i === 0 ? '#4CAF50' : '#388E3C';
ctx.fillRect(s.x * gridSize, s.y * gridSize, gridSize - 2, gridSize - 2);
if (i === 0) {
ctx.fillStyle = 'white';
ctx.beginPath();
ctx.arc(s.x*gridSize + (dx > 0 ? 14 : 6), s.y*gridSize + (dy > 0 ? 14 : 6), 3, 0, Math.PI*2);
ctx.fill();
}
});
// Food
ctx.fillStyle = '#FF5252';
ctx.beginPath();
ctx.arc(food.x * gridSize + gridSize/2, food.y * gridSize + gridSize/2, gridSize/3, 0, Math.PI*2);
ctx.fill();
// Particles
particles.forEach((p, i) => {
p.x += p.vx; p.y += p.vy; p.life -= 0.1;
ctx.fillStyle = `rgba(255,82,82,${p.life})`;
ctx.fillRect(p.x, p.y, 4, 4);
if (p.life <= 0) particles.splice(i, 1);
});
}
function update() {
if (!gameActive || paused) return;
dx = nextDx; dy = nextDy;
const head = { x: snake[0].x + dx, y: snake[0].y + dy };
if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount || snake.some(s => s.x === head.x && s.y === head.y)) {
gameActive = false;
best = Math.max(best, score);
bestEl.innerText = best;
msg.innerText = "GAME OVER";
submsg.innerText = "Press Space to Restart";
overlay.classList.remove('hidden');
return;
}
snake.unshift(head);
if (head.x === food.x && head.y === food.y) {
score += 10;
scoreEl.innerText = score;
for(let i=0; i<8; i++) particles.push({x: head.x*gridSize, y: head.y*gridSize, vx: (Math.random()-0.5)*4, vy: (Math.random()-0.5)*4, life: 1});
spawnFood();
} else {
snake.pop();
}
}
setInterval(() => { update(); draw(); }, 100);
</script>
</body>
</html>