The three pattern helpers

Three helpers cover most turn-based games. The example games are each built on one, writing your own model is what you do when none fits, and the reference has the signatures.

simultaneous(...)

Every player submits a hidden choice at once; the server resolves them together when all are in.

You supply the submission shape and a scoring function. The helper owns the collect-then-reveal lifecycle and the hidden-state boundary.

Example: battle — secret offensive and defensive moves, where an offense scores unless any opponent blocked it. A duel or an N-player free-for-all.

turnBased(...)

Players act one at a time, and the helper owns turn order and advancement. Anything staking a balance on the outcome wants seeded randomness and a hold.

You supply the shared state, how a move changes it, and win detection.

Example: connect-n — tic-tac-toe at 3×3 connect 3, Connect Four at 7×6 connect 4, gomoku at 15×15 connect 5. One model, three games, config apart.

wageringTable(...)

A persistent casino table. The helper owns the bet book, the ledger holds, the settlement and the table lifecycle.

You supply what a valid bet is, who may trigger the random event, and how it decides each bet.

Example: craps — pass and don’t-pass and field bets, come-out and point phases, shooter rotation, with the house as the off-ledger counterparty.

A craps table is config:

multiplayer({
  games: [
    {
      key: "craps",
      kind: "craps",
      mode: "table",
      players: 8,
      rules: { currency: "chips", minBet: 5, maxBet: 100 },
    },
  ],
})

Which one to reach for

Your gameHelper
Everyone chooses at once, then it resolvessimultaneous
One player acts, then the nextturnBased
A table that stays open across rounds, with money on itwageringTable
None of these**The raw **seam

Pick the closest pattern before writing a model from scratch. The plumbing a helper owns — turn advancement, the collect-then-reveal boundary, a bet book with its holds — is where the mistakes live, and it is the same for every game of that shape.

What “only the game logic is yours” means

The session is the same for every game: membership bound to an authenticated user, a lifecycle, hidden per-player state, an alarm-driven deadline, a durable result in your D1, a one-way leaderboard publish.

The examples are examples, not a library you are stuck inside. battle, connect-n and craps ship as working games and as the demonstration of how to build one on each helper.

ESC