@johnmorrisdotca/sugoroku 1.0.1 → 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.
- package/CHANGELOG.md +32 -0
- package/README.md +395 -77
- package/dist/board.d.ts +216 -12
- package/dist/board.js +204 -12
- package/dist/colours.d.ts +80 -8
- package/dist/colours.js +51 -6
- package/dist/computer.d.ts +138 -8
- package/dist/computer.js +109 -7
- package/dist/dice.d.ts +53 -4
- package/dist/dice.js +42 -3
- package/dist/draw.d.ts +43 -3
- package/dist/draw.js +33 -2
- package/dist/element-define.d.ts +1 -1
- package/dist/element-define.js +4 -13
- package/dist/element.d.ts +233 -3
- package/dist/element.js +402 -48
- package/dist/evaluate.d.ts +76 -4
- package/dist/evaluate.js +65 -3
- package/dist/game.d.ts +408 -23
- package/dist/game.js +328 -18
- package/dist/geometry.d.ts +50 -3
- package/dist/geometry.js +20 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/match.d.ts +66 -4
- package/dist/match.js +55 -4
- package/dist/mount.d.ts +75 -4
- package/dist/mount.js +25 -3
- package/dist/moves.d.ts +48 -1
- package/dist/moves.js +35 -1
- package/dist/notation.d.ts +92 -4
- package/dist/notation.js +82 -3
- 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/positionId.d.ts +29 -1
- package/dist/positionId.js +29 -1
- package/dist/random.d.ts +33 -3
- package/dist/random.js +22 -2
- package/dist/record.d.ts +150 -7
- package/dist/record.js +94 -5
- package/dist/rules.d.ts +130 -10
- package/dist/rules.js +99 -9
- 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 +34 -2
- package/dist/style.d.ts +6 -0
- package/dist/style.js +6 -0
- package/dist/variants.d.ts +113 -8
- package/dist/variants.js +62 -5
- package/dist/version.d.ts +9 -2
- package/dist/version.js +9 -2
- package/package.json +27 -19
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;
|
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[];
|