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

GameRecorderclass

A record written as a game is played. Call its methods as the game goes, in the order things happen, and text() is the record so far; a game not yet finished is a record that replays to a game still in play.

Import it

import { GameRecorder } from "@johnmorrisdotca/sugoroku";

Definition

class GameRecorder
new GameRecorder(settings: Settings, seed?: RecordSeed): GameRecorder

Parameters

NameTypeDescription
settingsSettings

The resolved variant and complete rules to record.

seed (optional)RecordSeed | undefined

Optional seed whose exact dice sequence replay must verify.

Members

NameTypeDescription
startGame(): void

Begin the next game of the match.

opening(throws: readonly [number, number]): void
turn(side: Side, dice: readonly number[], moves: readonly Move[]): void
double(side: Side): void
take(side: Side): void
drop(side: Side): void
beaver(side: Side): void
concede(side: Side, kind: WinKind): void
drawn(): void
result(result: GameResult): void
text(): string

The record, one line after another.

Examples

import { GameRecorder, legalPlaysOf, newGame, rollOpening, settingsFor, startGame } 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);
console.log(record.text());
sugoroku 1
variant backgammon
points 5
cube on
crawford on
jacoby off
beaver off
gammons off
game 1
open 3 1
white 31: 24/21 24/23

What it prints (run when this page was built)

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