@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 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
- Each game can publish named strategies alongside its reducer. Give each strategy
279
- a stable ID and a short description that helps players choose one for a seat.
280
- A strategy sees the same frame as that seat's UI, including its own cards, the
281
- public trick, and the interactions offered on the current step.
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
- const firstLegal: BotStrategy<typeof game> = {
295
- id: "first-legal",
296
- name: "First Legal Card",
297
- description: "Plays the first eligible card in hand order.",
298
- decide(frame) {
299
- const play = offeredInteraction(frame, "playing.playCard");
300
- const cards = offeredInputDomain(play, "cardId", "cardTarget");
301
- const card = frame.view?.hand.find(({ id }) =>
302
- cards?.eligibleTargets.includes(id),
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
- return card
305
- ? { interactionId: "playCard", params: { cardId: card.id } }
306
- : null;
324
+ yield { cards: lowFirst.slice(0, selection.cards.count) };
307
325
  },
308
- };
309
-
310
- export default createReducerBundle(game, { botStrategies: [firstLegal] });
326
+ score({ cards }) {
327
+ return -cards.reduce((sum, c) => sum + RANK_VALUE[c.properties.rank], 0);
328
+ },
329
+ },
311
330
  ```
312
331
 
313
- Look up an interaction using its phase-qualified key and return the ordinary
314
- interaction ID with its current input parameters. For a multi-step interaction,
315
- read the new frame after each accepted step. Return `null` when the seat has no
316
- decision. Use a stable tie-breaker so the same frame produces the same move.
317
- Keep the strategy in the reducer entry and use the catalogue's ID when selecting
318
- a strategy for a particular seat.
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
- The Hearts reference game has two complete examples. **Penalty Dodger** passes
321
- dangerous spades and tries to play below the highest card of the lead suit.
322
- **Moon Chaser** passes low cards and plays high to win tricks. Both choose from
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 that input once in
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-CNUw9Q8C.js';
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-CZRPUWCT.js.map
1623
+ //# sourceMappingURL=chunk-7GX27XU6.js.map