Fair badminton nights, no peg board.

A peg board depends on one volunteer, gives uneven court time, repeats the same partners and produces lopsided games. CourtPilot replaces it with a desktop app that checks players in, picks balanced and varied foursomes automatically, puts them on courts and shows the result on a big screen — all evening, with zero internet.
I wrote the functional spec and engine spec, then built the whole thing: the allocation engine, the SQLite data layer, the Electron app, the TV display, licensing and the Windows installer.




03Features
Every screen hangs off one question the engine answers in under 200 ms: who plays next, with whom, and against whom?
A weighted cost — predicted balance, skill spread, partner and opponent repeats, mixed ratio, fixed pairings — scored over every split, then a greedy build and seeded local search.
Players start from an admin grade of 1–10; OpenSkill ratings update after every result, so the engine’s idea of “even” sharpens week by week.
“Balanced 50–50 · Ana waited longest · First time Ana & Ben partner” — a short reason under each court, so nobody has to ask the volunteer.
Timer mode rotates every court together on a countdown. Game mode lets the captain pick a team — Suggest, Manual with live balance, or Auto — and courts turn over as games end.
Drag players between courts, switch two players, lock a court, pause a player or sit them out, and undo — every change written to the database first.
Barcode check-in cards and a USB scanner, CSV import, pairings and rules, fees by cash, card or UPI, reports with CSV export, and backup to a USB stick.
The engine is plain TypeScript with no I/O: time, the random seed and all state are passed in, so the same input always gives the same pick. The renderer never touches Node or the database — only typed tRPC procedures over Electron IPC. Hover a node to trace its connections.
Offline is enforced three ways: a CSP, a request filter that cancels anything not bundled, and lint bans on fetch and WebSocket.
A crash test SIGKILLs a live session mid-round; the recovered state is byte-identical.
05Tuning
Each simulated player gets a hidden “true skill”, results are decided by a logistic function of the skill gap, and whole sessions are replayed on fixed seeds. The acceptance bar is strict: games-played spread of at most one, nobody sitting out two rounds in a row, 80% of courts inside 40–60 predicted balance, no partner pair repeating more than twice, and ratings that rank players by true skill with a Spearman correlation of at least 0.8.
The spec’s default weights failed it — at the original selection penalty, balance won and some players fell three or four games behind. The fix was to raise three weights, confirm them on fresh seeds, and record every trade-off. Game mode got its own weights after the sim showed a fixed captain plus a FIFO queue can never hit the timer-mode bar; its threshold is now measured against a plain queue on the same seeds.

0 milestones (M0 → M10, two days), 0 unit tests (Vitest · engine, db, app), 0 end-to-end tests (Playwright against Electron), < 0 ms pick budget (16 courts · 100 players), 0 sim scenarios (fairness · balance · learning) and 0 network calls (offline, enforced).
Counted from the repo, the engine spec and the simulation suite.
11 Oct
A functional spec split into MVP and Full Product, an engine spec with every cost term and acceptance threshold, and eleven milestones.
15 Oct
Ratings, timer-mode picks and game-mode suggestions as pure TypeScript, tuned against the simulation suite before any UI existed.
15 Oct
Drizzle schema, embedded migrations, repositories, tRPC routers and crash recovery from rows, not snapshots.
16 Oct
Check-in and overrides, timer and game mode end to end, the TV display, payments, reports and backup.
16 Oct
Offline Ed25519 licence activation, auto-updates, a soak test of four session-hours, and a signed one-click Windows installer.
A drop page you steer with the cursor.