@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,297 @@
1
+ import {
2
+ canPlaceOnFoundation,
3
+ suitIndex
4
+ } from "./chunk-SDZPP3HI.mjs";
5
+ import {
6
+ pickBestTableauTarget
7
+ } from "./chunk-GFP5NUYK.mjs";
8
+ import {
9
+ columnsKey,
10
+ pileKey
11
+ } from "./chunk-FDHHAPZA.mjs";
12
+ import {
13
+ cardColor,
14
+ isDescendingAltColor,
15
+ shuffledDeck,
16
+ top
17
+ } from "./chunk-XSS5M6C7.mjs";
18
+
19
+ // src/games/freecell/rules.ts
20
+ var NUM_TABLEAU = 8;
21
+ var NUM_FREECELLS = 4;
22
+ var NUM_FOUNDATIONS = 4;
23
+ function cloneState(state) {
24
+ return {
25
+ tableau: state.tableau.slice(),
26
+ freecells: state.freecells.slice(),
27
+ foundation: state.foundation.slice()
28
+ };
29
+ }
30
+ function canPlaceOnTableau(dest, movingTop) {
31
+ const destTop = top(dest);
32
+ if (destTop === void 0) return true;
33
+ return movingTop.rank === destTop.rank - 1 && cardColor(movingTop.suit) !== cardColor(destTop.suit);
34
+ }
35
+ function runLengthAtTop(column) {
36
+ if (column.length === 0) return 0;
37
+ let len = 1;
38
+ for (let i = column.length - 2; i >= 0; i--) {
39
+ const cur = column[i];
40
+ const next = column[i + 1];
41
+ if (next.rank !== cur.rank - 1 || cardColor(next.suit) === cardColor(cur.suit)) break;
42
+ len++;
43
+ }
44
+ return len;
45
+ }
46
+ function countEmptyFreecells(state) {
47
+ return state.freecells.filter((c) => c === null).length;
48
+ }
49
+ function countEmptyTableauColumns(state, excludeIndex) {
50
+ return state.tableau.filter((col, i) => i !== excludeIndex && col.length === 0).length;
51
+ }
52
+ function maxSupermoveCount(state, destIndex) {
53
+ const emptyFreecells = countEmptyFreecells(state);
54
+ const emptyCols = countEmptyTableauColumns(state, destIndex);
55
+ return (emptyFreecells + 1) * 2 ** emptyCols;
56
+ }
57
+ function newGame(seed) {
58
+ const deck = shuffledDeck(seed, 1).map((c) => ({ ...c, faceUp: true }));
59
+ const tableau = [];
60
+ let cursor = 0;
61
+ for (let col = 0; col < NUM_TABLEAU; col++) {
62
+ const count = col < 4 ? 7 : 6;
63
+ tableau.push(deck.slice(cursor, cursor + count));
64
+ cursor += count;
65
+ }
66
+ const freecells = [null, null, null, null];
67
+ const foundation = [[], [], [], []];
68
+ return { tableau, freecells, foundation };
69
+ }
70
+ function tryMove(state, move) {
71
+ const { from, to, count } = move;
72
+ if (count < 1) return null;
73
+ if (from.zone === to.zone && from.index === to.index) return null;
74
+ if (from.zone === "foundation") return null;
75
+ let movingCards;
76
+ if (from.zone === "tableau") {
77
+ const col = state.tableau[from.index];
78
+ if (!col || col.length < count) return null;
79
+ movingCards = col.slice(col.length - count);
80
+ } else if (from.zone === "freecell") {
81
+ if (count !== 1) return null;
82
+ const card = state.freecells[from.index];
83
+ if (!card) return null;
84
+ movingCards = [card];
85
+ } else {
86
+ return null;
87
+ }
88
+ if (count > 1 && (from.zone !== "tableau" || to.zone !== "tableau")) return null;
89
+ if (count > 1 && !isDescendingAltColor(movingCards)) return null;
90
+ if (to.zone === "tableau") {
91
+ const destCol = state.tableau[to.index];
92
+ if (!destCol) return null;
93
+ if (count > 1 && count > maxSupermoveCount(state, to.index)) return null;
94
+ if (!canPlaceOnTableau(destCol, movingCards[0])) return null;
95
+ } else if (to.zone === "foundation") {
96
+ if (count !== 1) return null;
97
+ const destPile = state.foundation[to.index];
98
+ if (!destPile) return null;
99
+ const movingCard = movingCards[0];
100
+ if (suitIndex(movingCard.suit) !== to.index) return null;
101
+ if (!canPlaceOnFoundation(destPile, movingCard)) return null;
102
+ } else if (to.zone === "freecell") {
103
+ if (count !== 1) return null;
104
+ if (to.index < 0 || to.index >= NUM_FREECELLS) return null;
105
+ if (state.freecells[to.index] !== null) return null;
106
+ } else {
107
+ return null;
108
+ }
109
+ const next = cloneState(state);
110
+ if (from.zone === "tableau") {
111
+ next.tableau[from.index] = next.tableau[from.index].slice(0, next.tableau[from.index].length - count);
112
+ } else if (from.zone === "freecell") {
113
+ next.freecells[from.index] = null;
114
+ }
115
+ if (to.zone === "tableau") {
116
+ next.tableau[to.index] = next.tableau[to.index].concat(movingCards);
117
+ } else if (to.zone === "foundation") {
118
+ next.foundation[to.index] = next.foundation[to.index].concat(movingCards);
119
+ } else if (to.zone === "freecell") {
120
+ next.freecells[to.index] = movingCards[0];
121
+ }
122
+ return next;
123
+ }
124
+ function isWon(state) {
125
+ return state.foundation.every((pile) => {
126
+ const t = top(pile);
127
+ return t !== void 0 && t.rank === 13;
128
+ });
129
+ }
130
+ function legalMoves(state) {
131
+ const moves = [];
132
+ const tryAdd = (from, to, count) => {
133
+ const result = tryMove(state, { from, to, count });
134
+ if (result) moves.push({ from, to, count });
135
+ };
136
+ for (let fc = 0; fc < NUM_FREECELLS; fc++) {
137
+ if (state.freecells[fc] === null) continue;
138
+ const from = { zone: "freecell", index: fc };
139
+ for (let f = 0; f < NUM_FOUNDATIONS; f++) tryAdd(from, { zone: "foundation", index: f }, 1);
140
+ for (let t = 0; t < NUM_TABLEAU; t++) tryAdd(from, { zone: "tableau", index: t }, 1);
141
+ }
142
+ for (let col = 0; col < NUM_TABLEAU; col++) {
143
+ const pile = state.tableau[col];
144
+ if (pile.length === 0) continue;
145
+ const from = { zone: "tableau", index: col };
146
+ for (let f = 0; f < NUM_FOUNDATIONS; f++) tryAdd(from, { zone: "foundation", index: f }, 1);
147
+ for (let fc = 0; fc < NUM_FREECELLS; fc++) tryAdd(from, { zone: "freecell", index: fc }, 1);
148
+ let runStart = pile.length - 1;
149
+ while (runStart > 0 && isDescendingAltColor(pile.slice(runStart - 1))) {
150
+ runStart -= 1;
151
+ }
152
+ const maxRun = pile.length - runStart;
153
+ for (let count = 1; count <= maxRun; count++) {
154
+ const movingCards = pile.slice(pile.length - count);
155
+ const movingTop = movingCards[0];
156
+ const candidates = state.tableau.map((destPile, index) => ({ index, pile: destPile })).filter((c) => c.index !== col).filter((c) => canPlaceOnTableau(c.pile, movingTop)).filter((c) => count === 1 || count <= maxSupermoveCount(state, c.index));
157
+ const best = pickBestTableauTarget(candidates, isDescendingAltColor);
158
+ if (best) tryAdd(from, { zone: "tableau", index: best.index }, count);
159
+ }
160
+ }
161
+ return moves;
162
+ }
163
+ function autoMoveHint(state, from, cardId) {
164
+ let movingCards;
165
+ if (from.zone === "tableau") {
166
+ const col = state.tableau[from.index];
167
+ if (!col) return null;
168
+ const cardIndex = col.findIndex((c) => c.id === cardId);
169
+ if (cardIndex === -1) return null;
170
+ movingCards = col.slice(cardIndex);
171
+ if (movingCards.length > 1 && !isDescendingAltColor(movingCards)) return null;
172
+ } else if (from.zone === "freecell") {
173
+ const c = state.freecells[from.index];
174
+ if (!c || c.id !== cardId) return null;
175
+ movingCards = [c];
176
+ } else {
177
+ return null;
178
+ }
179
+ const count = movingCards.length;
180
+ const movingTop = movingCards[0];
181
+ if (count === 1) {
182
+ const f = suitIndex(movingTop.suit);
183
+ if (canPlaceOnFoundation(state.foundation[f], movingTop)) {
184
+ return { from, to: { zone: "foundation", index: f }, count: 1 };
185
+ }
186
+ }
187
+ const candidates = state.tableau.map((destPile, index) => ({ index, pile: destPile })).filter((c) => !(from.zone === "tableau" && from.index === c.index)).filter((c) => canPlaceOnTableau(c.pile, movingTop)).filter((c) => count === 1 || count <= maxSupermoveCount(state, c.index));
188
+ const best = pickBestTableauTarget(candidates, isDescendingAltColor);
189
+ if (best) return { from, to: { zone: "tableau", index: best.index }, count };
190
+ if (count === 1 && from.zone !== "freecell") {
191
+ const emptyFreecell = state.freecells.findIndex((c) => c === null);
192
+ if (emptyFreecell !== -1) {
193
+ return { from, to: { zone: "freecell", index: emptyFreecell }, count: 1 };
194
+ }
195
+ }
196
+ return null;
197
+ }
198
+ function scoreHintMove(state, move) {
199
+ if (move.to.zone === "foundation") return 0;
200
+ const fromCol = move.from.zone === "tableau" ? state.tableau[move.from.index] : void 0;
201
+ const toCol = move.to.zone === "tableau" ? state.tableau[move.to.index] : void 0;
202
+ if (move.from.zone === "tableau" && !fromCol) return 0;
203
+ if (move.to.zone === "tableau" && !toCol) return 0;
204
+ let a = 0;
205
+ if (fromCol && fromCol.length >= move.count) {
206
+ const remainder = fromCol.slice(0, fromCol.length - move.count);
207
+ const below = remainder[remainder.length - 1];
208
+ const base = fromCol[fromCol.length - move.count];
209
+ if (below !== void 0 && isDescendingAltColor([below, base])) a = runLengthAtTop(remainder);
210
+ }
211
+ const b = toCol ? runLengthAtTop(toCol) : 0;
212
+ const netRunStructureChange = Math.max(move.count + b, a) - Math.max(move.count + a, b);
213
+ const fromBecomesEmpty = fromCol !== void 0 && move.count === fromCol.length;
214
+ const toWasEmpty = toCol !== void 0 && toCol.length === 0;
215
+ const netEmptyColumnDelta = (fromBecomesEmpty ? 1 : 0) - (toWasEmpty ? 1 : 0);
216
+ const freesFreecell = move.from.zone === "freecell" ? 1 : 0;
217
+ const consumesFreecell = move.to.zone === "freecell" ? 1 : 0;
218
+ const netFreecellDelta = freesFreecell - consumesFreecell;
219
+ let score = netRunStructureChange * 30;
220
+ score += netEmptyColumnDelta * 50;
221
+ score += netFreecellDelta * 25;
222
+ if (score <= 0) return score;
223
+ return score + (move.count + b) * 2;
224
+ }
225
+ function moveHeadCard(state, from, count) {
226
+ if (from.zone === "tableau") return state.tableau[from.index]?.[state.tableau[from.index].length - count];
227
+ if (from.zone === "freecell") return count === 1 ? state.freecells[from.index] ?? void 0 : void 0;
228
+ return void 0;
229
+ }
230
+ function accessibleCards(state) {
231
+ const result = [];
232
+ state.freecells.forEach((card, index) => {
233
+ if (card) result.push({ ref: { zone: "freecell", index }, card });
234
+ });
235
+ state.tableau.forEach((pile, index) => {
236
+ const t = top(pile);
237
+ if (t) result.push({ ref: { zone: "tableau", index }, card: t });
238
+ });
239
+ return result;
240
+ }
241
+ function searchMoves(state) {
242
+ const moves = [];
243
+ const firstEmpty = state.freecells.indexOf(null);
244
+ const toFoundation = (from, card) => {
245
+ const f = suitIndex(card.suit);
246
+ if (canPlaceOnFoundation(state.foundation[f], card)) moves.push({ from, to: { zone: "foundation", index: f }, count: 1 });
247
+ };
248
+ state.freecells.forEach((card, fc) => {
249
+ if (!card) return;
250
+ const from = { zone: "freecell", index: fc };
251
+ toFoundation(from, card);
252
+ for (let t = 0; t < NUM_TABLEAU; t++) if (canPlaceOnTableau(state.tableau[t], card)) moves.push({ from, to: { zone: "tableau", index: t }, count: 1 });
253
+ });
254
+ for (let col = 0; col < NUM_TABLEAU; col++) {
255
+ const pile = state.tableau[col];
256
+ if (pile.length === 0) continue;
257
+ const from = { zone: "tableau", index: col };
258
+ toFoundation(from, pile[pile.length - 1]);
259
+ if (firstEmpty !== -1) moves.push({ from, to: { zone: "freecell", index: firstEmpty }, count: 1 });
260
+ const runLen = runLengthAtTop(pile);
261
+ for (let t = 0; t < NUM_TABLEAU; t++) {
262
+ if (t === col) continue;
263
+ const capacity = maxSupermoveCount(state, t);
264
+ for (let count = 1; count <= Math.min(runLen, capacity); count++) {
265
+ if (canPlaceOnTableau(state.tableau[t], pile[pile.length - count])) moves.push({ from, to: { zone: "tableau", index: t }, count });
266
+ }
267
+ }
268
+ }
269
+ return moves;
270
+ }
271
+ var progress = {
272
+ id: "freecell",
273
+ moves: searchMoves,
274
+ drawIsStep: false,
275
+ key: (state) => `${columnsKey(state.tableau)}/${state.freecells.map((c) => c ? pileKey([c]) : "").sort().join("")}`,
276
+ progress: (state) => [state.foundation.reduce((n, p) => n + p.length, 0)]
277
+ };
278
+ var FreeCellController = {
279
+ id: "freecell",
280
+ title: "FreeCell",
281
+ newGame,
282
+ legalMoves,
283
+ tryMove,
284
+ isWon,
285
+ autoMoveHint,
286
+ scoreHintMove,
287
+ accessibleCards,
288
+ progress
289
+ };
290
+
291
+ export {
292
+ countEmptyFreecells,
293
+ countEmptyTableauColumns,
294
+ maxSupermoveCount,
295
+ moveHeadCard,
296
+ FreeCellController
297
+ };
@@ -0,0 +1,23 @@
1
+ import {
2
+ buriedCount
3
+ } from "./chunk-XSS5M6C7.mjs";
4
+
5
+ // src/engine/autoMove.ts
6
+ function pickBestTableauTarget(candidates, isValidRun) {
7
+ const nonEmpty = candidates.filter((c) => c.pile.length > 0);
8
+ const pool = nonEmpty.length > 0 ? nonEmpty : candidates;
9
+ let best = null;
10
+ let bestBuried = Infinity;
11
+ for (const c of pool) {
12
+ const buried = buriedCount(c.pile, isValidRun);
13
+ if (best === null || buried < bestBuried || buried === bestBuried && c.pile.length > best.pile.length) {
14
+ best = c;
15
+ bestBuried = buried;
16
+ }
17
+ }
18
+ return best;
19
+ }
20
+
21
+ export {
22
+ pickBestTableauTarget
23
+ };
@@ -0,0 +1,131 @@
1
+ import {
2
+ shuffledDeck,
3
+ top
4
+ } from "./chunk-XSS5M6C7.mjs";
5
+
6
+ // src/games/golf/rules.ts
7
+ function cloneState(state) {
8
+ return {
9
+ tableau: state.tableau.slice(),
10
+ waste: state.waste,
11
+ stock: state.stock
12
+ };
13
+ }
14
+ function setPile(state, ref, pile) {
15
+ switch (ref.zone) {
16
+ case "tableau":
17
+ state.tableau[ref.index] = pile;
18
+ break;
19
+ case "waste":
20
+ state.waste = pile;
21
+ break;
22
+ case "stock":
23
+ state.stock = pile;
24
+ break;
25
+ }
26
+ }
27
+ function newGame(seed) {
28
+ const deck = shuffledDeck(seed, 1);
29
+ let cursor = 0;
30
+ const tableau = [];
31
+ for (let col = 0; col < 7; col++) {
32
+ const cards = [];
33
+ for (let i = 0; i < 5; i++) {
34
+ const card = deck[cursor++];
35
+ cards.push({ ...card, faceUp: true });
36
+ }
37
+ tableau.push(cards);
38
+ }
39
+ const starter = deck[cursor++];
40
+ const waste = [{ ...starter, faceUp: true }];
41
+ const stock = deck.slice(cursor).map((c) => ({ ...c, faceUp: false }));
42
+ return { tableau, waste, stock };
43
+ }
44
+ function isAdjacentRank(a, b, wrapAceKing) {
45
+ if (Math.abs(a.rank - b.rank) === 1) return true;
46
+ return wrapAceKing && (a.rank === 1 && b.rank === 13 || a.rank === 13 && b.rank === 1);
47
+ }
48
+ function drawStock(state) {
49
+ if (state.stock.length === 0) return null;
50
+ const next = cloneState(state);
51
+ const nextStock = next.stock.slice();
52
+ const nextWaste = next.waste.slice();
53
+ const card = nextStock.pop();
54
+ nextWaste.push(card.faceUp ? card : { ...card, faceUp: true });
55
+ setPile(next, { zone: "stock", index: 0 }, nextStock);
56
+ setPile(next, { zone: "waste", index: 0 }, nextWaste);
57
+ return next;
58
+ }
59
+ function isWon(state) {
60
+ return state.tableau.every((col) => col.length === 0);
61
+ }
62
+ function createGolfController(wrapAceKing) {
63
+ function tryMove(state, move) {
64
+ const { from, to, count } = move;
65
+ if (count !== 1) return null;
66
+ if (from.zone !== "tableau") return null;
67
+ if (to.zone !== "waste" || to.index !== 0) return null;
68
+ const col = state.tableau[from.index];
69
+ if (!col || col.length === 0) return null;
70
+ const movingCard = top(col);
71
+ const wasteTop = top(state.waste);
72
+ if (!wasteTop) return null;
73
+ if (!isAdjacentRank(movingCard, wasteTop, wrapAceKing)) return null;
74
+ const next = cloneState(state);
75
+ const nextCol = next.tableau[from.index].slice();
76
+ const moved = nextCol.pop();
77
+ setPile(next, from, nextCol);
78
+ const nextWaste = next.waste.slice();
79
+ nextWaste.push(moved);
80
+ setPile(next, to, nextWaste);
81
+ return next;
82
+ }
83
+ function legalMoves(state) {
84
+ const moves = [];
85
+ const wasteTop = top(state.waste);
86
+ if (!wasteTop) return moves;
87
+ state.tableau.forEach((col, index) => {
88
+ const t = top(col);
89
+ if (t && isAdjacentRank(t, wasteTop, wrapAceKing)) {
90
+ moves.push({ from: { zone: "tableau", index }, to: { zone: "waste", index: 0 }, count: 1 });
91
+ }
92
+ });
93
+ return moves;
94
+ }
95
+ function isStuck(state) {
96
+ return !isWon(state) && state.stock.length === 0 && legalMoves(state).length === 0;
97
+ }
98
+ function autoMoveHint(state, from, cardId) {
99
+ if (from.zone !== "tableau") return null;
100
+ const col = state.tableau[from.index];
101
+ const t = top(col);
102
+ if (!t || t.id !== cardId) return null;
103
+ const wasteTop = top(state.waste);
104
+ if (!wasteTop || !isAdjacentRank(t, wasteTop, wrapAceKing)) return null;
105
+ return { from, to: { zone: "waste", index: 0 }, count: 1 };
106
+ }
107
+ function scoreHintMove(state, move) {
108
+ const next = tryMove(state, move);
109
+ if (!next) return 0;
110
+ const fromCol = state.tableau[move.from.index];
111
+ const emptiesColumn = fromCol.length === move.count;
112
+ const followUpMoves = legalMoves(next).length;
113
+ return 1 + followUpMoves * 10 + (emptiesColumn ? 100 : 0);
114
+ }
115
+ return {
116
+ id: "golf",
117
+ title: "Golf",
118
+ newGame,
119
+ legalMoves,
120
+ tryMove,
121
+ drawStock,
122
+ isWon,
123
+ isStuck,
124
+ autoMoveHint,
125
+ scoreHintMove
126
+ };
127
+ }
128
+
129
+ export {
130
+ createGolfController
131
+ };
@@ -0,0 +1,165 @@
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 _chunkW5CPH6TDjs = require('./chunk-W5CPH6TD.js');
5
+
6
+ // src/games/tripeaks/rules.ts
7
+ var ROW_WIDTHS = [3, 6, 9, 10];
8
+ var ROW_STARTS = [0, 3, 9, 18, 28];
9
+ var TOTAL = 28;
10
+ function flatIndex(row, col) {
11
+ return ROW_STARTS[row] + col;
12
+ }
13
+ function rowColOf(index) {
14
+ let row = 0;
15
+ while (ROW_STARTS[row + 1] <= index) row++;
16
+ return { row, col: index - ROW_STARTS[row] };
17
+ }
18
+ function childIndices(row, col) {
19
+ if (row === 3) return null;
20
+ if (row === 0) {
21
+ return [flatIndex(1, col * 2), flatIndex(1, col * 2 + 1)];
22
+ }
23
+ if (row === 1) {
24
+ const peak2 = Math.floor(col / 2);
25
+ const local2 = col % 2;
26
+ const base2 = peak2 * 3 + local2;
27
+ return [flatIndex(2, base2), flatIndex(2, base2 + 1)];
28
+ }
29
+ const peak = Math.floor(col / 3);
30
+ const local = col % 3;
31
+ const base = peak * 3 + local;
32
+ return [flatIndex(3, base), flatIndex(3, base + 1)];
33
+ }
34
+ function isExposed(tableau, row, col) {
35
+ const idx = flatIndex(row, col);
36
+ if (!tableau[idx]) return false;
37
+ const children = childIndices(row, col);
38
+ if (!children) return true;
39
+ const [a, b] = children;
40
+ return !tableau[a] && !tableau[b];
41
+ }
42
+ function isExposedAt(tableau, index) {
43
+ const { row, col } = rowColOf(index);
44
+ return isExposed(tableau, row, col);
45
+ }
46
+ function countNewlyExposed(tableau, index) {
47
+ const after = tableau.slice();
48
+ after[index] = null;
49
+ let count = 0;
50
+ for (let i = 0; i < TOTAL; i++) {
51
+ if (i === index || !after[i]) continue;
52
+ if (!isExposedAt(tableau, i) && isExposedAt(after, i)) count++;
53
+ }
54
+ return count;
55
+ }
56
+ function scoreHintMove(state, move) {
57
+ if (move.from.zone !== "tableau" || move.to.zone !== "waste") return 0;
58
+ return 1 + countNewlyExposed(state.tableau, move.from.index);
59
+ }
60
+ function isAdjacentRank(a, b, wrapAceKing) {
61
+ if (Math.abs(a.rank - b.rank) === 1) return true;
62
+ return wrapAceKing && (a.rank === 1 && b.rank === 13 || a.rank === 13 && b.rank === 1);
63
+ }
64
+ function cloneState(state) {
65
+ return {
66
+ tableau: state.tableau,
67
+ waste: state.waste,
68
+ stock: state.stock
69
+ };
70
+ }
71
+ function newGame(seed) {
72
+ const deck = _chunkW5CPH6TDjs.shuffledDeck.call(void 0, seed, 1);
73
+ const tableau = deck.slice(0, TOTAL).map((c) => ({ ...c, faceUp: true }));
74
+ const starter = deck[TOTAL];
75
+ const waste = [{ ...starter, faceUp: true }];
76
+ const stock = deck.slice(TOTAL + 1).map((c) => ({ ...c, faceUp: false }));
77
+ return { tableau, waste, stock };
78
+ }
79
+ function cardAt(state, ref) {
80
+ if (ref.zone === "tableau") return _nullishCoalesce(state.tableau[ref.index], () => ( null));
81
+ if (ref.zone === "waste") return _nullishCoalesce(_chunkW5CPH6TDjs.top.call(void 0, state.waste), () => ( null));
82
+ return null;
83
+ }
84
+ function drawStock(state) {
85
+ if (state.stock.length === 0) return null;
86
+ const next = cloneState(state);
87
+ const nextStock = next.stock.slice();
88
+ const nextWaste = next.waste.slice();
89
+ const card = nextStock.pop();
90
+ nextWaste.push(card.faceUp ? card : { ...card, faceUp: true });
91
+ next.stock = nextStock;
92
+ next.waste = nextWaste;
93
+ return next;
94
+ }
95
+ function isWon(state) {
96
+ return state.tableau.every((c) => c === null);
97
+ }
98
+ function createTriPeaksController(wrapAceKing) {
99
+ function tryMove(state, move) {
100
+ const { from, to, count } = move;
101
+ if (count !== 1) return null;
102
+ if (from.zone !== "tableau") return null;
103
+ if (to.zone !== "waste" || to.index !== 0) return null;
104
+ const card = state.tableau[from.index];
105
+ if (!card) return null;
106
+ if (!isExposedAt(state.tableau, from.index)) return null;
107
+ const wasteTop = _chunkW5CPH6TDjs.top.call(void 0, state.waste);
108
+ if (!wasteTop) return null;
109
+ if (!isAdjacentRank(card, wasteTop, wrapAceKing)) return null;
110
+ const next = cloneState(state);
111
+ const nextTableau = next.tableau.slice();
112
+ const nextWaste = next.waste.slice();
113
+ nextTableau[from.index] = null;
114
+ nextWaste.push(card);
115
+ next.tableau = nextTableau;
116
+ next.waste = nextWaste;
117
+ return next;
118
+ }
119
+ function legalMoves(state) {
120
+ const moves = [];
121
+ const wasteTop = _chunkW5CPH6TDjs.top.call(void 0, state.waste);
122
+ if (!wasteTop) return moves;
123
+ for (let i = 0; i < TOTAL; i++) {
124
+ const card = state.tableau[i];
125
+ if (card && isExposedAt(state.tableau, i) && isAdjacentRank(card, wasteTop, wrapAceKing)) {
126
+ moves.push({ from: { zone: "tableau", index: i }, to: { zone: "waste", index: 0 }, count: 1 });
127
+ }
128
+ }
129
+ return moves;
130
+ }
131
+ function isStuck(state) {
132
+ return !isWon(state) && state.stock.length === 0 && legalMoves(state).length === 0;
133
+ }
134
+ function autoMoveHint(state, from, cardId) {
135
+ if (from.zone !== "tableau") return null;
136
+ const card = state.tableau[from.index];
137
+ if (!card || card.id !== cardId) return null;
138
+ if (!isExposedAt(state.tableau, from.index)) return null;
139
+ const wasteTop = _chunkW5CPH6TDjs.top.call(void 0, state.waste);
140
+ if (!wasteTop || !isAdjacentRank(card, wasteTop, wrapAceKing)) return null;
141
+ return { from, to: { zone: "waste", index: 0 }, count: 1 };
142
+ }
143
+ return {
144
+ id: "tripeaks",
145
+ title: "TriPeaks",
146
+ newGame,
147
+ legalMoves,
148
+ tryMove,
149
+ drawStock,
150
+ isWon,
151
+ isStuck,
152
+ autoMoveHint,
153
+ scoreHintMove
154
+ };
155
+ }
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+ exports.ROW_WIDTHS = ROW_WIDTHS; exports.flatIndex = flatIndex; exports.rowColOf = rowColOf; exports.childIndices = childIndices; exports.isExposed = isExposed; exports.cardAt = cardAt; exports.createTriPeaksController = createTriPeaksController;
@@ -0,0 +1,22 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkW5CPH6TDjs = require('./chunk-W5CPH6TD.js');
4
+
5
+ // src/engine/foundation.ts
6
+ var FOUNDATION_SUITS = ["spades", "diamonds", "clubs", "hearts"];
7
+ var FOUNDATION_LAYOUT = 1;
8
+ function canPlaceOnFoundation(dest, moving) {
9
+ const destTop = _chunkW5CPH6TDjs.top.call(void 0, dest);
10
+ if (destTop === void 0) return moving.rank === 1;
11
+ return destTop.suit === moving.suit && moving.rank === destTop.rank + 1;
12
+ }
13
+ function suitIndex(suit) {
14
+ return FOUNDATION_SUITS.indexOf(suit);
15
+ }
16
+
17
+
18
+
19
+
20
+
21
+
22
+ exports.FOUNDATION_SUITS = FOUNDATION_SUITS; exports.FOUNDATION_LAYOUT = FOUNDATION_LAYOUT; exports.canPlaceOnFoundation = canPlaceOnFoundation; exports.suitIndex = suitIndex;