Skip to main content
A ruleset defines the match rules for one game and runs in the game service. The platform handles rooms, matchmaking, autoplay, spectating, replays, and stake settlement. The ruleset is responsible only for: A ruleset is identified as “name@major version”, for example doudizhu@1. A game declares its ruleset in realtime.ruleset in manifest.json.

Determinism

A ruleset must be a pure function: the same state, action, and random numbers produce the same result.
  • Use only the random numbers the room provides. The seed is committed publicly before the match and revealed afterward, so the match can be replayed in full.
  • Do not read the clock or access the network or files.
  • The state must serialize to JSON and read back. The platform uses it for snapshots and cross-instance takeover.

First-party rulesets

The platform’s own games are written in Go and compiled into the game service, for example Dou Dizhu doudizhu@1 and Gomoku gomoku@1.

Third-party rulesets (WASM)

The third-party ruleset interface is final, and you can develop and test against it. The engine that runs WASM and upload review are not open yet; the upload endpoint currently returns 501 ruleset_upload_reserved.
A third-party ruleset is a WASM module that exports the following functions, all with JSON input and output: state is JSON defined by the ruleset, and the platform stores it as is. An event with an empty to is visible to everyone (including spectators); otherwise it is sent only to the listed seats. The error returned by nl_apply is sent back to the client as the failure reason in action.ack.

ABI (version 1)

  • Export memory, nl_abi_version() -> i32 (returns 1), nl_alloc(size i32) -> i32, and nl_free(ptr i32, size i32).
  • Every rule function has the signature (ptr i32, len i32) -> i64. The input JSON is at [ptr, ptr+len); the high 32 bits of the return value are the output pointer and the low 32 bits are the output length. The platform calls nl_free after reading it.
  • Imports from module "nl":
    • rng_u32() -> i32: the room’s deterministic random number. Call it only in nl_setup and nl_apply.
    • log(ptr i32, len i32): debug logging, rate-limited in production.
  • WASI is not imported: there is no clock, file system, network, or environment variables.
  • Limits: up to 16 MiB of linear memory and up to 50 milliseconds per call. A call that exceeds them fails.

ruleset.json

id consists of lowercase letters, digits, dots, and hyphens, and third-party rulesets carry a developer prefix (such as dev.). Bump the major version when you change the state format or the rules; rooms in progress keep using the old version. Player count is 1–16.

Planned publishing flow

  1. Upload module.wasm (up to 4 MiB) and ruleset.json. The response is {id, sha256, status: "pending_review"}.
  2. Staff review it: they check the source or a reproducible build, verify that the same input produces the same output twice, and run a large number of random matches within the limits.
  3. Once approved, the game service loads the module, and realtime.ruleset in manifest.json and table configurations can use the name.