@johnmorrisdotca/sugoroku 1.0.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +78 -68
- package/dist/board.d.ts +216 -12
- package/dist/board.js +205 -13
- package/dist/colours.d.ts +80 -8
- package/dist/colours.js +57 -7
- package/dist/computer.d.ts +139 -9
- package/dist/computer.js +118 -11
- package/dist/dice.d.ts +53 -4
- package/dist/dice.js +42 -3
- package/dist/draw-entry.d.ts +3 -3
- package/dist/draw-entry.js +2 -2
- package/dist/draw.d.ts +43 -3
- package/dist/draw.js +63 -13
- package/dist/element-define.d.ts +1 -1
- package/dist/element-define.js +4 -13
- package/dist/element.d.ts +116 -5
- package/dist/element.js +378 -102
- package/dist/elementFrame.d.ts +21 -0
- package/dist/elementFrame.js +110 -0
- package/dist/evaluate.d.ts +76 -4
- package/dist/evaluate.js +70 -5
- package/dist/game.d.ts +408 -23
- package/dist/game.js +344 -20
- package/dist/geometry.d.ts +50 -3
- package/dist/geometry.js +64 -28
- package/dist/index.d.ts +12 -11
- package/dist/index.js +10 -9
- package/dist/match.d.ts +66 -4
- package/dist/match.js +69 -6
- package/dist/mount.d.ts +77 -6
- package/dist/mount.js +105 -357
- package/dist/mountView.d.ts +58 -0
- package/dist/mountView.js +459 -0
- package/dist/moves.d.ts +48 -1
- package/dist/moves.js +35 -1
- package/dist/notation.d.ts +92 -4
- package/dist/notation.js +88 -5
- package/dist/play-entry.d.ts +4 -4
- package/dist/play-entry.js +1 -1
- package/dist/playStyle.d.ts +6 -0
- package/dist/playStyle.js +6 -0
- package/dist/plays.d.ts +108 -3
- package/dist/plays.js +96 -3
- package/dist/positionElement.d.ts +107 -0
- package/dist/positionElement.js +303 -0
- package/dist/positionId.d.ts +29 -1
- package/dist/positionId.js +33 -2
- package/dist/random.d.ts +33 -3
- package/dist/random.js +22 -2
- package/dist/record.d.ts +151 -8
- package/dist/record.js +121 -36
- package/dist/rules.d.ts +130 -10
- package/dist/rules.js +133 -14
- package/dist/side.d.ts +38 -3
- package/dist/side.js +30 -3
- package/dist/sound.d.ts +61 -3
- package/dist/sound.js +27 -2
- package/dist/strings.d.ts +42 -2
- package/dist/strings.js +37 -3
- package/dist/style.d.ts +6 -0
- package/dist/style.js +6 -0
- package/dist/variants.d.ts +113 -8
- package/dist/variants.js +81 -7
- package/dist/version.d.ts +9 -2
- package/dist/version.js +9 -2
- package/package.json +29 -22
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,36 @@ All notable changes to this project are written here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.1.1] - 2026-10-31
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Biome replaces ESLint as the formatter and linter, with the family's shared settings in `scripts/biome-family.json`; `pnpm lint` checks formatting too, and `pnpm format` applies it. The code is formatted once to 120 columns. Nothing a user of the package sees has changed.
|
|
14
|
+
- TypeScript targets ES2022, treats an indexed read as possibly missing, and refuses switch fallthrough and unmarked overrides.
|
|
15
|
+
- `pnpm check` also holds every source file to at most 500 lines of code (`scripts/check-size.mjs`; blank lines, comments, tests and data files are not counted). The board is split across `src/elementFrame.ts` and `src/positionElement.ts`, and the play view lives in `src/mountView.ts`, so those files stay within that.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- The issue chooser's security link shows again: an unquoted colon had made `.github/ISSUE_TEMPLATE/config.yml` invalid YAML.
|
|
20
|
+
|
|
21
|
+
## [1.1.0] - 2026-10-14
|
|
22
|
+
|
|
23
|
+
The board and the position are custom elements with the family's standard embed attributes and a shared builder, and the package has an English and Japanese documentation site with a checked example for every export. The rules, dice, records and computer players are unchanged.
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- Add the bilingual documentation site, checked public examples, paired guides, local search and machine-readable pages.
|
|
28
|
+
- Add the shared embed builder and validated playable/position iframe routes. Preserve playable board methods and structured state while adding reflected attributes, host options and display sizes. Add a native SVG position element for GNU position IDs or JSON data; events now bubble across shadow roots with JSON-safe detail.
|
|
29
|
+
- Share a package-independent embed builder for option controls, preview adapters, code tabs and shareable links.
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- The API link in the header reads "API" in English, so that the header takes the same number of rows in English and in Japanese on a phone, as the demo's test of a language change asks.
|
|
34
|
+
- Synchronize documentation tooling for repository layouts, generated type references, Node entry points and repository-specific README links.
|
|
35
|
+
- Keep complete resource catalogues on the documentation entry index and the active resource beside core navigation; render valid default imports in HTML and Markdown.
|
|
36
|
+
- Group the package family by kind, alphabetize each group, and include the geography packages and REST in Pieces in the shared footer and README.
|
|
37
|
+
- Update the shared family description for addresses in all seven supported countries, including France and Germany.
|
|
38
|
+
|
|
9
39
|
## [1.0.2] - 2026-10-06
|
|
10
40
|
|
|
11
41
|
Nothing that was exported has changed.
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<h1 align="center">Sugoroku <sub>双六</sub
|
|
1
|
+
<h1 align="center">Sugoroku <sub>双六</sub> — Backgammon and its variants</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center"><strong>Backgammon and its variants for JavaScript and TypeScript.</strong><br>
|
|
4
4
|
The full rules, the doubling cube and match play with the Crawford rule, Nackgammon, Long Gammon, Hypergammon, Tabula, Anti-Backgammon and a race that starts from the bar, games written as text that a server can replay move by move, a seeded dice sequence, standard move notation, position IDs, a computer player in four strengths, and the board drawn as SVG and played by touch and mouse in any page with one call or one tag. No dependencies.</p>
|
|
@@ -9,16 +9,18 @@ The full rules, the doubling cube and match play with the Crawford rule, Nackgam
|
|
|
9
9
|
<a href="./LICENSE"><img alt="MIT licence" src="https://img.shields.io/badge/licence-MIT-2f5d4a"></a>
|
|
10
10
|
<img alt="No dependencies" src="https://img.shields.io/badge/dependencies-0-2f5d4a">
|
|
11
11
|
<img alt="TypeScript" src="https://img.shields.io/badge/types-TypeScript-3178c6">
|
|
12
|
+
<a href="https://johnmorrisdotca.github.io/sugoroku/docs/api/main/index.html"><img alt="11.6 kB minified and gzipped" src="https://img.shields.io/badge/min%2Bgzip-11.6%20kB-2f5d4a"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@johnmorrisdotca/sugoroku#provenance"><img alt="Published with npm provenance" src="https://img.shields.io/badge/npm-provenance-2f5d4a"></a>
|
|
12
14
|
</p>
|
|
13
15
|
|
|
14
|
-
<p align="center"><a href="https://johnmorrisdotca.github.io/sugoroku/"><strong>Play a game →</strong></a> · <a href="https://johnmorrisdotca.github.io/sugoroku/api.html">API reference</a> · <a href="docs/VARIANTS.md">The variants and their sources</a></p>
|
|
16
|
+
<p align="center"><a href="https://johnmorrisdotca.github.io/sugoroku/"><strong>Play a game →</strong></a> · <a href="https://johnmorrisdotca.github.io/sugoroku/docs/">Documentation</a> · <a href="https://johnmorrisdotca.github.io/sugoroku/docs/guides/getting-started.html">Getting started</a> · <a href="https://johnmorrisdotca.github.io/sugoroku/api.html">API reference</a> · <a href="docs/VARIANTS.md">The variants and their sources</a></p>
|
|
15
17
|
|
|
16
18
|
<table align="center">
|
|
17
19
|
<tr>
|
|
18
20
|
<td align="center" valign="top">
|
|
19
21
|
<picture>
|
|
20
22
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/johnmorrisdotca/sugoroku/main/docs/images/hero-desk-dark.webp">
|
|
21
|
-
<img src="https://raw.githubusercontent.com/johnmorrisdotca/sugoroku/main/docs/images/hero-desk-light.webp" alt="The demo on a desk, in English: the page's header with its language chooser and cloth swatches, the game chooser (Backgammon, Race, Anti, Nackgammon, Long Gammon, Hypergammon, Tabula), the player choices, and a backgammon board in the middle of a match to 3 with the doubling cube at 2, black and white checkers on a green board with red and cream points, and the Roll dice, Double and Undo buttons under it." width="720">
|
|
23
|
+
<img src="https://raw.githubusercontent.com/johnmorrisdotca/sugoroku/main/docs/images/hero-desk-light.webp" alt="The demo on a desk, in English: the page's header with its language chooser, Docs link and cloth swatches, the game chooser (Backgammon, Race, Anti, Nackgammon, Long Gammon, Hypergammon, Tabula), the player choices, and a backgammon board in the middle of a match to 3 with the doubling cube at 2, black and white checkers on a green board with red and cream points, and the Roll dice, Double and Undo buttons under it." width="720">
|
|
22
24
|
</picture>
|
|
23
25
|
<br><em>A match to 3 against the computer, the cube at 2, on a desk.</em>
|
|
24
26
|
</td>
|
|
@@ -143,6 +145,17 @@ Each picture is a board drawn by the package's `drawSugoroku`, taken from [the d
|
|
|
143
145
|
|
|
144
146
|
## Use it in your project
|
|
145
147
|
|
|
148
|
+
### Install under another name
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
npm install backgammon@npm:@johnmorrisdotca/sugoroku
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
```ts no-check
|
|
155
|
+
import { settingsFor } from "backgammon";
|
|
156
|
+
console.log(settingsFor("backgammon").variant);
|
|
157
|
+
```
|
|
158
|
+
|
|
146
159
|
### Install
|
|
147
160
|
|
|
148
161
|
```sh
|
|
@@ -263,6 +276,12 @@ These recipes are written to the tag's documented attributes and events; they ar
|
|
|
263
276
|
|
|
264
277
|
The cookbook, with the output of each example, is under [Examples](#examples).
|
|
265
278
|
|
|
279
|
+
### Embed builder
|
|
280
|
+
|
|
281
|
+
[Build a playable board or position](https://johnmorrisdotca.github.io/sugoroku/builder.html) and copy its embed code. The board adds `size` (small/medium/large), pixel `width`, spoken `label` and host `options`. Attributes reflect to properties; `game`, `match` and all board methods remain. `beaver` assignment changes the rule while `beaver()` retains its action.
|
|
282
|
+
|
|
283
|
+
`<sugoroku-position position="4HPwATDgc/ABMA" turn="white" size="small">` shows a GNU position ID or JSON position. Its structured `value`, drawing `options`, custom tags and all host formats are described in [the embed guide](docs/embeds.md).
|
|
284
|
+
|
|
266
285
|
## Examples
|
|
267
286
|
|
|
268
287
|
Every TypeScript and JavaScript block that can run is type-checked against the built package and run by `pnpm test:readme`, so the output after `// →` is what the code prints. The rules need no page and no network, so most of these run under Node.
|
|
@@ -690,6 +709,8 @@ page's `lang`.
|
|
|
690
709
|
|
|
691
710
|
## API
|
|
692
711
|
|
|
712
|
+
The [documentation](https://johnmorrisdotca.github.io/sugoroku/docs/) provides paired guides, local search and checked examples. The [API index](https://johnmorrisdotca.github.io/sugoroku/api.html) retains export anchors.
|
|
713
|
+
|
|
693
714
|
| Export | What it does |
|
|
694
715
|
| --- | --- |
|
|
695
716
|
| `otherSide(side)`, `sideIndex(side)`, `SIDES` | the two sides, `white` and `black`, and where a side's counts are kept |
|
|
@@ -830,50 +851,7 @@ Left out on purpose: play over a network, which needs a server (a record is plai
|
|
|
830
851
|
|
|
831
852
|
## Architecture
|
|
832
853
|
|
|
833
|
-
The
|
|
834
|
-
drawing and the playable board are separate entries.
|
|
835
|
-
|
|
836
|
-
```text
|
|
837
|
-
src/
|
|
838
|
-
├── index.ts the main entry: everything but the drawing and the page
|
|
839
|
-
├── side.ts the two sides, white and black
|
|
840
|
-
├── variants.ts every variant as a row of settings
|
|
841
|
-
├── rules.ts the rules a name adds (match, cube, Crawford, Jacoby, gammons), and the named presets
|
|
842
|
-
├── board.ts a position as plain data: counts, pips, the start, which point is which
|
|
843
|
-
├── moves.ts every move of one die, and what a move does
|
|
844
|
-
├── plays.ts whole turns: the dice that must be played, every different play, what may be played next
|
|
845
|
-
├── game.ts a game in play: the opening, a roll, a move, undo, the cube, giving up, the result
|
|
846
|
-
├── match.ts a match: the score, the Crawford game, the end
|
|
847
|
-
├── random.ts the seeded random numbers
|
|
848
|
-
├── dice.ts seeded dice, and dice from the device
|
|
849
|
-
├── notation.ts moves and positions as text, and reading a written play back
|
|
850
|
-
├── positionId.ts position IDs for the standard board
|
|
851
|
-
├── record.ts games as text: written as they are played, and replayed against the rules
|
|
852
|
-
├── evaluate.ts how good a position is: pips, blots, points, primes, anchors, the Keith count
|
|
853
|
-
├── computer.ts the computer's play and cube, in four strengths
|
|
854
|
-
├── colours.ts the colours a board is made of, and the named boards and checkers
|
|
855
|
-
├── geometry.ts where everything is on the drawn board, lying down or standing up
|
|
856
|
-
├── style.ts the style that makes the drawing a board, and keeps it from being selected
|
|
857
|
-
├── draw.ts the board as SVG text
|
|
858
|
-
├── draw-entry.ts the "/draw" entry: everything that draws
|
|
859
|
-
├── strings.ts the words, in English and Japanese
|
|
860
|
-
├── sound.ts the optional sounds
|
|
861
|
-
├── playStyle.ts the style of the playable board
|
|
862
|
-
├── mount.ts a board to play in any element: touch, mouse, buttons, computer, events, record
|
|
863
|
-
├── play-entry.ts the "/play" entry
|
|
864
|
-
├── element.ts the <sugoroku-board> class
|
|
865
|
-
├── element-define.ts defines the tag on the page
|
|
866
|
-
└── version.ts the package's version
|
|
867
|
-
```
|
|
868
|
-
|
|
869
|
-
Tests sit beside the code they test (`*.test.ts`). The rules are held to `brute.fixture.ts`,
|
|
870
|
-
which tries every order of the dice and every move on thousands of positions of every
|
|
871
|
-
variant; `simulate.test.ts` plays thousands of games to their end, at random and by the
|
|
872
|
-
computer, and checks that every checker is accounted for and the pips move by what was
|
|
873
|
-
played; and a game written down must replay to the same result. `scripts/` builds the demo
|
|
874
|
-
and checks the package as npm packs it; `demo/` is the playable page and `e2e/` plays it in
|
|
875
|
-
real browsers (Chromium and WebKit, at a phone's width and a desk's). The sounds are in
|
|
876
|
-
`sounds/`; `docs/VARIANTS.md` says how each variant was read.
|
|
854
|
+
The board, move, turn, game and match layers, record validation and drawing are explained in the [architecture guide](docs/guides/architecture.md), which preserves the complete source tree.
|
|
877
855
|
|
|
878
856
|
## The name
|
|
879
857
|
|
|
@@ -906,35 +884,67 @@ Nobody is listed yet. Using Sugoroku in something? Open an *Add my project* issu
|
|
|
906
884
|
### The family
|
|
907
885
|
|
|
908
886
|
<!-- family:start (made by scripts/family-readme.mjs from scripts/family-template.mjs; change those, not this) -->
|
|
909
|
-
Sugoroku is one of
|
|
910
|
-
[github.com/johnmorrisdotca](https://github.com/johnmorrisdotca). The code of every one is MIT.
|
|
887
|
+
Sugoroku is one of thirty-two packages, each made for the same site, each at
|
|
888
|
+
[github.com/johnmorrisdotca](https://github.com/johnmorrisdotca) or [github.com/spxis](https://github.com/spxis). The code of every one is MIT.
|
|
911
889
|
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
- [
|
|
915
|
-
- [
|
|
916
|
-
- [Tane](https://github.com/johnmorrisdotca/tane) (種): seeded random numbers and daily seeds, the same in every browser and on every server. [Demo](https://johnmorrisdotca.github.io/tane/).
|
|
890
|
+
**Games — board**
|
|
891
|
+
|
|
892
|
+
- [Domino](https://github.com/johnmorrisdotca/domino) (ドミノ): dominoes and Mexican Train. [Demo](https://johnmorrisdotca.github.io/domino/).
|
|
893
|
+
- [Gunjin](https://github.com/johnmorrisdotca/gunjin) (軍人): five hidden-rank strategy games with pass-the-device play. [Demo](https://johnmorrisdotca.github.io/gunjin/).
|
|
917
894
|
- [Narabe](https://github.com/johnmorrisdotca/narabe) (並べ): one rules engine for abstract board games, from gomoku and Reversi to Go and checkers. [Demo](https://johnmorrisdotca.github.io/narabe/).
|
|
895
|
+
- [Sugoroku](https://github.com/johnmorrisdotca/sugoroku) (双六): backgammon and its variants, with the doubling cube and match play. [Demo](https://johnmorrisdotca.github.io/sugoroku/).
|
|
918
896
|
- [Tenka](https://github.com/johnmorrisdotca/tenka) (天下): world conquest for two to six, on a map of the real world. [Demo](https://johnmorrisdotca.github.io/tenka/).
|
|
919
|
-
|
|
920
|
-
|
|
897
|
+
|
|
898
|
+
**Games — cards & tiles**
|
|
899
|
+
|
|
900
|
+
- [Hitotsu](https://github.com/johnmorrisdotca/hitotsu) (一つ): a colour-card shedding game for two to eight, with the house rules people play. [Demo](https://johnmorrisdotca.github.io/hitotsu/).
|
|
921
901
|
- [Jarajara](https://github.com/johnmorrisdotca/jarajara) (ジャラジャラ): mahjong tiles drawn as SVG, stacked layouts, and the matching solitaire Awase. [Demo](https://johnmorrisdotca.github.io/jarajara/).
|
|
922
|
-
- [
|
|
923
|
-
- [
|
|
924
|
-
|
|
925
|
-
|
|
902
|
+
- [Kumimoji](https://github.com/johnmorrisdotca/kumimoji) (組み文字): a crossword tile race, in English and Japanese kana. [Demo](https://johnmorrisdotca.github.io/kumimoji/).
|
|
903
|
+
- [Toranpu](https://github.com/johnmorrisdotca/toranpu) (トランプ): a deck of playing cards, card games with computer players, and solitaires. [Demo](https://johnmorrisdotca.github.io/toranpu/).
|
|
904
|
+
|
|
905
|
+
**Games — puzzles**
|
|
906
|
+
|
|
907
|
+
- [Houseki](https://github.com/johnmorrisdotca/houseki) (宝石): gem and stone matching puzzles: falling triplets, stone collapse, colour chains and gem swap. [Demo](https://johnmorrisdotca.github.io/houseki/).
|
|
908
|
+
- [Jirai](https://github.com/johnmorrisdotca/jirai) (地雷): minesweeper on shaped grids with verified no-guess boards. [Demo](https://johnmorrisdotca.github.io/jirai/).
|
|
909
|
+
- [Karakuri](https://github.com/johnmorrisdotca/karakuri) (からくり): eight hyper-casual puzzle games, some of them physics: draw a shield, pull pins, cut ropes, slide blocks, pour tubes. [Demo](https://johnmorrisdotca.github.io/karakuri/).
|
|
926
910
|
- [Kazu](https://github.com/johnmorrisdotca/kazu) (数): grid number puzzles: Sudoku and its variants, Futoshiki and Skyscrapers. [Demo](https://johnmorrisdotca.github.io/kazu/).
|
|
911
|
+
- [Kyuubu](https://github.com/johnmorrisdotca/kyuubu) (キューブ): a turning cube for the browser, 2×2 to 7×7, with record solves to replay. [Demo](https://johnmorrisdotca.github.io/kyuubu/).
|
|
927
912
|
- [Meikyuu](https://github.com/johnmorrisdotca/meikyuu) (迷宮): mazes on squares, hexagons, triangles and circles, made from a seed and drawn through with a finger or the mouse. [Demo](https://johnmorrisdotca.github.io/meikyuu/).
|
|
913
|
+
- [Suido](https://github.com/johnmorrisdotca/suido) (水道): a pipe puzzle: turn the pieces until the water reaches every drain. [Demo](https://johnmorrisdotca.github.io/suido/).
|
|
914
|
+
- [Tobiishi](https://github.com/johnmorrisdotca/tobiishi) (飛び石): peg solitaire with nine boards and seeded solvable challenges. [Demo](https://johnmorrisdotca.github.io/tobiishi/).
|
|
915
|
+
- [Tsunagi](https://github.com/johnmorrisdotca/tsunagi) (繋ぎ): a line-joining logic puzzle whose every level has exactly one answer. [Demo](https://johnmorrisdotca.github.io/tsunagi/).
|
|
916
|
+
|
|
917
|
+
**Games — dice & random**
|
|
918
|
+
|
|
919
|
+
- [Korokoro](https://github.com/johnmorrisdotca/korokoro) (コロコロ): dice, with notation, exact odds, real sounds and the dice of many games. [Demo](https://johnmorrisdotca.github.io/korokoro/).
|
|
920
|
+
- [Tane](https://github.com/johnmorrisdotca/tane) (種): seeded random numbers and daily seeds, the same in every browser and on every server. [Demo](https://johnmorrisdotca.github.io/tane/).
|
|
921
|
+
|
|
922
|
+
**Language**
|
|
923
|
+
|
|
924
|
+
- [Bushu](https://github.com/johnmorrisdotca/bushu) (部首): find a kanji by the parts it is made of. [Demo](https://johnmorrisdotca.github.io/bushu/).
|
|
928
925
|
- [Hikidashi](https://github.com/johnmorrisdotca/hikidashi) (引き出し): a drawer of small Japanese text tools: era dates, kanji numerals, readings and sentence difficulty. [Demo](https://johnmorrisdotca.github.io/hikidashi/).
|
|
926
|
+
- [Kotoba](https://github.com/johnmorrisdotca/kotoba) (言葉): word lists and word-game rules in English, French, German and Japanese. [Demo](https://johnmorrisdotca.github.io/kotoba/).
|
|
927
|
+
|
|
928
|
+
**Geography & data**
|
|
929
|
+
|
|
930
|
+
- [address-plus](https://github.com/johnmorrisdotca/address-plus) (アドレスプラス): parse and format addresses in the United States, Canada, Japan, Australia, France, Germany and the United Kingdom. [Demo](https://johnmorrisdotca.github.io/address-plus/).
|
|
929
931
|
- [Chizu](https://github.com/johnmorrisdotca/chizu) (地図): maps of the world and of countries' regions, in English and Japanese, with a quiz and callouts. [Demo](https://johnmorrisdotca.github.io/chizu/).
|
|
930
|
-
- [
|
|
931
|
-
- [
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
- [
|
|
932
|
+
- [Hata](https://github.com/johnmorrisdotca/hata) (旗): country and regional flags as SVG, at their true proportions and keyed by ISO code. [Demo](https://johnmorrisdotca.github.io/hata/).
|
|
933
|
+
- [Kuni](https://github.com/johnmorrisdotca/kuni) (国): countries and their regions, with ISO codes and names in English and Japanese. [Demo](https://johnmorrisdotca.github.io/kuni/).
|
|
934
|
+
|
|
935
|
+
**Sports**
|
|
936
|
+
|
|
937
|
+
- [Dougu Sports](https://github.com/johnmorrisdotca/dougu-sports) (道具): sports emblems as SVG: trophies, medals, crests, and the ball and gear of every sport, with optional 3D turning. [Demo](https://johnmorrisdotca.github.io/dougu-sports/).
|
|
938
|
+
- [Kyogijo Stadiums](https://github.com/johnmorrisdotca/kyogijo-stadiums) (競技場): sports fields, rinks, courts and ballparks drawn to scale as SVG, with each team and the score on them. [Demo](https://johnmorrisdotca.github.io/kyogijo-stadiums/).
|
|
939
|
+
- [Senshu Jerseys](https://github.com/johnmorrisdotca/senshu-jerseys) (選手): sports jerseys, sweaters, kits, caps, helmets and retired-number banners as SVG, front and back, with optional 2.5D turning. [Demo](https://johnmorrisdotca.github.io/senshu-jerseys/).
|
|
940
|
+
- [Taisen Brackets](https://github.com/johnmorrisdotca/taisen-brackets) (対戦): a sport-agnostic tournament bracket, drawn as SVG, from a list of ties. [Demo](https://johnmorrisdotca.github.io/taisen-brackets/).
|
|
941
|
+
|
|
942
|
+
**Developer tools**
|
|
943
|
+
|
|
944
|
+
- [REST in Pieces](https://github.com/spxis/rest-in-pieces) (レスト・イン・ピーシーズ): seeded test data and REST APIs for frontend development, with latency and error drills. [Demo](https://spxis.github.io/rest-in-pieces/).
|
|
945
|
+
|
|
936
946
|
|
|
937
|
-
**This package is Sugoroku.** The demos of all
|
|
947
|
+
**This package is Sugoroku.** The demos of all thirty-two share one header and footer, so each links the rest.
|
|
938
948
|
<!-- family:end -->
|
|
939
949
|
|
|
940
950
|
## Development
|
|
@@ -961,7 +971,7 @@ Please follow the [code of conduct](./CODE_OF_CONDUCT.md). A record or a positio
|
|
|
961
971
|
|
|
962
972
|
See [CHANGELOG.md](./CHANGELOG.md).
|
|
963
973
|
|
|
964
|
-
The latest release
|
|
974
|
+
The latest release, 1.1.1, changes nothing a player sees.
|
|
965
975
|
|
|
966
976
|
## Licence
|
|
967
977
|
|
package/dist/board.d.ts
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { type Side } from "./side.ts";
|
|
2
2
|
import { type VariantSpec } from "./variants.ts";
|
|
3
|
-
/** The points on the board.
|
|
3
|
+
/** The points on the board.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { POINTS } from "@johnmorrisdotca/sugoroku";
|
|
8
|
+
* console.log(POINTS);
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
4
11
|
export declare const POINTS = 24;
|
|
5
|
-
/** The number a move's `from` has when a checker comes from the bar (or from off the board at the start of a race).
|
|
12
|
+
/** The number a move's `from` has when a checker comes from the bar (or from off the board at the start of a race).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { BAR } from "@johnmorrisdotca/sugoroku";
|
|
17
|
+
* console.log(BAR);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
6
20
|
export declare const BAR = 25;
|
|
7
21
|
/**
|
|
8
22
|
* WHERE THE CHECKERS ARE. Every count is in the side's own numbering: own
|
|
@@ -10,6 +24,18 @@ export declare const BAR = 25;
|
|
|
10
24
|
* from it, so `points[side][n - 1]` is how many of that side's checkers stand
|
|
11
25
|
* on its own point `n`. A position is plain data and is never changed: every
|
|
12
26
|
* function that moves a checker returns a new one.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
31
|
+
* import type { Position } from "@johnmorrisdotca/sugoroku";
|
|
32
|
+
*
|
|
33
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
34
|
+
* const spec = settings.variant;
|
|
35
|
+
* const position = startPosition(spec);
|
|
36
|
+
* const value: Position = position;
|
|
37
|
+
* console.log(value);
|
|
38
|
+
* ```
|
|
13
39
|
*/
|
|
14
40
|
export type Position = {
|
|
15
41
|
/** `[white, black]`, each 24 counts, index 0 being own point 1. */
|
|
@@ -21,37 +47,202 @@ export type Position = {
|
|
|
21
47
|
/** Checkers borne off, `[white, black]`. */
|
|
22
48
|
readonly off: readonly [number, number];
|
|
23
49
|
};
|
|
24
|
-
/** The position a variant starts from.
|
|
50
|
+
/** The position a variant starts from.
|
|
51
|
+
*
|
|
52
|
+
* @param spec - The native variant specification.
|
|
53
|
+
* @returns The position a variant starts from.
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
57
|
+
*
|
|
58
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
59
|
+
* const spec = settings.variant;
|
|
60
|
+
* console.log(startPosition(spec).bar);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
25
63
|
export declare function startPosition(spec: VariantSpec): Position;
|
|
26
64
|
/**
|
|
27
65
|
* The other side's own number for the point that is `side`'s own point `own`.
|
|
28
66
|
* With the sides going opposite ways round, a side's 24-point is the other's
|
|
29
67
|
* 1-point; going the same way, a point has the one number for both.
|
|
68
|
+
*
|
|
69
|
+
* @param spec - The native variant specification.
|
|
70
|
+
* @param own - A point in this side’s own numbering.
|
|
71
|
+
* @returns The other side's own number for the point that is `side`'s own point `own`. With the sides going opposite ways round, a side's 24-point is the other's 1-point; going the same way, a point has the one number for both.
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { mirrorPoint, settingsFor } from "@johnmorrisdotca/sugoroku";
|
|
75
|
+
*
|
|
76
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
77
|
+
* const spec = settings.variant;
|
|
78
|
+
* console.log(mirrorPoint(spec,24));
|
|
79
|
+
* ```
|
|
30
80
|
*/
|
|
31
81
|
export declare function mirrorPoint(spec: VariantSpec, own: number): number;
|
|
32
82
|
/**
|
|
33
83
|
* The point on the board, 1 to 24 counting the way white counts, that is
|
|
34
84
|
* `side`'s own point `own`. White's own numbers are the board's; black's are
|
|
35
85
|
* the board's reversed when the sides go opposite ways round.
|
|
86
|
+
*
|
|
87
|
+
* @param spec - The native variant specification.
|
|
88
|
+
* @param side - The side being examined: white or black.
|
|
89
|
+
* @param own - A point in this side’s own numbering.
|
|
90
|
+
* @returns The point on the board, 1 to 24 counting the way white counts, that is `side`'s own point `own`. White's own numbers are the board's; black's are the board's reversed when the sides go opposite ways round.
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { boardPoint, settingsFor } from "@johnmorrisdotca/sugoroku";
|
|
94
|
+
*
|
|
95
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
96
|
+
* const spec = settings.variant;
|
|
97
|
+
* console.log(boardPoint(spec,"black",24));
|
|
98
|
+
* ```
|
|
36
99
|
*/
|
|
37
100
|
export declare function boardPoint(spec: VariantSpec, side: Side, own: number): number;
|
|
38
|
-
/** How many of `side`'s checkers stand on its own point `own` (1 to 24).
|
|
101
|
+
/** How many of `side`'s checkers stand on its own point `own` (1 to 24).
|
|
102
|
+
*
|
|
103
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
104
|
+
* @param side - The side being examined: white or black.
|
|
105
|
+
* @param own - A point in this side’s own numbering.
|
|
106
|
+
* @returns How many of `side`'s checkers stand on its own point `own` (1 to 24).
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { countAt, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
110
|
+
*
|
|
111
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
112
|
+
* const spec = settings.variant;
|
|
113
|
+
* const position = startPosition(spec);
|
|
114
|
+
* console.log(countAt(position,"white",24));
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
39
117
|
export declare function countAt(position: Position, side: Side, own: number): number;
|
|
40
|
-
/** How many of the other side's checkers stand on the point that is `side`'s own point `own`.
|
|
118
|
+
/** How many of the other side's checkers stand on the point that is `side`'s own point `own`.
|
|
119
|
+
*
|
|
120
|
+
* @param spec - The native variant specification.
|
|
121
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
122
|
+
* @param side - The side being examined: white or black.
|
|
123
|
+
* @param own - A point in this side’s own numbering.
|
|
124
|
+
* @returns How many of the other side's checkers stand on the point that is `side`'s own point `own`.
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { opponentAt, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
128
|
+
*
|
|
129
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
130
|
+
* const spec = settings.variant;
|
|
131
|
+
* const position = startPosition(spec);
|
|
132
|
+
* console.log(opponentAt(spec,position,"white",24));
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
41
135
|
export declare function opponentAt(spec: VariantSpec, position: Position, side: Side, own: number): number;
|
|
42
|
-
/** How many checkers `side` has on the board's points, not counting the bar, the reserve and those borne off.
|
|
136
|
+
/** How many checkers `side` has on the board's points, not counting the bar, the reserve and those borne off.
|
|
137
|
+
*
|
|
138
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
139
|
+
* @param side - The side being examined: white or black.
|
|
140
|
+
* @returns How many checkers `side` has on the board's points, not counting the bar, the reserve and those borne off.
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { onBoard, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
144
|
+
*
|
|
145
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
146
|
+
* const spec = settings.variant;
|
|
147
|
+
* const position = startPosition(spec);
|
|
148
|
+
* console.log(onBoard(position,"white"));
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
43
151
|
export declare function onBoard(position: Position, side: Side): number;
|
|
44
|
-
/** Every checker of `side` that is still in the game: on the board, on the bar or yet to enter.
|
|
152
|
+
/** Every checker of `side` that is still in the game: on the board, on the bar or yet to enter.
|
|
153
|
+
*
|
|
154
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
155
|
+
* @param side - The side being examined: white or black.
|
|
156
|
+
* @returns Every checker of `side` that is still in the game: on the board, on the bar or yet to enter.
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { inPlay, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
160
|
+
*
|
|
161
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
162
|
+
* const spec = settings.variant;
|
|
163
|
+
* const position = startPosition(spec);
|
|
164
|
+
* console.log(inPlay(position,"white"));
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
45
167
|
export declare function inPlay(position: Position, side: Side): number;
|
|
46
|
-
/** The pip count of a side: the sum of every checker's distance from being borne off. A checker on the bar or yet to enter counts 25.
|
|
168
|
+
/** The pip count of a side: the sum of every checker's distance from being borne off. A checker on the bar or yet to enter counts 25.
|
|
169
|
+
*
|
|
170
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
171
|
+
* @param side - The side being examined: white or black.
|
|
172
|
+
* @returns The pip count of a side: the sum of every checker's distance from being borne off. A checker on the bar or yet to enter counts 25.
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { pipCount, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
176
|
+
*
|
|
177
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
178
|
+
* const spec = settings.variant;
|
|
179
|
+
* const position = startPosition(spec);
|
|
180
|
+
* console.log(pipCount(position,"white"));
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
47
183
|
export declare function pipCount(position: Position, side: Side): number;
|
|
48
|
-
/** Whether every checker of `side` still in play is in its home board (own points 1 to 6): the condition for bearing off.
|
|
184
|
+
/** Whether every checker of `side` still in play is in its home board (own points 1 to 6): the condition for bearing off.
|
|
185
|
+
*
|
|
186
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
187
|
+
* @param side - The side being examined: white or black.
|
|
188
|
+
* @returns Whether every checker of `side` still in play is in its home board (own points 1 to 6): the condition for bearing off.
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { allHome, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
192
|
+
*
|
|
193
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
194
|
+
* const spec = settings.variant;
|
|
195
|
+
* const position = startPosition(spec);
|
|
196
|
+
* console.log(allHome(position,"white"));
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
49
199
|
export declare function allHome(position: Position, side: Side): boolean;
|
|
50
|
-
/** A position as a short string that is the same for the same position, for keeping a set of them.
|
|
200
|
+
/** A position as a short string that is the same for the same position, for keeping a set of them.
|
|
201
|
+
*
|
|
202
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
203
|
+
* @returns A position as a short string that is the same for the same position, for keeping a set of them.
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* import { positionKey, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
207
|
+
*
|
|
208
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
209
|
+
* const spec = settings.variant;
|
|
210
|
+
* const position = startPosition(spec);
|
|
211
|
+
* console.log(positionKey(position));
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
51
214
|
export declare function positionKey(position: Position): string;
|
|
52
|
-
/** The whole count of each side's checkers: on the board, on the bar, yet to enter, and off. Always the variant's `checkers`.
|
|
215
|
+
/** The whole count of each side's checkers: on the board, on the bar, yet to enter, and off. Always the variant's `checkers`.
|
|
216
|
+
*
|
|
217
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
218
|
+
* @param side - The side being examined: white or black.
|
|
219
|
+
* @returns The whole count of each side's checkers: on the board, on the bar, yet to enter, and off. Always the variant's `checkers`.
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* import { checkersOf, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
223
|
+
*
|
|
224
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
225
|
+
* const spec = settings.variant;
|
|
226
|
+
* const position = startPosition(spec);
|
|
227
|
+
* console.log(checkersOf(position,"white"));
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
53
230
|
export declare function checkersOf(position: Position, side: Side): number;
|
|
54
|
-
/** A copy of a position with some counts changed.
|
|
231
|
+
/** A copy of a position with some counts changed.
|
|
232
|
+
*
|
|
233
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
234
|
+
* @param changes - The replacement checker-count fields.
|
|
235
|
+
* @returns A copy of a position with some counts changed.
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* import { settingsFor, startPosition, withCounts } from "@johnmorrisdotca/sugoroku";
|
|
239
|
+
*
|
|
240
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
241
|
+
* const spec = settings.variant;
|
|
242
|
+
* const position = startPosition(spec);
|
|
243
|
+
* console.log(withCounts(position,{off:[0,0]}).off);
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
55
246
|
export declare function withCounts(position: Position, changes: {
|
|
56
247
|
points?: [number[], number[]];
|
|
57
248
|
bar?: [number, number];
|
|
@@ -62,5 +253,18 @@ export declare function withCounts(position: Position, changes: {
|
|
|
62
253
|
* Whether the two sides can still hit one another. Once every checker of
|
|
63
254
|
* one side has gone past every checker of the other there is nothing more to
|
|
64
255
|
* play for but the race, and the game is a race.
|
|
256
|
+
*
|
|
257
|
+
* @param spec - The native variant specification.
|
|
258
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
259
|
+
* @returns Whether the two sides can still hit one another. Once every checker of one side has gone past every checker of the other there is nothing more to play for but the race, and the game is a race.
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* import { inContact, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
263
|
+
*
|
|
264
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
265
|
+
* const spec = settings.variant;
|
|
266
|
+
* const position = startPosition(spec);
|
|
267
|
+
* console.log(inContact(spec,position));
|
|
268
|
+
* ```
|
|
65
269
|
*/
|
|
66
270
|
export declare function inContact(spec: VariantSpec, position: Position): boolean;
|