@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,249 @@
1
+ import {
2
+ pickBestTableauTarget
3
+ } from "./chunk-GFP5NUYK.mjs";
4
+ import {
5
+ columnsKey,
6
+ faceDownCount
7
+ } from "./chunk-FDHHAPZA.mjs";
8
+ import {
9
+ SUITS,
10
+ isDescendingSameSuit,
11
+ shuffledDeck,
12
+ top
13
+ } from "./chunk-XSS5M6C7.mjs";
14
+
15
+ // src/games/spider/rules.ts
16
+ var NUM_COLUMNS = 10;
17
+ var DEAL_COUNTS = [6, 6, 6, 6, 5, 5, 5, 5, 5, 5];
18
+ function cloneState(state) {
19
+ return {
20
+ tableau: state.tableau.slice(),
21
+ stock: state.stock,
22
+ completed: state.completed,
23
+ completedRuns: state.completedRuns
24
+ };
25
+ }
26
+ function resolveCompletedSequence(tableau, colIndex) {
27
+ const col = tableau[colIndex];
28
+ if (col.length < 13) return null;
29
+ const topRun = col.slice(col.length - 13);
30
+ if (topRun[0].rank !== 13) return null;
31
+ if (!topRun.every((c2) => c2.faceUp)) return null;
32
+ if (!isDescendingSameSuit(topRun)) return null;
33
+ const remaining = col.slice(0, col.length - 13);
34
+ const i = remaining.length - 1;
35
+ const c = remaining[i];
36
+ if (c && !c.faceUp) remaining[i] = { ...c, faceUp: true };
37
+ tableau[colIndex] = remaining;
38
+ return { king: topRun[0], run: topRun };
39
+ }
40
+ function computeLegalMoves(state) {
41
+ const moves = [];
42
+ for (let from = 0; from < NUM_COLUMNS; from++) {
43
+ const col = state.tableau[from];
44
+ if (col.length === 0) continue;
45
+ let runLen = 1;
46
+ for (let i = col.length - 1; i > 0; i--) {
47
+ const cur = col[i];
48
+ const prev = col[i - 1];
49
+ if (!cur.faceUp || !prev.faceUp) break;
50
+ if (prev.rank !== cur.rank + 1 || prev.suit !== cur.suit) break;
51
+ runLen++;
52
+ }
53
+ for (let count = 1; count <= runLen; count++) {
54
+ const group = col.slice(col.length - count);
55
+ if (!isDescendingSameSuit(group)) continue;
56
+ const movingBottom = group[0];
57
+ const candidates = state.tableau.map((pile, index) => ({ index, pile })).filter((c) => c.index !== from).filter((c) => {
58
+ const destTop = top(c.pile);
59
+ return destTop === void 0 || destTop.faceUp && destTop.rank === movingBottom.rank + 1;
60
+ });
61
+ const best = pickBestTableauTarget(candidates, isDescendingSameSuit);
62
+ if (best) {
63
+ moves.push({ from: { zone: "tableau", index: from }, to: { zone: "tableau", index: best.index }, count });
64
+ }
65
+ }
66
+ }
67
+ return moves;
68
+ }
69
+ function runLengthAtTop(column) {
70
+ if (column.length === 0) return 0;
71
+ if (!column[column.length - 1].faceUp) return 0;
72
+ let len = 1;
73
+ for (let i = column.length - 2; i >= 0; i--) {
74
+ const cur = column[i];
75
+ const next = column[i + 1];
76
+ if (!cur.faceUp || cur.suit !== next.suit || cur.rank !== next.rank + 1) break;
77
+ len++;
78
+ }
79
+ return len;
80
+ }
81
+ function scoreHintMove(state, move) {
82
+ if (move.from.zone !== "tableau" || move.to.zone !== "tableau") return 0;
83
+ const fromCol = state.tableau[move.from.index];
84
+ const toCol = state.tableau[move.to.index];
85
+ if (!fromCol || !toCol) return 0;
86
+ const group = fromCol.slice(fromCol.length - move.count);
87
+ const merged = [...toCol, ...group];
88
+ if (merged.length >= 13) {
89
+ const topRun = merged.slice(merged.length - 13);
90
+ if (topRun[0].rank === 13 && topRun.every((c) => c.faceUp) && isDescendingSameSuit(topRun)) return 1e3;
91
+ }
92
+ const remainder = fromCol.slice(0, fromCol.length - move.count);
93
+ const below = remainder[remainder.length - 1];
94
+ const base = group[0];
95
+ const linkedAtSource = below !== void 0 && below.faceUp && below.suit === base.suit && below.rank === base.rank + 1;
96
+ const a = linkedAtSource ? runLengthAtTop(remainder) : 0;
97
+ const destTop = toCol[toCol.length - 1];
98
+ const b = destTop !== void 0 && destTop.suit === base.suit ? runLengthAtTop(toCol) : 0;
99
+ const netRunStructureChange = Math.max(move.count + b, a) - Math.max(move.count + a, b);
100
+ const fromBecomesEmpty = move.count === fromCol.length;
101
+ const toWasEmpty = toCol.length === 0;
102
+ const netEmptyDelta = (fromBecomesEmpty ? 1 : 0) - (toWasEmpty ? 1 : 0);
103
+ const revealsHiddenCard = below !== void 0 && !below.faceUp;
104
+ let score = revealsHiddenCard ? 500 : 0;
105
+ score += netRunStructureChange * 30;
106
+ score += netEmptyDelta * 40;
107
+ if (score <= 0) return score;
108
+ return score + move.count * 2;
109
+ }
110
+ function canDealStock(state) {
111
+ if (state.stock.length < NUM_COLUMNS) return false;
112
+ const emptyColumn = state.tableau.some((col) => col.length === 0);
113
+ if (!emptyColumn) return true;
114
+ return state.tableau.reduce((sum, col) => sum + col.length, 0) < NUM_COLUMNS;
115
+ }
116
+ function searchMoves(state) {
117
+ const moves = [];
118
+ for (let from = 0; from < NUM_COLUMNS; from++) {
119
+ const col = state.tableau[from];
120
+ const runLen = runLengthAtTop(col);
121
+ for (let count = 1; count <= runLen; count++) {
122
+ const bottom = col[col.length - count];
123
+ for (let to = 0; to < NUM_COLUMNS; to++) {
124
+ if (to === from) continue;
125
+ const destTop = top(state.tableau[to]);
126
+ if (destTop === void 0 || destTop.faceUp && destTop.rank === bottom.rank + 1) moves.push({ from: { zone: "tableau", index: from }, to: { zone: "tableau", index: to }, count });
127
+ }
128
+ }
129
+ }
130
+ return moves;
131
+ }
132
+ function createSpiderController(numSuits) {
133
+ const progress = {
134
+ id: `spider-${numSuits}suit`,
135
+ moves: searchMoves,
136
+ drawIsStep: false,
137
+ key: (state) => columnsKey(state.tableau),
138
+ progress: (state) => [-faceDownCount(state.tableau), state.completed.length]
139
+ };
140
+ return {
141
+ id: "spider",
142
+ title: "Spider",
143
+ newGame(seed) {
144
+ const numDecks = 8 / numSuits;
145
+ const suitFilter = SUITS.slice(0, numSuits);
146
+ const deck = shuffledDeck(seed, numDecks, suitFilter);
147
+ const tableau = Array.from({ length: NUM_COLUMNS }, () => []);
148
+ let cursor = 0;
149
+ for (let col = 0; col < NUM_COLUMNS; col++) {
150
+ const count = DEAL_COUNTS[col];
151
+ for (let i = 0; i < count; i++) {
152
+ const card = deck[cursor++];
153
+ card.faceUp = i === count - 1;
154
+ tableau[col].push(card);
155
+ }
156
+ }
157
+ const stock = deck.slice(cursor).map((c) => ({ ...c, faceUp: false }));
158
+ return { tableau, stock, completed: [], completedRuns: [] };
159
+ },
160
+ legalMoves(state) {
161
+ return computeLegalMoves(state);
162
+ },
163
+ tryMove(state, move) {
164
+ const { from, to, count } = move;
165
+ if (from.zone !== "tableau" || to.zone !== "tableau") return null;
166
+ if (from.index === to.index) return null;
167
+ const fromCol = state.tableau[from.index];
168
+ const toCol = state.tableau[to.index];
169
+ if (!fromCol || !toCol) return null;
170
+ if (count < 1 || count > fromCol.length) return null;
171
+ const group = fromCol.slice(fromCol.length - count);
172
+ if (!group.every((c) => c.faceUp)) return null;
173
+ if (!isDescendingSameSuit(group)) return null;
174
+ const movingBottom = group[0];
175
+ if (toCol.length > 0) {
176
+ const destTop = toCol[toCol.length - 1];
177
+ if (!destTop.faceUp || destTop.rank !== movingBottom.rank + 1) return null;
178
+ }
179
+ const next = cloneState(state);
180
+ const nextFrom = next.tableau[from.index].slice();
181
+ const nextTo = next.tableau[to.index].slice();
182
+ const moved = nextFrom.splice(nextFrom.length - count, count);
183
+ nextTo.push(...moved);
184
+ next.tableau[from.index] = nextFrom;
185
+ next.tableau[to.index] = nextTo;
186
+ const topIndex = nextFrom.length - 1;
187
+ const newTop = nextFrom[topIndex];
188
+ if (newTop && !newTop.faceUp) nextFrom[topIndex] = { ...newTop, faceUp: true };
189
+ const completedSequence = resolveCompletedSequence(next.tableau, to.index);
190
+ if (completedSequence) {
191
+ next.completed = next.completed.concat(completedSequence.king);
192
+ next.completedRuns = next.completedRuns.concat([completedSequence.run]);
193
+ }
194
+ return next;
195
+ },
196
+ drawStock(state) {
197
+ if (!canDealStock(state)) return null;
198
+ const next = cloneState(state);
199
+ const nextStock = next.stock.slice();
200
+ for (let col = 0; col < NUM_COLUMNS; col++) {
201
+ const card = nextStock.shift();
202
+ const flipped = card.faceUp ? card : { ...card, faceUp: true };
203
+ next.tableau[col] = next.tableau[col].concat(flipped);
204
+ }
205
+ next.stock = nextStock;
206
+ for (let col = 0; col < NUM_COLUMNS; col++) {
207
+ const completedSequence = resolveCompletedSequence(next.tableau, col);
208
+ if (completedSequence) {
209
+ next.completed = next.completed.concat(completedSequence.king);
210
+ next.completedRuns = next.completedRuns.concat([completedSequence.run]);
211
+ }
212
+ }
213
+ return next;
214
+ },
215
+ isWon(state) {
216
+ return state.completed.length === 8;
217
+ },
218
+ isStuck(state) {
219
+ if (canDealStock(state)) return false;
220
+ return computeLegalMoves(state).length === 0;
221
+ },
222
+ autoMoveHint(state, from, cardId) {
223
+ if (from.zone !== "tableau") return null;
224
+ const col = state.tableau[from.index];
225
+ if (!col) return null;
226
+ const cardIndex = col.findIndex((c) => c.id === cardId);
227
+ if (cardIndex === -1) return null;
228
+ const movingCards = col.slice(cardIndex);
229
+ if (movingCards.some((c) => !c.faceUp)) return null;
230
+ if (!isDescendingSameSuit(movingCards)) return null;
231
+ const movingBottom = movingCards[0];
232
+ const count = movingCards.length;
233
+ const candidates = state.tableau.map((destCol, index) => ({ index, pile: destCol })).filter((c) => c.index !== from.index).filter((c) => {
234
+ const destTop = top(c.pile);
235
+ return destTop === void 0 || destTop.faceUp && destTop.rank === movingBottom.rank + 1;
236
+ });
237
+ const best = pickBestTableauTarget(candidates, isDescendingSameSuit);
238
+ if (!best) return null;
239
+ return { from, to: { zone: "tableau", index: best.index }, count };
240
+ },
241
+ scoreHintMove,
242
+ progress
243
+ };
244
+ }
245
+
246
+ export {
247
+ canDealStock,
248
+ createSpiderController
249
+ };
@@ -0,0 +1,214 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkXV5OUPIWjs = require('./chunk-XV5OUPIW.js');
4
+
5
+
6
+
7
+ var _chunkW5CPH6TDjs = require('./chunk-W5CPH6TD.js');
8
+
9
+ // src/games/pyramid/rules.ts
10
+ var ROWS = 7;
11
+ var TOTAL = 28;
12
+ function flatIndex(row, col) {
13
+ return row * (row + 1) / 2 + col;
14
+ }
15
+ function rowColOf(index) {
16
+ let row = 0;
17
+ while (flatIndex(row + 1, 0) <= index) row++;
18
+ return { row, col: index - flatIndex(row, 0) };
19
+ }
20
+ function isExposed(pyramid, row, col) {
21
+ const idx = flatIndex(row, col);
22
+ if (!pyramid[idx]) return false;
23
+ if (row === ROWS - 1) return true;
24
+ const childLeft = flatIndex(row + 1, col);
25
+ const childRight = flatIndex(row + 1, col + 1);
26
+ return !pyramid[childLeft] && !pyramid[childRight];
27
+ }
28
+ function isExposedAt(pyramid, index) {
29
+ const { row, col } = rowColOf(index);
30
+ return isExposed(pyramid, row, col);
31
+ }
32
+ function cloneState(state) {
33
+ return {
34
+ pyramid: state.pyramid,
35
+ stock: state.stock,
36
+ waste: state.waste,
37
+ discard: state.discard,
38
+ removedCount: state.removedCount
39
+ };
40
+ }
41
+ function newGame(seed) {
42
+ const deck = _chunkW5CPH6TDjs.shuffledDeck.call(void 0, seed, 1);
43
+ const pyramid = deck.slice(0, TOTAL).map((c) => ({ ...c, faceUp: true }));
44
+ const stock = deck.slice(TOTAL).map((c) => ({ ...c, faceUp: false }));
45
+ return { pyramid, stock, waste: [], discard: [], removedCount: 0 };
46
+ }
47
+ function cardAt(state, ref) {
48
+ if (ref.zone === "pyramid") {
49
+ return _nullishCoalesce(state.pyramid[ref.index], () => ( null));
50
+ }
51
+ if (ref.zone === "waste") {
52
+ return _nullishCoalesce(_chunkW5CPH6TDjs.top.call(void 0, state.waste), () => ( null));
53
+ }
54
+ return null;
55
+ }
56
+ function isAvailable(state, ref) {
57
+ if (ref.zone === "waste") {
58
+ return _chunkW5CPH6TDjs.top.call(void 0, state.waste) !== void 0;
59
+ }
60
+ if (ref.zone === "pyramid") {
61
+ const card = state.pyramid[ref.index];
62
+ if (!card) return false;
63
+ return isExposedAt(state.pyramid, ref.index);
64
+ }
65
+ return false;
66
+ }
67
+ function consume(state, ref) {
68
+ const card = cardAt(state, ref);
69
+ if (ref.zone === "pyramid") {
70
+ const pyramid = state.pyramid.slice();
71
+ pyramid[ref.index] = null;
72
+ state.pyramid = pyramid;
73
+ } else if (ref.zone === "waste") {
74
+ const waste = state.waste.slice();
75
+ waste.pop();
76
+ state.waste = waste;
77
+ }
78
+ if (card) {
79
+ const discard = state.discard.slice();
80
+ discard.push({ ...card, faceUp: true });
81
+ state.discard = discard;
82
+ }
83
+ }
84
+ function sweepRemainderOnWin(state) {
85
+ if (!state.pyramid.every((c) => c === null)) return;
86
+ if (state.waste.length === 0 && state.stock.length === 0) return;
87
+ const discard = state.discard.slice();
88
+ for (const c of state.waste) discard.push({ ...c, faceUp: true });
89
+ for (const c of state.stock) discard.push({ ...c, faceUp: true });
90
+ state.discard = discard;
91
+ state.waste = [];
92
+ state.stock = [];
93
+ }
94
+ function tryMove(state, move) {
95
+ const { from, to, count } = move;
96
+ if (count !== 1) return null;
97
+ if (from.zone !== "pyramid" && from.zone !== "waste") return null;
98
+ if (to.zone !== "pyramid" && to.zone !== "waste") return null;
99
+ if (from.zone === to.zone && from.index === to.index) {
100
+ if (!isAvailable(state, from)) return null;
101
+ const card = cardAt(state, from);
102
+ if (!card || card.rank !== 13) return null;
103
+ const next2 = cloneState(state);
104
+ consume(next2, from);
105
+ next2.removedCount += 1;
106
+ sweepRemainderOnWin(next2);
107
+ return next2;
108
+ }
109
+ if (!isAvailable(state, from) || !isAvailable(state, to)) return null;
110
+ const fromCard = cardAt(state, from);
111
+ const toCard = cardAt(state, to);
112
+ if (!fromCard || !toCard) return null;
113
+ if (fromCard.id === toCard.id) return null;
114
+ if (fromCard.rank + toCard.rank !== 13) return null;
115
+ const next = cloneState(state);
116
+ consume(next, from);
117
+ consume(next, to);
118
+ next.removedCount += 2;
119
+ sweepRemainderOnWin(next);
120
+ return next;
121
+ }
122
+ function drawStock(state) {
123
+ if (state.stock.length > 0) {
124
+ const next = cloneState(state);
125
+ const stock = next.stock.slice();
126
+ const card = stock.pop();
127
+ const waste = next.waste.slice();
128
+ waste.push(card.faceUp ? card : { ...card, faceUp: true });
129
+ next.stock = stock;
130
+ next.waste = waste;
131
+ return next;
132
+ }
133
+ if (state.waste.length > 0) {
134
+ const next = cloneState(state);
135
+ const recycled = state.waste.slice().reverse().map((c) => ({ ...c, faceUp: false }));
136
+ next.stock = recycled;
137
+ next.waste = [];
138
+ return next;
139
+ }
140
+ return null;
141
+ }
142
+ function isWon(state) {
143
+ return state.pyramid.every((c) => c === null);
144
+ }
145
+ function legalMoves(state) {
146
+ const moves = [];
147
+ const availableRefs = [];
148
+ for (let i = 0; i < TOTAL; i++) {
149
+ if (state.pyramid[i] && isExposedAt(state.pyramid, i)) {
150
+ availableRefs.push({ zone: "pyramid", index: i });
151
+ }
152
+ }
153
+ if (_chunkW5CPH6TDjs.top.call(void 0, state.waste)) {
154
+ availableRefs.push({ zone: "waste", index: 0 });
155
+ }
156
+ for (const ref of availableRefs) {
157
+ const card = cardAt(state, ref);
158
+ if (card && card.rank === 13) {
159
+ moves.push({ from: ref, to: ref, count: 1 });
160
+ }
161
+ }
162
+ for (let a = 0; a < availableRefs.length; a++) {
163
+ for (let b = a + 1; b < availableRefs.length; b++) {
164
+ const refA = availableRefs[a];
165
+ const refB = availableRefs[b];
166
+ const cardA = cardAt(state, refA);
167
+ const cardB = cardAt(state, refB);
168
+ if (cardA && cardB && cardA.rank + cardB.rank === 13) {
169
+ moves.push({ from: refA, to: refB, count: 1 });
170
+ }
171
+ }
172
+ }
173
+ return moves;
174
+ }
175
+ function scoreHintMove(state, move) {
176
+ const refs = move.from.zone === move.to.zone && move.from.index === move.to.index ? [move.from] : [move.from, move.to];
177
+ const removedPyramidIndices = refs.filter((r) => r.zone === "pyramid").map((r) => r.index);
178
+ if (removedPyramidIndices.length === 0) return 1;
179
+ const nextPyramid = state.pyramid.slice();
180
+ for (const idx of removedPyramidIndices) nextPyramid[idx] = null;
181
+ let newlyExposed = 0;
182
+ for (let i = 0; i < TOTAL; i++) {
183
+ if (state.pyramid[i] && !isExposedAt(state.pyramid, i) && isExposedAt(nextPyramid, i)) {
184
+ newlyExposed++;
185
+ }
186
+ }
187
+ return 1 + newlyExposed * 10;
188
+ }
189
+ var progress = {
190
+ id: "pyramid",
191
+ moves: legalMoves,
192
+ drawIsStep: true,
193
+ key: (state) => `${state.pyramid.map((c) => c ? "1" : "0").join("")}/${_chunkXV5OUPIWjs.pileKey.call(void 0, state.stock)}/${_chunkXV5OUPIWjs.pileKey.call(void 0, state.waste)}`,
194
+ progress: (state) => [state.removedCount]
195
+ };
196
+ var PyramidController = {
197
+ id: "pyramid",
198
+ title: "Pyramid",
199
+ newGame,
200
+ legalMoves,
201
+ tryMove,
202
+ drawStock,
203
+ isWon,
204
+ scoreHintMove,
205
+ progress
206
+ };
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+ exports.flatIndex = flatIndex; exports.rowColOf = rowColOf; exports.isExposed = isExposed; exports.cardAt = cardAt; exports.PyramidController = PyramidController;
@@ -0,0 +1,115 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// 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
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+ exports.SUITS = SUITS; exports.cardColor = cardColor; exports.top = top; exports.isEmpty = isEmpty; exports.isDescendingAltColor = isDescendingAltColor; exports.isDescendingSameSuit = isDescendingSameSuit; exports.isDescendingAnySuit = isDescendingAnySuit; exports.alwaysValidRun = alwaysValidRun; exports.buriedCount = buriedCount; exports.runCountFrom = runCountFrom; exports.mulberry32 = mulberry32; exports.shuffle = shuffle; exports.randomSeed = randomSeed; exports.makeDeck = makeDeck; exports.shuffledDeck = shuffledDeck;