@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/evaluate.d.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { type Position } from "./board.ts";
|
|
2
2
|
import { type Side } from "./side.ts";
|
|
3
3
|
import type { VariantSpec } from "./variants.ts";
|
|
4
|
-
/** The numbers the evaluation is made of, each a number of pips.
|
|
4
|
+
/** The numbers the evaluation is made of, each a number of pips.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import type { EvaluationWeights } from "@johnmorrisdotca/sugoroku";
|
|
9
|
+
* import { EVALUATION_WEIGHTS } from "@johnmorrisdotca/sugoroku";
|
|
10
|
+
*
|
|
11
|
+
* const value: EvaluationWeights = EVALUATION_WEIGHTS;
|
|
12
|
+
* console.log(value);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
5
15
|
export type EvaluationWeights = {
|
|
6
16
|
/** What it is worth to have the roll, which the side that does not have it must give up. */
|
|
7
17
|
onRoll: number;
|
|
@@ -32,17 +42,65 @@ export type EvaluationWeights = {
|
|
|
32
42
|
/** How much of that the other side's checkers on the bar are worth to this side. */
|
|
33
43
|
barOther: number;
|
|
34
44
|
};
|
|
35
|
-
/** The weights the computer plays with: set by hand and then held against random changes of themselves, none of which won more often over two thousand games.
|
|
45
|
+
/** The weights the computer plays with: set by hand and then held against random changes of themselves, none of which won more often over two thousand games.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { EVALUATION_WEIGHTS } from "@johnmorrisdotca/sugoroku";
|
|
50
|
+
* console.log(EVALUATION_WEIGHTS);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
36
53
|
export declare const EVALUATION_WEIGHTS: EvaluationWeights;
|
|
37
54
|
/**
|
|
38
55
|
* The score of a position for `side`, with the other side to move, as a game
|
|
39
56
|
* where bearing off first wins. Large positive or negative numbers are a game
|
|
40
57
|
* won or lost; `evaluateFor` turns it over for a game played to lose.
|
|
58
|
+
*
|
|
59
|
+
* @param spec - The native variant specification.
|
|
60
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
61
|
+
* @param side - The side being examined: white or black.
|
|
62
|
+
* @param weights - Optional weights for the native position evaluation.
|
|
63
|
+
* @returns The score of a position for `side`, with the other side to move, as a game where bearing off first wins. Large positive or negative numbers are a game won or lost; `evaluateFor` turns it over for a game played to lose.
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { evaluate, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
67
|
+
*
|
|
68
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
69
|
+
* const spec = settings.variant;
|
|
70
|
+
* const position = startPosition(spec);
|
|
71
|
+
* console.log(evaluate(spec,position,"white"));
|
|
72
|
+
* ```
|
|
41
73
|
*/
|
|
42
74
|
export declare function evaluate(spec: VariantSpec, position: Position, side: Side, weights?: EvaluationWeights): number;
|
|
43
|
-
/** The score as `side` plays to win or to lose: a game played to lose is judged the other way up.
|
|
75
|
+
/** The score as `side` plays to win or to lose: a game played to lose is judged the other way up.
|
|
76
|
+
*
|
|
77
|
+
* @param spec - The native variant specification.
|
|
78
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
79
|
+
* @param side - The side being examined: white or black.
|
|
80
|
+
* @param weights - Optional weights for the native position evaluation.
|
|
81
|
+
* @returns The score as `side` plays to win or to lose: a game played to lose is judged the other way up.
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { evaluateFor, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
85
|
+
*
|
|
86
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
87
|
+
* const spec = settings.variant;
|
|
88
|
+
* const position = startPosition(spec);
|
|
89
|
+
* console.log(evaluateFor(spec,position,"white"));
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
44
92
|
export declare function evaluateFor(spec: VariantSpec, position: Position, side: Side, weights?: EvaluationWeights): number;
|
|
45
|
-
/** A chance of winning, 0 to 1, that a score in pips stands for: the logistic curve, which a lead of 25 pips in a position of this kind takes to about three in four.
|
|
93
|
+
/** A chance of winning, 0 to 1, that a score in pips stands for: the logistic curve, which a lead of 25 pips in a position of this kind takes to about three in four.
|
|
94
|
+
*
|
|
95
|
+
* @param score - The evaluation difference to map to a win chance.
|
|
96
|
+
* @returns A chance of winning, 0 to 1, that a score in pips stands for: the logistic curve, which a lead of 25 pips in a position of this kind takes to about three in four.
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { winChance } from "@johnmorrisdotca/sugoroku";
|
|
100
|
+
*
|
|
101
|
+
* console.log(winChance(0));
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
46
104
|
export declare function winChance(score: number): number;
|
|
47
105
|
/**
|
|
48
106
|
* The Keith count of a side, a pip count corrected for how badly the checkers
|
|
@@ -50,5 +108,19 @@ export declare function winChance(score: number): number;
|
|
|
50
108
|
* 1-point, 1 for each beyond the first on the 2-point and beyond three on the
|
|
51
109
|
* 3-point, and 1 for each empty point among the 4, 5 and 6, and then the side
|
|
52
110
|
* on roll adds a seventh (rounded down). For races only.
|
|
111
|
+
*
|
|
112
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
113
|
+
* @param side - The side being examined: white or black.
|
|
114
|
+
* @param onRoll - The side to roll, or whether this evaluated side is on roll, specified by the signature.
|
|
115
|
+
* @returns The Keith count of a side, a pip count corrected for how badly the checkers are placed for bearing off: plus 2 for each checker beyond the first on the 1-point, 1 for each beyond the first on the 2-point and beyond three on the 3-point, and 1 for each empty point among the 4, 5 and 6, and then the side on roll adds a seventh (rounded down). For races only.
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* import { keithCount, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
119
|
+
*
|
|
120
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
121
|
+
* const spec = settings.variant;
|
|
122
|
+
* const position = startPosition(spec);
|
|
123
|
+
* console.log(keithCount(position,"white",true));
|
|
124
|
+
* ```
|
|
53
125
|
*/
|
|
54
126
|
export declare function keithCount(position: Position, side: Side, onRoll: boolean): number;
|
package/dist/evaluate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inContact, mirrorPoint,
|
|
1
|
+
import { inContact, mirrorPoint, POINTS, pipCount } from "./board.js";
|
|
2
2
|
import { otherSide, sideIndex } from "./side.js";
|
|
3
3
|
/**
|
|
4
4
|
* HOW GOOD A POSITION IS FOR A SIDE, as a number in pips: positive is good for
|
|
@@ -23,7 +23,10 @@ const SHOT_ROLLS = (() => {
|
|
|
23
23
|
for (let b = 1; b <= 6; b += 1) {
|
|
24
24
|
const roll = (a - 1) * 6 + (b - 1);
|
|
25
25
|
const double = a === b;
|
|
26
|
-
if (distance === a ||
|
|
26
|
+
if (distance === a ||
|
|
27
|
+
distance === b ||
|
|
28
|
+
(!double && distance === a + b) ||
|
|
29
|
+
(double && distance <= 4 * a && distance % a === 0))
|
|
27
30
|
hits[roll] = 1;
|
|
28
31
|
}
|
|
29
32
|
}
|
|
@@ -53,7 +56,14 @@ function rollsThatHit(distances) {
|
|
|
53
56
|
}
|
|
54
57
|
return n;
|
|
55
58
|
}
|
|
56
|
-
/** The weights the computer plays with: set by hand and then held against random changes of themselves, none of which won more often over two thousand games.
|
|
59
|
+
/** The weights the computer plays with: set by hand and then held against random changes of themselves, none of which won more often over two thousand games.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { EVALUATION_WEIGHTS } from "@johnmorrisdotca/sugoroku";
|
|
64
|
+
* console.log(EVALUATION_WEIGHTS);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
57
67
|
export const EVALUATION_WEIGHTS = {
|
|
58
68
|
onRoll: 4,
|
|
59
69
|
raceChecker: 1.6,
|
|
@@ -87,6 +97,21 @@ function distancesTo(counts, onBarOrReserve, target) {
|
|
|
87
97
|
* The score of a position for `side`, with the other side to move, as a game
|
|
88
98
|
* where bearing off first wins. Large positive or negative numbers are a game
|
|
89
99
|
* won or lost; `evaluateFor` turns it over for a game played to lose.
|
|
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 weights - Optional weights for the native position evaluation.
|
|
105
|
+
* @returns The score of a position for `side`, with the other side to move, as a game where bearing off first wins. Large positive or negative numbers are a game won or lost; `evaluateFor` turns it over for a game played to lose.
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { evaluate, 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(evaluate(spec,position,"white"));
|
|
114
|
+
* ```
|
|
90
115
|
*/
|
|
91
116
|
export function evaluate(spec, position, side, weights = EVALUATION_WEIGHTS) {
|
|
92
117
|
const i = sideIndex(side);
|
|
@@ -159,12 +184,38 @@ export function evaluate(spec, position, side, weights = EVALUATION_WEIGHTS) {
|
|
|
159
184
|
score += oppBar * (w.bar + w.barBoard * myHome) * w.barOther;
|
|
160
185
|
return score;
|
|
161
186
|
}
|
|
162
|
-
/** The score as `side` plays to win or to lose: a game played to lose is judged the other way up.
|
|
187
|
+
/** The score as `side` plays to win or to lose: a game played to lose is judged the other way up.
|
|
188
|
+
*
|
|
189
|
+
* @param spec - The native variant specification.
|
|
190
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
191
|
+
* @param side - The side being examined: white or black.
|
|
192
|
+
* @param weights - Optional weights for the native position evaluation.
|
|
193
|
+
* @returns The score as `side` plays to win or to lose: a game played to lose is judged the other way up.
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* import { evaluateFor, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
197
|
+
*
|
|
198
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
199
|
+
* const spec = settings.variant;
|
|
200
|
+
* const position = startPosition(spec);
|
|
201
|
+
* console.log(evaluateFor(spec,position,"white"));
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
163
204
|
export function evaluateFor(spec, position, side, weights = EVALUATION_WEIGHTS) {
|
|
164
205
|
const score = evaluate(spec, position, side, weights);
|
|
165
206
|
return spec.goal === "first-off" ? score : -score;
|
|
166
207
|
}
|
|
167
|
-
/** A chance of winning, 0 to 1, that a score in pips stands for: the logistic curve, which a lead of 25 pips in a position of this kind takes to about three in four.
|
|
208
|
+
/** A chance of winning, 0 to 1, that a score in pips stands for: the logistic curve, which a lead of 25 pips in a position of this kind takes to about three in four.
|
|
209
|
+
*
|
|
210
|
+
* @param score - The evaluation difference to map to a win chance.
|
|
211
|
+
* @returns A chance of winning, 0 to 1, that a score in pips stands for: the logistic curve, which a lead of 25 pips in a position of this kind takes to about three in four.
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* import { winChance } from "@johnmorrisdotca/sugoroku";
|
|
215
|
+
*
|
|
216
|
+
* console.log(winChance(0));
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
168
219
|
export function winChance(score) {
|
|
169
220
|
return 1 / (1 + Math.exp(-score / 22));
|
|
170
221
|
}
|
|
@@ -174,6 +225,20 @@ export function winChance(score) {
|
|
|
174
225
|
* 1-point, 1 for each beyond the first on the 2-point and beyond three on the
|
|
175
226
|
* 3-point, and 1 for each empty point among the 4, 5 and 6, and then the side
|
|
176
227
|
* on roll adds a seventh (rounded down). For races only.
|
|
228
|
+
*
|
|
229
|
+
* @param position - The native checker counts, bar, reserve and borne-off counts.
|
|
230
|
+
* @param side - The side being examined: white or black.
|
|
231
|
+
* @param onRoll - The side to roll, or whether this evaluated side is on roll, specified by the signature.
|
|
232
|
+
* @returns The Keith count of a side, a pip count corrected for how badly the checkers are placed for bearing off: plus 2 for each checker beyond the first on the 1-point, 1 for each beyond the first on the 2-point and beyond three on the 3-point, and 1 for each empty point among the 4, 5 and 6, and then the side on roll adds a seventh (rounded down). For races only.
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* import { keithCount, settingsFor, startPosition } from "@johnmorrisdotca/sugoroku";
|
|
236
|
+
*
|
|
237
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
238
|
+
* const spec = settings.variant;
|
|
239
|
+
* const position = startPosition(spec);
|
|
240
|
+
* console.log(keithCount(position,"white",true));
|
|
241
|
+
* ```
|
|
177
242
|
*/
|
|
178
243
|
export function keithCount(position, side, onRoll) {
|
|
179
244
|
const points = position.points[sideIndex(side)];
|