Reference · Rules, games and records
ReplayOktype
A successfully validated record, its settings, completed games and optional current game.
Import it
import type { ReplayOk } from "@johnmorrisdotca/sugoroku";
Definition
type ReplayOk = {
readonly ok: true;
readonly settings: Settings;
readonly seed: RecordSeed | null;
readonly match: Match;
readonly games: readonly ReplayedGame[];
readonly current: GameState | null;
};
Members
| Name | Type | Description |
|---|---|---|
ok | true | |
settings | Settings | |
seed | RecordSeed | null | |
match | Match | The match as it stands after every finished game. |
games | readonly ReplayedGame[] | Every finished game, in order. |
current | GameState | null | The game still in play when the record ends, or null if the last was finished. |
Examples
import { GameRecorder, legalPlaysOf, newGame, replayRecord, rollOpening, settingsFor, startGame } from "@johnmorrisdotca/sugoroku";
import type { ReplayOk } from "@johnmorrisdotca/sugoroku";
const settings = settingsFor("backgammon",{points:5,cube:true});
const game = rollOpening(newGame(settings),[3,1]);
const play = legalPlaysOf(game)[0];
const record = new GameRecorder(settings);
record.startGame();
record.opening([3,1]);
record.turn("white",[3,1],play.moves);
const replay = replayRecord(record.text());
if(!replay.ok) throw new Error(replay.reason);
const value: ReplayOk = replay;
console.log(value);{
ok: true,
settings: {
variant: {
checkers: 15,
dice: 2,
doubles: 'four',
direction: 'opposed',
opening: 'roll-off',
goal: 'first-off',
holdBelow: 0,
drawAfter: 0,
key: 'backgammon',
layout: [Array]
},
rules: {
points: 5,
cube: true,
crawford: true,
jacoby: false,
beaver: false,
gammons: false
}
},
seed: null,
match: {
settings: { variant: [Object], rules: [Object] },
score: [ 0, 0 ],
results: [],
crawfordNext: false,
crawfordPlayed: false,
over: false,
winner: null
},
games: [],
current: {
settings: { variant: [Object], rules: [Object] },
crawford: false,
score: [ 0, 0 ],
position: { points: [Array], bar: [Array], reserve: [Array], off: [Array] },
turn: 'black',
phase: 'before-roll',
dice: null,
need: [],
plan: [],
moves: [],
turnStart: { points: [Array], bar: [Array], reserve: [Array], off: [Array] },
cube: { value: 1, owner: null },
offeredBy: null,
turns: [ 1, 0 ],
opening: [ 3, 1 ],
result: null
}
}What it prints (run when this page was built)