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 · Playable board

SugorokuMounttype

The mounted native board, current game/match/record, actions and cleanup handle.

Import it

import type { SugorokuMount } from "@johnmorrisdotca/sugoroku/play";

Definition

type SugorokuMount = {
    readonly host: HTMLElement;
    game: () => GameState;
    match: () => Match;
    record: () => string;
    roll: (dice?: readonly number[]) => void;
    move: (from: number, to: number) => boolean;
    undo: () => void;
    done: () => void;
    double: () => void;
    take: () => void;
    drop: () => void;
    beaver: () => void;
    resign: () => void;
    nextGame: () => void;
    newMatch: (change?: {
        variant?: VariantKey;
        rules?: Partial<Rules>;
        preset?: string;
        seed?: RecordSeed;
    }) => void;
    set: (changes: SugorokuLook & {
        computer?: SugorokuMountOptions["computer"];
        language?: SugorokuLanguage;
        names?: SugorokuMountOptions["names"];
        sound?: boolean | SoundUrls;
    }) => void;
    destroy: () => void;
};

Members

NameTypeDescription
hostHTMLElement
game() => GameState

The game as it stands.

match() => Match
record() => string

The match so far as a record a server can replay (see replayRecord).

roll(dice?: readonly number[]) => void

Roll for the side that is to: with no dice, from the seed or at random; with them, the dice the page gives (two for the opening throw, one for white and one for black).

move(from: number, to: number) => boolean

Make a move for the side on turn, from its own point to its own point (the bar is 25, off is 0). False if it is not legal.

undo() => void
done() => void

End the turn once it is played out.

double() => void
take() => void
drop() => void
beaver() => void
resign() => void

Give up the game, as the side on turn.

nextGame() => void

The next game of the match.

newMatch(change?: { variant?: VariantKey; rules?: Partial<Rules>; preset?: string; seed?: RecordSeed; }) => void

A new match, in the same variant and rules unless others are given.

set(changes: SugorokuLook & { computer?: SugorokuMountOptions["computer"]; language?: SugorokuLanguage; names?: SugorokuMountOptions["names"]; sound?: boolean | SoundUrls; }) => void

Change how it looks or who plays: the look, the computer, the language, the names.

destroy() => void

Take the board down: its listeners, its timers and everything it put in the host.

Examples

import { newGame, rollOpening, settingsFor } from "@johnmorrisdotca/sugoroku";
import type { SugorokuMount } from "@johnmorrisdotca/sugoroku/play";
import { mountSugoroku } from "@johnmorrisdotca/sugoroku/play";

const settings = settingsFor("backgammon",{points:5,cube:true});
const game = rollOpening(newGame(settings),[3,1]);
const host = document.createElement("div");
document.body.append(host);
const board: SugorokuMount = mountSugoroku(host,{variant:"backgammon",seed:42,computer:{white:null,black:null}});
console.log(board.game().phase);
board.destroy();

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