Hidden information — cards in your hand, a fog of war, a secret fleet placement — lives inDocumentation Index
Fetch the complete documentation index at: https://openturn.io/docs/llms.txt
Use this file to discover all available pages before exploring further.
G, the authoritative state. The engine decides who sees what when it computes player views. The hosted server sends each client only their view, so opponents never receive the secret bytes.
The rule
- Store everything in
G. The server needs the full state to validate moves. - Never expose secrets in
views.public. Spectators and the default path read this. - Filter secrets in
views.player. Each seat gets its own projection.
A battleship sketch
Fromexamples/games/battleship:
Public view: everyone can see this
Player view: you see your own fleet
views.player is called once per seat. Each player’s response only includes their own fleet. The hosted server sends the right response to each client.
Rules of thumb
- If in doubt, leave it out of
views.public. Adding something later is easier than noticing it leaked. - Use
computedfor counts. Show “opponent has 3 cards” via a computed value (opponentHandSize), not the hand itself. - Beware of array references. Passing
G.players[id].fleetinto the public view exposes it. Destructure first.
Another worked example: Splendor reserved cards
examples/games/splendor applies the same pattern at production polish. Each merchant’s reserved cards live in G.players[id].reserved (full card IDs the server needs to validate buyCard). views.player projects opponents’ reserved arrays down to a count — opponentReservedCount — so the table UI can render face-down placeholders without the IDs ever leaving the worker. The game-package test suite asserts this invariant: opponent reserved IDs never appear in any player’s view, regardless of game state. Use it as the reference implementation when designing your own per-player projections.
Local testing
Because local sessions run the same reducer, you can unit-test the player view:Related
- Concepts: selectors and player views explains the model.
- Reference: react covers
useMatch().state.getPlayerView(...)and the hosted player snapshot.