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

Explanation

Architecture and immutable state

Follow the board, move, turn, game and match layers.

Source organization

The rules, the formats and the computer are plain functions over plain data with no DOM. The drawing and the playable board are separate entries.

src/
├── index.ts          the main entry: everything but the drawing and the page
├── side.ts           the two sides, white and black
├── variants.ts       every variant as a row of settings
├── rules.ts          the rules a name adds (match, cube, Crawford, Jacoby, gammons), and the named presets
├── board.ts          a position as plain data: counts, pips, the start, which point is which
├── moves.ts          every move of one die, and what a move does
├── plays.ts          whole turns: the dice that must be played, every different play, what may be played next
├── game.ts           a game in play: the opening, a roll, a move, undo, the cube, giving up, the result
├── match.ts          a match: the score, the Crawford game, the end
├── random.ts         the seeded random numbers
├── dice.ts           seeded dice, and dice from the device
├── notation.ts       moves and positions as text, and reading a written play back
├── positionId.ts     position IDs for the standard board
├── record.ts         games as text: written as they are played, and replayed against the rules
├── evaluate.ts       how good a position is: pips, blots, points, primes, anchors, the Keith count
├── computer.ts       the computer's play and cube, in four strengths
├── colours.ts        the colours a board is made of, and the named boards and checkers
├── geometry.ts       where everything is on the drawn board, lying down or standing up
├── style.ts          the style that makes the drawing a board, and keeps it from being selected
├── draw.ts           the board as SVG text
├── draw-entry.ts     the "/draw" entry: everything that draws
├── strings.ts        the words, in English and Japanese
├── sound.ts          the optional sounds
├── playStyle.ts      the style of the playable board
├── mount.ts          a board to play in any element: the game, the computer, events and the record
├── mountView.ts      drawing, words, buttons and the pointer on that board
├── play-entry.ts     the "/play" entry
├── elementFrame.ts   the shared frame of the board and position elements
├── element.ts        the <sugoroku-board> class
├── positionElement.ts the <sugoroku-position> class
├── element-define.ts defines the tag on the page
└── version.ts        the package's version

Tests sit beside the code they test (*.test.ts). The rules are held to brute.fixture.ts, which tries every order of the dice and every move on thousands of positions of every variant; simulate.test.ts plays thousands of games to their end, at random and by the computer, and checks that every checker is accounted for and the pips move by what was played; and a game written down must replay to the same result. scripts/ builds the demo and checks the package as npm packs it; demo/ is the playable page and e2e/ plays it in real browsers (Chromium and WebKit, at a phone's width and a desk's). The sounds are in sounds/; docs/VARIANTS.md says how each variant was read.

State and display

Position is checker counts, independent of dice and phase. GameState adds the turn plan, cube and result; Match carries completed results and Crawford bookkeeping. Lower-level move helpers assume native legal preconditions; public game transitions enforce phase and full-turn obligations. Record replay checks an action sequence through those transitions instead of trusting a supplied snapshot.

Drawing and mounting consume this state; they do not provide alternate rules. Colours and orientation affect SVG only. The static docs generator reads public comments and checked examples, and its build/search dependencies remain development tools. The variant notes preserve existing rule-source readings.

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