Skip to the content

Sugoroku双六

Play backgammon and its relatives with native rules, cube and match scoring, seeded dice and replayable records.

Sugoroku is the Japanese name 双六 for games of tables. About the name

Contents

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

NameTypeDescription
oktrue
settingsSettings
seedRecordSeed | null
matchMatch

The match as it stands after every finished game.

gamesreadonly ReplayedGame[]

Every finished game, in order.

currentGameState | 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)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/sugoroku 1.1.1.