Skip to main content
Worker-safe. Compiles to a normal GameDefinition<...> from @openturn/core. Every gamekit game is a core game.

Install

Authoring

defineGame(definition)

maxPlayers, playerIDs, and minPlayers work the same as in core’s defineGame — see @openturn/core. Pass exactly one of maxPlayers (default IDs) or playerIDs (named seats); set minPlayers lower than the pool size for variable-player games.

move(definition)

Build a move. Supports three forms:
A move definition:

defineMoves(moves)

Typing helper for a { [name]: move(...) } record. Optional; inlining the record works too.

defineProfile(config)

Gamekit-flavored re-export of core’s defineProfile. Same signature, but defaults the result type to GamekitResultState | null so commit({ result }) gets result.winner typed without a cast. See Profiles below.

GamekitSetupContext<TPlayers, TProfile>

The context passed to setup(context). Provides:
Use the typed match (with match.players) so helpers like roster.record(match, 0) narrow to the declared player IDs. RNG is created from seed by gamekit itself; setup runs before any random draws.

Outcomes (move.*)

move.finish accepts any JSON-compatible record as the result; the conventional shapes — { winner: playerID } and { draw: true } — are typed for ergonomics, but multi-winner, ranked, scored, and co-op results are all valid:
Every non-invalid outcome accepts a final options bag with { enqueue?, profile? }:
  • enqueue?: readonly QueuedEvent[] — internal follow-up events to chain.
  • profile?: ProfileCommitDeltaMap — per-player profile deltas applied atomically with the move. Build them with profile.bind(...).inc/push/set/remove or profile.update(...). Apply failures reject the move. See persistent profiles.

Turn policies

turn.roundRobin()

The only built-in turn policy. Assigns currentPlayer as players[(turn - 1) % players.length].

Views

view.computed(context, ...keys)

Pluck computed values into a view:

view.merge(base, context, ...keys)

Spread computed values into an existing object:

Modifiers

Helpers for composing modular effects (auras, buffs, item effects) into a final value through a callback-based modifier pipeline. Re-exported under modifiers from ./modifiers.
  • modifiers.evaluateValue({ base, context, modifiers, stageOrder? }) — fold an ordered list of modifiers over base, returning { value, applied }.
  • modifiers.evaluateNumber(...) — same as evaluateValue with TValue = number.
Modifiers are sorted by stage (using stageOrder plus first-seen order for unknown stages), then priority (higher first), then declaration order. Pass an empty context object ({}) when you do not need a context.

Modifier types

Modifier.id must be non-empty; stageOrder entries must be non-empty and unique (the helper throws otherwise).

Profiles

Gamekit’s defineGame accepts an optional profile field that hydrates match.profiles before setup and runs a pure commit function when the match terminates. The API is re-exported from @openturn/core:
Gamekit’s result is Record<string, JsonValue | undefined> & { draw?: true; winner?: PlayerID }, so commit can read result.winner (or any custom field your game records). Also re-exported: applyProfileDelta, computeProfileCommit, validateProfileDelta, and the delta grammar types. See concepts: persistent profiles and how-to: persist player state.

Core escape hatch

For the rare case gamekit’s shape does not fit, pass raw core pieces via core:

Key types

  • GamekitDefinition<...> — the shape of the input definition.
  • GamekitMoveDefinition<...> — a single move.
  • GamekitPhaseConfig<...> — a phase’s configuration (activePlayers, label).
  • GamekitState<TState> — the internal wrapper type (TState & { __gamekit: GamekitInternalState }). You rarely touch it; it is exposed for typing views in edge cases.
  • GamekitInternalState — the private compartment gamekit owns inside a game’s G. Exposed at runtime as G.__gamekit. Carries the optional result: GamekitResultState | null plus arbitrary JSON-shaped slots gamekit reserves for future internal state. You should not write to it directly; use move.finish / move.invalid instead.
  • GamekitResultStateRecord<string, JsonValue | undefined> & { draw?: true; winner?: PlayerID }.
  • GamekitViews<...> — the shape of the optional views field on a GamekitDefinition.
  • MovePlayerContext, MovePermissionContext, MoveRunContext — the context passed to run (and the slice of it that’s also available on phase resolvers).
  • MoveOutcome, MoveHelpers — outcome and helper types.
  • TurnContext, TurnPolicy — turn types.

See also