@johnmorrisdotca/sugoroku 1.1.0 → 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 +12 -0
- package/README.md +1 -1
- package/dist/board.js +1 -1
- package/dist/colours.js +6 -1
- package/dist/computer.d.ts +1 -1
- package/dist/computer.js +9 -4
- package/dist/draw-entry.d.ts +3 -3
- package/dist/draw-entry.js +2 -2
- package/dist/draw.js +30 -11
- package/dist/element.d.ts +3 -122
- package/dist/element.js +327 -405
- package/dist/elementFrame.d.ts +21 -0
- package/dist/elementFrame.js +110 -0
- package/dist/evaluate.js +5 -2
- package/dist/game.js +16 -2
- package/dist/geometry.js +44 -27
- package/dist/index.d.ts +11 -11
- package/dist/index.js +9 -9
- package/dist/match.js +14 -2
- package/dist/mount.d.ts +2 -2
- package/dist/mount.js +80 -354
- package/dist/mountView.d.ts +58 -0
- package/dist/mountView.js +459 -0
- package/dist/notation.js +6 -2
- package/dist/play-entry.d.ts +4 -4
- package/dist/play-entry.js +1 -1
- package/dist/positionElement.d.ts +107 -0
- package/dist/positionElement.js +303 -0
- package/dist/positionId.js +4 -1
- package/dist/record.d.ts +1 -1
- package/dist/record.js +27 -31
- package/dist/rules.js +34 -5
- package/dist/strings.js +3 -1
- package/dist/variants.js +19 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +11 -11
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The shared frame of `<sugoroku-board>` and `<sugoroku-position>`: size, width, label and the dark-theme rule. */
|
|
2
|
+
declare const ElementBase: typeof HTMLElement;
|
|
3
|
+
export declare const isOn: (value: string | null, fallback?: boolean) => boolean;
|
|
4
|
+
export declare const oneOf: <T extends string>(value: string | null, allowed: readonly T[]) => T | undefined;
|
|
5
|
+
/** The attributes that name the game: changing one starts a new match. */
|
|
6
|
+
export declare const GAME_ATTRIBUTES: readonly ["variant", "preset", "points", "cube", "crawford", "jacoby", "beaver", "gammons", "seed", "dice", "controls", "drag", "auto-end", "sound", "computer-delay"];
|
|
7
|
+
export declare class SugorokuFrame extends ElementBase {
|
|
8
|
+
#private;
|
|
9
|
+
protected frame(): void;
|
|
10
|
+
protected write(name: string, value: unknown): void;
|
|
11
|
+
/** Symbolic display size, reflected. */
|
|
12
|
+
get size(): string | null;
|
|
13
|
+
set size(value: string | null);
|
|
14
|
+
/** Pixel display width, reflected. */
|
|
15
|
+
get width(): string | null;
|
|
16
|
+
set width(value: string | number | null);
|
|
17
|
+
/** Spoken group label, reflected. */
|
|
18
|
+
get label(): string | null;
|
|
19
|
+
set label(value: string | null);
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { SUGOROKU_STYLE } from "./style.js";
|
|
2
|
+
/** The shared frame of `<sugoroku-board>` and `<sugoroku-position>`: size, width, label and the dark-theme rule. */
|
|
3
|
+
const ElementBase = typeof HTMLElement === "undefined" ? class {
|
|
4
|
+
} : HTMLElement;
|
|
5
|
+
export const isOn = (value, fallback = false) => value === null ? fallback : !["false", "off", "0", "no"].includes(value.trim().toLowerCase());
|
|
6
|
+
export const oneOf = (value, allowed) => allowed.includes(value) ? value : undefined;
|
|
7
|
+
/** The attributes that name the game: changing one starts a new match. */
|
|
8
|
+
export const GAME_ATTRIBUTES = [
|
|
9
|
+
"variant",
|
|
10
|
+
"preset",
|
|
11
|
+
"points",
|
|
12
|
+
"cube",
|
|
13
|
+
"crawford",
|
|
14
|
+
"jacoby",
|
|
15
|
+
"beaver",
|
|
16
|
+
"gammons",
|
|
17
|
+
"seed",
|
|
18
|
+
"dice",
|
|
19
|
+
"controls",
|
|
20
|
+
"drag",
|
|
21
|
+
"auto-end",
|
|
22
|
+
"sound",
|
|
23
|
+
"computer-delay",
|
|
24
|
+
];
|
|
25
|
+
export class SugorokuFrame extends ElementBase {
|
|
26
|
+
#widthBefore = null;
|
|
27
|
+
#widthOwned = false;
|
|
28
|
+
#labelBefore = null;
|
|
29
|
+
frame() {
|
|
30
|
+
this.style.display = "block";
|
|
31
|
+
this.style.maxWidth = "100%";
|
|
32
|
+
const width = Number(this.getAttribute("width"));
|
|
33
|
+
const size = this.getAttribute("size");
|
|
34
|
+
const pixels = this.hasAttribute("width") && width > 0 && Number.isFinite(width)
|
|
35
|
+
? Math.min(width, 2000)
|
|
36
|
+
: size === "small"
|
|
37
|
+
? 320
|
|
38
|
+
: size === "medium"
|
|
39
|
+
? 480
|
|
40
|
+
: size === "large"
|
|
41
|
+
? 640
|
|
42
|
+
: null;
|
|
43
|
+
if (pixels !== null) {
|
|
44
|
+
if (!this.#widthOwned)
|
|
45
|
+
this.#widthBefore = this.style.width;
|
|
46
|
+
this.#widthOwned = true;
|
|
47
|
+
this.style.width = `${pixels}px`;
|
|
48
|
+
}
|
|
49
|
+
else if (this.#widthOwned) {
|
|
50
|
+
this.style.width = this.#widthBefore ?? "";
|
|
51
|
+
this.#widthOwned = false;
|
|
52
|
+
}
|
|
53
|
+
const theme = this.getAttribute("theme");
|
|
54
|
+
this.style.colorScheme = theme === "light" || theme === "dark" ? theme : "light dark";
|
|
55
|
+
this.setAttribute("data-sugoroku-embed", "");
|
|
56
|
+
const root = this.getRootNode();
|
|
57
|
+
const target = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root : this.ownerDocument.head;
|
|
58
|
+
if (target.querySelector("style[data-sugoroku-embed-style]") === null) {
|
|
59
|
+
const style = this.ownerDocument.createElement("style");
|
|
60
|
+
style.setAttribute("data-sugoroku-embed-style", "");
|
|
61
|
+
const palette = SUGOROKU_STYLE.match(/\.sugoroku\[data-theme="dark"\] \{([^}]+)\}/)?.[1] ?? "";
|
|
62
|
+
style.textContent = `@media(prefers-color-scheme:dark){[data-sugoroku-embed] .sugoroku:not([data-theme="light"]){${palette}}}`;
|
|
63
|
+
target.append(style);
|
|
64
|
+
}
|
|
65
|
+
if (this.hasAttribute("label")) {
|
|
66
|
+
this.#labelBefore ??= { role: this.getAttribute("role"), label: this.getAttribute("aria-label") };
|
|
67
|
+
this.setAttribute("role", "group");
|
|
68
|
+
this.setAttribute("aria-label", this.getAttribute("label"));
|
|
69
|
+
}
|
|
70
|
+
else if (this.#labelBefore !== null) {
|
|
71
|
+
for (const [name, value] of [
|
|
72
|
+
["role", this.#labelBefore.role],
|
|
73
|
+
["aria-label", this.#labelBefore.label],
|
|
74
|
+
]) {
|
|
75
|
+
if (value === null)
|
|
76
|
+
this.removeAttribute(name);
|
|
77
|
+
else
|
|
78
|
+
this.setAttribute(name, value);
|
|
79
|
+
}
|
|
80
|
+
this.#labelBefore = null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
write(name, value) {
|
|
84
|
+
if (value === null || value === undefined)
|
|
85
|
+
this.removeAttribute(name);
|
|
86
|
+
else
|
|
87
|
+
this.setAttribute(name, String(value));
|
|
88
|
+
}
|
|
89
|
+
/** Symbolic display size, reflected. */
|
|
90
|
+
get size() {
|
|
91
|
+
return this.getAttribute("size");
|
|
92
|
+
}
|
|
93
|
+
set size(value) {
|
|
94
|
+
this.write("size", value);
|
|
95
|
+
}
|
|
96
|
+
/** Pixel display width, reflected. */
|
|
97
|
+
get width() {
|
|
98
|
+
return this.getAttribute("width");
|
|
99
|
+
}
|
|
100
|
+
set width(value) {
|
|
101
|
+
this.write("width", value);
|
|
102
|
+
}
|
|
103
|
+
/** Spoken group label, reflected. */
|
|
104
|
+
get label() {
|
|
105
|
+
return this.getAttribute("label");
|
|
106
|
+
}
|
|
107
|
+
set label(value) {
|
|
108
|
+
this.write("label", value);
|
|
109
|
+
}
|
|
110
|
+
}
|
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
|
}
|
package/dist/game.js
CHANGED
|
@@ -281,7 +281,17 @@ export function endTurn(game) {
|
|
|
281
281
|
fail("The turn is not played out yet.");
|
|
282
282
|
const turns = [game.turns[0], game.turns[1]];
|
|
283
283
|
turns[sideIndex(side)] += 1;
|
|
284
|
-
const next = {
|
|
284
|
+
const next = {
|
|
285
|
+
...game,
|
|
286
|
+
turn: otherSide(side),
|
|
287
|
+
phase: "before-roll",
|
|
288
|
+
dice: null,
|
|
289
|
+
need: [],
|
|
290
|
+
plan: [],
|
|
291
|
+
moves: [],
|
|
292
|
+
turnStart: game.position,
|
|
293
|
+
turns,
|
|
294
|
+
};
|
|
285
295
|
const limit = game.settings.variant.drawAfter;
|
|
286
296
|
if (limit > 0 && turns[0] >= limit && turns[1] >= limit)
|
|
287
297
|
return finish(next, { winner: null, how: "draw", kind: "single", multiplier: 1, cube: game.cube.value, points: 0 });
|
|
@@ -478,7 +488,11 @@ export function takeDouble(game) {
|
|
|
478
488
|
export function dropDouble(game) {
|
|
479
489
|
const dropper = responder(game);
|
|
480
490
|
const winner = otherSide(dropper);
|
|
481
|
-
const value = game.phase === "beaver-offered"
|
|
491
|
+
const value = game.phase === "beaver-offered"
|
|
492
|
+
? game.cube.value * 2
|
|
493
|
+
: game.phase === "double-offered"
|
|
494
|
+
? game.cube.value
|
|
495
|
+
: fail("No double has been offered.");
|
|
482
496
|
return finish(game, { winner, how: "drop", kind: "single", multiplier: 1, cube: value, points: value });
|
|
483
497
|
}
|
|
484
498
|
/** Whether the side that was doubled may beaver: redouble at once and keep the cube. Only where the rules allow it.
|
package/dist/geometry.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _BoardLayout_fieldLeft;
|
|
13
1
|
export const PAD = 14;
|
|
14
2
|
/** The strip above and below the points that holds their numbers. */
|
|
15
3
|
export const STRIP = 18;
|
|
@@ -29,7 +17,10 @@ export const DIE = 46;
|
|
|
29
17
|
/** The width and height of the board drawn lying down. */
|
|
30
18
|
export function landscapeSize(cube) {
|
|
31
19
|
const rail = cube ? RAIL_WIDTH + 10 : 0;
|
|
32
|
-
return {
|
|
20
|
+
return {
|
|
21
|
+
width: PAD + rail + 2 * HALF_WIDTH + BAR_WIDTH + TRAY_GAP + TRAY_WIDTH + PAD,
|
|
22
|
+
height: PAD + STRIP + 2 * POINT_LENGTH + MIDDLE + STRIP + PAD,
|
|
23
|
+
};
|
|
33
24
|
}
|
|
34
25
|
/** The width and height the board is drawn in, which is the other way about when it stands up.
|
|
35
26
|
*
|
|
@@ -60,14 +51,17 @@ export function boardSize(options) {
|
|
|
60
51
|
* ```
|
|
61
52
|
*/
|
|
62
53
|
export class BoardLayout {
|
|
54
|
+
width;
|
|
55
|
+
height;
|
|
56
|
+
fieldTop = PAD + STRIP;
|
|
57
|
+
options;
|
|
58
|
+
#fieldLeft;
|
|
63
59
|
constructor(options) {
|
|
64
|
-
this.fieldTop = PAD + STRIP;
|
|
65
|
-
_BoardLayout_fieldLeft.set(this, void 0);
|
|
66
60
|
this.options = options;
|
|
67
61
|
const size = landscapeSize(options.cube);
|
|
68
62
|
this.width = size.width;
|
|
69
63
|
this.height = size.height;
|
|
70
|
-
|
|
64
|
+
this.#fieldLeft = PAD + (options.cube ? RAIL_WIDTH + 10 : 0);
|
|
71
65
|
}
|
|
72
66
|
/** An x, for something `w` wide, after the board is mirrored for trays on the left. */
|
|
73
67
|
mx(x, w = 0) {
|
|
@@ -75,16 +69,16 @@ export class BoardLayout {
|
|
|
75
69
|
}
|
|
76
70
|
/** The x the field of points starts at, before mirroring. */
|
|
77
71
|
get fieldLeft() {
|
|
78
|
-
return
|
|
72
|
+
return this.#fieldLeft;
|
|
79
73
|
}
|
|
80
74
|
get fieldHeight() {
|
|
81
75
|
return 2 * POINT_LENGTH + MIDDLE;
|
|
82
76
|
}
|
|
83
77
|
get barLeft() {
|
|
84
|
-
return
|
|
78
|
+
return this.#fieldLeft + HALF_WIDTH;
|
|
85
79
|
}
|
|
86
80
|
get trayLeft() {
|
|
87
|
-
return
|
|
81
|
+
return this.#fieldLeft + 2 * HALF_WIDTH + BAR_WIDTH + TRAY_GAP;
|
|
88
82
|
}
|
|
89
83
|
/**
|
|
90
84
|
* Which slot of the drawing a point of the board is in: its row (the top
|
|
@@ -100,37 +94,60 @@ export class BoardLayout {
|
|
|
100
94
|
}
|
|
101
95
|
/** The x of the left edge of column `col`, before mirroring. */
|
|
102
96
|
columnLeft(col) {
|
|
103
|
-
return col < 6
|
|
97
|
+
return col < 6
|
|
98
|
+
? this.#fieldLeft + col * POINT_WIDTH
|
|
99
|
+
: this.#fieldLeft + HALF_WIDTH + BAR_WIDTH + (col - 6) * POINT_WIDTH;
|
|
104
100
|
}
|
|
105
101
|
/** The box of a point, as a base on its edge of the field and its length. */
|
|
106
102
|
pointBox(point) {
|
|
107
103
|
const { top, col } = this.slotOf(point);
|
|
108
104
|
const x = this.columnLeft(col);
|
|
109
|
-
return {
|
|
105
|
+
return {
|
|
106
|
+
x,
|
|
107
|
+
y: top ? this.fieldTop : this.fieldTop + this.fieldHeight - POINT_LENGTH,
|
|
108
|
+
w: POINT_WIDTH,
|
|
109
|
+
h: POINT_LENGTH,
|
|
110
|
+
top,
|
|
111
|
+
};
|
|
110
112
|
}
|
|
111
113
|
/** The tray of a side: the bottom one is white's when seen from white's side. */
|
|
112
114
|
trayBox(side) {
|
|
113
115
|
const top = (side === "black") === (this.options.view === "white");
|
|
114
|
-
return {
|
|
116
|
+
return {
|
|
117
|
+
x: this.trayLeft,
|
|
118
|
+
y: top ? this.fieldTop : this.fieldTop + this.fieldHeight - POINT_LENGTH,
|
|
119
|
+
w: TRAY_WIDTH,
|
|
120
|
+
h: POINT_LENGTH,
|
|
121
|
+
top,
|
|
122
|
+
};
|
|
115
123
|
}
|
|
116
124
|
/** The half of the bar a side's checkers wait in: the nearer half to the side's own tray. */
|
|
117
125
|
barBox(side) {
|
|
118
126
|
const top = this.trayBox(side).top;
|
|
119
|
-
return {
|
|
127
|
+
return {
|
|
128
|
+
x: this.barLeft,
|
|
129
|
+
y: top ? this.fieldTop : this.fieldTop + this.fieldHeight / 2,
|
|
130
|
+
w: BAR_WIDTH,
|
|
131
|
+
h: this.fieldHeight / 2,
|
|
132
|
+
top,
|
|
133
|
+
};
|
|
120
134
|
}
|
|
121
135
|
/** Where the cube rests: the middle of the rail, or the end of it nearer its owner. */
|
|
122
136
|
cubeBox(owner) {
|
|
123
137
|
const size = 44;
|
|
124
138
|
const x = PAD + (RAIL_WIDTH - size) / 2;
|
|
125
139
|
const top = owner === null ? null : (owner === "black") === (this.options.view === "white");
|
|
126
|
-
const y = top === null
|
|
140
|
+
const y = top === null
|
|
141
|
+
? this.fieldTop + this.fieldHeight / 2 - size / 2
|
|
142
|
+
: top
|
|
143
|
+
? this.fieldTop + 4
|
|
144
|
+
: this.fieldTop + this.fieldHeight - size - 4;
|
|
127
145
|
return { x, y, w: size, h: size };
|
|
128
146
|
}
|
|
129
147
|
/** The middle of the row of dice, on the half of the board a side plays from: its own home half for white, the other for black. */
|
|
130
148
|
diceCentre(side) {
|
|
131
|
-
const rightHalf =
|
|
132
|
-
const leftHalf =
|
|
149
|
+
const rightHalf = this.#fieldLeft + HALF_WIDTH + BAR_WIDTH + HALF_WIDTH / 2;
|
|
150
|
+
const leftHalf = this.#fieldLeft + HALF_WIDTH / 2;
|
|
133
151
|
return { x: side === "white" ? rightHalf : leftHalf, y: this.fieldTop + this.fieldHeight / 2 };
|
|
134
152
|
}
|
|
135
153
|
}
|
|
136
|
-
_BoardLayout_fieldLeft = new WeakMap();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/** Pure backgammon and variant rules, legal turns, cube and match scoring, dice, records and computer choices. */
|
|
2
|
-
export * from "./side.ts";
|
|
3
|
-
export * from "./variants.ts";
|
|
4
|
-
export * from "./rules.ts";
|
|
5
2
|
export * from "./board.ts";
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
3
|
+
export * from "./computer.ts";
|
|
4
|
+
export * from "./dice.ts";
|
|
5
|
+
export type { EvaluationWeights } from "./evaluate.ts";
|
|
6
|
+
export { EVALUATION_WEIGHTS, evaluate, evaluateFor, keithCount, winChance } from "./evaluate.ts";
|
|
8
7
|
export * from "./game.ts";
|
|
9
8
|
export * from "./match.ts";
|
|
10
|
-
export * from "./
|
|
11
|
-
export { hashSeed, seededRandom } from "./random.ts";
|
|
12
|
-
export type { Random } from "./random.ts";
|
|
9
|
+
export * from "./moves.ts";
|
|
13
10
|
export * from "./notation.ts";
|
|
11
|
+
export * from "./plays.ts";
|
|
14
12
|
export * from "./positionId.ts";
|
|
13
|
+
export type { Random } from "./random.ts";
|
|
14
|
+
export { hashSeed, seededRandom } from "./random.ts";
|
|
15
15
|
export * from "./record.ts";
|
|
16
|
-
export * from "./
|
|
17
|
-
export
|
|
18
|
-
export
|
|
16
|
+
export * from "./rules.ts";
|
|
17
|
+
export * from "./side.ts";
|
|
18
|
+
export * from "./variants.ts";
|
|
19
19
|
export { VERSION } from "./version.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/** Pure backgammon and variant rules, legal turns, cube and match scoring, dice, records and computer choices. */
|
|
2
|
-
export * from "./side.js";
|
|
3
|
-
export * from "./variants.js";
|
|
4
|
-
export * from "./rules.js";
|
|
5
2
|
export * from "./board.js";
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
3
|
+
export * from "./computer.js";
|
|
4
|
+
export * from "./dice.js";
|
|
5
|
+
export { EVALUATION_WEIGHTS, evaluate, evaluateFor, keithCount, winChance } from "./evaluate.js";
|
|
8
6
|
export * from "./game.js";
|
|
9
7
|
export * from "./match.js";
|
|
10
|
-
export * from "./
|
|
11
|
-
export { hashSeed, seededRandom } from "./random.js";
|
|
8
|
+
export * from "./moves.js";
|
|
12
9
|
export * from "./notation.js";
|
|
10
|
+
export * from "./plays.js";
|
|
13
11
|
export * from "./positionId.js";
|
|
12
|
+
export { hashSeed, seededRandom } from "./random.js";
|
|
14
13
|
export * from "./record.js";
|
|
15
|
-
export * from "./
|
|
16
|
-
export
|
|
14
|
+
export * from "./rules.js";
|
|
15
|
+
export * from "./side.js";
|
|
16
|
+
export * from "./variants.js";
|
|
17
17
|
export { VERSION } from "./version.js";
|
package/dist/match.js
CHANGED
|
@@ -13,7 +13,15 @@ import { sideIndex } from "./side.js";
|
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export function newMatch(settings) {
|
|
16
|
-
return {
|
|
16
|
+
return {
|
|
17
|
+
settings,
|
|
18
|
+
score: [0, 0],
|
|
19
|
+
results: [],
|
|
20
|
+
crawfordNext: false,
|
|
21
|
+
crawfordPlayed: false,
|
|
22
|
+
over: false,
|
|
23
|
+
winner: null,
|
|
24
|
+
};
|
|
17
25
|
}
|
|
18
26
|
/** The first game, or the next game, of a match.
|
|
19
27
|
*
|
|
@@ -79,6 +87,10 @@ export function finishGame(match, result) {
|
|
|
79
87
|
return { ...match, score, results, crawfordNext: false, over: true, winner: result.winner };
|
|
80
88
|
// The Crawford game is the one after a side first comes within a point of winning, and there is only one.
|
|
81
89
|
const crawfordPlayed = match.crawfordPlayed || match.crawfordNext;
|
|
82
|
-
const reachedNow = points > 1 &&
|
|
90
|
+
const reachedNow = points > 1 &&
|
|
91
|
+
crawford &&
|
|
92
|
+
!crawfordPlayed &&
|
|
93
|
+
Math.max(score[0], score[1]) === points - 1 &&
|
|
94
|
+
Math.max(match.score[0], match.score[1]) < points - 1;
|
|
83
95
|
return { ...match, score, results, crawfordNext: reachedNow, crawfordPlayed, over: false, winner: null };
|
|
84
96
|
}
|
package/dist/mount.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { SugorokuBoardName, SugorokuCheckerSetName, SugorokuColours } from "./colours.ts";
|
|
2
2
|
import { type Strength } from "./computer.ts";
|
|
3
|
-
import { type Orientation } from "./geometry.ts";
|
|
4
3
|
import { type GameResult, type GameState } from "./game.ts";
|
|
4
|
+
import type { Orientation } from "./geometry.ts";
|
|
5
5
|
import { type Match } from "./match.ts";
|
|
6
6
|
import type { Move } from "./moves.ts";
|
|
7
7
|
import { type RecordSeed } from "./record.ts";
|
|
8
8
|
import { type Rules } from "./rules.ts";
|
|
9
|
-
import {
|
|
9
|
+
import type { Side } from "./side.ts";
|
|
10
10
|
import { type SoundUrls } from "./sound.ts";
|
|
11
11
|
import { type SugorokuLanguage } from "./strings.ts";
|
|
12
12
|
import type { VariantKey } from "./variants.ts";
|