pkg:clod/com.clodhub/turn-engine 0.13.0 The game-independent engine behind a multiplayer table: lifecycle, checked actions with error codes, turn order, scheduled steps, and the GameAdapter that realtime-rooms calls. It drives a game through the game-rules interface and composes seating, clock, views, presence, tournament, computer players, history and settings by injection. `turn-engine` runs a multiplayer table for any turn-based game: people gather in a lobby, the game starts, rounds follow one another with turns that time out, and the table ends, all on the server, so every player's screen agrees. The game itself (poker, rummy, a quiz) plugs in through the `game-rules` interface. In detail, it runs the lifecycle (lobby, started, a cycle of rounds with rebuy offers between them, completed or cancelled, and back to a lobby), checks every action and answers with an error code, keeps turn order (the actor, a settle time, a decision countdown, acting for absent or timed-out players, computer moves), schedules everything that falls due (`advance`, `computerMove`, `nextWake`), builds the per-viewer view with legal actions and prompts, and exposes all of it as the GameAdapter that realtime-rooms calls. It contains no game rules, seating, clocks, presence tracking, chip accounting, tournament placing or computer play: each is injected, and a game plugs in through the `game-rules` interface. Examples Two people and a computer sit; the host starts; a counting game is played one move at a time; the loser of enough rounds is offered a rebuy, declines by silence, and the other is crowned; thirty seconds later the room is a lobby again. A person's connection drops mid-round: the table keeps running, the person is acted for when their countdown ends, and their next turns are acted for as soon as the settle ends. The host goes away between rounds: everything pauses until the host is back. Package URL: pkg:clod/com.clodhub/turn-engine@0.13.0 Class: Turn engine (pkg:clod/com.clodhub/turn-engine-class@1.1.0): Lobby, turns, timing and computer players around a game's own rules. Any component of this class can fill a recipe slot that asks for it. Category games/turns-and-timing; https://clodhub.com/classes/turn-engine-class.txt; 0 other components of this class: https://clodhub.com/components.txt?class=pkg%3Aclod%2Fcom.clodhub%2Fturn-engine-class Provides (1) - game-adapter (com.clodhub/game-adapter 1.0.0): The GameAdapter a room server calls (realtime-rooms), over a turn engine that drives any game written to com.clodhub/game-rules. Build it with createGameAdapter(parts, settings), where parts holds one implementation of each required interface; methods named `GameAdapter.` are members of the object it returns. State is JSON-serialisable and every method is pure. Wire actions: start, addBot, kick {playerId}, leave, sitOut, return, pause, resume, cancel, newGame, rebuy {accept}, and any move the game's parseMove accepts. Error codes and HTTP status: badName 400, badRequest 400, roomFull 409, staleVersion 409, badToken, notYourTurn, wrongPhase, notEnoughPlayers, badAmount, badTarget, notAllowed, paused, unknownPlayer 422; a code a game reports that is not in this list is sent as notAllowed. Without a computer-players part (parts.computers omitted) addBot is refused and no seat is filled. TypeScript, `implementation/server/adapter.ts` (engine.ts, parts.ts, no-computers.ts). components that use it: https://clodhub.com/components.txt?requires=com.clodhub%2Fgame-adapter Requires (9) - game-rules (com.clodhub/game-rules 1.0.0): The game-rules interface a turn engine drives, provided for Texas hold'em. Build it with createGameRules(deps, settings, pacing); methods named `GameRules.` are members of the object it returns. A round is { hand, autoSteps }: JSON-safe and opaque to the engine. The chip ledger (com.clodhub/chip-ledger) is passed in and returned on every call that moves chips; the hand moves chips only through chip-ledger operations, so the ledger's sidePots, oddChipRule and minimumUnit settings decide the pots. Every operation is pure: it returns new values and never changes its arguments. Engine contract: at the start of a round call newRound with the players still in, keep the returned carry for the next round and write the returned ledger back; while phase(...).stage is acting, wait for a move, parseMove it and act it (or act defaultMove with auto true), writing the ledger back every time; while it is auto, call step after autoDelayMs; when it is over, outcome gives holdMs for the result pause, result for the clients and historyEntry for round-history; to cancel mid-round, voidRound returns every wager through the ledger. The lower layer, the hand state machine, is createHoldem; its members are the `Holdem.` methods. Server: TypeScript `implementation/server/index.ts` (rules.ts, holdem.ts, pots.ts, types.ts). Client betting controls: TypeScript `implementation/web/betting.ts`; Swift `implementation/apple/Sources/Betting.swift` and Kotlin `com.clodhub.holdem` `Betting.kt` have BetRange (adjusted, allows, canSlide, kind, snap rounding down), betStep, betPresets, callIsAllIn and betIsAllIn. components that provide it: https://clodhub.com/components.txt?provides=com.clodhub%2Fgame-rules - seating (com.clodhub/seating 1.0.0): Seats for a table of people and computer players. Build the component once with createSeating(settings, identity); methods named `Seating.` are members of the object it returns. Every member takes a state and returns a new one, never changing its input. Server: TypeScript `implementation/server/seating.ts` and `implementation/server/migrate.ts` (exportAll, importAll). Client lobby rows: TypeScript `implementation/web/lobby.ts`, Swift `implementation/apple/Sources/SeatRows.swift`, Kotlin `com.clodhub.seating` `SeatRows.kt` (seatRows, canTakeSeat; Swift and Kotlin take the same values as structs and enums). components that provide it: https://clodhub.com/components.txt?provides=com.clodhub%2Fseating - game-clock (com.clodhub/game-clock 1.0.0): Game clocks as pure functions over an injected `now` (epoch milliseconds). The caller says which clocks run between two readings (create, advance, reset, elapsed, wallAt); pauses and holds belong to presence and are not stored here. The action clock times decisions, runouts, result holds and offers; the level clock times stake levels. Timers (after, startDecision, startThinking, renewIfPresent, delay, isDue, remainingMs, settleLeftMs, timeoutAction, nextWake) read the action clock. Server: TypeScript `implementation/server/clock.ts`. Client countdowns: TypeScript `implementation/web/countdown.ts` (remaining, endsAt, formatClock), Swift `implementation/apple/Sources/Countdown.swift` and Kotlin `com.clodhub.clock` `Countdown.kt` (remaining, formatClock). Every function returns a new value. components that provide it: https://clodhub.com/components.txt?provides=com.clodhub%2Fgame-clock - private-views (com.clodhub/private-views 1.0.0): Send each viewer only what they may see. Server (server/private-views.ts): viewFor conceals a copy of the state by a policy; redact does the same for facts grouped by owner. Clients (web/views.ts; Swift enum PrivateViews and protocol ViewEnvelope; Kotlin package com.clodhub.views): which arriving view to keep. Methods are tagged with the languages that provide them. S is the application's state and V its view; both are JSON values. components that provide it: https://clodhub.com/components.txt?provides=com.clodhub%2Fprivate-views - presence (com.clodhub/presence 1.0.0): Who is present, who has gone quiet, and whether the activity pauses or carries on (TypeScript module server/presence.ts). Pure functions over plain JSON state; the caller supplies the clock and keeps the state. Participant ids are the ids guest-identity issues; automatic participants (computer players) are always present. Presence is the one owner of pause flags (hostAbsent, allOffline, manual) and holds (look, learn); an engine derives game-clock run flags from them. Events: a request from a participant is seen; a live connection opening or closing is setLive; the application going to the background is away; time passing is refresh. Methods named PresenceApi.* are the functions of createPresenceApi(settings), which a turn engine calls. components that provide it: https://clodhub.com/components.txt?provides=com.clodhub%2Fpresence - tournament (com.clodhub/tournament 1.0.0): A tournament of rounds: entries, rebuy offers, eliminations, finishing places and the winner. Pure: every member takes a state and returns a new one. Chips live in an injected chip ledger, levels in an injected level schedule, the people and computers in a seating. Times given to it (actionMs) are milliseconds on the table's action clock. Server: TypeScript `implementation/server/tournament.ts`, `implementation/server/migrate.ts` (exportAll, importAll). Build once with createTournament(settings, {ledger, schedule, seating}); methods named `Tournament.` are members of the object it returns. Client standings rows: TypeScript `implementation/web/results.ts`, Swift `implementation/apple/Sources/ResultRows.swift`, Kotlin `com.clodhub.tournament` `ResultRows.kt` (resultRows, headingKey). components that provide it: https://clodhub.com/components.txt?provides=com.clodhub%2Ftournament - computer-players (com.clodhub/computer-players 1.0.0, optional): Computer players: which names they sit under, how long they wait before moving, and when one plays for a person who is away. Pure over a small state (the strategy's memory); the moves come from an injected player strategy. TypeScript, `implementation/server/computers.ts`. Build once with createComputers(settings, {strategy, clock, seating}); methods named `Computers.` are members of the object it returns. Seating state, game clock state and observations are opaque here. Clock times are milliseconds on the action clock; wall times are epoch milliseconds. components that provide it: https://clodhub.com/components.txt?provides=com.clodhub%2Fcomputer-players - round-history (com.clodhub/round-history 1.0.0): A bounded record of rounds and their results: the oldest rounds fall off the end. No game knowledge. Two forms of the same history: typed (appendRound with a RoundEntry) and the engine's (push a plain object, list plain objects) for a game that records its own fields beside the result; those fields are stored in RoundEntry.extra and flattened again by list. Every function returns a new history. Server: TypeScript `implementation/server/history.ts`; methods named `HistoryApi.` are members of the object createHistoryApi returns. Clients: Swift `RoundHistory` (`implementation/apple/Sources/RoundHistory.swift`) and Kotlin `com.clodhub.history.RoundHistory` hold HistoryEntry values decoded from a view's `history` list (no, level, winners, voided; game fields ignored); methods named `RoundHistory.` are theirs. components that provide it: https://clodhub.com/components.txt?provides=com.clodhub%2Fround-history - rules-settings (com.clodhub/rules-settings 1.0.0): A house rules file checked against its schema and read by path. The engine form is `RulesReader.value(path)` over checked rules, from createRulesSettings(rules) or loadRulesSettings({rulesFile, strict}, folder); methods named `RulesReader.` are members of that object. The `rulesFile` setting is a name (a lower-case slug, default house-rules), not a path: the rules are /.json with their schema beside them as /.schema.json. The checker supports type, enum, const, minimum, maximum, minLength, maxLength, pattern, items, minItems, maxItems, properties, required, additionalProperties, oneOf, anyOf and local $ref; annotation keywords are ignored and any other keyword makes the schema unusable. Browser and server: TypeScript `implementation/web/schema.ts`; file loading (server only): `implementation/server/rules.ts`, which also exports everything of schema.ts. components that provide it: https://clodhub.com/components.txt?provides=com.clodhub%2Frules-settings Settings (5) Settings (all optional): `decisionSeconds` (empty reads the house rules `timing.decision_seconds`, then 30), `settleMs` (4000: the table settles this long after a deal or a move before the countdown starts), `staleMinutes` (30: an idle lobby or ended table is emptied; a table paused with nobody connected is cancelled), `standingsSeconds` (20: standings stay up after the end) and `lobbyDropSeconds` (60: a lobby seat whose person has not been heard from is given up). - decisionSeconds: integer; optional, no default - settleMs: integer; optional, default 4000 - staleMinutes: integer; optional, default 30 - standingsSeconds: integer; optional, default 20 - lobbyDropSeconds: integer; optional, default 60 Depends on components: none How to use in a recipe A recipe uses it through a slot of class Turn engine (pkg:clod/com.clodhub/turn-engine-class 1.1.0), naming pkg:clod/com.clodhub/turn-engine as the slot's preferred component or substituting it for another component of the class. The recipe connects what it provides (game-adapter) to the slots that use it. It fills what the component needs (game-rules, seating, game-clock, private-views, presence, tournament, round-history and rules-settings) from slots whose components provide them; computer-players may stay unconnected. The recipe sets decisionSeconds, settleMs, staleMinutes, standingsSeconds and lobbyDropSeconds; any it leaves out takes its default. - as a slot in recipe.json components: {"id":"turn-engine","class":{"name":"pkg:clod/com.clodhub/turn-engine-class","version":"1.1.0","digest":"edf80bd659ad68bbf71fc3f13641805ea55b5be2b0d5783c3638186bd4be9d46"},"preferred":{"name":"pkg:clod/com.clodhub/turn-engine","version":"0.13.0"}} - in place of another component of the class: clod fetch turn-engine@0.13.0 --store store --from https://clodhub.com, then clod design RECIPE@VERSION --store store --answers answers.json --substitute SLOT=turn-engine@0.13.0 --out definition.json Used by recipes: pkg:clod/com.clodhub/ourpoker-recipe 0.13.0 (slot turn-engine) For developers: how an application uses it Build the adapter with `createGameAdapter(parts, settings)` from `implementation/server/adapter.ts`, where `parts` (`implementation/server/parts.ts`) holds one component for each required interface: `{rules, seating, clock, views, presence, tournament, computers, history, settings}`. `computers` may be left out: the engine then uses `implementation/server/no-computers.ts` (nobody plays for a computer, `addBot` is refused and not offered, no seat is filled). The manifest marks the `computer-players` requirement `optional: true`, so a design without computer players leaves it unconnected and the engine runs on this stand-in. Hand the adapter to `createRoomClass` from realtime-rooms. Wire actions: `start`, `addBot`, `kick`, `leave`, `sitOut`, `return`, `pause`, `resume`, `cancel`, `newGame`, `rebuy`, plus any move `game-rules.parseMove` accepts. The view carries `players` (each with the game's redacted record), `round`, `game` (the game's own public view), `legal` (engine actions and the game's legal moves), `prompt` (in the lobby `lobbyWaitingOne` or `lobbyWaiting` with the number of people still needed, or `lobbyFill` with the number of seats computers will take when computers fill empty seats at the start; `legal.start` is then offered to one person alone), `rebuyOffers`, `holds` and `history`. The engine state is JSON-serialisable and every call is pure. Error codes (all answered with HTTP status 400, 409 or 422): `badName badRequest roomFull staleVersion badToken notYourTurn wrongPhase notEnoughPlayers badAmount badTarget notAllowed paused unknownPlayer`; a code a game reports that is not in this list (`asErrorCode` in `engine.ts`) is sent as `notAllowed`, so every refusal holdem-rules can give (`unknownPlayer`, `notEnoughPlayers` included) is representable. The engine decides which clocks run: the action clock runs unless the table is paused or held, and the level clock also stops while `tournament.levelClockRuns(t)` is false (a rebuy offer is open); both are passed to game-clock `advance(clock, now, {action, level})`. `presence.setManualPause(state, on, now)` receives the time. Accounts and services No service is deployed. The room (realtime-rooms) stores the state and sets the alarm from `nextWake`. No accounts or keys. How it is checked `node --test tests/web.test.ts` runs the whole adapter against a trivial two-player counting game and small fakes for every required interface (`tests/fakes/parts.ts`, no poker): joining and names, start rules, computers, turn order and every error code, countdowns, acting for absent players and for sat-out players who return, computer pacing, automatic steps and result pauses, `nextWake`, manual and automatic pauses, holds, leaving and returning, cancellation (including by a watcher), the end and the new lobby, stale lobbies, rebuy offers taken, declined and timed out, computer rebuys, views and redaction, restore, settings and the runnable consumer. The suite also checks every refusal code a game may give, that the pause passes the time to presence, a table with no computer-players part, and that the level clock is frozen exactly while a rebuy offer is open. `authoring/integration.test.ts` (not packaged) runs the engine with the real seating, tournament and computer-players components. `authoring/integration-real.test.ts` (not packaged) plays a complete scripted counting-game tournament and, when holdem-rules offers the game-rules operations, a full poker hand, over the real implementation of every required component; a provider missing declared operations makes it skip with the list (`FILL_GAPS_WITH_FAKES=1` fills such a gap with the test fakes). - `node --test tests/web.test.ts` (web, required-local; tools: node 26.5) Updates Patch updates replace files. The saved game state carries `schema: 1`; `restore` refuses anything else. Removal deletes the owned sources and the application's imports; stored room state stays in the room's own storage. Tags: engine, games, turn, turns-and-timing Targets: client none; server none Publisher: George McIntyre (george-mcintyre) Guardians: Level N Ltd (guardian key 08775f20) Source: clodhub/turn-engine release v0.13.0; digest sha256:0662a49b07d5db997d6d4ba367dae98f62f0965d4f0649bedd6cc9516be8b4b3 Release: features Line 0.13: no security releases Quality: Integration-tested, certified Known vulnerabilities: none known (checked 2026-11-26 at OSV); https://clodhub.com/api/components/turn-engine/0.13.0/vulnerabilities Downloads: 1 in 30 days; 1 of this version Classes: https://clodhub.com/classes.txt; this component as JSON: https://clodhub.com/api/components/turn-engine/0.13.0 Bundle download: GET https://clodhub.com/api/components/turn-engine/0.13.0/bundle returns a link valid for one hour Implements: pkg:clod/com.clodhub/turn-engine-class@1.1.0 edf80bd659ad68bbf71fc3f13641805ea55b5be2b0d5783c3638186bd4be9d46 com.clodhub/game-adapter 1.0.0 entry modules: server server/index.ts shared behaviour suites: shared Platforms: server Toolchains: node >=26.5.0 <27.0.0 Frameworks: none Styles: scope none; 0 namespaces; 0 conflicts Licence: Apache-2.0; 0 upstream sources, 0 exact dependencies, 34 files (listed on the details page) Suitable for jobs: turn-engine profile any: cost none; load none; regions any; compliance none Notes: Pure library; no state of its own beyond the game state the room stores. Data migration: this component keeps no data Maintainers: Level N Ltd; https://github.com/clodhub/turn-engine/issues; updates https://github.com/clodhub/turn-engine/releases (manual) What you download turn-engine-0.13.0.tar, from release v0.13.0 of clodhub/turn-engine: 34 files - Documents and manifests (8): CONTRACT.md, INSTRUCTIONS.md, LICENCE, NOTICE, PROVENANCE.md, SOURCE.md, ... - Source code (5): server/ (5) - Tests (2): fakes/ (1), web.test.ts - Interface documents (10): game-adapter.json, required-computer-players.json, required-game-clock.json, required-game-rules.json, required-presence.json, required-private-views.json, ... - Class files: the class's interfaces and shared checks (3): turn-engine-class/ (3) - Examples (1): consumer.ts - Diagrams (5): definition.json, examples/ (1), output/ (3) Installing copies 5 of them into the application under components/turn-engine/: server 5 Not included: the components that provide what it requires (com.clodhub/game-rules, com.clodhub/seating, com.clodhub/game-clock, com.clodhub/private-views, com.clodhub/presence, com.clodhub/tournament, com.clodhub/computer-players, com.clodhub/round-history, com.clodhub/rules-settings), each a separate download; the values of its settings, which the recipe writes; any secret The archive is a release file on the publisher's public GitHub repository; ClodHub keeps this page and a pointer to the release, not the code. clod checks the archive's sha256 fingerprint before anything is copied, and installing runs none of the package's code. Versions - 0.13.0 features (2026-11-26T11:34:59.060Z) sha256:0662a49b07d5db997d6d4ba367dae98f62f0965d4f0649bedd6cc9516be8b4b3 Links Details (package foundations, upstream sources, exact dependencies, styles, class inventories, files): https://clodhub.com/components/turn-engine/details.txt?version=0.13.0 Page: https://clodhub.com/components/turn-engine; JSON: https://clodhub.com/api/components/turn-engine/0.13.0; connections diagram: https://clodhub.com/api/components/turn-engine/0.13.0/connections.svg Copyright Level N Ltd 2026