work / unsound-chess

Unsound Chess

Chess for people who play outside the book.

Crisp 2D chess with premoves, a human-like neural opponent that runs in the browser, real-time online games with clocks and spectators, and a one-click 3D battle mode where captures turn into fights. Built on Cloudflare Workers and Durable Objects.

status
beta
started
November 2026
domain
Games · Chess
role
Everything. Game design, rules engine, 3D, multiplayer, infrastructure.
layers
Product · Interface · Application · Data · Edge & network · Security
stack
Vanilla JS (ES modules, no build step)three.jsMaia-3 via onnxruntime-web (WASM)Cloudflare WorkersDurable Objects (WebSockets)D1 (SQLite)R2Workers Rate Limitingnode:test
  • 9neural opponent levels, 600 to 2500
  • 197kperft(4) positions, checked
  • 4time controls online
  • 0build steps

The idea

Most chess sites are built around the engine’s verdict: every move gets a number, and the number says your gambit was unsound. Unsound Chess leans the other way. It is for playing the sharp, dubious, fun lines, against an opponent that plays like a person at your level rather than a machine that punishes everything.

What it does

  • A human-like opponent, on your device. The AI is Maia-3, a small transformer trained to predict the move a human of a given rating would play. It runs in the browser through onnxruntime-web (WebAssembly), cached after the first load, at nine levels from 600 to 2500. Nothing about your game leaves the page.
  • Online play. Quick match or a private room with a code, 3+2, 5+0, 10+0 or untimed, premoves, ratings, and a link that lets anyone watch live.
  • Variants that break the rules on purpose. Poison Chalice: each side secretly poisons one of its own pieces, and whoever captures it pays. Loki Chaos: as the clock runs down, lightning strikes random pieces off the board, while the position always stays legal.
  • 2D by default, 3D in one click. The everyday board is flat and fast. Battle mode swaps in a three.js board where pieces are animated characters and every capture plays out as a short fight.

How it is built

The client is plain ES modules served as static files, with three.js and the model runtime loaded from a CDN through an import map. There is no bundler and nothing to compile.

The rules engine is shared. The same chess.js module runs in the browser for instant feedback and inside the server for the final word. It is checked by perft (counting every legal position to a given depth from known positions, start position to depth 4 and Kiwipete to depth 3) plus tests for castling, en passant, repetition and the variants.

Each online game is a Durable Object. One object per room holds the authoritative position and the clocks, accepts moves over a WebSocket, validates them with the shared engine, and broadcasts to both players and any spectators. A second Durable Object tracks who is online for the lobby. Accounts, ratings and finished games live in D1; 3D models sit in R2 behind the Worker.

Decisions worth writing down

The server owns the game, the client owns the feel

Premoves and animations happen locally so the board never waits on the network, but a move only counts once the room’s Durable Object has applied it. Variants with hidden state, like which piece is poisoned, are resolved on the server, so the other player’s browser never has the secret to leak.

Run the AI where the player is

A neural opponent on a server costs money per move and adds latency. Running a 5M-parameter model in WebAssembly costs nothing after a one-off download, works offline, and scales with the number of players for free.

Small, strict edge

Sign-in, room creation and other abuse-prone routes sit behind per-IP rate limits, sessions are HttpOnly cookies, and the Worker only runs for /api, /auth, /ws and model routes; everything else is a static asset straight from the edge.