Hidden information and randomness
Many games hide things: your hand, the order of the deck, the card you’ve chosen but not yet revealed. And many use chance: a shuffled deck, a roll of the dice. In the rules DSL, a zone’s visibility decides who sees what, and every random draw comes from the match’s own seeded stream, so the server stays in charge of both.
Who sees what
Section titled “Who sees what”Each zone has a visibility. The server never sends a player what their visibility hides: each player’s view of the
match, in the web player, in your own client and to the bots, is worked out on the server and holds only what that
player may see. A hidden card isn’t sent and then covered up; it isn’t sent at all.
| Visibility | Who sees the components | Typical use |
|---|---|---|
public |
Everyone | The board, cards in play |
owner |
The seat the zone belongs to; the others see how many there are | Hands |
hidden |
No one; how many there are is public | Decks |
topPublic |
Everyone sees the top one; the rest are hidden | Discard piles |
countOnly |
No one sees them; only the count is shown | Face-down piles |
allButOwner |
Everyone except the zone’s owner | Hanabi’s hands |
The rules file reference lists every visibility.
An owner zone is almost always perSeat: true, so every seat has its own:
zones: deck: { kind: stack, of: card, visibility: hidden } hand: { kind: set, of: card, perSeat: true, visibility: owner }Shuffling and dealing
Section titled “Shuffling and dealing”shuffle puts a zone’s components in a random order, and deal moves them one at a time from the top of one zone to
another. Hearts deals a fresh hand like this:
- shuffle: deck- forEach: { in: "allSeats()", as: s, do: [{ deal: { from: deck, to: "hand[s]", count: 13 } }] }Dice and random picks
Section titled “Dice and random picks”Randomness may appear only in an effect’s arguments. These draw from the match’s random stream:
| Expression | Gives | From |
|---|---|---|
die(6) |
A roll from 1 to 6 | Backgammon: set: { target: global.dice, value: "[die(6), die(6)]" } |
random(list) |
One item of a list, at random | Avalon: set: { target: global.leader, value: "random(playingSeats())" } |
list.shuffled() |
The list in a random order | Brass: set: { target: global.order, value: "playingSeats().shuffled()" } |
A function, a condition, a filter or the bot heuristic can’t use them; the checker reports a determinism problem if
one does. That keeps every legal-move list and every condition the same each time it’s worked out.
Why randomness is seeded
Section titled “Why randomness is seeded”Every match has a seed, and every shuffle and roll draws from a stream that seed starts. The server keeps the seed and the log of moves, so it can replay the match exactly, and players never see what’s coming. Every match commits to its seed when it starts and serves its replay once it ends.
Secret choices, revealed together
Section titled “Secret choices, revealed together”In some games everyone chooses at once and reveals together, such as 7 Wonders’ card picks. A simultaneous step asks
each listed seat for one move of an action. Each choice is checked as it’s made, then kept hidden until every seat has
chosen; then they all take effect, in seat order. mode: snapshot checks every choice against the state at the start
of the step, so nobody’s choice depends on another’s.
flow: - phase: choose simultaneous: { seats: "allSeats()", action: playCard, mode: snapshot, reveal: afterAll }reveal: never keeps the choices hidden even after they take effect, as when Hearts’ players pass three cards to a
neighbor.
Example: high card
Section titled “Example: high card”In this small card game, 2 to 4 players are dealt three cards each from a shuffled deck of 52 (four of each rank from 1 to 13). Over three rounds, everyone plays a card in secret, all are revealed together, and the highest card wins the round; a tie for highest wins nothing. Whoever wins the most rounds wins.
dsl: "1.1"
game: id: high-card name: High card players: { min: 2, max: 4 } seats: topology: ring
components: card: props: rank: "int = 1"
zones: deck: { kind: stack, of: card, visibility: hidden } # nobody sees the deck, only how many cards it holds hand: { kind: set, of: card, perSeat: true, visibility: owner } # each player sees their own hand; others see its size played: { kind: set, of: card, perSeat: true, visibility: public } discard: { kind: set, of: card, visibility: public }
state: global: round: "int = 0" seat: points: "int = 0"
functions: # The rank a seat played this round; 0 before it has played. playedRank: params: { s: seat } returns: int expr: "played[s].sum(c => c.rank)"
setup: - forEach: in: "range(1, 14)" as: r do: - forEach: { in: "range(0, 4)", as: copy, do: [{ create: { type: card, props: { rank: r }, into: deck } }] } - shuffle: deck - forEach: { in: "allSeats()", as: s, do: [{ deal: { from: deck, to: "hand[s]", count: 3 } }] }
flow: - repeat: var: global.round values: [1, 2, 3] steps: - phase: choose simultaneous: { seats: "allSeats()", action: playCard, mode: snapshot, reveal: afterAll } - phase: score do: - let: { name: best, value: "allSeats().max(s => playedRank(s))" } - let: { name: leaders, value: "allSeats().where(s => playedRank(s) == best)" } - if: cond: "leaders.count() == 1" then: [{ add: { target: "leaders.first().points", value: 1 } }] - forEach: { in: "allSeats()", as: s, do: [{ moveAll: { from: "played[s]", to: discard } }] }
actions: playCard: choose: - card: { from: "hand[self]", label: Choose a card to play } effect: - move: { what: card, to: "played[self]" }
end: when: afterFlow scoring: - { category: rounds, value: "s.points" }A few things to notice:
- The deck is
hiddenand the hands areowner, so each player sees only their own three cards, and how many the others hold. - The only randomness is
shuffle: deck, insetup. repeatsetsglobal.roundto 1, 2 and 3 in turn and runs its steps each time. The field it sets must be declared instate.range(1, 14)is the numbers 1 to 13: a range includes its start and stops before its end.- The game ends when the flow runs out (
end.when: afterFlow), and theend.scoringcategory decides the winner; Scoring and game end explains how.