Scoring and game end
A game ends in one of three ways: a move or a phase ends it with endGame, a condition in end.when becomes true, or
the flow runs out with end.when: afterFlow. Whichever it is, every game must end one of these ways: a flow that runs
out with no ending is an error the engine reports.
Ending it directly: endGame
Section titled “Ending it directly: endGame”endGame ends the game at once, with a winner or a draw, and a reason players see. It can sit in any list of effects:
an action, a phase, a trigger. Tic-tac-toe ends from the move that completes a line, and as a draw when the player to
move has no square left:
- if: cond: "wins(self)" then: [{ endGame: { winner: self, reason: three in a row } }]onNoLegalAction: - endGame: { draw: true, reason: board full }winner is an expression that gives a seat, so the winner can be worked out. In Hearts the lowest score wins, and the
last phase names that player:
- phase: end do: - endGame: { winner: "allSeats().orderBy(s => s.score).first()", reason: lowest score }The reason can be an expression too, as long as it gives text:
reason: "history.count(position) >= 3 ? 'threefold repetition' : '50-move rule'".
Ending on a condition: end.when
Section titled “Ending on a condition: end.when”end.when is a condition the engine checks as play goes on. When it holds, the game ends and is scored. By default it’s
checked after every action; checkAfter checks it at the end of each turn or phase instead. Dominion ends when the
Provinces run out or three supply piles are empty, checked at the end of a turn so the player finishes it:
end: when: "pileCount('Province') == 0 || emptyPiles() >= 3" checkAfter: [turn] scoring: - { category: cards, value: "allCards(s).sum(c => c.vp.valueFor(c, s))" } tiebreak: ["-s.turnsTaken"] shareTies: trueEnding when the flow runs out: afterFlow
Section titled “Ending when the flow runs out: afterFlow”Many games end after a set number of rounds. Write the rounds into the flow, with repeat or loop, and say
end.when: afterFlow: when the last step finishes, the game is scored. Brass: Birmingham plays two eras, then scores:
end: when: afterFlow scoring: - { category: victoryPoints, value: "s.vp" } tiebreak: ["income(s)", "s.money"] shareTies: trueScoring
Section titled “Scoring”end.scoring is a list of categories. Each has a name and a value, an expression worked out for every seat with the
seat as s. A seat’s score is the sum of its categories, and the highest score wins. 7 Wonders scores seven
categories, the rows of its score pad; here are three:
scoring: - { category: military, value: "s.conflict.sum(t => t)" } - { category: treasury, value: "s.coins / 3" } - { category: civilian, value: "city[s].where(c => c.color == color.blue).scoreSum()" }The engine uses only the categories you list, and only when the game ends by end.when or afterFlow. A game that
ends with endGame names its winner itself.
When lower is better
Section titled “When lower is better”The highest score always wins, so for a game where fewer is better, score the negative: value: "-s.penalties". Or
work out the winner yourself and end the game with endGame, as Hearts does.
tiebreak is a list of expressions, each worked out for the tied seats with the seat as s. The first one that
separates them decides; the highest value wins. Brass breaks a tie on income, then on money. Dominion’s
"-s.turnsTaken" gives the tie to the player who took fewer turns. Seats still tied after every tiebreak share the
win, which is what shareTies: true says.
Who can win
Section titled “Who can win”end.seats limits who can win to the seats it lists. 7 Wonders’ two-player variant plays a neutral third city, the
Free City, which scores but never wins:
seats: "playingSeats()" # the Free City never winsRatings
Section titled “Ratings”A game’s rated matches update each player’s rating for that game: Arbitas uses Glicko-2 for every game, by game and by
pool (the pace and the number of players). The rules’ end.rating names the system a game’s rules intend, but it
doesn’t change how Arbitas rates matches today.