Skip to content

Tables and turns

tilttek/tavern-games

The tables

CallWhat it does
open($game, $tableId, $seats, $options, $seed)Opens a table of a tavern game; its first seat plays first
play($tableId, $move, $expected)Plays a move; refused with ConcurrentMove when $expected is not the number of moves
timeout($tableId, $seat, $sequence)Plays the timeout of a seat's turn, when it still applies
view($tableId, $seat)What a seat sees of the table — the audience, with no seat
state($tableId)The whole state, secrets included: for the server only
ending($tableId, $seat)How the game ended for a seat, or null while it goes on

The game's own turns

A tavern game ends a turn by its rules — a die that shows 1, a card played, the third roll —, so its phase leaves the turns to the game: the engine's turn order is Free, and the game keeps Turns in its data — the seats in the order they play and the seat playing — and refuses, in allows(), a move of any other seat. TavernGame::toAct() says whose turn it is, null once the game is over; the views give it as turn.

The turn timer

The library depends on no clock. An application that gives turns a delay implements Contract\TurnTimer:

MethodWhen
started($tableId, $seat, $sequence)A seat's turn starts, after $sequence moves of the table: on opening, and after each move that leaves the game going
stopped($tableId)The game is over

The timer chooses the delay — a setting of the table, of the application — and, when it runs out, calls TavernTables::timeout($tableId, $seat, $sequence) with what it was told. The timeout is played only when the seat still plays after the same number of moves: a seat that played in time, or a game over, makes it a no-op that returns the state. It is the move tavern.timeout ({seat}), made by the table itself, and the game ends the turn by its rules: Pig holds, Ship, Captain and Crew stops, Crazy Eights draws a card when none was drawn, then passes. A timeout never takes away more than the turn.

Store\NullTurnTimer, the default, keeps no clock: a turn lasts until it is played.

Endings

Ending::of($outcome, $seat), which TavernTables::ending() gives, tells the end of a game in one of three tones.

ToneWhenWhat the application does
VictoryThe seat is the only winnerIt plays a celebration — the celebration recipe of its interface kit — announced in a live region and cut by a preference for reduced motion
TieThe seat shares the win with othersThe same celebration: a shared victory is a victory
GoodGameThe seat did not win, or nobody did, or the view is the audience'sA kind word and an invitation to play again: never a mocking message, sound or animation

Tone::celebrates() is true for a victory, alone or shared. Ending::$reason is the game's word for the ending and Ending::$winners the seats that won.