Skip to main content
createLocalSession(game, options) is the lowest-level way to run an openturn match. It is a reducer wrapped in a subscribable handle. Everything else (React bindings, hosted server, replay materialization) sits on top of it.

Create

  • match is required. match.players is the seated subset for this session — a non-empty subset of the game’s player pool (game.playerIDs). For variable-player games (e.g. maxPlayers: 4, minPlayers: 2), seat fewer players by passing players: ["0", "1"] etc.
  • seed (optional) is a string used by @openturn/core’s RNG. Omit it and the session generates one. Fix it for reproducible tests.
  • now (optional) is the initial time in milliseconds, used when transitions read context.now. Defaults to 0.

Read state

snapshot is the same shape every part of openturn uses. See concepts: authoritative state and snapshots.

Apply events

The first argument is the player ID, the second is the event name, the rest is the payload. Gamekit moves show up by the move name you gave them (placeMark above), because gamekit emits one core event per move.

Read player views

The engine runs your views.player with that player ID. If you only defined views.public, getPlayerView returns the public shape.

Snapshot the replay data

replayData contains everything needed to reconstruct the match elsewhere: the match roster, the seed, the initial time, and the full action log. Hand it to @openturn/replay’s createSavedReplayFromSession to produce a portable envelope.

Subscribe to changes

The React binding (createOpenturnBindings) uses the same subscription under the hood.

Use in tests

Fixing seed makes the test deterministic across machines.