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

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

NameTypeDescription
settingsSettings
crawfordboolean

Whether this is the Crawford game of a match: no cube.

scorereadonly [number, number]

The match score as the game began, [white, black]: what the dead cube is judged by.

positionPosition
turnSide | null

The side to move; null until the opening throw has decided.

phasePhase
dicereadonly number[] | null

The roll being played, as thrown.

needreadonly number[]

The dice this turn must still play, highest first. Empty when the turn has been played, or when nothing can be.

planreadonly number[]

The dice this turn had to play to begin with, highest first.

movesreadonly Move[]

The moves made so far this turn, in order.

turnStartPosition

The position the turn began from: the moves are made from it.

cubeCube
offeredBySide | null

Who offered the double that is waiting to be answered, when phase is double-offered or beaver-offered.

turnsreadonly [number, number]

The turns each side has taken.

openingreadonly [number, number] | null

The last throw of a die each at the start: [white, black]. A tie means the sides throw again.

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

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