@dreamboard-games/sdk 0.5.0-alpha.32 → 0.5.0-alpha.34

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.
@@ -1,4 +1,6 @@
1
1
  import {
2
+ BotDecisionSchema,
3
+ BotStrategyCatalogSchema,
2
4
  CARD_REFERENCE_PREFIX,
3
5
  GameEventSchema,
4
6
  GameInputSchema,
@@ -9,7 +11,7 @@ import {
9
11
  boardSpaceHostId,
10
12
  isCardReferenceNamespace,
11
13
  parseBoardSpaceHostId
12
- } from "./chunk-IEMZ26FI.js";
14
+ } from "./chunk-BSS4ORU3.js";
13
15
  import {
14
16
  AuthoredTileDisclosureSchema,
15
17
  BoardProjectionSchema,
@@ -188,8 +190,13 @@ var bundleSchema = z3.object({
188
190
  reducerContractVersion: z3.literal(REDUCER_CONTRACT_VERSION),
189
191
  initialize: callable,
190
192
  dispatch: callable,
191
- project: callable
192
- });
193
+ project: callable,
194
+ botStrategies: BotStrategyCatalogSchema.optional(),
195
+ decideBot: callable.optional()
196
+ }).refine(
197
+ (bundle) => bundle.botStrategies === void 0 === (bundle.decideBot === void 0),
198
+ "Bot strategies and decideBot must be provided together."
199
+ );
193
200
  function assertReducerBundleContract(value, source) {
194
201
  const result = bundleSchema.safeParse(value);
195
202
  if (result.success) return;
@@ -203,6 +210,11 @@ function assertReducerBundleContract(value, source) {
203
210
  );
204
211
  }
205
212
  const method = result.error.issues[0]?.path[0];
213
+ if (!method || method === "botStrategies" || method === "decideBot") {
214
+ throw new Error(
215
+ `Reducer bundle ${source} has an invalid bot strategy contract: ${result.error.message}`
216
+ );
217
+ }
206
218
  throw new Error(`Reducer bundle ${source} is missing ${String(method)}().`);
207
219
  }
208
220
 
@@ -1522,6 +1534,23 @@ function createStateQueries(state, definitions) {
1522
1534
  );
1523
1535
  }
1524
1536
 
1537
+ // src/reducer/bundle/bot-strategies.ts
1538
+ function createBotCapability(strategies) {
1539
+ if (!strategies?.length) return {};
1540
+ const botStrategies = BotStrategyCatalogSchema.parse(
1541
+ strategies.map(({ id: id2, name, description }) => ({ id: id2, name, description }))
1542
+ );
1543
+ const byId = new Map(strategies.map((strategy) => [strategy.id, strategy]));
1544
+ return {
1545
+ botStrategies,
1546
+ decideBot({ strategyId, frame }) {
1547
+ const strategy = byId.get(strategyId);
1548
+ if (!strategy) throw new Error(`Unknown bot strategy '${strategyId}'.`);
1549
+ return BotDecisionSchema.parse(strategy.decide(frame));
1550
+ }
1551
+ };
1552
+ }
1553
+
1525
1554
  // src/shared/domain/event-admission.ts
1526
1555
  function assertGameEventReferences(events, table) {
1527
1556
  const roster = new Set(table.playerOrder);
@@ -4275,13 +4304,30 @@ function buildInteractionDescriptor(scope, state, playerId, interactionId, inter
4275
4304
  scope.manifest
4276
4305
  );
4277
4306
  const shouldMaterializeInputDomains = decision.available || decision.code === FrameworkErrorCodes.NO_LEGAL_INPUT;
4278
- const inputs = shouldMaterializeInputDomains ? enrichResourceInputPresentation(
4279
- collectInteractionInputs(projectedInteraction, domainState, playerId, {
4280
- queries,
4281
- definitions: scope.manifest
4282
- }),
4283
- scope.manifest
4284
- ) : [];
4307
+ let inputs = [];
4308
+ if (shouldMaterializeInputDomains) {
4309
+ const cache = options.projection?.inputDomains;
4310
+ let playerInputs = cache?.get(projectedInteraction);
4311
+ const cached = playerInputs?.get(playerId);
4312
+ if (cached) {
4313
+ inputs = cached;
4314
+ } else {
4315
+ inputs = enrichResourceInputPresentation(
4316
+ collectInteractionInputs(projectedInteraction, domainState, playerId, {
4317
+ queries,
4318
+ definitions: scope.manifest
4319
+ }),
4320
+ scope.manifest
4321
+ );
4322
+ if (cache) {
4323
+ if (!playerInputs) {
4324
+ playerInputs = /* @__PURE__ */ new Map();
4325
+ cache.set(projectedInteraction, playerInputs);
4326
+ }
4327
+ playerInputs.set(playerId, inputs);
4328
+ }
4329
+ }
4330
+ }
4285
4331
  const baseDescriptor = {
4286
4332
  phaseName,
4287
4333
  interactionKey: `${phaseName}.${interactionId}`,
@@ -6496,7 +6542,8 @@ function createProjectionContext(options) {
6496
6542
  const q = createStateQueries(options.domainState, options.definitions);
6497
6543
  return {
6498
6544
  domainState: options.domainState,
6499
- q
6545
+ q,
6546
+ inputDomains: /* @__PURE__ */ new WeakMap()
6500
6547
  };
6501
6548
  }
6502
6549
 
@@ -7105,6 +7152,7 @@ function createReducerBundle(definition, options = {}) {
7105
7152
  const projection = createProjectionBuilder(scope, interactions);
7106
7153
  let submissionCounter = 0;
7107
7154
  return {
7155
+ ...createBotCapability(options.botStrategies),
7108
7156
  reducerContractVersion: REDUCER_CONTRACT_VERSION,
7109
7157
  async initialize({ table, playerIds, rngSeed, options: options2 }) {
7110
7158
  const parsed = codec.parseInitialTable(table, playerIds);
@@ -7222,4 +7270,4 @@ export {
7222
7270
  createProjectionBuilder,
7223
7271
  createReducerBundle
7224
7272
  };
7225
- //# sourceMappingURL=chunk-63GWNBZX.js.map
7273
+ //# sourceMappingURL=chunk-KYQQIFXN.js.map