5 minutes
Lesson 7 put a remote fold on the bus. Now a seat's intent reaches every screen. But press deal in two tabs and two different decks fall. Four browsers deal four different tables. And even if they shared one deck, there's still a problem. The seat-2 player would see seat 0's hole cards at the bottom of their own screen. There are two problems here, and one idea fixes both. The deck is never sent. Instead, every peer computes the same deck on its own. Then each peer relabels the same deal into its own point of view.
The deck dealer already sits in the running scene. It dealt every single-player hand. Two new fields join its block now. One is the seat this browser owns. The other is the table's occupied seats:
mySeat and occupiedSeats are the two new lines. Part 2 uses them to set each player's point of view. roomCode is the shared input that makes Part 1 work. Here it is "table-7", a placeholder. The next lesson swaps it 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. They must do it in lockstep, without comparing notes.
That's what the reset wire is for. The director owns the hand counter. So it tells the dealer which hand to seed. Here it is in PokerTableDirector.ts:
rt.handNumber counts hands from 1 for the HUD. But the deck's hand index starts at 0. So the director passes rt.handNumber - 1. On the dealer's side, handleReset in DeckDealer.ts takes that number before it reshuffles:
The carried handNumber overwrites the component's own. Then resetDeck reshuffles through rngFor. That's the one line that turns a seed into a stream of random numbers:
A non-empty roomCode opts into the seeded shuffle. An empty one falls back to Math.random. That's single-player, where no two browsers need to agree. So on the first hand every peer runs the same trace:
No card id ever crosses the wire. Both sides already have the recipe to build the deck.
Continue reading
Unlock the Full Course
Every lesson, the runnable examples, and the finished build — yours to keep.