Skip to content

Win conditions

A game ends when an end_game action fires, when countdownSeconds expires, or when a team is eliminated. Here are the common shapes.

compare fires for anyone over the threshold; a won flag makes it announce once.

- id: win
when:
kind: and
children:
- { kind: compare, who: any, op: gte, left: { ref: same.state.score }, right: 30 }
- { kind: state_equals, who: same, key: won, value: false }
do:
- { kind: set_state, target: same, key: won, value: true }
- { kind: send_event, to: any, event: { type: toast, text: "Game over — someone reached 30!" } }
- { kind: end_game }

Adapted from king_of_the_hill (which announces but, if you want a hard stop, add end_game as shown).

count_state n: 1 holds when exactly one player still matches; bind that survivor and declare them the winner.

- id: winner
when:
kind: and
children:
- { kind: count_state, who: any, key: alive, value: true, n: 1 }
- { kind: state_equals, who: same, key: alive, value: true }
do:
- { kind: send_event, to: same, event: { type: toast, text: "You win." } }
- { kind: end_game }

Source: apps/wage-engine/src/games/assassin/game.json (the winner rule; add end_game to stop the session).

For a fixed-duration game, set the timer at the top level and let the engine end it:

countdownSeconds: 900 # 15 minutes

When it expires the engine ends the game automatically. Decide the winner however you like at that point — Pirate’s Booty compares each crew’s total score.

If every member of a team is out, the engine can end the game on elimination. You typically drive “out” yourself by setting alive: false (see Freeze & thaw and Bots vs Humans’ death rule), then either count_state the survivors or rely on the engine’s elimination check.