Simulation: PVP System (BETA)
Add asynchronous PVP to your game. Each player serializes their board into a personal room; the server matches them against another player's room; the client fetches the opponent's snapshot and runs the battle locally. A separate effect lets the server validate the reported outcome before any reward flow runs.
This is a self-contained recipe. Everything you need (config, client code, and patterns) is on this page.
Ranking, MMR, and season leaderboards are intentionally out of scope here; they're covered separately.
The rooms on this page are simulation rooms that
ensure_roomcreates to hold board snapshots. They are not realtime multiplayer rooms, and no player connects to them.
Where Config Goes
All JSON config on this page is simulation config: server-authoritative state, actions, and rewards. The CLI uploads it automatically when you rundot deploy.
Recommended: rundot/simulation/
Place simulation config in the rundot/simulation/ directory, one file per system. Each file holds raw simulation content with no {"simulation": {...}} wrapper (the directory implies it). Files are deep-merged alphabetically at deploy time with collision detection.
my-game/
├── rundot/
│ └── simulation/
│ └── pvp-system.json ← raw content, no "simulation" wrapper
├── game.config.prod.json ← game ID + build settings only (separate)
└── package.jsonCommit
rundot/to your repo; it's project config likepackage.json, not a build artifact. It's env-agnostic and takes priority over legacyconfig.{local,staging}.json.game.config.prod.jsonis for CLI metadata only; simulation config does not go there.
Also supported: legacy config.json / config/
Legacy layouts keep working indefinitely. Run rundot migrate-config (with --dry-run to preview) to move them into rundot/simulation/ automatically.
What You'll Build
Board snapshots: each player's deck/board is serialized into their own room as actors, so an opponent can fetch it later without both players needing to be online
Server-side matchmaking: the server returns rooms belonging to other players that match a filter you supply
Server-validated outcomes: the server can reject reports that don't match the board state it knows about, so wins aren't taken on trust
The three effects doing the work are replace_room_actors, matchmaking, and validate_battle_outcome.
Server Configuration
Entities
Only one entity is required for the snapshot/matchmaking flow: a per-player number the server can compare against reported battle power. Add any other entities your game already has; this doc doesn't dictate the rest of your data model.
pvp_board_power
Cached total power of the player's latest snapshot. Supporting state for the server-side validation effect.
Recipes
Four recipes wrap the three PVP effects. Effects that produce a return value use endEffects so the as-named outputs are available on the client in result.data.state.
ensure_room
Idempotently create (or update) a room scoped to this player. The room ID pvp_{{profileId}} ensures one room per player. Metadata on the room (set here) is what matchmaking filters on.
replace_room_actors
Atomically clear all actors with a given tag in the room and replace them with new ones from inputs.units. Each input element becomes an actor, perfect for storing a serialized deck.
get_room_actors
Read actors back out of a room. Returns them under the as key in effectResults.
matchmaking
Server-side opponent search. Returns up to count rooms of the given roomType. The current player's own room is excluded automatically. Add a filters block (see "Filtering Opponents" below) if you want to narrow the pool.
validate_battle_outcome
Server-side check on a reported battle outcome. Rejects reports that look implausible given the board state the server has on record. On rejection the recipe aborts and an anomaly is logged.
Initialization
No explicit initialization is required. pvp_snapshot_board calls ensure_room on every invocation, so the player's room is created lazily on their first snapshot. If you want the room (and a default pvp_board_power) to exist before the player has ever played a match, so they show up in matchmaking results, trigger pvp_snapshot_board once with an empty unit list from an onStart lifecycle recipe.
Client-Side Implementation
Step 1: Serialize Your Board
replace_room_actors needs a flat list of unit objects; each one becomes an actor in the room. Convert your in-game board to a serialized form, and total the power up while you're at it:
Step 2: Snapshot the Board to Your Room
Pass units and totalPower as recipe inputs. The recipe stores the units as actors and caches totalPower in pvp_board_power for later validation.
Call snapshotBoard whenever the player's board changes: after a shop phase, after a deck edit, etc. That way an opponent who matches you while you're between rounds still gets a coherent board to fight.
Step 3: Find an Opponent
pvp_find_opponent returns up to 5 rooms of roomType: "pvp_board". The player's own room is excluded server-side, so you don't have to filter it client-side.
Step 4: Fetch the Opponent's Board
Hydrate the returned units back into your in-game representation and simulate the battle however your game does it. The server doesn't need to play out turns, just to validate the final outcome (see Step 5).
Step 5 (optional): Report the Outcome with Server Validation
If wins should grant rewards (currency, trophies, your own ranking system), gate the reward recipe on a successful pvp_report_battle. The client reports the outcome and the validation effect decides whether the rest of the reward flow gets to run.
Treat pvp_report_battle as a gate. Only run your reward recipe(s) if it succeeds. Because the client can't mutate trophy/currency entities directly (only guarded reward recipes can), a rejected report short-circuits the payout before it begins.
How Server-Authoritative Validation Works
Outcomes that hand out rewards shouldn't be decided by the client alone. validate_battle_outcome lets the server take a reported result and decide whether it's consistent with the board state the server already has, without needing to simulate the battle turn-by-turn. The recipe aborts on rejection, so any reward effect chained after the validation never runs.
To wire it up, make sure each player's snapshot recipe writes the supporting state the validation effect expects (in this doc, pvp_board_power set during pvp_snapshot_board). With that in place, the report recipe can be treated as a gate on the rest of the reward flow: successful validation lets the chain continue, a rejection stops it and logs an anomaly you can review.
Filtering Opponents
The example above passes no filters to matchmaking, so the server returns any other pvp_board room. To narrow the pool, write the field you want to filter on into the room's metadata at snapshot time, then reference it in matchmaking.params.filters. For example, to bucket on a generic skill_bucket entity, add it to the ensure_room metadata in pvp_snapshot_board:
…and add a matching filter in pvp_find_opponent:
Keep the bucket coarse; too narrow a filter and the server will return zero matches for players outside the meta.
Bot Fallback When No Humans Match
pvp_find_opponent returns an empty list when the player is at the edge of a filter bucket or when the game is new. Fall back to a procedurally generated opponent so the player isn't stuck:
The client never tells the server whether an opponent was a human or a bot; if you use pvp_report_battle, outcomes go through the same validation path either way.
Best Practices
Snapshot the board after every change to it, not just before a battle. Opponents matching against a stale room get a worse experience.
Always treat
pvp_find_opponentas best-effort. The server may return zero matches; have a fallback ready (bot, retry with a wider filter, queue).Pick a match at random from the top N results instead of always taking index 0; that spreads load across players in the same bucket.
If you use
pvp_report_battle, call it before any reward recipe. A rejected validation should short-circuit the payout.Tune variance bands conservatively for your own game's power curve; too tight and legitimate underdog wins get flagged. The values shown above are illustrative placeholders, not recommended settings — pick your own and avoid documenting them publicly so opponents can't calibrate against them.
Log
validate_battle_outcomeanomalies but don't ban on them; false positives happen. Use them as inputs to a heuristic, not a verdict.Cache the player's own
totalPoweron the server (viapvp_board_power) at snapshot time so the validation effect has the supporting state it needs.
Last updated