@tastic/cardtastic-engine 0.0.0-stage → 0.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 (87) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +68 -2
  3. package/dist/acesup.d.mts +17 -0
  4. package/dist/acesup.d.ts +17 -0
  5. package/dist/acesup.js +8 -0
  6. package/dist/acesup.mjs +8 -0
  7. package/dist/autoFoundation-CfnFNysj.d.ts +63 -0
  8. package/dist/autoFoundation-Ctp9LKa-.d.mts +63 -0
  9. package/dist/canfield.d.mts +64 -0
  10. package/dist/canfield.d.ts +64 -0
  11. package/dist/canfield.js +20 -0
  12. package/dist/canfield.mjs +20 -0
  13. package/dist/chunk-22DC2YH6.js +95 -0
  14. package/dist/chunk-3BMUGHKQ.mjs +95 -0
  15. package/dist/chunk-4HJ7QMYV.mjs +339 -0
  16. package/dist/chunk-4WAWIFQF.js +131 -0
  17. package/dist/chunk-5266UC2Q.mjs +271 -0
  18. package/dist/chunk-6JWUTZVU.mjs +214 -0
  19. package/dist/chunk-AY3CR5EH.mjs +212 -0
  20. package/dist/chunk-B56TRALO.js +23 -0
  21. package/dist/chunk-CV3VJX34.mjs +341 -0
  22. package/dist/chunk-FDHHAPZA.mjs +177 -0
  23. package/dist/chunk-FTR733R7.mjs +297 -0
  24. package/dist/chunk-GFP5NUYK.mjs +23 -0
  25. package/dist/chunk-IKLYXDG7.mjs +131 -0
  26. package/dist/chunk-LH3UZP7D.js +165 -0
  27. package/dist/chunk-LSS44UKH.js +22 -0
  28. package/dist/chunk-M37CNJHF.mjs +165 -0
  29. package/dist/chunk-PLSNST56.mjs +163 -0
  30. package/dist/chunk-PTRHGPCN.js +163 -0
  31. package/dist/chunk-S3WNVF2K.js +339 -0
  32. package/dist/chunk-SDZPP3HI.mjs +22 -0
  33. package/dist/chunk-SLQ7RGMZ.js +212 -0
  34. package/dist/chunk-TNMFNWEM.mjs +249 -0
  35. package/dist/chunk-VGJPT3CX.js +214 -0
  36. package/dist/chunk-W5CPH6TD.js +115 -0
  37. package/dist/chunk-WJGEX74V.js +341 -0
  38. package/dist/chunk-WKES4P36.js +297 -0
  39. package/dist/chunk-XPTQNUF3.js +348 -0
  40. package/dist/chunk-XSS5M6C7.mjs +115 -0
  41. package/dist/chunk-XTHDUWJF.js +271 -0
  42. package/dist/chunk-XV5OUPIW.js +177 -0
  43. package/dist/chunk-YKY4K67K.mjs +348 -0
  44. package/dist/chunk-ZMNGTXU5.js +249 -0
  45. package/dist/fortythieves.d.mts +50 -0
  46. package/dist/fortythieves.d.ts +50 -0
  47. package/dist/fortythieves.js +22 -0
  48. package/dist/fortythieves.mjs +22 -0
  49. package/dist/freecell.d.mts +30 -0
  50. package/dist/freecell.d.ts +30 -0
  51. package/dist/freecell.js +18 -0
  52. package/dist/freecell.mjs +18 -0
  53. package/dist/gameTypes-BnfLkwzA.d.mts +201 -0
  54. package/dist/gameTypes-BnfLkwzA.d.ts +201 -0
  55. package/dist/golf.d.mts +17 -0
  56. package/dist/golf.d.ts +17 -0
  57. package/dist/golf.js +7 -0
  58. package/dist/golf.mjs +7 -0
  59. package/dist/index.d.mts +176 -0
  60. package/dist/index.d.ts +176 -0
  61. package/dist/index.js +446 -0
  62. package/dist/index.mjs +446 -0
  63. package/dist/klondike.d.mts +25 -0
  64. package/dist/klondike.d.ts +25 -0
  65. package/dist/klondike.js +15 -0
  66. package/dist/klondike.mjs +15 -0
  67. package/dist/pyramid.d.mts +36 -0
  68. package/dist/pyramid.d.ts +36 -0
  69. package/dist/pyramid.js +16 -0
  70. package/dist/pyramid.mjs +16 -0
  71. package/dist/scorpion.d.mts +14 -0
  72. package/dist/scorpion.d.ts +14 -0
  73. package/dist/scorpion.js +9 -0
  74. package/dist/scorpion.mjs +9 -0
  75. package/dist/spider.d.mts +22 -0
  76. package/dist/spider.d.ts +22 -0
  77. package/dist/spider.js +11 -0
  78. package/dist/spider.mjs +11 -0
  79. package/dist/tripeaks.d.mts +43 -0
  80. package/dist/tripeaks.d.ts +43 -0
  81. package/dist/tripeaks.js +19 -0
  82. package/dist/tripeaks.mjs +19 -0
  83. package/dist/yukon.d.mts +24 -0
  84. package/dist/yukon.d.ts +24 -0
  85. package/dist/yukon.js +15 -0
  86. package/dist/yukon.mjs +15 -0
  87. package/package.json +187 -4
@@ -0,0 +1,348 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+
4
+ var _chunk22DC2YH6js = require('./chunk-22DC2YH6.js');
5
+
6
+
7
+ var _chunkLSS44UKHjs = require('./chunk-LSS44UKH.js');
8
+
9
+
10
+
11
+
12
+ var _chunkXV5OUPIWjs = require('./chunk-XV5OUPIW.js');
13
+
14
+
15
+
16
+
17
+
18
+ var _chunkW5CPH6TDjs = require('./chunk-W5CPH6TD.js');
19
+
20
+ // src/games/canfield/rules.ts
21
+ function suitIndex(suit) {
22
+ return _chunkLSS44UKHjs.FOUNDATION_SUITS.indexOf(suit);
23
+ }
24
+ function cyclicPrevRank(rank) {
25
+ return rank === 1 ? 13 : rank - 1;
26
+ }
27
+ function cyclicNextRank(rank) {
28
+ return rank === 13 ? 1 : rank + 1;
29
+ }
30
+ function isDescendingAltColorCyclic(cards) {
31
+ for (let i = 1; i < cards.length; i++) {
32
+ const prev = cards[i - 1];
33
+ const cur = cards[i];
34
+ if (cur.rank !== cyclicPrevRank(prev.rank)) return false;
35
+ if (_chunkW5CPH6TDjs.cardColor.call(void 0, cur.suit) === _chunkW5CPH6TDjs.cardColor.call(void 0, prev.suit)) return false;
36
+ }
37
+ return true;
38
+ }
39
+ function canPlaceOnFoundationCyclic(dest, moving, foundationRank) {
40
+ const destTop = _chunkW5CPH6TDjs.top.call(void 0, dest);
41
+ if (destTop === void 0) return moving.rank === foundationRank;
42
+ return destTop.suit === moving.suit && moving.rank === cyclicNextRank(destTop.rank);
43
+ }
44
+ function canPlaceOnTableau(reserve, dest, moving, fromZone) {
45
+ if (moving.length === 0) return false;
46
+ const movingTop = moving[0];
47
+ const destTop = _chunkW5CPH6TDjs.top.call(void 0, dest);
48
+ if (destTop === void 0) {
49
+ return reserve.length > 0 ? fromZone === "reserve" : true;
50
+ }
51
+ if (!destTop.faceUp) return false;
52
+ return _chunkW5CPH6TDjs.cardColor.call(void 0, movingTop.suit) !== _chunkW5CPH6TDjs.cardColor.call(void 0, destTop.suit) && movingTop.rank === cyclicPrevRank(destTop.rank);
53
+ }
54
+ function runLengthAtTop(column) {
55
+ if (column.length === 0) return 0;
56
+ let runStart = column.length - 1;
57
+ while (runStart > 0 && column[runStart - 1].faceUp) {
58
+ if (!isDescendingAltColorCyclic(column.slice(runStart - 1))) break;
59
+ runStart -= 1;
60
+ }
61
+ return column.length - runStart;
62
+ }
63
+ function cloneState(state) {
64
+ return {
65
+ tableau: state.tableau.slice(),
66
+ foundation: state.foundation.slice(),
67
+ foundationRank: state.foundationRank,
68
+ reserve: state.reserve,
69
+ stock: state.stock,
70
+ waste: state.waste
71
+ };
72
+ }
73
+ function getPile(state, ref) {
74
+ switch (ref.zone) {
75
+ case "tableau":
76
+ return _nullishCoalesce(state.tableau[ref.index], () => ( null));
77
+ case "foundation":
78
+ return _nullishCoalesce(state.foundation[ref.index], () => ( null));
79
+ case "reserve":
80
+ return state.reserve;
81
+ case "waste":
82
+ return state.waste;
83
+ default:
84
+ return null;
85
+ }
86
+ }
87
+ function setPile(state, ref, pile) {
88
+ switch (ref.zone) {
89
+ case "tableau":
90
+ state.tableau[ref.index] = pile;
91
+ break;
92
+ case "foundation":
93
+ state.foundation[ref.index] = pile;
94
+ break;
95
+ case "reserve":
96
+ state.reserve = pile;
97
+ break;
98
+ case "waste":
99
+ state.waste = pile;
100
+ break;
101
+ case "stock":
102
+ state.stock = pile;
103
+ break;
104
+ }
105
+ }
106
+ function flipFaceUp(pile) {
107
+ const i = pile.length - 1;
108
+ const c = pile[i];
109
+ if (c && !c.faceUp) pile[i] = { ...c, faceUp: true };
110
+ }
111
+ function newGame(seed) {
112
+ const deck = _chunkW5CPH6TDjs.shuffledDeck.call(void 0, seed, 1);
113
+ let cursor = 0;
114
+ const starter = deck[cursor++];
115
+ const foundation = [[], [], [], []];
116
+ foundation[suitIndex(starter.suit)] = [{ ...starter, faceUp: true }];
117
+ const tableau = [];
118
+ for (let col = 0; col < 4; col++) {
119
+ tableau.push([{ ...deck[cursor++], faceUp: true }]);
120
+ }
121
+ const reserve = [];
122
+ for (let i = 0; i < 13; i++) {
123
+ reserve.push({ ...deck[cursor++], faceUp: i === 12 });
124
+ }
125
+ const stock = deck.slice(cursor).map((c) => ({ ...c, faceUp: false }));
126
+ return { tableau, foundation, foundationRank: starter.rank, reserve, stock, waste: [] };
127
+ }
128
+ function tryMove(state, move) {
129
+ const { from, to, count } = move;
130
+ if (count < 1) return null;
131
+ if (from.zone === to.zone && from.index === to.index) return null;
132
+ if (from.zone === "foundation" && (to.zone !== "tableau" || count !== 1)) return null;
133
+ if (from.zone === "stock") return null;
134
+ const sourcePile = getPile(state, from);
135
+ if (!sourcePile || sourcePile.length < count) return null;
136
+ if (count > 1 && from.zone !== "tableau") return null;
137
+ const movingCards = sourcePile.slice(sourcePile.length - count);
138
+ if (movingCards.some((c) => !c.faceUp)) return null;
139
+ if (from.zone === "tableau" && count > 1) {
140
+ if (!isDescendingAltColorCyclic(movingCards)) return null;
141
+ }
142
+ const destPile = getPile(state, to);
143
+ if (!destPile) return null;
144
+ if (to.zone === "tableau") {
145
+ if (!canPlaceOnTableau(state.reserve, destPile, movingCards, from.zone)) return null;
146
+ } else if (to.zone === "foundation") {
147
+ if (count !== 1) return null;
148
+ const movingCard = movingCards[0];
149
+ if (suitIndex(movingCard.suit) !== to.index) return null;
150
+ if (!canPlaceOnFoundationCyclic(destPile, movingCard, state.foundationRank)) return null;
151
+ } else {
152
+ return null;
153
+ }
154
+ const next = cloneState(state);
155
+ const nextSourcePile = getPile(next, from).slice();
156
+ const nextDestPile = getPile(next, to).slice();
157
+ setPile(next, from, nextSourcePile);
158
+ setPile(next, to, nextDestPile);
159
+ const moved = nextSourcePile.splice(nextSourcePile.length - count, count);
160
+ nextDestPile.push(...moved);
161
+ if (from.zone === "reserve") {
162
+ flipFaceUp(nextSourcePile);
163
+ }
164
+ return next;
165
+ }
166
+ function makeDrawStock(drawCount) {
167
+ return function drawStock(state) {
168
+ if (state.stock.length > 0) {
169
+ const next = cloneState(state);
170
+ const nextStock = next.stock.slice();
171
+ const nextWaste = next.waste.slice();
172
+ const n = Math.min(drawCount, nextStock.length);
173
+ const drawn = nextStock.splice(nextStock.length - n, n);
174
+ for (const c of drawn) {
175
+ nextWaste.push(c.faceUp ? c : { ...c, faceUp: true });
176
+ }
177
+ setPile(next, { zone: "stock", index: 0 }, nextStock);
178
+ setPile(next, { zone: "waste", index: 0 }, nextWaste);
179
+ return next;
180
+ }
181
+ if (state.waste.length > 0) {
182
+ const next = cloneState(state);
183
+ const recycled = state.waste.slice().reverse().map((c) => ({ ...c, faceUp: false }));
184
+ setPile(next, { zone: "stock", index: 0 }, recycled);
185
+ setPile(next, { zone: "waste", index: 0 }, []);
186
+ return next;
187
+ }
188
+ return null;
189
+ };
190
+ }
191
+ function isWon(state) {
192
+ return state.foundation.every((pile) => pile.length === 13);
193
+ }
194
+ function legalMoves(state) {
195
+ const moves = [];
196
+ const tryAdd = (from, to, count) => {
197
+ if (tryMove(state, { from, to, count })) moves.push({ from, to, count });
198
+ };
199
+ if (state.waste.length > 0) {
200
+ const from = { zone: "waste", index: 0 };
201
+ for (let f = 0; f < 4; f++) tryAdd(from, { zone: "foundation", index: f }, 1);
202
+ for (let t = 0; t < 4; t++) tryAdd(from, { zone: "tableau", index: t }, 1);
203
+ }
204
+ if (state.reserve.length > 0) {
205
+ const from = { zone: "reserve", index: 0 };
206
+ for (let f = 0; f < 4; f++) tryAdd(from, { zone: "foundation", index: f }, 1);
207
+ for (let t = 0; t < 4; t++) tryAdd(from, { zone: "tableau", index: t }, 1);
208
+ }
209
+ for (let col = 0; col < 4; col++) {
210
+ const pile = state.tableau[col];
211
+ if (pile.length === 0) continue;
212
+ const runLen = runLengthAtTop(pile);
213
+ const from = { zone: "tableau", index: col };
214
+ for (let f = 0; f < 4; f++) tryAdd(from, { zone: "foundation", index: f }, 1);
215
+ for (let count = 1; count <= runLen; count++) {
216
+ for (let t = 0; t < 4; t++) {
217
+ if (t === col) continue;
218
+ tryAdd(from, { zone: "tableau", index: t }, count);
219
+ }
220
+ }
221
+ }
222
+ return moves;
223
+ }
224
+ function isStuck(state) {
225
+ return state.stock.length === 0 && state.waste.length === 0 && legalMoves(state).length === 0;
226
+ }
227
+ function autoMoveHint(state, from, cardId) {
228
+ const pile = getPile(state, from);
229
+ if (!pile) return null;
230
+ const cardIndex = pile.findIndex((c) => c.id === cardId);
231
+ if (cardIndex === -1) return null;
232
+ const movingCards = pile.slice(cardIndex);
233
+ if (movingCards.some((c) => !c.faceUp)) return null;
234
+ const count = movingCards.length;
235
+ if (count > 1 && (from.zone !== "tableau" || !isDescendingAltColorCyclic(movingCards))) return null;
236
+ if (count === 1) {
237
+ const movingCard = movingCards[0];
238
+ const f = suitIndex(movingCard.suit);
239
+ if (canPlaceOnFoundationCyclic(state.foundation[f], movingCard, state.foundationRank)) {
240
+ return { from, to: { zone: "foundation", index: f }, count: 1 };
241
+ }
242
+ }
243
+ for (let t = 0; t < 4; t++) {
244
+ if (from.zone === "tableau" && from.index === t) continue;
245
+ if (canPlaceOnTableau(state.reserve, state.tableau[t], movingCards, from.zone)) {
246
+ return { from, to: { zone: "tableau", index: t }, count };
247
+ }
248
+ }
249
+ return null;
250
+ }
251
+ function scoreHintMove(state, move) {
252
+ if (move.to.zone !== "tableau") return 0;
253
+ const toCol = state.tableau[move.to.index];
254
+ if (!toCol) return 0;
255
+ const fromPile = getPile(state, move.from);
256
+ if (!fromPile || fromPile.length < move.count) return 0;
257
+ const fromZone = move.from.zone;
258
+ const remainder = fromPile.slice(0, fromPile.length - move.count);
259
+ const below = remainder[remainder.length - 1];
260
+ const base = fromPile[fromPile.length - move.count];
261
+ const linkedAtSource = fromZone === "tableau" && below !== void 0 && below.faceUp && isDescendingAltColorCyclic([below, base]);
262
+ const a = linkedAtSource ? runLengthAtTop(remainder) : 0;
263
+ const b = runLengthAtTop(toCol);
264
+ const netRunStructureChange = Math.max(move.count + b, a) - Math.max(move.count + a, b);
265
+ const fromBecomesEmpty = fromZone === "tableau" && move.count === fromPile.length;
266
+ const toWasEmpty = toCol.length === 0;
267
+ const netEmptyDelta = (fromBecomesEmpty ? 1 : 0) - (toWasEmpty ? 1 : 0);
268
+ const depletesReserve = fromZone === "reserve";
269
+ let score = depletesReserve ? 500 : 0;
270
+ score += netRunStructureChange * 30;
271
+ score += netEmptyDelta * 40;
272
+ if (score <= 0) return score;
273
+ return score + move.count * 2;
274
+ }
275
+ function accessibleCards(state) {
276
+ const result = [];
277
+ const wasteTop = _chunkW5CPH6TDjs.top.call(void 0, state.waste);
278
+ if (wasteTop) result.push({ ref: { zone: "waste", index: 0 }, card: wasteTop });
279
+ const reserveTop = _chunkW5CPH6TDjs.top.call(void 0, state.reserve);
280
+ if (reserveTop) result.push({ ref: { zone: "reserve", index: 0 }, card: reserveTop });
281
+ state.tableau.forEach((pile, index) => {
282
+ const t = _chunkW5CPH6TDjs.top.call(void 0, pile);
283
+ if (t && t.faceUp) result.push({ ref: { zone: "tableau", index }, card: t });
284
+ });
285
+ return result;
286
+ }
287
+ function cyclicPosition(rank, foundationRank) {
288
+ return (rank - foundationRank + 13) % 13;
289
+ }
290
+ function isSafeAutoPlay(state, card) {
291
+ const oppositeColor = _chunkW5CPH6TDjs.cardColor.call(void 0, card.suit) === "red" ? "black" : "red";
292
+ const oppositeSuits = _chunkW5CPH6TDjs.SUITS.filter((s) => _chunkW5CPH6TDjs.cardColor.call(void 0, s) === oppositeColor);
293
+ const oppMinLength = Math.min(...oppositeSuits.map((s) => state.foundation[suitIndex(s)].length));
294
+ return oppMinLength >= cyclicPosition(card.rank, state.foundationRank);
295
+ }
296
+ function findSafeAutoPlay(state, accessible) {
297
+ for (const entry of accessible) {
298
+ const f = suitIndex(entry.card.suit);
299
+ if (canPlaceOnFoundationCyclic(state.foundation[f], entry.card, state.foundationRank) && isSafeAutoPlay(state, entry.card)) {
300
+ return entry;
301
+ }
302
+ }
303
+ return null;
304
+ }
305
+ function canAutoFinish(controller, state) {
306
+ if (controller.isWon(state)) return false;
307
+ if (state.reserve.length > 0 || state.stock.length > 0 || state.waste.length > 0) return false;
308
+ if (state.tableau.some((column) => column.some((c) => !c.faceUp))) return false;
309
+ return _chunk22DC2YH6js.isFullyAutoCompletable.call(void 0, controller, state);
310
+ }
311
+ function nextFinishMove(controller, state) {
312
+ if (!canAutoFinish(controller, state)) return null;
313
+ const entry = _chunk22DC2YH6js.nextAutoCompleteMove.call(void 0, controller, state);
314
+ return entry ? { entry, to: { zone: "foundation", index: suitIndex(entry.card.suit) } } : null;
315
+ }
316
+ function createCanfieldController(drawCount) {
317
+ const progress = {
318
+ id: `canfield-draw${drawCount}`,
319
+ moves: legalMoves,
320
+ rescueMoves: (state) => _chunkXV5OUPIWjs.foundationDownMoves.call(void 0, state.foundation, state.tableau, (column, moving) => canPlaceOnTableau(state.reserve, column, moving, "foundation")),
321
+ drawIsStep: true,
322
+ key: (state) => `${_chunkXV5OUPIWjs.columnsKey.call(void 0, state.tableau)}/${_chunkXV5OUPIWjs.pileKey.call(void 0, state.reserve)}/${_chunkXV5OUPIWjs.pileKey.call(void 0, state.stock)}/${_chunkXV5OUPIWjs.pileKey.call(void 0, state.waste)}`,
323
+ progress: (state) => [state.foundation.reduce((n, p) => n + p.length, 0), -state.reserve.length]
324
+ };
325
+ return {
326
+ id: "canfield",
327
+ title: "Canfield",
328
+ newGame,
329
+ legalMoves,
330
+ tryMove,
331
+ drawStock: makeDrawStock(drawCount),
332
+ isWon,
333
+ isStuck,
334
+ autoMoveHint,
335
+ scoreHintMove,
336
+ accessibleCards,
337
+ progress
338
+ };
339
+ }
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+ exports.isDescendingAltColorCyclic = isDescendingAltColorCyclic; exports.isSafeAutoPlay = isSafeAutoPlay; exports.findSafeAutoPlay = findSafeAutoPlay; exports.canAutoFinish = canAutoFinish; exports.nextFinishMove = nextFinishMove; exports.createCanfieldController = createCanfieldController;
@@ -0,0 +1,115 @@
1
+ // src/engine/types.ts
2
+ var SUITS = ["clubs", "diamonds", "hearts", "spades"];
3
+ function cardColor(suit) {
4
+ return suit === "hearts" || suit === "diamonds" ? "red" : "black";
5
+ }
6
+
7
+ // src/engine/pile.ts
8
+ function top(pile) {
9
+ return pile.length ? pile[pile.length - 1] : void 0;
10
+ }
11
+ function isEmpty(pile) {
12
+ return pile.length === 0;
13
+ }
14
+ function isDescendingAltColor(cards) {
15
+ for (let i = 1; i < cards.length; i++) {
16
+ const prev = cards[i - 1];
17
+ const cur = cards[i];
18
+ if (cur.rank !== prev.rank - 1) return false;
19
+ if (cardColor(cur.suit) === cardColor(prev.suit)) return false;
20
+ }
21
+ return true;
22
+ }
23
+ function isDescendingSameSuit(cards) {
24
+ for (let i = 1; i < cards.length; i++) {
25
+ const prev = cards[i - 1];
26
+ const cur = cards[i];
27
+ if (cur.rank !== prev.rank - 1) return false;
28
+ if (cur.suit !== prev.suit) return false;
29
+ }
30
+ return true;
31
+ }
32
+ function isDescendingAnySuit(cards) {
33
+ for (let i = 1; i < cards.length; i++) {
34
+ if (cards[i].rank !== cards[i - 1].rank - 1) return false;
35
+ }
36
+ return true;
37
+ }
38
+ function alwaysValidRun() {
39
+ return true;
40
+ }
41
+ function buriedCount(pile, isValidRun) {
42
+ let runStart = pile.length;
43
+ while (runStart > 0 && pile[runStart - 1].faceUp && isValidRun(pile.slice(runStart - 1))) {
44
+ runStart -= 1;
45
+ }
46
+ return runStart;
47
+ }
48
+ function runCountFrom(pile, indexFromTop, isValidRun) {
49
+ const count = indexFromTop + 1;
50
+ const run = pile.slice(pile.length - count);
51
+ if (run.some((c) => !c.faceUp)) return 0;
52
+ if (count > 1 && !isValidRun(run)) return 0;
53
+ return count;
54
+ }
55
+
56
+ // src/engine/rng.ts
57
+ function mulberry32(seed) {
58
+ let a = seed >>> 0;
59
+ return function() {
60
+ a |= 0;
61
+ a = a + 1831565813 | 0;
62
+ let t = Math.imul(a ^ a >>> 15, 1 | a);
63
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
64
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
65
+ };
66
+ }
67
+ function shuffle(items, rng) {
68
+ const result = items.slice();
69
+ for (let i = result.length - 1; i > 0; i--) {
70
+ const j = Math.floor(rng() * (i + 1));
71
+ [result[i], result[j]] = [result[j], result[i]];
72
+ }
73
+ return result;
74
+ }
75
+ function randomSeed() {
76
+ return Math.floor(Math.random() * 2 ** 31);
77
+ }
78
+
79
+ // src/engine/deck.ts
80
+ function makeDeck(deckIndex = 0) {
81
+ const cards = [];
82
+ for (const suit of SUITS) {
83
+ for (let rank = 1; rank <= 13; rank++) {
84
+ cards.push({ id: `${suit}-${rank}-${deckIndex}`, suit, rank, faceUp: false });
85
+ }
86
+ }
87
+ return cards;
88
+ }
89
+ function shuffledDeck(seed, numDecks = 1, suitFilter) {
90
+ let all = [];
91
+ for (let d = 0; d < numDecks; d++) {
92
+ const deck = makeDeck(d);
93
+ all = all.concat(suitFilter ? deck.filter((c) => suitFilter.includes(c.suit)) : deck);
94
+ }
95
+ const rng = mulberry32(seed);
96
+ return shuffle(all, rng);
97
+ }
98
+
99
+ export {
100
+ SUITS,
101
+ cardColor,
102
+ top,
103
+ isEmpty,
104
+ isDescendingAltColor,
105
+ isDescendingSameSuit,
106
+ isDescendingAnySuit,
107
+ alwaysValidRun,
108
+ buriedCount,
109
+ runCountFrom,
110
+ mulberry32,
111
+ shuffle,
112
+ randomSeed,
113
+ makeDeck,
114
+ shuffledDeck
115
+ };