Variants, options and expansions
Most games are played more than one way. The rules DSL has three tiers for it:
| Tier | What it is | Example |
|---|---|---|
| Variants | Official alternative rules inside one rules file, switched on for a match | Misère tic-tac-toe; 7 Wonders’ two-player Free City |
| Options | A table setting or house rule that changes one constant | Dominion with 11 or 12 kingdom piles |
| Expansions | Separate, versioned files layered onto a base game | Dominion’s Intrigue; Terraforming Mars’ Prelude |
Variants
Section titled “Variants”A variant is declared under variants with an id and a name. The rules ask whether it’s on with variant('id').
Misère tic-tac-toe, where three in a row loses, changes one line of
the tic-tac-toe rules: the winner is the other player when the variant is on.
variants: - id: misere name: "Misère: three in a row loses"
# ...
actions: mark: choose: - at: { from: "board.cells()", where: "pieceAt(at) == null", label: Choose an empty square } effect: - create: { type: mark, props: { owner: self }, into: at } - if: cond: "wins(self)" then: - endGame: { winner: "variant('misere') ? opponent(self) : self", reason: three in a row }A variant can also be limited to some player counts with when, an expression over players, and made always on
where it applies with required: true. 7 Wonders’ two-player variant applies only to two players, and is then the
rule:
variants: - id: free-city name: Two-player expert variant when: "players == 2" required: trueReplacing whole actions and phases
Section titled “Replacing whole actions and phases”variant('id') guards suit a difference of a line or two. When a variant changes more, overrides replaces whole
actions, by name, or whole flow phases, by their phase name, while the variant is on. The checker makes sure each one
replaces an action or phase that exists. 7 Wonders’ two-player variant replaces two phases and its card-playing action
this way. Its deal gives the neutral Free City’s cards a pile of their own:
overrides: phases: dealAge: phase: dealAge do: - forEach: in: "playingSeats()" as: s do: [{ deal: { from: "deck[global.age]", to: "hand[s]", count: 7 } }] - moveAll: { from: "deck[global.age]", to: freeCityPile } - move: { what: "freeCityToken.first()", to: "hand[global.age == 2 ? rightOf(freeCity) : leftOf(freeCity)]" } - drawForFreeCity: {}drawForFreeCity is one of the game’s own procedures.
Choosing variants for a match
Section titled “Choosing variants for a match”A match’s variants are fixed when it starts. A lobby created through the Player API can switch variants
on by id, in its variants list. The web player doesn’t offer a choice of variants yet, so its matches play without
them, except the ones marked required.
Options
Section titled “Options”An option lets the table change one constant, within limits. It names the constant it changes, its type (int, bool
or enum), its default, and its range or values. rated says whether a match with a value other than the default
may be rated. In the tic-tac-toe match from Build tic-tac-toe,
an option could let players choose how many rounds win:
consts: roundsToWin: 2
options: roundsToWin: label: Rounds to win type: int default: 2 min: 1 max: 5 const: roundsToWin rated: falseThe rules keep reading roundsToWin as before; a match where the option is set reads the value chosen instead. Lobbies
can’t set options yet, so for now every match plays with each option’s default.
Expansions
Section titled “Expansions”An expansion is a file of its own that adds to, replaces or removes parts of a base game. It names itself, its version, and which versions of the base it fits, as a semantic version range. Dominion’s Envoy promo adds one card to the base game’s card table and one action:
dsl: "0.4"
expansion: id: dominion-promos name: Promos version: 1.0.0 requires: { base: "dominion@^1.0.0" }
add: data: cards: rows: - { name: Envoy, cost: { coins: 4 }, types: [action], set: promo, effect: [ { draw: { from: "deck[owner]", to: "revealed[owner]", count: 5 } }, { prompt: { seat: "leftOf(owner)", action: envoyPick, args: { target: owner } } }, ], } actions: envoyPick: choose: [{ c: { from: "revealed[event.target]", decider: "leftOf(event.target)" } }] effect: - move: { what: c, to: "discard[event.target]" } - moveAll: { from: "revealed[event.target]", to: "hand[event.target]" }The changes come in three sections, applied in this order:
removetakes out data rows, actions, triggers or variants.replaceswaps whole named things: actions, procedures, functions, consts, flow phases, triggers, modifiers or end settings. What it replaces must exist.addadds new things: enum values, consts, components and their properties, data tables and rows, zones, state, functions, procedures, actions, triggers, setup steps, options, flow steps at a named anchor, end conditions and scoring categories. Adding a name that already exists is an error; usereplace.
The base, its chosen expansions and its options are composed into one ruleset, which the checker checks like any rules
file. The composition never depends on the order expansions were chosen in: dependencies come
first, then after hints, then ids. Two expansions that replace the same thing are refused unless one requires the
other or names it in after. A match records the composed ruleset’s hash, so a replay rebuilds exactly the same
rules.
Designing a base that expansions can extend
Section titled “Designing a base that expansions can extend”Expansions compose best when the base game leaves room for them on purpose:
- Keep lists that expansions extend as data. Cards, tiles and global tracks in data tables take new rows; logic that names each one has to be replaced.
- Mark extension points in the flow. A flow step
- anchor: endOfGenerationdoes nothing itself, but gives expansions a place to add their own steps, as Terraforming Mars’ does for Colonies’ and Turmoil’s. - Route changes through one place. If every gain of a resource goes through one procedure, an expansion can change that procedure instead of every action.
- Replace as little as possible. Two expansions that each replace the same action can’t be played together.
The expansion manifest reference lists every field.