@polycode-projects/the-mechanical-code-talker 5.0.30 → 5.0.31

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.
@@ -156,15 +156,26 @@ export function routeBetweenCells(factRows, fromCell, toCell) {
156
156
  *
157
157
  * `getTeachEnabled` is read fresh on every turn, so a visitor can tick the
158
158
  * page's teach box mid-session and have the very next line read as a fact to
159
- * store rather than a command to run. */
159
+ * store rather than a command to run.
160
+ *
161
+ * A world `layoutNamed` holds no layout for — the river-crossing puzzle,
162
+ * PLAN_RIVER_CROSSING.md's R6 — is not a town square: it has no grid, no
163
+ * roster and no chase, only a fixed cast of passengers the world's own facts
164
+ * already place. This session still opens the store and answers
165
+ * `outlook`/`applyEdit`/`applyAgentEdit` for it, the same way it does for a
166
+ * square; `tick`, `driveAgent`, `recast` and `board` never get anything real
167
+ * to do without a layout, so they answer with the same "nothing moved" shape
168
+ * a resting board would rather than throwing — the page simply never wires
169
+ * its play/step/drive controls to a puzzle scenario (see mudiii-viz.mjs's
170
+ * `puzzle` flag). */
160
171
  export async function createMudiiiSession(
161
172
  worldPayload, { agents = [], epoch = 0, getTeachEnabled = () => false } = {},
162
173
  ) {
163
- // Every engine call is layout-scoped: the world pack ships the BOARD, and
164
- // the layout carries the geometry plus the cast counts the engine mints the
165
- // animals from. Resolved once here so no call site has to remember it.
174
+ // Every engine call for a chase board is layout-scoped: the world pack
175
+ // ships the BOARD, and the layout carries the geometry plus the cast counts
176
+ // the engine mints the animals from. Resolved once here so no call site has
177
+ // to remember it. Null for a puzzle world (see the header above).
166
178
  const layout = layoutNamed(worldPayload.name);
167
- if (!layout) throw new Error(`createMudiiiSession: no town-square layout named "${worldPayload.name}"`);
168
179
 
169
180
  const memoryDir = createInMemoryStore();
170
181
  const tag = worldProvenanceTag(worldPayload.name);
@@ -174,9 +185,11 @@ export async function createMudiiiSession(
174
185
  for (const rule of worldPayload.rules || []) {
175
186
  await appendRule(memoryDir, { name: rule.name, kind: rule.ruleKind, slots: rule.slots, provenance: tag });
176
187
  }
177
- await startTownSquareGame(memoryDir, {
178
- layout, epoch, ...townSquareRosterArgs(agents, (id) => roleOfId(id)),
179
- });
188
+ if (layout) {
189
+ await startTownSquareGame(memoryDir, {
190
+ layout, epoch, ...townSquareRosterArgs(agents, (id) => roleOfId(id)),
191
+ });
192
+ }
180
193
 
181
194
  // The slot holds one game at a time, and the lane a line reaches is decided
182
195
  // by which key is in it. This session's world is a town square, so the slot
@@ -208,11 +221,20 @@ export async function createMudiiiSession(
208
221
  },
209
222
  });
210
223
 
224
+ /** The empty tick/board payload a layout-less puzzle world answers with:
225
+ * nothing minted, nothing moved, nothing to show that a resting board's
226
+ * own shape does not already say plainly. */
227
+ const emptyBoardPayload = () => ({
228
+ turn: 0, epoch: 0, agents: {}, items: {}, ecology: [], rungs: {}, activeWebs: [],
229
+ });
230
+
211
231
  /** ONE whole-world step (`runTownSquareTick`) — every live agent moves,
212
232
  * the ecology pass runs, and the result names what happened this turn.
213
233
  * The engine counts the turns; the result's own `turn` is what a page
214
- * displays. */
234
+ * displays. A puzzle world has no roster to move, so this is a no-op for
235
+ * one: the page never wires its play/step controls to such a scenario. */
215
236
  async function tick() {
237
+ if (!layout) return emptyBoardPayload();
216
238
  return runTownSquareTick(memoryDir, { layout });
217
239
  }
218
240
 
@@ -228,6 +250,7 @@ export async function createMudiiiSession(
228
250
  * the board — still advances the world, and that agent decides for itself
229
251
  * this turn rather than freezing. */
230
252
  async function driveAgent(agentId, direction) {
253
+ if (!layout) return { ...emptyBoardPayload(), driven: { agent: agentId, direction: String(direction ?? ""), accepted: false, from: null, cell: null, facing: null } };
231
254
  const state = foldTownSquareState(readFactRows(await loadMemory(memoryDir)));
232
255
  const standing = state.removed.has(agentId) ? null : state.placements.get(agentId);
233
256
  const facing = state.facing.get(agentId)?.value ?? DEFAULT_FACING;
@@ -260,6 +283,7 @@ export async function createMudiiiSession(
260
283
  * `agents` sizes the new cast the same way `createMudiiiSession`'s own
261
284
  * roster does; `epoch` defaults to one past whatever the store is on. */
262
285
  async function recast({ agents: nextAgents = [], epoch: nextEpoch = null } = {}) {
286
+ if (!layout) return emptyBoardPayload();
263
287
  await recastTownSquare(memoryDir, {
264
288
  layout, epoch: nextEpoch, ...townSquareRosterArgs(nextAgents, (id) => roleOfId(id)),
265
289
  });
@@ -270,8 +294,11 @@ export async function createMudiiiSession(
270
294
  * turn spent. A page opens a session and then draws THIS — otherwise its
271
295
  * first sight of where anything stands is the first tick, and every mesh
272
296
  * sits unplaced until the visitor presses play. `ecology` is empty and
273
- * `turn` is the last tick played (0 on a fresh board). */
297
+ * `turn` is the last tick played (0 on a fresh board). A puzzle world has
298
+ * no roster, so this is the same empty shape `tick` answers with — the
299
+ * page reads its passengers straight off the world's own facts instead. */
274
300
  async function board() {
301
+ if (!layout) return emptyBoardPayload();
275
302
  return townSquareBoard(memoryDir, { layout });
276
303
  }
277
304
 
@@ -286,9 +313,11 @@ export async function createMudiiiSession(
286
313
  * belief map and plan, computed from the store as it stands, with no turn
287
314
  * spent and no write — see agentOutlook (mudiii-turn.mjs). The page calls
288
315
  * this on boot and after every edit, world or actor, so both panels
289
- * recompute live without a tick ever running. */
316
+ * recompute live without a tick ever running. A puzzle world passes no
317
+ * layout: agentOutlook then answers `agents: {}` and still computes
318
+ * `puzzle`, which is the only field a scenario with no roster ever had. */
290
319
  async function outlook() {
291
- return agentOutlook(memoryDir, { layout });
320
+ return agentOutlook(memoryDir, layout ? { layout } : {});
292
321
  }
293
322
 
294
323
  /** The world editor's own store sync, reusing mud-editor.mjs UNCHANGED —
@@ -314,8 +343,11 @@ export async function createMudiiiSession(
314
343
 
315
344
  /** Places one player-placed food item, with player provenance rather than
316
345
  * the world tag — the same "who put that there?" grounding
317
- * test/fixtures/mudiii-ticks.json's turn-8 `place-food` event names. */
346
+ * test/fixtures/mudiii-ticks.json's turn-8 `place-food` event names.
347
+ * Nothing to place on a board with no grid, so a puzzle world refuses
348
+ * rather than reaching into a layout that is not there. */
318
349
  async function placeFood(opts) {
350
+ if (!layout) return { placed: false };
319
351
  return engPlaceFood(memoryDir, { layout, ...opts });
320
352
  }
321
353