No description
  • TypeScript 86.7%
  • CSS 10.9%
  • Python 1%
  • JavaScript 0.6%
  • HTML 0.5%
  • Other 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-12-04 13:44:08 -05:00
openspec Archive review-the-usability-of-the-mobile-exper-mvvsn9 2026-12-04 15:05:13 +00:00
packages UX review pass: brighter felt and tavern backdrop, lighter landing and room overlays, service worker bump 2026-12-04 13:44:04 -05:00
scripts apply: implement the change and its tests 2026-11-11 04:56:51 +00:00
.dockerignore apply: implement the change and its tests 2026-11-06 10:16:22 +00:00
.gitignore apply: implement the change and its tests 2026-12-04 10:19:29 +00:00
.npmrc propose: the change, its specs, its tasks and its estimate 2026-11-06 07:01:25 +00:00
.nvmrc propose: the change, its specs, its tasks and its estimate 2026-11-06 07:01:25 +00:00
AGENTS.md propose: the change, its specs, its tasks and its estimate 2026-11-06 07:01:25 +00:00
Dockerfile apply: implement the change and its tests 2026-11-06 10:16:22 +00:00
package-lock.json apply: implement the change and its tests 2026-11-11 04:56:51 +00:00
package.json apply: implement the change and its tests 2026-11-11 04:56:51 +00:00
README.md apply: implement the change and its tests 2026-12-04 10:19:29 +00:00
tsconfig.json apply: implement the change and its tests 2026-11-11 04:56:51 +00:00
vitest.config.ts apply: implement the change and its tests 2026-11-06 10:16:22 +00:00

Scratch

A multiplayer online trick-taking card game in the Oh Hell family. Bid how many tricks you think you'll win, play to win exactly that many, and collect the fewest scratches to take the game. Play against friends in real time over the web — create a room in one browser tab, share the 4-letter code, and join from as many as four more.

The game is a small npm-workspaces monorepo:

  • packages/shared — the rules engine (deck, bidding, play, scoring, winner) and the client/server protocol types. Pure TypeScript, no I/O.
  • packages/server — a Socket.IO server that owns rooms and authoritative game state, and serves the built client. One process, one port.
  • packages/client — a React + Vite + TypeScript single-page app.

Requirements

  • Node.js 26 (the repo pins 26 in .nvmrc; anything >= 20 works). If you use nvm, nvm use in the repo root picks the right version automatically.
  • npm (ships with Node).

Install

nvm use          # optional: select Node 26 from .nvmrc
npm install

This installs the root and all workspace dependencies.

Run it locally

npm start

npm start typechecks, builds the client, and starts the server. When it prints Scratch server listening on http://127.0.0.1:3000, open that URL in your browser.

For development with server auto-reload on change:

npm run dev

npm run dev builds the client once, then runs the server under tsx watch so server edits reload automatically. Re-run it after client edits to rebuild.

The server binds to 127.0.0.1 by default and reads the port from PORT (default 3000). To serve on a specific host/port:

PORT=8080 HOST=0.0.0.0 npm start

Play a full game with multiple browser tabs

Everything runs from the same origin, so each browser tab (or window, or machine on your network) is a separate player:

  1. Open http://127.0.0.1:3000 in a first tab. Enter a display name, pick an avatar (remembered on this device for next time), and choose Create game. Pick your house rules (schedule, first lead, dealer restriction), the game speed (Relaxed, Normal, or Fast), and the four-colour deck and tap-once-to-play options, and create the room. You'll see a 4-letter room code.
  2. Open the same URL in a second tab (a private window works too). Enter a different display name and choose Join with code, then type the room code. (You can also use Browse open games to see and join rooms by name.)
  3. Back in the first tab, the room now shows both seats. The creator presses Start game.
  4. Play: bid when it's your turn, then tap a card to select it and tap it again (or press Enter) to play it. Cards you're not allowed to play are dimmed.
  5. When the final round ends, the end screen shows the winner. Everyone presses Accept rematch to play again with the same players and settings.

Playing with bots

The creator can fill empty seats with named bots from the waiting room. Each bot plays in its own style:

  • Cautious Carl — bids almost nothing and dumps low cards.
  • Bluffing Bea — bids and plays unpredictably.
  • Aggressive Archie — bids high and fights for every trick.
  • Master Marge — counts the cards and plays to hit her bid exactly; the bot to beat.
  • Grandpa — bids zero and ducks everything; quietly banks the easy point.

Tap an empty seat to open the bot picker — a row of avatar chips, one per bot — and tap a chip to seat that bot. The Fill seats with bots button below the seat list takes the whole table in one tap (it is disabled once the table is full). Remove a seated bot with Remove on its seat row. Bots are played automatically by the server and accept rematches on their own, so a room with one human and four bots plays itself to the end.

The server also understands a fill:bots intent (exposed on the window.__app test surface as fillBots(n)) that seats bots from the roster in order — used by the automated judge and handy for a quick solo game.

Seated bots act with a short randomized delay (roughly 0.8–2.5 s per move) so a table of bots feels human-paced rather than instant; the delay is applied by the server, so every player sees the same pacing. The automated judge and smoke runs opt out of it by starting the server with SCRATCH_BOT_DELAY_MS=0, which makes bot moves apply instantly:

SCRATCH_BOT_DELAY_MS=0 npm start

The server also reads SCRATCH_SEED=<n>: with a seed set, every game draw (deals, trumps, bot moves) comes from a seeded PRNG, so a run is reproducible from round 1 onward. Unset (or not a number) keeps the normal random games.

Deploy with Docker

A multi-stage Dockerfile builds the client and runs it together with the server in a single small Node image:

docker build -t scratch .
docker run --rm -p 3000:3000 scratch

Then open http://127.0.0.1:3000. The container listens on port 3000 inside; map it to any host port with -p. Set HOST=0.0.0.0 if you need to reach it from outside the container's network:

docker run --rm -p 3000:3000 -e HOST=0.0.0.0 scratch

Install as a PWA

The app is installable: on iOS, use Safari's Share → Add to Home Screen; on Android/Chrome, use the address-bar install icon. It launches in standalone mode (no browser chrome) with its own icon, and a service worker caches the app shell so it opens instantly — and still loads when the network is down (a game itself needs a connection, since it is played in real time over WebSockets).

Launching is dark from the first painted frame (the background is set on html inline in the document head, before any stylesheet loads, so there is no white flash), iOS shows a branded startup (splash) image while the app loads, and the layout respects the phone's safe areas so nothing sits under the status bar or the home indicator. The manifest lists a separate maskable icon, so the home-screen icon is never cropped to a circle or squircle.

The splash images and the maskable icon are generated PNGs (a felt background with the wordmark; the icon art padded into the maskable safe zone). To regenerate them after a brand change, run the script with Pillow and the Pacifico font available (pass the font path as the first argument if it is not in the default locations):

python3 scripts/generate_pwa_assets.py /path/to/Pacifico-Regular.ttf

How to play Scratch

The same rules are available in-app under Help (reachable from the landing screen, the lobby, and the table).

  • Goal. Win exactly the number of tricks you bid. Fewer scratches than everyone else wins the game.
  • Rounds. Down plays 10 rounds, dealing 10, 9, 8, …, 1 cards per player. Down-and-Up plays 19 rounds: 10 down to 1, then 2, 3, …, 10 (the 1-card round is never repeated).
  • Trump. After each round is dealt, one card is flipped face up. Its suit is trump for that round and stays visible to everyone.
  • Bidding. Bidding starts with the player left of the dealer and goes clockwise, with the dealer last. Each player bids from 0 up to their hand size — the number of tricks they expect to win. All bids are public.
  • Play. The first trick is led, then play goes clockwise. You must follow the suit led if you can; if you have none, play anything. The highest trump wins the trick, otherwise the highest card of the led suit. The winner leads next.
  • Scratches. At the end of a round, any player who did not win exactly their bid — over or under — takes one scratch.
  • Winner. After the final round, the player with the fewest scratches wins. Ties are broken by the most total tricks won; if still tied, the win is shared.
  • House rules.
    • Dealer restriction (default off): when on, the dealer may not bid the number that would make the total of all bids equal the number of tricks in the round.
    • First lead (default player left of dealer): who leads the first trick of each round. The alternative, highest bidder, makes the highest bidder lead, with ties broken toward the dealer's left.

Tests

npm test

Runs the whole suite with Vitest: rules-engine unit tests (bidding, play, scoring, winner, and a full-game replay harness across every house-rule combination), server integration tests (rooms, sessions, legality, disconnection, rematch) driven by real Socket.IO clients, and client unit tests (the Web Audio sound module).

There is also one browser smoke test (Playwright) that builds the client, starts a zero-delay seeded server (SCRATCH_BOT_DELAY_MS=0, SCRATCH_SEED=7), creates a game with three bots through the app's window.__app surface, and asserts the table screen is shown. It also runs the mobile audit: an entire round driven through deal, bid, play, the trick hold, the round-end summary and the next round, at 390x844 portrait and 844x390 landscape phone viewports and a 768x1024 small-tablet viewport — one screenshot per moment saved into the Playwright output directory (not the repo) — with the audit's checks asserted at each viewport: every seat renders a resolved avatar and name and its trick pile, every tappable element is at least 44x44 pt, no element overlaps a seat, the compact layout applies, the viewport meta carries no zoom restriction, the served manifest carries no portrait-only orientation lock, and the offline banner appears on a dropped connection and hides when the connection returns.

npx playwright test --config packages/client/e2e/playwright.config.ts

To typecheck without running tests:

npm run typecheck

Project layout

packages/
  shared/    Rules engine + protocol types (no I/O)
  server/    Socket.IO game server + static client hosting
  client/    React + Vite single-page app