Defender — implementation plan

_Project dir ~/defender · target https://defender.arnao.ai · written 2026-11-21 (Claude Code, session defender) · status: plan, awaiting Byron's go_

Byron's ask (2026-11-21): a faithful browser build of Williams' 1981 Defender as an installable app at

defender.arnao.ai; a hotkey (O) that flips between the original look and a high-resolution modern look while the

game keeps running; an AI mode, available only after Google sign-in, where a model flies the ship and you can switch

between models (Anthropic's as the first family) as an experiment; and a plan that ships the exact replica first but is

built so the other two drop in without a rewrite.

Reference: the original game and its rules — https://en.wikipedia.org/wiki/Defender_(1981_video_game) · the enemy roster

and scoring on StrategyWiki — https://strategywiki.org/wiki/Defender · Jarvis on the design (Computer History Museum

oral history) — https://www.computerhistory.org/collections/catalog/102738171


1. The one architecture decision that makes all three waves possible

Simulation, presentation and control are three separate layers from the first commit.

 input shells            simulation (the game)                renderers (the look)
 ───────────────         ─────────────────────────            ─────────────────────
 keyboard  ─┐            fixed 60 Hz step                     retro  : 2D canvas, 320×256 logical,
 touch     ─┼─ intents ─► seeded RNG                  state ─► integer-scaled, 16-colour palette
 gamepad   ─┤            entities + planet + scanner           hd     : WebGL 2, particles, bloom,
 AI pilot  ─┘            input log (replayable)                lit planet, debris physics

hyperspace) once per tick and emits state. That is what lets an AI pilot sit beside the keyboard as just another shell.

game. That gives replays, ghost ships, server-verified high scores (re-run the input log) and, above all, a fair model

comparison: every model flies the identical wave.

notices. The HD renderer may add cosmetic physics (debris, shockwaves, humanoid tumble) but **never changes what the

sim does**, so a score in HD is a score in retro. A true "Newtonian physics" variant, if wanted later, is a *separate

labelled mode with its own scoreboard*, not a renderer option.

tab or a Node process, without any scheduled job (see §6 on the freeze).

One static site: index.html + sim.js + render-retro.js + render-hd.js + input.js + audio.js + ai.js

+ sw.js + manifest.webmanifest, plus two serverless routes (api/pilot.js, api/role.js). No framework, no build.


2. Waves

WaveDeliverableBuild time (my work)Sittings*
0This plan; domain claimed; project dirdone today—
1Faithful replica, installable PWA, keyboard + touch + gamepad, synthesized sound, Playwright tests, live at defender.arnao.ai2–3 h1
2HD renderer + O toggle (WebGL 2, particles, bloom, lit parallax planet, debris); attract mode; high-score table2–3 h1
3AI mode: Google sign-in gate + roles, commander/autopilot pilot, model switch (Haiku · Sonnet · Opus; Fable if the key allows), live cost meter, intent captions3–4 h1–2
4Experiments: replays + ghost ship, model league (on demand, headless), AI enemy commander, commentator voice3–4 h1–2

\* A sitting is one of my sessions under the 5-hour usage cap. Total roughly **10–14 hours of build time over 4–6

sittings**; Wave 1 playable the same day it starts. Each wave ships live before the next begins, so there is always a

working game at the address.

Wave 1 — the exact replica (MVP)

What "faithful" means here, so we can check it:

the top showing the whole planet, screen scrolls so the ship sits a third in from the edge it faces.

horizontal bolt that persists a few frames, 3 lives, 3 smart bombs, hyperspace with the original ~1 in 7 chance of death.

fast, homing, jittery), Baiter (arrives when a wave drags on, faster than you), Bomber (drops mines), Pod (bursts into

Swarmers when shot), Swarmer (small, fast, homing).

every Lander becomes a Mutant until wave 5 restores the planet; bonus per surviving humanoid at wave end; extra life and

smart bomb every 10,000.

sampled ROM audio.

Artwork is ours, drawn to match the silhouettes — no ROM assets (see §7).

gamepad; touch layout for the TriFold — left thumb column = up / down / reverse, right thumb = fire (hold) with

thrust as a second finger, bomb and hyperspace as small corner buttons you cannot hit by accident. Landscape locked

on phones. Haptics on Android only (iOS blocks web haptics, as found on Buzzer).

by default and marks the score.

same seed + inputs → same final state; a scripted 2-minute input log must end on the same score every run).

Wave 2 — HD look and the O key

drawn as a lit ridge with parallax stars and a distant city glow, ship and enemies as high-resolution sprites with the

same silhouettes and hitboxes as retro so nothing plays differently.

remembered per device.

against the retro silhouettes. Nothing generative runs during play.

(cheap, and it makes cheating require beating the sim rather than a form).

Wave 3 — AI mode (sign-in only)

The honest design: the model is the commander, not the stick. A language model answers in 0.5–5 s; Defender ticks

60 times a second. So:

  1. Every 1–2 s (tunable) the page sends the model a compact text snapshot: ship position/velocity, bombs, lives, wave;

each humanoid (walking / being carried / falling, where); each enemy by type with position relative to the ship;

what the scanner shows off-screen.

  1. The model returns one JSON order: `{heading: "left"|"right", target: "<entity id>"|null, fire: "hold"|"burst"|"off",

bomb: bool, hyperspace: bool, why: "<one line>"}`.

  1. A deterministic autopilot (plain code, 60 Hz) executes the order: steers to the target, dodges in the last 200 ms,

fires on the policy. The autopilot alone, with a fixed heuristic, is also the attract mode and the "no model" baseline.

  1. The why line is shown as a HUD caption: "Opus: breaking right, Lander at 40 % height with a humanoid." That is

what makes watching it fun and makes model differences visible.

Model switch: a menu (M) listing Haiku 5.5 · Sonnet 5.5 · Opus 5.5 · Fable 5.1 (if the key permits), plus

"Autopilot only" and "Human" — switchable mid-game, so you can hand the ship to Opus when you are about to die and take

it back. Later families (Gemini, GPT) are one adapter each.

Sign-in and roles — reuse the fleet's Google broker (auth.arnao.ai; cookie is valid on every arnao.ai host; api/role.js

forwards it to /api/verify exactly as brain.arnao.ai's api/lens.js does, no new auth code):

RoleWhoGets
anonymousanyonethe whole game, both looks, local high scores
signed-inany Google accountAI mode on Haiku, 3 AI games a day, scores on the shared board
ownerByronevery model, mid-game switching, league runs; a daily dollar cap (default $5) that the meter enforces

Cost, so it is never a surprise — the HUD shows a live meter and the game stops the model (autopilot takes over) at the

cap:

ModelRoughly per order (≈1.5 K in / 100 out, cached system prompt)5-minute game at 1 order/s
Haiku 5.5$0.0002about $0.06
Sonnet 5.5about a third of Opusabout $0.80
Opus 5.5$0.008about $2.40

Server: api/pilot.js on the Vercel project, Anthropic key as a Vercel env var (the trust project already works this

way), 30 orders/min per account, hard daily cap per role. The key never reaches the browser.

Wave 4 — the experiments worth doing

20× speed, then publishes a table at /league — score, humanoids saved, waves reached, dollars spent, per model. Runs on

demand in the tab, so it is not a scheduled job (freeze-safe, §6).

Baiter is released). Opus flies, Haiku commands the enemies, or the reverse. One call per wave, so cheap enough for

signed-in guests too.

free; ElevenLabs if we want a real voice). Latency does not matter here, which is why it works.


3. Things we should be considering (answers to "anything else?")

  1. The name and the artwork (intellectual property). Defender is a Williams/Midway trademark now held by Warner

Bros. Games. A public page at defender.arnao.ai using the name and look-alike graphics is a homage with real takedown

exposure, especially with sign-in and a scoreboard. Mitigations built into Wave 1: no ROM code, sprites or samples;

our own pixel art; a clear "unofficial homage, non-commercial" line; no Williams logos. Byron's call: keep the

name as a tribute (fine for a personal site, accept the small risk) or ship under a sibling name (e.g. Sentinel,

Defend) with the original credited. See §8.

  1. Phone controls are the hard part, not the code. The original needs five buttons and a two-way stick. The TriFold

cover screen in landscape is 900×412 logical; thumbs cover about 25 % of it. Wave 1 budgets real time for the touch

layout and tests it on both fold states before anything else is polished.

  1. Determinism is non-negotiable (replays, verified scores, fair model comparison). It costs nothing on day one and

is impossible to add later.

  1. HD must not change play. Cosmetic physics only; same hitboxes. Anything that changes outcomes is a separate

labelled mode with its own board.

  1. Spend. AI mode is the only part that costs money; it is gated, metered on screen and capped by role. The

Anthropic key goes on the defender Vercel project the same way trust's does; I will copy it at Wave 3 and say so.

  1. The 90-day freeze (no new daemons, consoles or dashboards until 2027-01-16). A game is none of those. The model

league runs on demand in the browser, not on a schedule; a nightly league is a January item.

  1. Abuse of the free AI tier. Sign-in + per-account limits + per-IP rate limit on api/pilot.js; the key never

leaves the server; the cap is enforced server-side, the meter is only the display.

  1. Readability. Byron reads without readers: HUD text 18 px minimum at phone scale, score and lives large, the

retro font scaled up rather than kept at 8 px authenticity.

  1. Accessibility of the original's difficulty. Trainer toggle off by default, marked on scores; never silently easier.

4. Build order inside Wave 1 (so a playable game exists after the first hour)

  1. Sim core: planet, scroll, ship with inertia and reverse, laser, scanner. Retro renderer. Keyboard. (playable)
  2. Humanoids + Landers + Mutants + abduction + rescue + planet explosion rule. (it is Defender)
  3. Baiter, Bomber, Pod, Swarmer; waves; scoring; lives; bombs; hyperspace. (complete rules)
  4. WebAudio synth; attract text; game over; local high score.
  5. Touch layout + gamepad; manifest + service worker; TriFold tests; deploy; link audit; Fable critique pass; slog.

5. What I need from Byron


6. Risks

RiskLikelihoodHandling
Takedown over the name/looklow for a personal site, not zero§3.1; rename is a one-line change; artwork is ours
Touch controls feel badmediumthe whole of Wave 1 step 5 is this; two layouts to pick from on the real device
Model orders too slow to mattermediumthe autopilot handles reflexes; the order rate is tunable; captions make the model's role visible either way
Opus costs more than expectedlowhard server cap per role; meter on screen; Haiku default
WebGL 2 on the TriFoldlowBrainPhotos already runs WebGL 2 there; retro renderer is the fallback
Scope creep into Wave 4 before Wave 1 is solidhigh (it is fun)each wave ships before the next starts

7. Self-critique (this session; the formal Fable adversarial pass runs on the built Wave 1 before it ships)

commander will look clumsy against it. Answer: that clumsiness is the experiment, shown honestly with captions; the

attract-mode autopilot gives a human-free baseline so the model's judgement is what varies.

it a repeatable experiment rather than a party trick; if Wave 3 is not fun on its own, Wave 4 should be reconsidered,

not assumed.

day one; HD sprites checked pixel-for-pixel against the retro ones.

determinism this plan needs; the sim is small (under 1,500 lines) and ours to own.


8. Decision log