Reference · Rules, games and records
GameStatetype
The immutable game phase, board, dice, remaining moves, cube and optional result.
Import it
import type { GameState } from "@johnmorrisdotca/sugoroku";
Definition
type GameState = {
readonly settings: Settings;
readonly crawford: boolean;
readonly score: readonly [
number,
number
];
readonly position: Position;
readonly turn: Side | null;
readonly phase: Phase;
readonly dice: readonly number[] | null;
readonly need: readonly number[];
readonly plan: readonly number[];
readonly moves: readonly Move[];
readonly turnStart: Position;
readonly cube: Cube;
readonly offeredBy: Side | null;
readonly turns: readonly [
number,
number
];
readonly opening: readonly [
number,
number
] | null;
readonly result: GameResult | null;
};
Members
| Name | Type | Description |
|---|---|---|
settings | Settings | |
crawford | boolean | Whether this is the Crawford game of a match: no cube. |
score | readonly [number, number] | The match score as the game began, |
position | Position | |
turn | Side | null | The side to move; null until the opening throw has decided. |
phase | Phase | |
dice | readonly number[] | null | The roll being played, as thrown. |
need | readonly number[] | The dice this turn must still play, highest first. Empty when the turn has been played, or when nothing can be. |
plan | readonly number[] | The dice this turn had to play to begin with, highest first. |
moves | readonly Move[] | The moves made so far this turn, in order. |
turnStart | Position | The position the turn began from: the moves are made from it. |
cube | Cube | |
offeredBy | Side | null | Who offered the double that is waiting to be answered, when |
turns | readonly [number, number] | The turns each side has taken. |
opening | readonly [number, number] | null | The last throw of a die each at the start: |
result | GameResult | null |
Examples
import { newGame, rollOpening, settingsFor } from "@johnmorrisdotca/sugoroku";
import type { GameState } from "@johnmorrisdotca/sugoroku";
const settings = settingsFor("backgammon",{points:5,cube:true});
const game = rollOpening(newGame(settings),[3,1]);
const value: GameState = game;
console.log(value);{
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
}
},
crawford: false,
score: [ 0, 0 ],
position: {
points: [ [Array], [Array] ],
bar: [ 0, 0 ],
reserve: [ 0, 0 ],
off: [ 0, 0 ]
},
turn: 'white',
phase: 'playing',
dice: [ 3, 1 ],
need: [ 3, 1 ],
plan: [ 3, 1 ],
moves: [],
turnStart: {
points: [ [Array], [Array] ],
bar: [ 0, 0 ],
reserve: [ 0, 0 ],
off: [ 0, 0 ]
},
cube: { value: 1, owner: null },
offeredBy: null,
turns: [ 0, 0 ],
opening: [ 3, 1 ],
result: null
}What it prints (run when this page was built)