@dreamboard-games/sdk 0.5.0-alpha.33 → 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 +88 -6
- package/dist/{board-element-BZ9e3pLb.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-VCQ23Z5U.js → chunk-G4MY5YMA.js} +26 -5
- package/dist/chunk-G4MY5YMA.js.map +1 -0
- package/dist/{chunk-BVWJS3AB.js → chunk-JWPWE5EI.js} +2 -2
- package/dist/{chunk-F46EZJCX.js → chunk-RNR4M67F.js} +3 -3
- package/dist/{chunk-M7GZANGG.js → chunk-UGWQKBR6.js} +333 -78
- package/dist/chunk-UGWQKBR6.js.map +1 -0
- package/dist/{diagnostics-BYGF8kfA.d.ts → diagnostics-DNGfYfY8.d.ts} +7 -1
- package/dist/{extract-BG3V3c2c.d.ts → extract-BF6nUlze.d.ts} +150 -7
- package/dist/index.d.ts +78 -79
- package/dist/index.js +5 -5
- package/dist/{shortcuts-BFbp5Y3C.d.ts → model-C7ScBVY5.d.ts} +3 -122
- package/dist/react.d.ts +4 -4
- package/dist/react.js +2 -2
- package/dist/reducer.d.ts +147 -16
- package/dist/reducer.js +9 -4
- package/dist/reducer.js.map +1 -1
- package/dist/shortcuts-BQEIVHSm.d.ts +123 -0
- package/dist/testing.d.ts +18 -6
- package/dist/testing.js +21 -6
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-M7GZANGG.js.map +0 -1
- package/dist/chunk-VCQ23Z5U.js.map +0 -1
- package/dist/types-Bfg8s5dP.d.ts +0 -125
- /package/dist/{chunk-BVWJS3AB.js.map → chunk-JWPWE5EI.js.map} +0 -0
- /package/dist/{chunk-F46EZJCX.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({
|
|
@@ -273,11 +276,92 @@ the SDK's model.
|
|
|
273
276
|
To migrate an older manifest, replace each card's `type` with `id` and set
|
|
274
277
|
`cardType` explicitly (often to the former `type` value).
|
|
275
278
|
|
|
279
|
+
## Author a bot strategy
|
|
280
|
+
|
|
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.
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
import { createReducerBundle, defineBots } from "@dreamboard-games/sdk/reducer";
|
|
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
|
+
```
|
|
309
|
+
|
|
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],
|
|
323
|
+
);
|
|
324
|
+
yield { cards: lowFirst.slice(0, selection.cards.count) };
|
|
325
|
+
},
|
|
326
|
+
score({ cards }) {
|
|
327
|
+
return -cards.reduce((sum, c) => sum + RANK_VALUE[c.properties.rank], 0);
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
```
|
|
331
|
+
|
|
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.
|
|
338
|
+
|
|
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)
|
|
342
|
+
|
|
343
|
+
Use a seeded local source to test a decision through normal submission. For
|
|
344
|
+
an authored checkpoint, use `scenarioSource(game, scenario, { bundle, at, as })`
|
|
345
|
+
with the same reducer bundle. The result includes the choice and its acceptance
|
|
346
|
+
or rejection. The source returns `null` for a strategy that declines to act.
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
const source = await localSource(game, { bundle, players: 4, seed: 7 });
|
|
350
|
+
try {
|
|
351
|
+
source.switchSeat("player-1");
|
|
352
|
+
const turn = await source.playBotTurn("penalty-dodger");
|
|
353
|
+
assert.equal(turn?.decision.interactionId, "submit");
|
|
354
|
+
assert.equal(turn.result.accepted, true);
|
|
355
|
+
} finally {
|
|
356
|
+
source.dispose();
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
276
360
|
## Reducer runner contract
|
|
277
361
|
|
|
278
|
-
`createReducerBundle(game)`
|
|
279
|
-
|
|
280
|
-
and `project({ state, playerIds, referenceBasis })`. The runner contract is `0.11.0`; hosts must
|
|
362
|
+
`createReducerBundle(game)` exposes the contract version and the operations
|
|
363
|
+
`initialize(input)`, `dispatch({ state, input, referenceBasis })`,
|
|
364
|
+
and `project({ state, playerIds, referenceBasis })`. When strategies are registered, the bundle also exposes their metadata in `botStrategies` and their decision function in `decideBot`. The runner contract is `0.11.0`; hosts must
|
|
281
365
|
require that exact version. The host supplies `referenceBasis: { sessionId, version }`:
|
|
282
366
|
use a fresh session ID for each authority lifetime, increment version exactly once
|
|
283
367
|
for every accepted input, and advance it on restore without restoring an old
|
|
@@ -602,9 +686,7 @@ features(core, context) {
|
|
|
602
686
|
|
|
603
687
|
Use `game.cardSelection.set(ids)`, `.toggle(id)` and `.clear()` for authored
|
|
604
688
|
controls. A selected group can drop only onto an interaction with a `many(...)`
|
|
605
|
-
card input that admits the entire group. Dropping submits
|
|
606
|
-
selection order, replacing its draft; it never submits a sequence of single-card
|
|
607
|
-
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
|
|
608
690
|
atomically. An unselected card retains ordinary single-card draft behavior.
|
|
609
691
|
`useDragOverlay().cardIds` identifies all lifted cards; `cardId` is the anchor.
|
|
610
692
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|