Real-time online chess on Cloudflare — a Radical Party project
Play by shareable link, vs the Radical Bot, or pass-and-play. Server-authoritative moves (chess.js) in a per-game Durable Object, clocks with idle flag-fall via DO alarms, draw/resign/rematch/chat, D1 game archive, custom board UI (drag + click). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| client | ||
| migrations | ||
| public | ||
| src | ||
| .gitignore | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| wrangler.jsonc | ||
♞ Radical Chess
Real-time online chess, live at chess.theradicalparty.com. A Radical Party project — Vibe, Vote, Veto.
Play a friend by shareable link, take on the homegrown Radical Bot, or pass-and-play on one device. No account, no ads.
Features
- Play online — create a game, pick a time control, share the link. Moves stream live over WebSockets; reconnect keeps your seat.
- Server-authoritative — every move is validated server-side with chess.js; illegal moves are rejected.
- Clocks — bullet → classical presets with increment, plus an unlimited mode. Flag-fall is detected even when a player is idle (Durable Object alarms).
- Full ruleset — castling, en passant, promotion, checkmate, stalemate, threefold repetition, insufficient material, fifty-move rule.
- Draw offers, resign, rematch (colors swap on rematch), and in-game chat.
- Radical Bot — a minimax + alpha-beta engine (Easy / Medium / Hard) with piece-square evaluation, running entirely client-side.
- Spectate — anyone with the link watches live once both seats are taken.
- Game archive — finished games are stored (PGN) and listed under
/watch.
Stack
- Cloudflare Workers + Hono — HTTP + WebSocket routing
- Durable Objects — one instance per game holds authoritative state and broadcasts to all sockets using WebSocket hibernation
- D1 — finished-game archive and public feed
- Static assets — vanilla-JS SPA; the board is rendered from scratch (drag-and-drop + click-to-move, no external board library)
Layout
src/index.js Worker entry (Hono) — /api/new, /ws/:id, /api/recent
src/game.js Game Durable Object — rules, clocks, chat, archival
client/app.js SPA: router, board UI, online/bot/local views, bot engine
public/ index.html, style.css, built app.js (public/dist)
migrations/ D1 schema
Develop
npm install
npm run dev # builds client, runs wrangler dev
Deploy
Pushing to main auto-deploys via the Forgejo post-receive hook
(npm run build:client runs automatically before wrangler deploy).
npm run db:migrate # apply D1 migrations (remote)
npm run deploy # wrangler deploy