@dreamboard-games/sdk 0.5.0-alpha.34 → 0.5.0-alpha.35
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/README.md +56 -41
- package/dist/{board-element-DCjHsEnF.d.ts → board-element-Bdc0Kv6W.d.ts} +1 -1
- package/dist/{chunk-CZRPUWCT.js → chunk-7GX27XU6.js} +23 -2
- package/dist/{chunk-CZRPUWCT.js.map → chunk-7GX27XU6.js.map} +1 -1
- package/dist/{chunk-BSS4ORU3.js → chunk-G4MY5YMA.js} +8 -5
- package/dist/chunk-G4MY5YMA.js.map +1 -0
- package/dist/{chunk-BVWJS3AB.js → chunk-JWPWE5EI.js} +2 -2
- package/dist/{chunk-2GUPNL7A.js → chunk-RNR4M67F.js} +3 -3
- package/dist/{chunk-KYQQIFXN.js → chunk-UGWQKBR6.js} +303 -78
- package/dist/chunk-UGWQKBR6.js.map +1 -0
- package/dist/{diagnostics-Cl8mSexe.d.ts → diagnostics-DNGfYfY8.d.ts} +1 -1
- package/dist/{extract-CNUw9Q8C.d.ts → extract-BF6nUlze.d.ts} +1 -1
- package/dist/index.d.ts +78 -78
- package/dist/index.js +5 -5
- package/dist/{model-BD0OKVEc.d.ts → model-C7ScBVY5.d.ts} +1 -1
- package/dist/react.d.ts +3 -3
- package/dist/react.js +2 -2
- package/dist/reducer.d.ts +130 -186
- package/dist/reducer.js +9 -17
- package/dist/reducer.js.map +1 -1
- package/dist/{shortcuts-Br5h9mEV.d.ts → shortcuts-BQEIVHSm.d.ts} +2 -2
- package/dist/testing.d.ts +10 -4
- package/dist/testing.js +4 -4
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-BSS4ORU3.js.map +0 -1
- package/dist/chunk-KYQQIFXN.js.map +0 -1
- /package/dist/{chunk-BVWJS3AB.js.map → chunk-JWPWE5EI.js.map} +0 -0
- /package/dist/{chunk-2GUPNL7A.js.map → chunk-RNR4M67F.js.map} +0 -0
package/README.md
CHANGED
|
@@ -120,6 +120,9 @@ commits exactly one current value. Factories receive only earlier parsed
|
|
|
120
120
|
`selected` values; descriptors expose only the current input. The final commit
|
|
121
121
|
runs complete-parameter validation and the reducer once. Use explicit `null`
|
|
122
122
|
for a no-target choice, and `many(...)` for one atomic multi-selection.
|
|
123
|
+
Each `many(...)` selection is unordered. The reducer receives eligible targets
|
|
124
|
+
and choices in projected domain order, regardless of the order players pick them. `distinct: true`
|
|
125
|
+
independently requires each value to be selected at most once.
|
|
123
126
|
|
|
124
127
|
```ts
|
|
125
128
|
const choose = play.interaction({
|
|
@@ -275,53 +278,67 @@ To migrate an older manifest, replace each card's `type` with `id` and set
|
|
|
275
278
|
|
|
276
279
|
## Author a bot strategy
|
|
277
280
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
For a game with a `playing.playCard` interaction:
|
|
281
|
+
Register a game's strategies together with `defineBots`. By default, a bot scores the choices
|
|
282
|
+
enumerated from its seat's available interactions. The highest finite score wins
|
|
283
|
+
across all offered interactions, including actions with empty parameters.
|
|
284
|
+
Give each personality a stable ID for the seat picker.
|
|
284
285
|
|
|
285
286
|
```ts
|
|
286
|
-
import {
|
|
287
|
-
createReducerBundle,
|
|
288
|
-
offeredInputDomain,
|
|
289
|
-
offeredInteraction,
|
|
290
|
-
type BotStrategy,
|
|
291
|
-
} from "@dreamboard-games/sdk/reducer";
|
|
287
|
+
import { createReducerBundle, defineBots } from "@dreamboard-games/sdk/reducer";
|
|
292
288
|
import game from "./game";
|
|
289
|
+
import { RANK_VALUE } from "./rules";
|
|
290
|
+
|
|
291
|
+
const botStrategies = defineBots(game, {
|
|
292
|
+
resolve: { card: (view) => view.hand },
|
|
293
|
+
strategies: [
|
|
294
|
+
{
|
|
295
|
+
id: "moon-chaser",
|
|
296
|
+
name: "Moon Chaser",
|
|
297
|
+
description: "Passes low cards and plays high to win tricks.",
|
|
298
|
+
score: {
|
|
299
|
+
"passing.submit": ({ cards }) =>
|
|
300
|
+
-cards.reduce((sum, c) => sum + RANK_VALUE[c.properties.rank], 0),
|
|
301
|
+
"playing.playCard": ({ card }) => RANK_VALUE[card.properties.rank],
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
export default createReducerBundle(game, { botStrategies });
|
|
308
|
+
```
|
|
293
309
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
310
|
+
The shared resolver supplies visible objects for eligible IDs. For an unordered
|
|
311
|
+
pass of three distinct cards, `cards` is one legal triple. From a hand of 13,
|
|
312
|
+
the SDK evaluates 286 triples. To propose a shortlist, replace that one pass
|
|
313
|
+
function with an object containing `candidates` and `score`. The SDK checks
|
|
314
|
+
each proposal against the projected card IDs and selection constraints, then
|
|
315
|
+
passes the selected objects to the scorer in eligible-ID order. The winning
|
|
316
|
+
move goes through the same reducer validation as a human submission.
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
"passing.submit": {
|
|
320
|
+
*candidates({ eligible, selection }) {
|
|
321
|
+
const lowFirst = [...eligible.cards].sort(
|
|
322
|
+
(a, b) => RANK_VALUE[a.properties.rank] - RANK_VALUE[b.properties.rank],
|
|
303
323
|
);
|
|
304
|
-
|
|
305
|
-
? { interactionId: "playCard", params: { cardId: card.id } }
|
|
306
|
-
: null;
|
|
324
|
+
yield { cards: lowFirst.slice(0, selection.cards.count) };
|
|
307
325
|
},
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
326
|
+
score({ cards }) {
|
|
327
|
+
return -cards.reduce((sum, c) => sum + RANK_VALUE[c.properties.rank], 0);
|
|
328
|
+
},
|
|
329
|
+
},
|
|
311
330
|
```
|
|
312
331
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
332
|
+
Use `"skip"` for an interaction the bot deliberately declines. Supported
|
|
333
|
+
scoring shapes are zero inputs, a single card and one fixed, distinct card
|
|
334
|
+
selection declared with `many()`. Skipping the only available
|
|
335
|
+
interaction leaves the seat pending. Ties follow frame offer order, eligible
|
|
336
|
+
ID order for exhaustive choices, and yield order for custom proposals.
|
|
337
|
+
An empty candidate list declines that offer. A null seat view produces no decision.
|
|
319
338
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
the same eligible hand cards during the sealed pass and all thirteen tricks.
|
|
324
|
-
[Hearts strategy implementations](https://github.com/dreamboard-games/dreamboard-sdk/blob/main/examples/reference-games/hearts/app/bot-strategies.ts)
|
|
339
|
+
Both Hearts strategies use the same resolver. Penalty Dodger sheds dangerous
|
|
340
|
+
spades and ducks tricks. Moon Chaser keeps high cards and tries to win.
|
|
341
|
+
[Hearts strategies](https://github.com/dreamboard-games/dreamboard-sdk/blob/main/examples/reference-games/hearts/app/bot-strategies.ts)
|
|
325
342
|
|
|
326
343
|
Use a seeded local source to test a decision through normal submission. For
|
|
327
344
|
an authored checkpoint, use `scenarioSource(game, scenario, { bundle, at, as })`
|
|
@@ -669,9 +686,7 @@ features(core, context) {
|
|
|
669
686
|
|
|
670
687
|
Use `game.cardSelection.set(ids)`, `.toggle(id)` and `.clear()` for authored
|
|
671
688
|
controls. A selected group can drop only onto an interaction with a `many(...)`
|
|
672
|
-
card input that admits the entire group. Dropping submits
|
|
673
|
-
selection order, replacing its draft; it never submits a sequence of single-card
|
|
674
|
-
moves. The reducer remains responsible for validating and applying the group
|
|
689
|
+
card input that admits the entire group. Dropping submits the group once and replaces its draft. The reducer remains responsible for validating and applying the group
|
|
675
690
|
atomically. An unselected card retains ordinary single-card draft behavior.
|
|
676
691
|
`useDragOverlay().cardIds` identifies all lifted cards; `cardId` is the anchor.
|
|
677
692
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as BoardEdgeId, p as BoardVertexId } from './extract-
|
|
1
|
+
import { h as BoardEdgeId, p as BoardVertexId } from './extract-BF6nUlze.js';
|
|
2
2
|
|
|
3
3
|
declare function boardEdgeId<BoardId extends string>(layout: "hex" | "square", boardId: BoardId, latticeId: string): BoardEdgeId<BoardId>;
|
|
4
4
|
declare function boardVertexId<BoardId extends string>(layout: "hex" | "square", boardId: BoardId, latticeId: string): BoardVertexId<BoardId>;
|
|
@@ -1498,6 +1498,19 @@ function inputDomainErrors(domain, value, selection, options = {}) {
|
|
|
1498
1498
|
function inputValueInDomain(domain, value, selection, options = {}) {
|
|
1499
1499
|
return inputDomainErrors(domain, value, selection, options).length === 0;
|
|
1500
1500
|
}
|
|
1501
|
+
function canonicalizeInputSelection(value, selection, domain) {
|
|
1502
|
+
if (selection?.mode !== "many") return value;
|
|
1503
|
+
if (!Array.isArray(value)) return value;
|
|
1504
|
+
const values = value;
|
|
1505
|
+
const choices = domain?.type === "cardTarget" || domain?.type === "tileTarget" || domain?.type === "boardTarget" ? domain.eligibleTargets : domain?.type === "choice" ? domain.choices.map((choice) => choice.value) : [];
|
|
1506
|
+
const positions = /* @__PURE__ */ new Map();
|
|
1507
|
+
choices.forEach(
|
|
1508
|
+
(choice, index) => positions.set(inputValueKey(choice), index)
|
|
1509
|
+
);
|
|
1510
|
+
return values.map((item) => ({ item, key: inputValueKey(item) })).sort(
|
|
1511
|
+
(a, b) => (positions.get(a.key) ?? choices.length) - (positions.get(b.key) ?? choices.length) || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)
|
|
1512
|
+
).map(({ item }) => item);
|
|
1513
|
+
}
|
|
1501
1514
|
function inputTargetInDomain(domain, value) {
|
|
1502
1515
|
switch (domain.type) {
|
|
1503
1516
|
case "choice":
|
|
@@ -1545,7 +1558,14 @@ function inputValueKey(value) {
|
|
|
1545
1558
|
case "undefined":
|
|
1546
1559
|
return `${typeof value}:${String(value)}`;
|
|
1547
1560
|
default:
|
|
1548
|
-
return `json:${JSON.stringify(value)
|
|
1561
|
+
return `json:${JSON.stringify(value, (_key, item) => {
|
|
1562
|
+
if (item === null || typeof item !== "object" || Array.isArray(item))
|
|
1563
|
+
return item;
|
|
1564
|
+
const record3 = item;
|
|
1565
|
+
return Object.fromEntries(
|
|
1566
|
+
Object.keys(record3).sort().map((key) => [key, record3[key]])
|
|
1567
|
+
);
|
|
1568
|
+
})}`;
|
|
1549
1569
|
}
|
|
1550
1570
|
}
|
|
1551
1571
|
function pluralize(word, count) {
|
|
@@ -1596,7 +1616,8 @@ export {
|
|
|
1596
1616
|
sameBoardSpaceTarget,
|
|
1597
1617
|
inputDomainErrors,
|
|
1598
1618
|
inputValueInDomain,
|
|
1619
|
+
canonicalizeInputSelection,
|
|
1599
1620
|
inputTargetInDomain,
|
|
1600
1621
|
inputValueKey
|
|
1601
1622
|
};
|
|
1602
|
-
//# sourceMappingURL=chunk-
|
|
1623
|
+
//# sourceMappingURL=chunk-7GX27XU6.js.map
|