# Cribbage Board

## Running it

```
npm install
npm start
```

This starts a server on `localhost:47121`, reachable only from this machine.
The odd default port keeps it from colliding with other node apps on the box.
On startup it prints the room links:

```
Cribbage board running on 127.0.0.1:47121
  http://localhost:47121/gpy
  http://localhost:47121/gma
  http://localhost:47121/dad
```

Overrides:

- `PORT=xxxx npm start` -- different port.
- `HOST=0.0.0.0 npm start` -- also listen on the LAN, so other devices on your
  network can reach it. In that mode startup also prints `network:` links with
  your LAN IP; share the one for the right room with the other player.

If you see `Port ... is already in use`, either an old copy is still running
(`lsof -iTCP:47121 -sTCP:LISTEN`, then `kill <pid>`) or just pick another port
with `PORT=48000 npm start`.

## Rooms

`/gpy`, `/gma`, and `/dad` are three fixed 2-player rooms (names in
`rooms.json`). Opening one shows a one-time "who's playing" picker; the choice
is remembered on that device (localStorage), so reloading or reopening the
link goes straight back in as the same player.

Everything on the board -- pegs, cards, the deck, whose turn/dealer it is --
stays synced live between the two players in a room, including while
something is mid-drag. Each player's own hand is only ever shown on their own
screen.

Opening `cribbage_board.html` directly (no room path) still works exactly as
a single-screen, unsynced local board, e.g. for one person playing both
hands, or offline.

## Files

- `server.js` -- static file server + the websocket relay (`ws`) that syncs
  each room. It doesn't know cribbage rules; it just remembers the latest
  full board snapshot per room and rebroadcasts every message to the other
  socket(s) in that room.
- `rooms.json` / `js/rooms.js` -- the fixed room -> player-name mapping (kept
  in the two places since the server needs it in Node and the client needs it
  synchronously before anything else runs).
- `js/multiplayer.js` -- room detection, the name picker, the websocket
  connection, and the remote-cursor colour math.
- `js/board.js` / `js/config.js` / `css/style.css` -- the board itself.
