Worker-safe. Compiles to a normalDocumentation Index
Fetch the complete documentation index at: https://openturn.io/docs/llms.txt
Use this file to discover all available pages before exploring further.
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:
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:
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.*)
| Helper | Compiles to |
|---|---|
move.stay(patch?, options?) | same phase, turn: "preserve" |
move.endTurn(patch?, options?) | same phase, turn: "increment" |
move.goto(phase, patch?, options?) | target phase (options.endTurn?: boolean) |
move.finish(result, patch?, options?) | terminal __gamekit_finished with the given result |
move.invalid(reason?, details?) | rejectTransition(reason, details) |
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:
{ enqueue?, profile? }:
enqueue?: readonly QueuedEvent[]— internal follow-up events to chain.profile?: ProfileCommitDeltaMap— per-player profile deltas applied atomically with the move. Build them withprofile.bind(...).inc/push/set/removeorprofile.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 undermodifiers from ./modifiers.
modifiers.evaluateValue({ base, context, modifiers, stageOrder? })— fold an ordered list of modifiers overbase, returning{ value, applied }.modifiers.evaluateNumber(...)— same asevaluateValuewithTValue = number.
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’sdefineGame 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:
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 viacore:
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’sG. Exposed at runtime asG.__gamekit. Carries the optionalresult: GamekitResultState | nullplus arbitrary JSON-shaped slots gamekit reserves for future internal state. You should not write to it directly; usemove.finish/move.invalidinstead.GamekitResultState—Record<string, JsonValue | undefined> & { draw?: true; winner?: PlayerID }.GamekitViews<...>— the shape of the optionalviewsfield on aGamekitDefinition.MovePlayerContext,MovePermissionContext,MoveRunContext— the context passed torun(and the slice of it that’s also available on phase resolvers).MoveOutcome,MoveHelpers— outcome and helper types.TurnContext,TurnPolicy— turn types.