Skip to main content
Deterministic replay is one of openturn’s core guarantees: an action log plus a seed reproduces the exact match. This tutorial captures a tic-tac-toe match, persists it as JSON, and builds a viewer that loads replays and replays them locally. It reuses the @my/tic-tac-toe-game package from tutorial 1. Reference code: examples/replays/tic-tac-toe-replay-viewer.

1. Capture a replay from a local match

@openturn/replay turns any local session’s action log into a serializable envelope.

From the React app

In the React component from tutorial 1, add a “download replay” button:
replayData is exposed on the local match.state. It carries the initial bootstrap, the seed, the initial time, and the action log. createSavedReplayFromSession wraps it into a versioned envelope.

From the CLI

If you also ran the CLI variant, pass --save-replay <path>:
Both paths produce the same JSON shape, so the viewer can load either.

2. Build a viewer app

A replay viewer is just another local-runtime openturn app that, instead of letting the player click, replays a loaded action log.

app/app/openturn.ts

app/app/page.tsx

Same shape as before — it renders a React component.

app/src/components/TicTacToeReplayViewer.tsx

The viewer runs a fresh local session, resets it, and re-dispatches the recorded actions in order. Because the authored game is deterministic, the resulting snapshot on each step is byte-identical to the original match.

3. Browse frames with inspector

For an interactive timeline, drop in the ReplayInspector returned by @openturn/inspector-ui’s createInspector. It gives you a timeline, state diff viewer, and graph highlight:
The inspector materializes the envelope internally with materializeSavedReplay, then renders the timeline, frame diffs, and graph highlights.

What you learned

  • @openturn/replay serializes matches into a versioned JSON envelope.
  • Replaying is just re-dispatching the recorded actions against a fresh session.
  • @openturn/inspector-ui turns a timeline into an interactive inspector with no extra code.

What to do next