logo
By Lawrence

5 minutes

One Shared Deck, Each Player's Own Cards

Lesson 7 put a remote fold on the bus, so a seat's intent now reaches every screen. But press deal in two tabs and four browsers deal four different tables. And even sharing one deck wouldn't be enough: the seat-2 player would see seat 0's hole cards at the bottom of their own screen. One idea fixes both. The deck is never sent — every peer computes the same deck on its own, then relabels that same deal into its own point of view.

The deck dealer already sits in the running scene, where it dealt every single-player hand. Two new fields join its block: the seat this browser owns, and the table's occupied seats:

"Dealer": {
  "components": {
    "DeckDealer": {
      "playerCount": 4,
      "cardsPerPlayer": 2,
      "riverSize": 5,
      "localIndex": 0,
      "roomCode": "table-7",
      "handNumber": 0,
      "mySeat": 0,
      "occupiedSeats": [0, 1, 2, 3]
    },
    "PokerSeating": { "cardsPerPlayer": 2, "riverSize": 5, "npcCount": 3 }
  }
}

mySeat and occupiedSeats are the two new lines, and Part 2 uses them to set each player's point of view. roomCode is the shared input that makes Part 1 work — here a placeholder, "table-7", which the next lesson swaps for the server's secret seed. Feed two browsers the same code and they shuffle the identical deck.

How every browser builds the same deck

If both ends can rebuild the deck, none of it has to cross the wire. The dealer seeds its shuffle from createGameRng(roomCode, handNumber). Same code, same hand index. So Fisher-Yates walks the identical swaps on every peer. The only catch is the next hand: when the table reshuffles, every peer has to land on the same new deck, in lockstep, without comparing notes.

Continue reading

Unlock the Full Course

Every lesson, the runnable examples, and the finished build — yours to keep.

$9one-time

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search