@johnmorrisdotca/sugoroku 1.0.2 → 1.1.0

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +78 -68
  3. package/dist/board.d.ts +216 -12
  4. package/dist/board.js +204 -12
  5. package/dist/colours.d.ts +80 -8
  6. package/dist/colours.js +51 -6
  7. package/dist/computer.d.ts +138 -8
  8. package/dist/computer.js +109 -7
  9. package/dist/dice.d.ts +53 -4
  10. package/dist/dice.js +42 -3
  11. package/dist/draw.d.ts +43 -3
  12. package/dist/draw.js +33 -2
  13. package/dist/element-define.d.ts +1 -1
  14. package/dist/element-define.js +4 -13
  15. package/dist/element.d.ts +233 -3
  16. package/dist/element.js +402 -48
  17. package/dist/evaluate.d.ts +76 -4
  18. package/dist/evaluate.js +65 -3
  19. package/dist/game.d.ts +408 -23
  20. package/dist/game.js +328 -18
  21. package/dist/geometry.d.ts +50 -3
  22. package/dist/geometry.js +20 -1
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/match.d.ts +66 -4
  26. package/dist/match.js +55 -4
  27. package/dist/mount.d.ts +75 -4
  28. package/dist/mount.js +25 -3
  29. package/dist/moves.d.ts +48 -1
  30. package/dist/moves.js +35 -1
  31. package/dist/notation.d.ts +92 -4
  32. package/dist/notation.js +82 -3
  33. package/dist/playStyle.d.ts +6 -0
  34. package/dist/playStyle.js +6 -0
  35. package/dist/plays.d.ts +108 -3
  36. package/dist/plays.js +96 -3
  37. package/dist/positionId.d.ts +29 -1
  38. package/dist/positionId.js +29 -1
  39. package/dist/random.d.ts +33 -3
  40. package/dist/random.js +22 -2
  41. package/dist/record.d.ts +150 -7
  42. package/dist/record.js +94 -5
  43. package/dist/rules.d.ts +130 -10
  44. package/dist/rules.js +99 -9
  45. package/dist/side.d.ts +38 -3
  46. package/dist/side.js +30 -3
  47. package/dist/sound.d.ts +61 -3
  48. package/dist/sound.js +27 -2
  49. package/dist/strings.d.ts +42 -2
  50. package/dist/strings.js +34 -2
  51. package/dist/style.d.ts +6 -0
  52. package/dist/style.js +6 -0
  53. package/dist/variants.d.ts +113 -8
  54. package/dist/variants.js +62 -5
  55. package/dist/version.d.ts +9 -2
  56. package/dist/version.js +9 -2
  57. package/package.json +25 -18
package/dist/board.js CHANGED
@@ -1,10 +1,36 @@
1
1
  import { sideIndex, otherSide } from "./side.js";
2
2
  import { startCounts, startReserve } from "./variants.js";
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 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 const BAR = 25;
7
- /** The position a variant starts from. */
21
+ /** The position a variant starts from.
22
+ *
23
+ * @param spec - The native variant specification.
24
+ * @returns The position a variant starts from.
25
+ * @example
26
+ * ```ts
27
+ * import { settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
28
+ *
29
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
30
+ * const spec = settings.variant;
31
+ * console.log(startPosition(spec).bar);
32
+ * ```
33
+ */
8
34
  export function startPosition(spec) {
9
35
  const counts = startCounts(spec);
10
36
  const reserve = startReserve(spec);
@@ -14,6 +40,18 @@ export function startPosition(spec) {
14
40
  * The other side's own number for the point that is `side`'s own point `own`.
15
41
  * With the sides going opposite ways round, a side's 24-point is the other's
16
42
  * 1-point; going the same way, a point has the one number for both.
43
+ *
44
+ * @param spec - The native variant specification.
45
+ * @param own - A point in this side’s own numbering.
46
+ * @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.
47
+ * @example
48
+ * ```ts
49
+ * import { mirrorPoint, settingsFor } from "@johnmorrisdotca/sugoroku";
50
+ *
51
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
52
+ * const spec = settings.variant;
53
+ * console.log(mirrorPoint(spec,24));
54
+ * ```
17
55
  */
18
56
  export function mirrorPoint(spec, own) {
19
57
  return spec.direction === "opposed" ? POINTS + 1 - own : own;
@@ -22,28 +60,114 @@ export function mirrorPoint(spec, own) {
22
60
  * The point on the board, 1 to 24 counting the way white counts, that is
23
61
  * `side`'s own point `own`. White's own numbers are the board's; black's are
24
62
  * the board's reversed when the sides go opposite ways round.
63
+ *
64
+ * @param spec - The native variant specification.
65
+ * @param side - The side being examined: white or black.
66
+ * @param own - A point in this side’s own numbering.
67
+ * @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.
68
+ * @example
69
+ * ```ts
70
+ * import { boardPoint, settingsFor } from "@johnmorrisdotca/sugoroku";
71
+ *
72
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
73
+ * const spec = settings.variant;
74
+ * console.log(boardPoint(spec,"black",24));
75
+ * ```
25
76
  */
26
77
  export function boardPoint(spec, side, own) {
27
78
  return side === "white" ? own : mirrorPoint(spec, own);
28
79
  }
29
- /** How many of `side`'s checkers stand on its own point `own` (1 to 24). */
80
+ /** How many of `side`'s checkers stand on its own point `own` (1 to 24).
81
+ *
82
+ * @param position - The native checker counts, bar, reserve and borne-off counts.
83
+ * @param side - The side being examined: white or black.
84
+ * @param own - A point in this side’s own numbering.
85
+ * @returns How many of `side`'s checkers stand on its own point `own` (1 to 24).
86
+ * @example
87
+ * ```ts
88
+ * import { countAt, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
89
+ *
90
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
91
+ * const spec = settings.variant;
92
+ * const position = startPosition(spec);
93
+ * console.log(countAt(position,"white",24));
94
+ * ```
95
+ */
30
96
  export function countAt(position, side, own) {
31
97
  return position.points[sideIndex(side)][own - 1] ?? 0;
32
98
  }
33
- /** How many of the other side's checkers stand on the point that is `side`'s own point `own`. */
99
+ /** How many of the other side's checkers stand on the point that is `side`'s own point `own`.
100
+ *
101
+ * @param spec - The native variant specification.
102
+ * @param position - The native checker counts, bar, reserve and borne-off counts.
103
+ * @param side - The side being examined: white or black.
104
+ * @param own - A point in this side’s own numbering.
105
+ * @returns How many of the other side's checkers stand on the point that is `side`'s own point `own`.
106
+ * @example
107
+ * ```ts
108
+ * import { opponentAt, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
109
+ *
110
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
111
+ * const spec = settings.variant;
112
+ * const position = startPosition(spec);
113
+ * console.log(opponentAt(spec,position,"white",24));
114
+ * ```
115
+ */
34
116
  export function opponentAt(spec, position, side, own) {
35
117
  return countAt(position, otherSide(side), mirrorPoint(spec, own));
36
118
  }
37
- /** How many checkers `side` has on the board's points, not counting the bar, the reserve and those borne off. */
119
+ /** How many checkers `side` has on the board's points, not counting the bar, the reserve and those borne off.
120
+ *
121
+ * @param position - The native checker counts, bar, reserve and borne-off counts.
122
+ * @param side - The side being examined: white or black.
123
+ * @returns How many checkers `side` has on the board's points, not counting the bar, the reserve and those borne off.
124
+ * @example
125
+ * ```ts
126
+ * import { onBoard, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
127
+ *
128
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
129
+ * const spec = settings.variant;
130
+ * const position = startPosition(spec);
131
+ * console.log(onBoard(position,"white"));
132
+ * ```
133
+ */
38
134
  export function onBoard(position, side) {
39
135
  return position.points[sideIndex(side)].reduce((sum, count) => sum + count, 0);
40
136
  }
41
- /** Every checker of `side` that is still in the game: on the board, on the bar or yet to enter. */
137
+ /** Every checker of `side` that is still in the game: on the board, on the bar or yet to enter.
138
+ *
139
+ * @param position - The native checker counts, bar, reserve and borne-off counts.
140
+ * @param side - The side being examined: white or black.
141
+ * @returns Every checker of `side` that is still in the game: on the board, on the bar or yet to enter.
142
+ * @example
143
+ * ```ts
144
+ * import { inPlay, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
145
+ *
146
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
147
+ * const spec = settings.variant;
148
+ * const position = startPosition(spec);
149
+ * console.log(inPlay(position,"white"));
150
+ * ```
151
+ */
42
152
  export function inPlay(position, side) {
43
153
  const i = sideIndex(side);
44
154
  return onBoard(position, side) + position.bar[i] + position.reserve[i];
45
155
  }
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. */
156
+ /** 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.
157
+ *
158
+ * @param position - The native checker counts, bar, reserve and borne-off counts.
159
+ * @param side - The side being examined: white or black.
160
+ * @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.
161
+ * @example
162
+ * ```ts
163
+ * import { pipCount, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
164
+ *
165
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
166
+ * const spec = settings.variant;
167
+ * const position = startPosition(spec);
168
+ * console.log(pipCount(position,"white"));
169
+ * ```
170
+ */
47
171
  export function pipCount(position, side) {
48
172
  const i = sideIndex(side);
49
173
  let total = 25 * (position.bar[i] + position.reserve[i]);
@@ -52,7 +176,21 @@ export function pipCount(position, side) {
52
176
  });
53
177
  return total;
54
178
  }
55
- /** Whether every checker of `side` still in play is in its home board (own points 1 to 6): the condition for bearing off. */
179
+ /** Whether every checker of `side` still in play is in its home board (own points 1 to 6): the condition for bearing off.
180
+ *
181
+ * @param position - The native checker counts, bar, reserve and borne-off counts.
182
+ * @param side - The side being examined: white or black.
183
+ * @returns Whether every checker of `side` still in play is in its home board (own points 1 to 6): the condition for bearing off.
184
+ * @example
185
+ * ```ts
186
+ * import { allHome, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
187
+ *
188
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
189
+ * const spec = settings.variant;
190
+ * const position = startPosition(spec);
191
+ * console.log(allHome(position,"white"));
192
+ * ```
193
+ */
56
194
  export function allHome(position, side) {
57
195
  const i = sideIndex(side);
58
196
  if (position.bar[i] > 0 || position.reserve[i] > 0)
@@ -63,15 +201,56 @@ export function allHome(position, side) {
63
201
  return false;
64
202
  return true;
65
203
  }
66
- /** A position as a short string that is the same for the same position, for keeping a set of them. */
204
+ /** A position as a short string that is the same for the same position, for keeping a set of them.
205
+ *
206
+ * @param position - The native checker counts, bar, reserve and borne-off counts.
207
+ * @returns A position as a short string that is the same for the same position, for keeping a set of them.
208
+ * @example
209
+ * ```ts
210
+ * import { positionKey, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
211
+ *
212
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
213
+ * const spec = settings.variant;
214
+ * const position = startPosition(spec);
215
+ * console.log(positionKey(position));
216
+ * ```
217
+ */
67
218
  export function positionKey(position) {
68
219
  return `${position.points[0].join(",")}|${position.points[1].join(",")}|${position.bar.join(",")}|${position.reserve.join(",")}|${position.off.join(",")}`;
69
220
  }
70
- /** The whole count of each side's checkers: on the board, on the bar, yet to enter, and off. Always the variant's `checkers`. */
221
+ /** The whole count of each side's checkers: on the board, on the bar, yet to enter, and off. Always the variant's `checkers`.
222
+ *
223
+ * @param position - The native checker counts, bar, reserve and borne-off counts.
224
+ * @param side - The side being examined: white or black.
225
+ * @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`.
226
+ * @example
227
+ * ```ts
228
+ * import { checkersOf, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
229
+ *
230
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
231
+ * const spec = settings.variant;
232
+ * const position = startPosition(spec);
233
+ * console.log(checkersOf(position,"white"));
234
+ * ```
235
+ */
71
236
  export function checkersOf(position, side) {
72
237
  return inPlay(position, side) + position.off[sideIndex(side)];
73
238
  }
74
- /** A copy of a position with some counts changed. */
239
+ /** A copy of a position with some counts changed.
240
+ *
241
+ * @param position - The native checker counts, bar, reserve and borne-off counts.
242
+ * @param changes - The replacement checker-count fields.
243
+ * @returns A copy of a position with some counts changed.
244
+ * @example
245
+ * ```ts
246
+ * import { settingsFor, startPosition, withCounts } from "@johnmorrisdotca/sugoroku";
247
+ *
248
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
249
+ * const spec = settings.variant;
250
+ * const position = startPosition(spec);
251
+ * console.log(withCounts(position,{off:[0,0]}).off);
252
+ * ```
253
+ */
75
254
  export function withCounts(position, changes) {
76
255
  return {
77
256
  points: changes.points ?? position.points,
@@ -84,6 +263,19 @@ export function withCounts(position, changes) {
84
263
  * Whether the two sides can still hit one another. Once every checker of
85
264
  * one side has gone past every checker of the other there is nothing more to
86
265
  * play for but the race, and the game is a race.
266
+ *
267
+ * @param spec - The native variant specification.
268
+ * @param position - The native checker counts, bar, reserve and borne-off counts.
269
+ * @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.
270
+ * @example
271
+ * ```ts
272
+ * import { inContact, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
273
+ *
274
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
275
+ * const spec = settings.variant;
276
+ * const position = startPosition(spec);
277
+ * console.log(inContact(spec,position));
278
+ * ```
87
279
  */
88
280
  export function inContact(spec, position) {
89
281
  if (position.bar[0] + position.bar[1] + position.reserve[0] + position.reserve[1] > 0)
package/dist/colours.d.ts CHANGED
@@ -4,6 +4,15 @@
4
4
  * style may change any of them, and `drawSugoroku` takes any of them as an
5
5
  * option. Where a colour is left out the drawing uses the theme's: light by
6
6
  * default, dark when the device is (see `SUGOROKU_STYLE`).
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import type { SugorokuColours } from "@johnmorrisdotca/sugoroku/draw";
11
+ * import { SUGOROKU_COLOUR_NAMES } from "@johnmorrisdotca/sugoroku/draw";
12
+ *
13
+ * const value: SugorokuColours = Object.fromEntries(SUGOROKU_COLOUR_NAMES.map(name=>[name,"#ffffff"])) as SugorokuColours;
14
+ * console.log(value);
15
+ * ```
7
16
  */
8
17
  export type SugorokuColours = {
9
18
  /** The frame the board is set in. */
@@ -32,19 +41,82 @@ export type SugorokuColours = {
32
41
  cube: string;
33
42
  cubeInk: string;
34
43
  };
35
- /** The names of the colours, as the custom properties spell them (`--sg-` and the name in kebab case). */
44
+ /** The names of the colours, as the custom properties spell them (`--sg-` and the name in kebab case).
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { SUGOROKU_COLOUR_NAMES } from "@johnmorrisdotca/sugoroku/draw";
49
+ * console.log(SUGOROKU_COLOUR_NAMES);
50
+ * ```
51
+ */
36
52
  export declare const SUGOROKU_COLOUR_NAMES: readonly (keyof SugorokuColours)[];
37
- /** The custom property a colour is set on. */
53
+ /** The custom property a colour is set on.
54
+ *
55
+ * @param name - The colour property, preset name or sound identifier specified by this signature.
56
+ * @returns The custom property a colour is set on.
57
+ * @example
58
+ * ```ts
59
+ * import { colourProperty } from "@johnmorrisdotca/sugoroku/draw";
60
+ *
61
+ * console.log(colourProperty("pointA"));
62
+ * ```
63
+ */
38
64
  export declare function colourProperty(name: keyof SugorokuColours): string;
39
- /** A named board, a set of colours for the board and its points. */
65
+ /** A named board, a set of colours for the board and its points.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import type { SugorokuBoardName } from "@johnmorrisdotca/sugoroku/draw";
70
+ *
71
+ * const value: SugorokuBoardName = "wood";
72
+ * console.log(value);
73
+ * ```
74
+ */
40
75
  export type SugorokuBoardName = "green" | "blue" | "red" | "black" | "wood";
41
- /** The boards the drawing knows by name, set against any theme. Each changes only the surfaces: the frame, the felt, the points, the bar and the trays. */
76
+ /** The boards the drawing knows by name, set against any theme. Each changes only the surfaces: the frame, the felt, the points, the bar and the trays.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { SUGOROKU_BOARDS } from "@johnmorrisdotca/sugoroku/draw";
81
+ * console.log(SUGOROKU_BOARDS);
82
+ * ```
83
+ */
42
84
  export declare const SUGOROKU_BOARDS: Readonly<Record<SugorokuBoardName, Pick<SugorokuColours, "frame" | "felt" | "pointA" | "pointB" | "bar" | "tray">>>;
43
- /** The names of the boards. */
85
+ /** The names of the boards.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * import { SUGOROKU_BOARD_NAMES } from "@johnmorrisdotca/sugoroku/draw";
90
+ * console.log(SUGOROKU_BOARD_NAMES);
91
+ * ```
92
+ */
44
93
  export declare const SUGOROKU_BOARD_NAMES: readonly SugorokuBoardName[];
45
- /** A named pair of checker colours. */
94
+ /** A named pair of checker colours.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * import type { SugorokuCheckerSetName } from "@johnmorrisdotca/sugoroku/draw";
99
+ *
100
+ * const value: SugorokuCheckerSetName = "contrast";
101
+ * console.log(value);
102
+ * ```
103
+ */
46
104
  export type SugorokuCheckerSetName = "classic" | "red-and-white" | "gold-and-blue" | "contrast";
47
- /** The checkers the drawing knows by name. `contrast` is for readers who tell colours apart with difficulty: pale and near-black, with strong rims. */
105
+ /** The checkers the drawing knows by name. `contrast` is for readers who tell colours apart with difficulty: pale and near-black, with strong rims.
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * import { SUGOROKU_CHECKER_SETS } from "@johnmorrisdotca/sugoroku/draw";
110
+ * console.log(SUGOROKU_CHECKER_SETS);
111
+ * ```
112
+ */
48
113
  export declare const SUGOROKU_CHECKER_SETS: Readonly<Record<SugorokuCheckerSetName, Pick<SugorokuColours, "white" | "whiteEdge" | "black" | "blackEdge">>>;
49
- /** The names of the checker sets. */
114
+ /** The names of the checker sets.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { SUGOROKU_CHECKER_SET_NAMES } from "@johnmorrisdotca/sugoroku/draw";
119
+ * console.log(SUGOROKU_CHECKER_SET_NAMES);
120
+ * ```
121
+ */
50
122
  export declare const SUGOROKU_CHECKER_SET_NAMES: readonly SugorokuCheckerSetName[];
package/dist/colours.js CHANGED
@@ -1,4 +1,11 @@
1
- /** The names of the colours, as the custom properties spell them (`--sg-` and the name in kebab case). */
1
+ /** The names of the colours, as the custom properties spell them (`--sg-` and the name in kebab case).
2
+ *
3
+ * @example
4
+ * ```ts
5
+ * import { SUGOROKU_COLOUR_NAMES } from "@johnmorrisdotca/sugoroku/draw";
6
+ * console.log(SUGOROKU_COLOUR_NAMES);
7
+ * ```
8
+ */
2
9
  export const SUGOROKU_COLOUR_NAMES = [
3
10
  "frame",
4
11
  "felt",
@@ -18,12 +25,29 @@ export const SUGOROKU_COLOUR_NAMES = [
18
25
  "cube",
19
26
  "cubeInk",
20
27
  ];
21
- /** The custom property a colour is set on. */
28
+ /** The custom property a colour is set on.
29
+ *
30
+ * @param name - The colour property, preset name or sound identifier specified by this signature.
31
+ * @returns The custom property a colour is set on.
32
+ * @example
33
+ * ```ts
34
+ * import { colourProperty } from "@johnmorrisdotca/sugoroku/draw";
35
+ *
36
+ * console.log(colourProperty("pointA"));
37
+ * ```
38
+ */
22
39
  export function colourProperty(name) {
23
40
  return `--sg-${name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}`;
24
41
  }
25
42
  const POINTS_CLASSIC = { pointA: "#e7d8b1", pointB: "#8e3a2b" };
26
- /** The boards the drawing knows by name, set against any theme. Each changes only the surfaces: the frame, the felt, the points, the bar and the trays. */
43
+ /** The boards the drawing knows by name, set against any theme. Each changes only the surfaces: the frame, the felt, the points, the bar and the trays.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * import { SUGOROKU_BOARDS } from "@johnmorrisdotca/sugoroku/draw";
48
+ * console.log(SUGOROKU_BOARDS);
49
+ * ```
50
+ */
27
51
  export const SUGOROKU_BOARDS = {
28
52
  green: { frame: "#5b3a1f", felt: "#2f5d4a", ...POINTS_CLASSIC, bar: "#4a2f19", tray: "#24493a" },
29
53
  blue: { frame: "#2c3a52", felt: "#2865a6", pointA: "#dfe6ef", pointB: "#16345c", bar: "#1f2b40", tray: "#1d4d80" },
@@ -31,14 +55,35 @@ export const SUGOROKU_BOARDS = {
31
55
  black: { frame: "#1d1f22", felt: "#2f3236", pointA: "#d8d4c6", pointB: "#a3342e", bar: "#141618", tray: "#222427" },
32
56
  wood: { frame: "#6b4a2b", felt: "#e2ba7a", pointA: "#f3dfae", pointB: "#7a4a22", bar: "#6b4a2b", tray: "#c4954f" },
33
57
  };
34
- /** The names of the boards. */
58
+ /** The names of the boards.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { SUGOROKU_BOARD_NAMES } from "@johnmorrisdotca/sugoroku/draw";
63
+ * console.log(SUGOROKU_BOARD_NAMES);
64
+ * ```
65
+ */
35
66
  export const SUGOROKU_BOARD_NAMES = ["green", "blue", "red", "black", "wood"];
36
- /** The checkers the drawing knows by name. `contrast` is for readers who tell colours apart with difficulty: pale and near-black, with strong rims. */
67
+ /** The checkers the drawing knows by name. `contrast` is for readers who tell colours apart with difficulty: pale and near-black, with strong rims.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * import { SUGOROKU_CHECKER_SETS } from "@johnmorrisdotca/sugoroku/draw";
72
+ * console.log(SUGOROKU_CHECKER_SETS);
73
+ * ```
74
+ */
37
75
  export const SUGOROKU_CHECKER_SETS = {
38
76
  classic: { white: "#f6f0df", whiteEdge: "#b3a888", black: "#2b2724", blackEdge: "#0d0b0a" },
39
77
  "red-and-white": { white: "#f6f0df", whiteEdge: "#b3a888", black: "#b3332b", blackEdge: "#5d1712" },
40
78
  "gold-and-blue": { white: "#e8bf4a", whiteEdge: "#8d6a14", black: "#27508f", blackEdge: "#102446" },
41
79
  contrast: { white: "#ffffff", whiteEdge: "#000000", black: "#111111", blackEdge: "#ffffff" },
42
80
  };
43
- /** The names of the checker sets. */
81
+ /** The names of the checker sets.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import { SUGOROKU_CHECKER_SET_NAMES } from "@johnmorrisdotca/sugoroku/draw";
86
+ * console.log(SUGOROKU_CHECKER_SET_NAMES);
87
+ * ```
88
+ */
44
89
  export const SUGOROKU_CHECKER_SET_NAMES = ["classic", "red-and-white", "gold-and-blue", "contrast"];
@@ -20,10 +20,36 @@ import { type Side } from "./side.ts";
20
20
  * take when the doubler's is 2 or more above the taker's. In a position where the sides are still in
21
21
  * contact (`careful` and `strong` only), the evaluation is turned into a
22
22
  * chance of winning (`winChance`) and a side doubles at 70% and takes at 25%.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import type { Strength } from "@johnmorrisdotca/sugoroku";
27
+ *
28
+ * const value: Strength = "greedy";
29
+ * console.log(value);
30
+ * ```
23
31
  */
24
32
  export type Strength = "random" | "greedy" | "careful" | "strong";
25
- /** The strengths, weakest first. */
33
+ /** The strengths, weakest first.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { STRENGTHS } from "@johnmorrisdotca/sugoroku";
38
+ * console.log(STRENGTHS);
39
+ * ```
40
+ */
26
41
  export declare const STRENGTHS: readonly Strength[];
42
+ /** Strength, tie-breaking randomness, lookahead time budget and evaluation weights for computer decisions.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import type { ComputerOptions } from "@johnmorrisdotca/sugoroku";
47
+ * import { seededRandom } from "@johnmorrisdotca/sugoroku";
48
+ *
49
+ * const value: ComputerOptions = {strength:"greedy",random:seededRandom(42)};
50
+ * console.log(value);
51
+ * ```
52
+ */
27
53
  export type ComputerOptions = {
28
54
  /** The strength. Default `strong`. */
29
55
  strength?: Strength;
@@ -38,15 +64,81 @@ export type ComputerOptions = {
38
64
  /** Weights for the evaluation, to play with a different taste. Default `EVALUATION_WEIGHTS`. */
39
65
  weights?: EvaluationWeights;
40
66
  };
41
- /** The play the computer makes for the rest of the turn of the side on turn, from the plays the rules leave it. */
67
+ /** The play the computer makes for the rest of the turn of the side on turn, from the plays the rules leave it.
68
+ *
69
+ * @param game - The current immutable native game state.
70
+ * @param options - Native drawing, geometry, mounting or computer choices specified by the signature.
71
+ * @returns The play the computer makes for the rest of the turn of the side on turn, from the plays the rules leave it.
72
+ * @example
73
+ * ```ts
74
+ * import { choosePlay, newGame, rollOpening, seededRandom, settingsFor } from "@johnmorrisdotca/sugoroku";
75
+ *
76
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
77
+ * const game = rollOpening(newGame(settings),[3,1]);
78
+ * console.log(choosePlay(game,{strength:"greedy",random:seededRandom(42)}).moves);
79
+ * ```
80
+ */
42
81
  export declare function choosePlay(game: GameState, options?: ComputerOptions): Play;
43
- /** The chance, 0 to 1, that `side` wins from here, by the evaluation, or by the Keith count's rule of thumb in a race (as 0.5 plus a share of the count's lead). */
82
+ /** The chance, 0 to 1, that `side` wins from here, by the evaluation, or by the Keith count's rule of thumb in a race (as 0.5 plus a share of the count's lead).
83
+ *
84
+ * @param game - The current immutable native game state.
85
+ * @param side - The side being examined: white or black.
86
+ * @returns The chance, 0 to 1, that `side` wins from here, by the evaluation, or by the Keith count's rule of thumb in a race (as 0.5 plus a share of the count's lead).
87
+ * @example
88
+ * ```ts
89
+ * import { chanceOfWinning, newGame, rollOpening, settingsFor } from "@johnmorrisdotca/sugoroku";
90
+ *
91
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
92
+ * const game = rollOpening(newGame(settings),[3,1]);
93
+ * console.log(chanceOfWinning(game,"white"));
94
+ * ```
95
+ */
44
96
  export declare function chanceOfWinning(game: GameState, side: Side): number;
45
- /** Whether the computer, to move before it rolls, should offer a double. */
97
+ /** Whether the computer, to move before it rolls, should offer a double.
98
+ *
99
+ * @param game - The current immutable native game state.
100
+ * @param options - Native drawing, geometry, mounting or computer choices specified by the signature.
101
+ * @returns Whether the computer, to move before it rolls, should offer a double.
102
+ * @example
103
+ * ```ts
104
+ * import { endTurn, legalPlaysOf, newGame, playTurn, rollOpening, settingsFor, wantsToDouble } from "@johnmorrisdotca/sugoroku";
105
+ *
106
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
107
+ * const game = rollOpening(newGame(settings),[3,1]);
108
+ * const play = legalPlaysOf(game)[0];
109
+ * const beforeRoll = playTurn(game,play.moves);
110
+ * console.log(wantsToDouble(beforeRoll,{strength:"greedy"}));
111
+ * ```
112
+ */
46
113
  export declare function wantsToDouble(game: GameState, options?: ComputerOptions): boolean;
47
- /** Whether the computer, doubled, should take. */
114
+ /** Whether the computer, doubled, should take.
115
+ *
116
+ * @param game - The current immutable native game state.
117
+ * @param options - Native drawing, geometry, mounting or computer choices specified by the signature.
118
+ * @returns Whether the computer, doubled, should take.
119
+ * @example
120
+ * ```ts
121
+ * import { endTurn, legalPlaysOf, newGame, offerDouble, playTurn, rollOpening, settingsFor, wantsToTake } from "@johnmorrisdotca/sugoroku";
122
+ *
123
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
124
+ * const game = rollOpening(newGame(settings),[3,1]);
125
+ * const play = legalPlaysOf(game)[0];
126
+ * const beforeRoll = playTurn(game,play.moves);
127
+ * const offered = offerDouble(beforeRoll);
128
+ * console.log(wantsToTake(offered,{strength:"greedy"}));
129
+ * ```
130
+ */
48
131
  export declare function wantsToTake(game: GameState, options?: ComputerOptions): boolean;
49
- /** What the computer does next in a game, for the side it plays. */
132
+ /** What the computer does next in a game, for the side it plays.
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * import type { ComputerAction } from "@johnmorrisdotca/sugoroku";
137
+ *
138
+ * const value: ComputerAction = {kind:"roll"};
139
+ * console.log(value);
140
+ * ```
141
+ */
50
142
  export type ComputerAction = {
51
143
  kind: "throw";
52
144
  } | {
@@ -63,16 +155,54 @@ export type ComputerAction = {
63
155
  } | {
64
156
  kind: "drop";
65
157
  };
66
- /** What the side that has to act in a game would do, if the computer were playing it. Nothing is done: the game is not changed. Null when the game is over. */
158
+ /** What the side that has to act in a game would do, if the computer were playing it. Nothing is done: the game is not changed. Null when the game is over.
159
+ *
160
+ * @param game - The current immutable native game state.
161
+ * @param options - Native drawing, geometry, mounting or computer choices specified by the signature.
162
+ * @returns The phase-appropriate computer action, or null when the game is over.
163
+ * @example
164
+ * ```ts
165
+ * import { computerAction, newGame, rollOpening, seededRandom, settingsFor } from "@johnmorrisdotca/sugoroku";
166
+ *
167
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
168
+ * const game = rollOpening(newGame(settings),[3,1]);
169
+ * console.log(computerAction(game,{strength:"greedy",random:seededRandom(42)}));
170
+ * ```
171
+ */
67
172
  export declare function computerAction(game: GameState, options?: ComputerOptions): ComputerAction | null;
68
173
  /**
69
174
  * Carry out one step of what the computer would do, with dice from `dice`.
70
175
  * Returns the game after it, and what was done, so a caller can write it down
71
176
  * or show it. Which side plays is up to the caller: this plays for whichever side is to act.
177
+ *
178
+ * @param game - The current immutable native game state.
179
+ * @param dice - Dice values as thrown, or a reproducible source specified by the signature.
180
+ * @param options - Native drawing, geometry, mounting or computer choices specified by the signature.
181
+ * @returns The next state and selected computer action, or null when no action remains.
182
+ * @example
183
+ * ```ts
184
+ * import { newGame, rollOpening, seededDice, seededRandom, settingsFor, stepComputer } from "@johnmorrisdotca/sugoroku";
185
+ *
186
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
187
+ * const game = rollOpening(newGame(settings),[3,1]);
188
+ * console.log(stepComputer(game,seededDice(42),{strength:"greedy",random:seededRandom(42)})?.game.phase);
189
+ * ```
72
190
  */
73
191
  export declare function stepComputer(game: GameState, dice: DiceSource, options?: ComputerOptions): {
74
192
  game: GameState;
75
193
  action: ComputerAction;
76
194
  } | null;
77
- /** Whether a side is the one the computer would act for at this moment of a game: the side on turn, or the side that must answer a double. */
195
+ /** Whether a side is the one the computer would act for at this moment of a game: the side on turn, or the side that must answer a double.
196
+ *
197
+ * @param game - The current immutable native game state.
198
+ * @returns The side to make the next decision, or null during opening or after the game ends.
199
+ * @example
200
+ * ```ts
201
+ * import { newGame, rollOpening, settingsFor, sideToAct } from "@johnmorrisdotca/sugoroku";
202
+ *
203
+ * const settings = settingsFor("backgammon",{points:5,cube:true});
204
+ * const game = rollOpening(newGame(settings),[3,1]);
205
+ * console.log(sideToAct(game));
206
+ * ```
207
+ */
78
208
  export declare function sideToAct(game: GameState): Side | null;