@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/dist/variants.d.ts
CHANGED
|
@@ -1,26 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THE VARIANTS, AS ROWS OF SETTINGS. Nothing in the engine branches on a
|
|
3
3
|
* variant's name: it reads the row. A new game on the same board is a new row.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { VariantKey } from "@johnmorrisdotca/sugoroku";
|
|
8
|
+
*
|
|
9
|
+
* const value: VariantKey = "tabula";
|
|
10
|
+
* console.log(value);
|
|
11
|
+
* ```
|
|
4
12
|
*/
|
|
5
13
|
export type VariantKey = "backgammon" | "backgammon-race" | "anti-backgammon" | "nackgammon" | "long-gammon" | "hypergammon" | "tabula";
|
|
6
|
-
/** How the sides' tracks lie on the board.
|
|
14
|
+
/** How the sides' tracks lie on the board.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import type { Direction } from "@johnmorrisdotca/sugoroku";
|
|
19
|
+
*
|
|
20
|
+
* const value: Direction = "opposed";
|
|
21
|
+
* console.log(value);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
7
24
|
export type Direction =
|
|
8
25
|
/** Opposite ways round, as in backgammon: one side's 24-point is the other's 1-point. */
|
|
9
26
|
"opposed"
|
|
10
27
|
/** The same way round, from the same start, as in Tabula: both sides' own point 24 is the one place. */
|
|
11
28
|
| "same";
|
|
12
|
-
/** How a game is opened.
|
|
29
|
+
/** How a game is opened.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import type { Opening } from "@johnmorrisdotca/sugoroku";
|
|
34
|
+
*
|
|
35
|
+
* const value: Opening = "roll-off";
|
|
36
|
+
* console.log(value);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
13
39
|
export type Opening =
|
|
14
40
|
/** Each side throws one die; the higher plays both dice as the first roll of the game, as in backgammon. */
|
|
15
41
|
"roll-off"
|
|
16
42
|
/** Each side throws one die; the higher goes first and then rolls a roll of their own. */
|
|
17
43
|
| "die-each";
|
|
18
|
-
/** What it takes to win.
|
|
44
|
+
/** What it takes to win.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import type { Goal } from "@johnmorrisdotca/sugoroku";
|
|
49
|
+
*
|
|
50
|
+
* const value: Goal = "first-off";
|
|
51
|
+
* console.log(value);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
19
54
|
export type Goal =
|
|
20
55
|
/** Bear off every checker first. */
|
|
21
56
|
"first-off"
|
|
22
57
|
/** Be last to bear off: whoever bears off every checker first loses (Anti-Backgammon). */
|
|
23
58
|
| "last-off";
|
|
59
|
+
/** A native variant’s checker counts, starting layout, dice, directions, opening and winning goal.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { settingsFor } from "@johnmorrisdotca/sugoroku";
|
|
64
|
+
* import type { VariantSpec } from "@johnmorrisdotca/sugoroku";
|
|
65
|
+
*
|
|
66
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
67
|
+
* const spec = settings.variant;
|
|
68
|
+
* const value: VariantSpec = spec;
|
|
69
|
+
* console.log(value);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
24
72
|
export type VariantSpec = {
|
|
25
73
|
readonly key: VariantKey;
|
|
26
74
|
/** Checkers each side has. */
|
|
@@ -46,15 +94,72 @@ export type VariantSpec = {
|
|
|
46
94
|
/**
|
|
47
95
|
* Every variant. Where each comes from, and where the sources disagree or say
|
|
48
96
|
* nothing, is in `docs/VARIANTS.md`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { VARIANTS } from "@johnmorrisdotca/sugoroku";
|
|
101
|
+
* console.log(VARIANTS);
|
|
102
|
+
* ```
|
|
49
103
|
*/
|
|
50
104
|
export declare const VARIANTS: Readonly<Record<VariantKey, VariantSpec>>;
|
|
51
|
-
/** The variants' keys, in the order the demo lists them.
|
|
105
|
+
/** The variants' keys, in the order the demo lists them.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { VARIANT_KEYS } from "@johnmorrisdotca/sugoroku";
|
|
110
|
+
* console.log(VARIANT_KEYS);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
52
113
|
export declare const VARIANT_KEYS: readonly VariantKey[];
|
|
53
|
-
/** Whether `key` names a variant.
|
|
114
|
+
/** Whether `key` names a variant.
|
|
115
|
+
*
|
|
116
|
+
* @param key - The native variant, preset or localized-label key specified by the signature.
|
|
117
|
+
* @returns Whether `key` names a variant.
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { isVariantKey } from "@johnmorrisdotca/sugoroku";
|
|
121
|
+
*
|
|
122
|
+
* console.log(isVariantKey("tabula"));
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
54
125
|
export declare function isVariantKey(key: unknown): key is VariantKey;
|
|
55
|
-
/** The row for a variant.
|
|
126
|
+
/** The row for a variant.
|
|
127
|
+
*
|
|
128
|
+
* @param key - The native variant, preset or localized-label key specified by the signature.
|
|
129
|
+
* @returns The row for a variant.
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { variantSpec } from "@johnmorrisdotca/sugoroku";
|
|
133
|
+
*
|
|
134
|
+
* console.log(variantSpec("tabula").dice);
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
56
137
|
export declare function variantSpec(key: VariantKey): VariantSpec;
|
|
57
|
-
/** Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
138
|
+
/** Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
139
|
+
*
|
|
140
|
+
* @param spec - The native variant specification.
|
|
141
|
+
* @returns Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* import { settingsFor, startCounts } from "@johnmorrisdotca/sugoroku";
|
|
145
|
+
*
|
|
146
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
147
|
+
* const spec = settings.variant;
|
|
148
|
+
* console.log(startCounts(spec));
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
58
151
|
export declare function startCounts(spec: VariantSpec): number[];
|
|
59
|
-
/** How many checkers each side begins off the board, to be entered with the dice.
|
|
152
|
+
/** How many checkers each side begins off the board, to be entered with the dice.
|
|
153
|
+
*
|
|
154
|
+
* @param spec - The native variant specification.
|
|
155
|
+
* @returns How many checkers each side begins off the board, to be entered with the dice.
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* import { settingsFor, startReserve } from "@johnmorrisdotca/sugoroku";
|
|
159
|
+
*
|
|
160
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
161
|
+
* const spec = settings.variant;
|
|
162
|
+
* console.log(startReserve(spec));
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
60
165
|
export declare function startReserve(spec: VariantSpec): number;
|
package/dist/variants.js
CHANGED
|
@@ -18,6 +18,12 @@ const BASE = {
|
|
|
18
18
|
/**
|
|
19
19
|
* Every variant. Where each comes from, and where the sources disagree or say
|
|
20
20
|
* nothing, is in `docs/VARIANTS.md`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { VARIANTS } from "@johnmorrisdotca/sugoroku";
|
|
25
|
+
* console.log(VARIANTS);
|
|
26
|
+
* ```
|
|
21
27
|
*/
|
|
22
28
|
export const VARIANTS = {
|
|
23
29
|
/** The classic game. */
|
|
@@ -52,26 +58,94 @@ export const VARIANTS = {
|
|
|
52
58
|
],
|
|
53
59
|
},
|
|
54
60
|
/** The Roman game: three dice, no doubles, both sides entering the same way round the same track. */
|
|
55
|
-
tabula: {
|
|
61
|
+
tabula: {
|
|
62
|
+
...BASE,
|
|
63
|
+
key: "tabula",
|
|
64
|
+
layout: [],
|
|
65
|
+
dice: 3,
|
|
66
|
+
doubles: "none",
|
|
67
|
+
direction: "same",
|
|
68
|
+
opening: "die-each",
|
|
69
|
+
holdBelow: 12,
|
|
70
|
+
},
|
|
56
71
|
};
|
|
57
|
-
/** The variants' keys, in the order the demo lists them.
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
/** The variants' keys, in the order the demo lists them.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { VARIANT_KEYS } from "@johnmorrisdotca/sugoroku";
|
|
77
|
+
* console.log(VARIANT_KEYS);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export const VARIANT_KEYS = [
|
|
81
|
+
"backgammon",
|
|
82
|
+
"backgammon-race",
|
|
83
|
+
"anti-backgammon",
|
|
84
|
+
"nackgammon",
|
|
85
|
+
"long-gammon",
|
|
86
|
+
"hypergammon",
|
|
87
|
+
"tabula",
|
|
88
|
+
];
|
|
89
|
+
/** Whether `key` names a variant.
|
|
90
|
+
*
|
|
91
|
+
* @param key - The native variant, preset or localized-label key specified by the signature.
|
|
92
|
+
* @returns Whether `key` names a variant.
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { isVariantKey } from "@johnmorrisdotca/sugoroku";
|
|
96
|
+
*
|
|
97
|
+
* console.log(isVariantKey("tabula"));
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
60
100
|
export function isVariantKey(key) {
|
|
61
101
|
return typeof key === "string" && VARIANT_KEYS.includes(key);
|
|
62
102
|
}
|
|
63
|
-
/** The row for a variant.
|
|
103
|
+
/** The row for a variant.
|
|
104
|
+
*
|
|
105
|
+
* @param key - The native variant, preset or localized-label key specified by the signature.
|
|
106
|
+
* @returns The row for a variant.
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { variantSpec } from "@johnmorrisdotca/sugoroku";
|
|
110
|
+
*
|
|
111
|
+
* console.log(variantSpec("tabula").dice);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
64
114
|
export function variantSpec(key) {
|
|
65
115
|
return VARIANTS[key];
|
|
66
116
|
}
|
|
67
|
-
/** Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
117
|
+
/** Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
118
|
+
*
|
|
119
|
+
* @param spec - The native variant specification.
|
|
120
|
+
* @returns Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { settingsFor, startCounts } from "@johnmorrisdotca/sugoroku";
|
|
124
|
+
*
|
|
125
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
126
|
+
* const spec = settings.variant;
|
|
127
|
+
* console.log(startCounts(spec));
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
68
130
|
export function startCounts(spec) {
|
|
69
131
|
const counts = new Array(24).fill(0);
|
|
70
132
|
for (const [point, count] of spec.layout)
|
|
71
133
|
counts[point - 1] = count;
|
|
72
134
|
return counts;
|
|
73
135
|
}
|
|
74
|
-
/** How many checkers each side begins off the board, to be entered with the dice.
|
|
136
|
+
/** How many checkers each side begins off the board, to be entered with the dice.
|
|
137
|
+
*
|
|
138
|
+
* @param spec - The native variant specification.
|
|
139
|
+
* @returns How many checkers each side begins off the board, to be entered with the dice.
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* import { settingsFor, startReserve } from "@johnmorrisdotca/sugoroku";
|
|
143
|
+
*
|
|
144
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
145
|
+
* const spec = settings.variant;
|
|
146
|
+
* console.log(startReserve(spec));
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
75
149
|
export function startReserve(spec) {
|
|
76
150
|
return spec.checkers - spec.layout.reduce((sum, [, count]) => sum + count, 0);
|
|
77
151
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
/** The package's version.
|
|
2
|
-
|
|
1
|
+
/** The package's version.
|
|
2
|
+
*
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { VERSION } from "@johnmorrisdotca/sugoroku";
|
|
6
|
+
* console.log(VERSION);
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare const VERSION = "1.1.1";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/sugoroku",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Sugoroku
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Sugoroku 双六 — Backgammon and its variants: native rules, doubling cube, match play, Long Gammon, Nackgammon, Hypergammon and Tabula, replayable records, computer players and an SVG board. TypeScript, zero dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"backgammon",
|
|
7
|
-
"nackgammon",
|
|
8
|
-
"long-gammon",
|
|
9
|
-
"hypergammon",
|
|
10
|
-
"tabula",
|
|
11
|
-
"tables-games",
|
|
12
7
|
"board-game",
|
|
8
|
+
"browser",
|
|
9
|
+
"computer-player",
|
|
13
10
|
"dice",
|
|
11
|
+
"dice-game",
|
|
14
12
|
"doubling-cube",
|
|
15
|
-
"match-play",
|
|
16
13
|
"game-engine",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"seeded-random",
|
|
20
|
-
"typescript",
|
|
14
|
+
"hypergammon",
|
|
15
|
+
"itsutsu",
|
|
21
16
|
"javascript",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
17
|
+
"long-gammon",
|
|
18
|
+
"match-play",
|
|
19
|
+
"nackgammon",
|
|
24
20
|
"node",
|
|
25
|
-
"
|
|
21
|
+
"seeded-random",
|
|
22
|
+
"svg",
|
|
23
|
+
"tables-games",
|
|
24
|
+
"tabula",
|
|
25
|
+
"typescript",
|
|
26
|
+
"zero-dependencies"
|
|
26
27
|
],
|
|
27
28
|
"homepage": "https://johnmorrisdotca.github.io/sugoroku/",
|
|
28
29
|
"repository": {
|
|
@@ -80,25 +81,31 @@
|
|
|
80
81
|
},
|
|
81
82
|
"scripts": {
|
|
82
83
|
"build": "tsc -p tsconfig.json",
|
|
83
|
-
"lint": "
|
|
84
|
+
"lint": "biome check .",
|
|
84
85
|
"typecheck": "tsc -p tsconfig.check.json",
|
|
85
86
|
"test": "vitest run",
|
|
86
87
|
"test:package": "pnpm build && node scripts/check-package.mjs",
|
|
87
88
|
"family:readme": "node scripts/family-readme.mjs",
|
|
88
|
-
"check": "pnpm lint && pnpm typecheck && pnpm test",
|
|
89
|
+
"check": "pnpm lint && pnpm typecheck && pnpm test && pnpm check:size",
|
|
89
90
|
"prepublishOnly": "pnpm check && pnpm build",
|
|
90
91
|
"site": "pnpm build && node scripts/site.mjs",
|
|
91
|
-
"test:demo": "pnpm site && playwright test",
|
|
92
|
+
"test:demo": "pnpm site && node scripts/docs-site.mjs build && playwright test",
|
|
92
93
|
"docs:make": "node scripts/docs.mjs",
|
|
93
94
|
"screenshots:readme": "pnpm site && node scripts/readme-pictures.mjs",
|
|
94
|
-
"test:readme": "pnpm build && node scripts/check-readme-examples.mjs"
|
|
95
|
+
"test:readme": "pnpm build && node scripts/check-readme-examples.mjs",
|
|
96
|
+
"docs:site": "pnpm build && node scripts/docs-site.mjs build",
|
|
97
|
+
"docs:check": "pnpm build && node scripts/docs-site.mjs check",
|
|
98
|
+
"size": "node scripts/docs-site.mjs size",
|
|
99
|
+
"format": "biome check --write .",
|
|
100
|
+
"check:size": "node scripts/check-size.mjs"
|
|
95
101
|
},
|
|
96
102
|
"devDependencies": {
|
|
97
|
-
"@
|
|
103
|
+
"@biomejs/biome": "2.6.4",
|
|
98
104
|
"@playwright/test": "^1.63.0",
|
|
99
|
-
"
|
|
105
|
+
"esbuild": "^0.28.0",
|
|
106
|
+
"marked": "^18.0.0",
|
|
107
|
+
"pagefind": "^1.5.2",
|
|
100
108
|
"typescript": "^5.9.0",
|
|
101
|
-
"typescript-eslint": "^8.0.0",
|
|
102
109
|
"vitest": "^5.0.0"
|
|
103
110
|
},
|
|
104
111
|
"packageManager": "pnpm@10.11.0"
|