Nim Stack

Q8FMADE BY Qwen3.8-Flash-Next

Nim duel with matchsticks against three CPU brains. Take any number of sticks from one row; whoever is forced to take the last stick loses. A live NIM SUM readout shows the XOR of the rows, and H flashes the safe move once a bout.

▸ CARTRIDGE SLOT · NIM STACK
↗

* THE GAME RUNS IN A SANDBOXED FRAME — IT CAN’T SEE THIS SITE OR YOUR OTHER TABS. BEST SCORES STAY IN THIS BROWSER.

Cartridge promptTHE EXACT PROMPT THAT BUILT THIS GAME
Build a tiny browser game called "Nim Stack".

Game spec
---------
A pile-of-sticks nim duel against a CPU. Three rows of glowing matchsticks sit on a dark table; on your turn you take any number of sticks from ONE row only — click and drag across sticks, or use the arrows to move a cursor plus Up/Down to choose how many and Enter to take them. Whoever is forced to take the last stick loses. The CPU has three brains: easy takes a random legal amount, medium plays the correct binary-nim sum only when one row already decides it, hard always plays to a zero nim-sum and will trap you if you hand it one. A small NIM SUM readout in the HUD shows the XOR of the row lengths so the player can learn the winning idea, and a hint key (H) flashes the safe move once per bout. Winning a bout scores 300 plus 20 per stick left on the table, the next bout starts from a bigger random layout, and losing ends the run with a score screen and retry. Matchstick-and-brass look: warm amber sticks with lit heads on charcoal slate, beveled brass row plates, a match-strike spark on take, and a gold ring around the row the CPU just hit.

Hard constraints — the game will be embedded in a sandboxed iframe on a static gallery site, and a headless browser will screenshot it:

1. Output exactly ONE self-contained HTML file. All CSS and JS inline. Zero external requests: no CDNs, no external fonts, images, or sounds, no fetch/XHR/WebSocket. Any sound must be synthesized with WebAudio.
2. The iframe sandbox is "allow-scripts allow-pointer-lock" (plus an autoplay permission). So: no localStorage, cookies, or indexedDB (opaque origin — access throws); no popups, window.open, or navigation; no access to the parent page; alert()/prompt()/confirm() are silently blocked.
3. The playfield must be visible within 800 ms of load — that is when the screenshot is taken. No dead white screen. If there is a start screen, make it visually rich.
4. Controls: keyboard AND mouse must both work, plus on-screen touch buttons for phones. Call preventDefault() on game keys (arrows, space) so the page never scrolls.
5. The view is 16:9 and must scale to fill the viewport with no overflow or scrollbars.
6. Show a visible score. If the genre has a losing state, show a game-over screen with a restart (button and a key). Idle/clicker games skip game over but still need clear numeric feedback.
7. If you track a score, report it to the arcade shell so the player's best is remembered between visits: on every score change, call parent.postMessage({ source: "ai-arcade", type: "score", score: <number> }, "*"). It is safe to call it no matter what the parent does with it.
8. Keep it tiny: aim for under 400 lines, 60 fps, no frameworks. That 400-line target does not apply to 3D games — true 3D (a camera and perspective-projected world) or pseudo-3D (projected road/track, depth-sorted sprites) — which need their own software renderer and typically land at 800–1400 lines. The rest of this constraint still binds every game: 60 fps, no frameworks, no external assets, and no padding to reach a length.
9. Difficulty: the arcade shell passes the player's chosen difficulty as a URL query parameter. Read it with new URLSearchParams(location.search).get("difficulty") — the value is "easy", "medium", or "hard" (missing or unknown means "medium"). Make the three levels meaningfully different — speed, lives, enemy pressure, reaction time, whatever fits the genre; clicker/idle games with no losing state use starting resources and upgrade cost curves instead. Show the active level in the HUD. Without the parameter the game must be fully playable at its default (medium) tuning.

Return only the complete HTML file, no commentary.