Models 44

gpt-oss-120b

by OpenAIReasoningClean
Open in new window

Running live in a sandboxed frame. Click inside it before using the keyboard.

How it went

Total time
14.9 s
Cost
$0.0008
Output tokens
1,799
Spent thinking
90 tokens
Speed
131.4 tok/s
Console errors
0
First token after
1.2 s
First visible text after
1.7 s
Prompt tokens
557
Code size
5.5 KB
Finish reason
stop
Served by
Sail Research
Model id
openai/gpt-oss-120b
Reasoning sent
{"effort":"low"}
Max output
64,000 tokens
Generated
Nov 11, 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 · 202 lines

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Snake Demo</title>
<style>
  html,body{margin:0;height:100%;background:#111;color:#eee;font-family:sans-serif;display:flex;align-items:center;justify-content:center;}
  #game{position:relative;display:flex;flex-direction:column;align-items:center;}
  canvas{background:#222;image-rendering:pixelated;}
  #overlay{position:absolute;top:0;left:0;width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;background:rgba(0,0,0,0.7);color:#fff;font-size:1.2rem;pointer-events:none;opacity:0;transition:opacity .3s;}
  #overlay.show{opacity:1;}
  #msg{margin-top:0.5rem;font-size:.9rem;color:#aaa;}
  #scoreboard{margin-top:0.5rem;font-size:.9rem;}
</style>
</head>
<body>
<div id="game">
  <canvas id="c"></canvas>
  <div id="overlay"><div id="status"></div><div id="msg">Click or press a key to start</div></div>
  <div id="scoreboard">Score: <span id="score">0</span> | Best: <span id="best">0</span></div>
</div>
<script>
(() => {
  const canvas = document.getElementById('c');
  const ctx = canvas.getContext('2d');
  const overlay = document.getElementById('overlay');
  const status = document.getElementById('status');
  const scoreEl = document.getElementById('score');
  const bestEl = document.getElementById('best');

  const GRID = 20;
  const CELL = 20; // pixel size
  const WIDTH = GRID * CELL;
  const HEIGHT = GRID * CELL;
  canvas.width = WIDTH;
  canvas.height = HEIGHT;

  const dirs = {
    ArrowUp: {x:0,y:-1}, ArrowDown:{x:0,y:1},
    ArrowLeft:{x:-1,y:0}, ArrowRight:{x:1,y:0},
    w:{x:0,y:-1}, s:{x:0,y:1}, a:{x:-1,y:0}, d:{x:1,y:0}
  };
  let snake, dir, nextDir, food, particles, score, best, paused, running, aiMode;
  function init() {
    snake = [{x:10,y:10}];
    dir = {x:0,y:-1};
    nextDir = dir;
    placeFood();
    particles=[];
    score=0;
    paused=false;
    running=false;
    aiMode=false;
    updateScore();
    overlay.classList.add('show');
    status.textContent='Press any key to start';
  }
  function placeFood(){
    let pos;
    do{
      pos={x:Math.floor(Math.random()*GRID),y:Math.floor(Math.random()*GRID)};
    }while(snake.some(s=>s.x===pos.x&&s.y===pos.y));
    food=pos;
  }
  function updateScore(){
    scoreEl.textContent=score;
    best=Math.max(best||0,score);
    bestEl.textContent=best;
  }
  function drawCell(x,y,color){
    ctx.fillStyle=color;
    ctx.fillRect(x*CELL,y*CELL,CELL,CELL);
  }
  function draw(){
    ctx.clearRect(0,0,WIDTH,HEIGHT);
    // food
    drawCell(food.x,food.y,'red');
    // snake
    snake.forEach((seg,i)=>{
      const isHead=i===0;
      const col=isHead?'lime':'green';
      drawCell(seg.x,seg.y,col);
      if(isHead){
        // eyes
        ctx.fillStyle='black';
        const eyeOffset = 2;
        const ex = seg.x*CELL + CELL/2 + dir.x*eyeOffset;
        const ey = seg.y*CELL + CELL/2 + dir.y*eyeOffset;
        ctx.beginPath();
        ctx.arc(ex-4,ey-4,2,0,2*Math.PI);
        ctx.arc(ex+4,ey-4,2,0,2*Math.PI);
        ctx.fill();
      }
    });
    // particles
    particles.forEach(p=>{
      ctx.fillStyle=`rgba(255,215,0,${p.life})`;
      ctx.fillRect(p.x*CELL,p.y*CELL,CELL,CELL);
    });
  }
  function step(){
    if(paused||!running)return;
    // direction handling
    if(Math.abs(nextDir.x)!==Math.abs(dir.x) || Math.abs(nextDir.y)!==Math.abs(dir.y)){
      dir = nextDir;
    }
    const head = {x:snake[0].x+dir.x, y:snake[0].y+dir.y};
    // wall collide
    if(head.x<0||head.x>=GRID||head.y<0||head.y>=GRID||snake.some(s=>s.x===head.x&&s.y===head.y)){
      gameOver();
      return;
    }
    snake.unshift(head);
    // food
    if(head.x===food.x && head.y===food.y){
      score+=10;
      updateScore();
      spawnParticles(head);
      placeFood();
    }else{
      snake.pop();
    }
    // update particles
    particles.forEach(p=>p.life-=0.05);
    particles = particles.filter(p=>p.life>0);
    draw();
  }
  function spawnParticles(pos){
    for(let i=0;i<8;i++){
      particles.push({x:pos.x,y:pos.y,life:1});
    }
  }
  function gameOver(){
    running=false;
    overlay.classList.add('show');
    status.textContent=`Game Over – Score ${score} (Press Space/Enter)`;
  }
  function start(){
    running=true;
    overlay.classList.remove('show');
    aiMode=true;
  }
  function pauseToggle(){
    paused=!paused;
    overlay.classList.toggle('show',paused);
    status.textContent=paused?'Paused – Press P to resume':'';
  }
  // AI: simple greedy towards food
  function aiStep(){
    if(!aiMode) return;
    const head=snake[0];
    const dx=food.x-head.x;
    const dy=food.y-head.y;
    const prefers = [];
    if(Math.abs(dx)>Math.abs(dy)){
      prefers.push(dx>0?dirs.d:dirs.a);
      prefers.push(dy>0?dirs.s:dirs.w);
    }else{
      prefers.push(dy>0?dirs.s:dirs.w);
      prefers.push(dx>0?dirs.d:dirs.a);
    }
    for(const d of prefers){
      const nx=head.x+d.x, ny=head.y+d.y;
      if(nx<0||nx>=GRID||ny<0||ny>=GRID) continue;
      if(snake.some(s=>s.x===nx&&s.y===ny)) continue;
      nextDir=d;
      break;
    }
  }

  document.addEventListener('keydown',e=>{
    if(!running){
      start();
    }
    if(e.key==='p' || e.key==='P'){
      pauseToggle();
      return;
    }
    if(!running) return;
    if(e.key===' '|| e.key==='Enter'){
      init();
      start();
      return;
    }
    const d = dirs[e.key];
    if(d){
      // prevent reverse
      if(d.x===-dir.x && d.y===-dir.y) return;
      nextDir=d;
    }
  });
  document.addEventListener('click',()=>{if(!running) start();});

  init();
  setInterval(()=>{
    aiStep();
    step();
  },100);
})();
</script>
</body>
</html>
Reasoning trace (90 tokens)
We need provide HTML code. Include canvas, script. Implement snake with smooth movement using interpolation? Simple step but animate. We'll do grid 20x20 cell size maybe 20px each => canvas 400x400, centered with flex. Show score overlay. Include start message "Click or press a key to start". We'll auto start demo with simple AI moving towards food. Provide self-playing mode until user interacts. Implement.