@polycode-projects/the-mechanical-code-talker 5.0.35 → 5.0.36

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
- // mudiii-scene.mjs — the town square's own three.js scene, reached from
1
+ // mudiii-scene.mjs — the three.js scene behind mudiii.html, drawing whichever
2
+ // world the page has open: a town square, or the river the crossing puzzle is
3
+ // played on. Reached from
2
4
  // mudiii-viz.mjs (the page shell) through exactly one frozen function:
3
5
  // `mudiiiSceneScript(opts) -> string`, a standalone inline <script> the page
4
6
  // embeds next to its own (see mudiii-viz.mjs's own header on the split: two
@@ -31,6 +33,17 @@
31
33
  // test/fixtures/mudiii-ticks.json's own _readme.tickPayload
32
34
  // documents (agents/items keyed by id, ecology a tagged-union
33
35
  // array).
36
+ // .bootRiver({ passengers, assetManifest, agentPresentation }) in
37
+ // boot()'s place for a scenario with no grid: the ground and the grid
38
+ // helper give way to two banks, water, a boat and one labelled figure
39
+ // per passenger. Returns false when three.js could not be vendored,
40
+ // which is the page shell's cue to show its own flat crossing board.
41
+ // .applyRiver({ banks, position, aboard, boatPlace, crossingMs }) per
42
+ // crossing, in applyTick's place — every field read off the plan the
43
+ // page is playing, so nothing about a move is decided here either.
44
+ // .riverSnapshot() — read-only, where every passenger and the boat now
45
+ // stand in world units, for an e2e assertion on a canvas whose pixels
46
+ // cannot be read.
34
47
  // .setCamera({ mode, selectedId }) whenever the page's own camera
35
48
  // state changes — a mode button, the agent-select dropdown, or a
36
49
  // nextCameraSelection fallback the page shell already computes and
@@ -605,6 +618,9 @@ export function mudiiiSceneScript({ canvasId, statusId, gridSize, cellSize } = {
605
618
  // orbited keeps the view they made: pulling it back to the board's centre
606
619
  // would undo their own gesture.
607
620
  function refitOverheadCamera() {
621
+ // The crossing's own rig frames a river, not a board, so a resize leaves
622
+ // it where it is rather than pulling it back to a grid that is not there.
623
+ if (riverMode) return;
608
624
  if (!cameraRigged || cameraState.mode !== "overhead" || overheadOrbited) return;
609
625
  var rig = cameraRigFor("overhead", null, GRID_SIZE, cameraView());
610
626
  if (rig) tweenCameraToRig(rig, performance.now());
@@ -1024,6 +1040,301 @@ export function mudiiiSceneScript({ canvasId, statusId, gridSize, cellSize } = {
1024
1040
  }
1025
1041
  }
1026
1042
 
1043
+ // ---- the crossing, on this same stage -------------------------------------
1044
+ // A puzzle world has no grid to walk, so the ground plane and the grid helper
1045
+ // give way to two banks with water between them, a boat, and one labelled
1046
+ // figure per passenger. Nothing here decides a move: applyRiver draws the
1047
+ // position the page hands it, and the page reads that off the plan the
1048
+ // planner already found.
1049
+ var RIVER_BANK_X = 4.6;
1050
+ var RIVER_BANK_WIDTH = 4.4;
1051
+ var RIVER_BANK_DEPTH = 9;
1052
+ var RIVER_WATER_WIDTH = 5;
1053
+ var RIVER_BOAT_X = 2.05;
1054
+ var RIVER_BANK_SPACING = 1.15;
1055
+ var RIVER_SEAT_SPACING = 0.62;
1056
+ var RIVER_DECK_Y = 0.24;
1057
+ // Each kind's own silhouette and colour, used for a passenger the asset
1058
+ // manifest carries no model for. A kind the manifest DOES carry (the fox)
1059
+ // loads its real GLB through the same loader the chase agents use, so the
1060
+ // crossing reuses those meshes rather than drawing a second fox of its own.
1061
+ var RIVER_FIGURES = {
1062
+ farmer: { color: 0xC9A227, height: 0.95, shape: "person" },
1063
+ goat: { color: 0xE3DCCB, height: 0.62, shape: "beast" },
1064
+ fox: { color: 0xC8622B, height: 0.55, shape: "beast" },
1065
+ cabbage: { color: 0x6F9E3F, height: 0.42, shape: "orb" },
1066
+ };
1067
+ var riverMode = false;
1068
+ var riverStageParts = [];
1069
+ var riverBoatGroup = null;
1070
+ var riverBoatTween = null;
1071
+ var riverBoatSide = "near";
1072
+ var riverPassengers = {};
1073
+ var riverBankNames = ["", ""];
1074
+
1075
+ // Where the nth of "count" figures stands along the bank, or sits in the
1076
+ // boat: centred on zero, so a bank of one and a bank of four both read as
1077
+ // arranged rather than pushed to an edge.
1078
+ function riverSlotOffset(index, count, spacing) {
1079
+ if (index < 0 || count <= 1) return 0;
1080
+ return (index - (count - 1) / 2) * spacing;
1081
+ }
1082
+
1083
+ function clearRiverStage() {
1084
+ for (var i = 0; i < riverStageParts.length; i += 1) {
1085
+ if (riverStageParts[i].parent) riverStageParts[i].parent.remove(riverStageParts[i]);
1086
+ }
1087
+ riverStageParts = [];
1088
+ for (var id in riverPassengers) {
1089
+ if (riverPassengers[id].group.parent) riverPassengers[id].group.parent.remove(riverPassengers[id].group);
1090
+ }
1091
+ riverPassengers = {};
1092
+ if (riverBoatGroup && riverBoatGroup.parent) riverBoatGroup.parent.remove(riverBoatGroup);
1093
+ riverBoatGroup = null;
1094
+ riverBoatTween = null;
1095
+ riverBankNames = ["", ""];
1096
+ riverMode = false;
1097
+ }
1098
+
1099
+ function buildRiverStage() {
1100
+ if (groundMesh) {
1101
+ scene.remove(groundMesh);
1102
+ groundMesh.geometry.dispose();
1103
+ groundMesh.material.dispose();
1104
+ groundMesh = null;
1105
+ }
1106
+ var grid = scene.getObjectByName("townSquareGrid");
1107
+ if (grid) scene.remove(grid);
1108
+ var turf = new THREE.MeshStandardMaterial({ color: 0x7c9a5b });
1109
+ var sides = [["river-bank-near", -RIVER_BANK_X], ["river-bank-far", RIVER_BANK_X]];
1110
+ for (var i = 0; i < sides.length; i += 1) {
1111
+ var slab = new THREE.Mesh(new THREE.BoxGeometry(RIVER_BANK_WIDTH, 0.3, RIVER_BANK_DEPTH), turf);
1112
+ slab.name = sides[i][0];
1113
+ slab.position.set(sides[i][1], -0.15, 0);
1114
+ scene.add(slab);
1115
+ riverStageParts.push(slab);
1116
+ }
1117
+ var water = new THREE.Mesh(
1118
+ new THREE.PlaneGeometry(RIVER_WATER_WIDTH, RIVER_BANK_DEPTH),
1119
+ new THREE.MeshStandardMaterial({ color: 0x2F6F96, transparent: true, opacity: 0.92 }),
1120
+ );
1121
+ water.name = "river-water";
1122
+ water.rotation.x = -Math.PI / 2;
1123
+ water.position.set(0, -0.12, 0);
1124
+ scene.add(water);
1125
+ riverStageParts.push(water);
1126
+ }
1127
+
1128
+ function buildRiverBoat() {
1129
+ var group = new THREE.Group();
1130
+ group.name = "river-boat";
1131
+ var timber = new THREE.MeshStandardMaterial({ color: 0x8A5A2B });
1132
+ var hull = new THREE.Mesh(new THREE.BoxGeometry(1.5, 0.22, 2.5), timber);
1133
+ hull.position.y = 0.11;
1134
+ group.add(hull);
1135
+ var gunwale = new THREE.BoxGeometry(0.12, 0.32, 2.5);
1136
+ var offsets = [-0.69, 0.69];
1137
+ for (var i = 0; i < offsets.length; i += 1) {
1138
+ var side = new THREE.Mesh(gunwale, timber);
1139
+ side.position.set(offsets[i], 0.3, 0);
1140
+ group.add(side);
1141
+ }
1142
+ var label = makeAgentLabel("boat", 0.55);
1143
+ label.name = "label-boat";
1144
+ group.add(label);
1145
+ group.position.set(-RIVER_BOAT_X, -0.02, 0);
1146
+ scene.add(group);
1147
+ return group;
1148
+ }
1149
+
1150
+ function buildRiverFigure(kind) {
1151
+ var spec = RIVER_FIGURES[kind] || { color: 0xB0A48A, height: 0.7, shape: "person" };
1152
+ var material = new THREE.MeshStandardMaterial({ color: spec.color });
1153
+ var group = new THREE.Group();
1154
+ group.name = "figure-" + kind;
1155
+ if (spec.shape === "orb") {
1156
+ var orb = new THREE.Mesh(new THREE.SphereGeometry(spec.height / 2, 18, 14), material);
1157
+ orb.position.y = spec.height / 2;
1158
+ group.add(orb);
1159
+ return group;
1160
+ }
1161
+ if (spec.shape === "beast") {
1162
+ var body = new THREE.Mesh(new THREE.BoxGeometry(0.34, spec.height * 0.45, 0.8), material);
1163
+ body.position.y = spec.height * 0.62;
1164
+ group.add(body);
1165
+ var head = new THREE.Mesh(new THREE.BoxGeometry(0.26, spec.height * 0.3, 0.3), material);
1166
+ head.position.set(0, spec.height * 0.82, 0.5);
1167
+ group.add(head);
1168
+ var legGeometry = new THREE.BoxGeometry(0.1, spec.height * 0.42, 0.1);
1169
+ var feet = [[-0.12, 0.3], [0.12, 0.3], [-0.12, -0.3], [0.12, -0.3]];
1170
+ for (var f = 0; f < feet.length; f += 1) {
1171
+ var leg = new THREE.Mesh(legGeometry, material);
1172
+ leg.position.set(feet[f][0], spec.height * 0.21, feet[f][1]);
1173
+ group.add(leg);
1174
+ }
1175
+ return group;
1176
+ }
1177
+ var torso = new THREE.Mesh(new THREE.CylinderGeometry(0.17, 0.21, spec.height * 0.62, 14), material);
1178
+ torso.position.y = spec.height * 0.42;
1179
+ group.add(torso);
1180
+ var crown = new THREE.Mesh(new THREE.SphereGeometry(0.16, 16, 12), material);
1181
+ crown.position.y = spec.height * 0.85;
1182
+ group.add(crown);
1183
+ return group;
1184
+ }
1185
+
1186
+ function ensureRiverPassenger(id) {
1187
+ if (riverPassengers[id]) return riverPassengers[id];
1188
+ var kind = roleOfAgentId(id);
1189
+ var pres = presentationFor(id, kind);
1190
+ var group = new THREE.Group();
1191
+ group.name = "passenger-" + id;
1192
+ // Held back until applyRiver says which bank it stands on, so nobody is
1193
+ // drawn standing in the middle of the water while the plan is still
1194
+ // being read.
1195
+ group.visible = false;
1196
+ scene.add(group);
1197
+ var entry = {
1198
+ group: group, tween: null, aboard: false, seat: 0, kind: kind, placed: false,
1199
+ label: (pres && pres.label) ? pres.label : id,
1200
+ };
1201
+ riverPassengers[id] = entry;
1202
+ var asset = manifestByKind[(pres && pres.model) || kind];
1203
+ var figureHeight = RIVER_FIGURES[kind] ? RIVER_FIGURES[kind].height : 0.7;
1204
+ group.add(makeAgentLabel(entry.label, asset ? asset.targetHeight : figureHeight));
1205
+ if (!asset) {
1206
+ group.add(buildRiverFigure(kind));
1207
+ return entry;
1208
+ }
1209
+ loadGlbRaw(modelUrlFor(asset.destPath)).then(function (gltf) {
1210
+ if (riverPassengers[id] !== entry) return;
1211
+ normalizeToHeight(gltf.scene, asset.targetHeight);
1212
+ group.add(gltf.scene);
1213
+ }).catch(function (err) {
1214
+ // eslint-disable-next-line no-console
1215
+ console.warn("tmct: a passenger model failed to load", id, err);
1216
+ if (riverPassengers[id] === entry) group.add(buildRiverFigure(kind));
1217
+ });
1218
+ return entry;
1219
+ }
1220
+
1221
+ function nameRiverBank(slot, name) {
1222
+ if (riverBankNames[slot] === name) return;
1223
+ riverBankNames[slot] = name;
1224
+ var existing = scene.getObjectByName("river-bank-label-" + slot);
1225
+ if (existing && existing.parent) existing.parent.remove(existing);
1226
+ if (!name) return;
1227
+ var sprite = makeAgentLabel(name, 1.5);
1228
+ sprite.name = "river-bank-label-" + slot;
1229
+ sprite.position.set(slot === 1 ? RIVER_BANK_X : -RIVER_BANK_X, 1.8, -RIVER_BANK_DEPTH / 2 + 0.7);
1230
+ scene.add(sprite);
1231
+ riverStageParts.push(sprite);
1232
+ }
1233
+
1234
+ // Draw one position of the crossing. "state" is { banks: [near, far],
1235
+ // position: { id: place }, aboard: [ids], boatPlace, crossingMs } — every
1236
+ // field read straight off the plan the page is playing.
1237
+ function applyRiver(state) {
1238
+ if (!riverMode || !scene) return;
1239
+ var banks = (state && state.banks) || [];
1240
+ nameRiverBank(0, banks[0] || "");
1241
+ nameRiverBank(1, banks[1] || "");
1242
+ var position = (state && state.position) || {};
1243
+ var aboardList = (state && state.aboard) || [];
1244
+ var aboard = {};
1245
+ for (var a = 0; a < aboardList.length; a += 1) aboard[aboardList[a]] = true;
1246
+ var ids = Object.keys(position).sort();
1247
+ var standing = {};
1248
+ for (var s = 0; s < ids.length; s += 1) {
1249
+ if (aboard[ids[s]]) continue;
1250
+ var place = position[ids[s]];
1251
+ if (!standing[place]) standing[place] = [];
1252
+ standing[place].push(ids[s]);
1253
+ }
1254
+ var now = performance.now();
1255
+ for (var i = 0; i < ids.length; i += 1) {
1256
+ var id = ids[i];
1257
+ var entry = ensureRiverPassenger(id);
1258
+ entry.aboard = Boolean(aboard[id]);
1259
+ entry.group.visible = true;
1260
+ if (entry.aboard) {
1261
+ entry.seat = riverSlotOffset(aboardList.indexOf(id), aboardList.length, RIVER_SEAT_SPACING);
1262
+ entry.tween = null;
1263
+ entry.placed = true;
1264
+ continue;
1265
+ }
1266
+ var onFarBank = banks.indexOf(position[id]) === 1;
1267
+ var neighbours = standing[position[id]] || [];
1268
+ var target = {
1269
+ x: onFarBank ? RIVER_BANK_X : -RIVER_BANK_X,
1270
+ z: riverSlotOffset(neighbours.indexOf(id), neighbours.length, RIVER_BANK_SPACING),
1271
+ };
1272
+ if (entry.placed) {
1273
+ entry.tween = startTween(
1274
+ { x: entry.group.position.x, z: entry.group.position.z }, target, now, tweenDurationMs,
1275
+ );
1276
+ } else {
1277
+ entry.group.position.set(target.x, 0, target.z);
1278
+ entry.tween = null;
1279
+ entry.placed = true;
1280
+ }
1281
+ entry.group.rotation.y = onFarBank ? Math.PI : 0;
1282
+ }
1283
+ var boatIsFar = (state && state.boatPlace) === banks[1];
1284
+ riverBoatSide = aboardList.length ? "crossing" : (boatIsFar ? "far" : "near");
1285
+ if (!riverBoatGroup) return;
1286
+ var boatX = boatIsFar ? RIVER_BOAT_X : -RIVER_BOAT_X;
1287
+ if (Math.abs(riverBoatGroup.position.x - boatX) < 0.001) {
1288
+ riverBoatTween = null;
1289
+ return;
1290
+ }
1291
+ var crossingMs = Number(state && state.crossingMs) || tweenDurationMs;
1292
+ riverBoatTween = startTween(
1293
+ { x: riverBoatGroup.position.x }, { x: boatX }, now,
1294
+ reduced ? 0 : (aboardList.length ? crossingMs : tweenDurationMs),
1295
+ );
1296
+ }
1297
+
1298
+ function stepRiverFrame(ts) {
1299
+ if (riverBoatTween && riverBoatGroup) {
1300
+ var boatPoint = tweenStep(riverBoatTween, ts);
1301
+ riverBoatGroup.position.x = boatPoint.x;
1302
+ if (boatPoint.done) riverBoatTween = null;
1303
+ }
1304
+ for (var id in riverPassengers) {
1305
+ var entry = riverPassengers[id];
1306
+ if (entry.aboard) {
1307
+ if (riverBoatGroup) entry.group.position.set(riverBoatGroup.position.x, RIVER_DECK_Y, entry.seat);
1308
+ continue;
1309
+ }
1310
+ if (!entry.tween) continue;
1311
+ var point = tweenStep(entry.tween, ts);
1312
+ entry.group.position.set(point.x, 0, point.z);
1313
+ if (point.done) entry.tween = null;
1314
+ }
1315
+ }
1316
+
1317
+ // A crossing is watched from one fixed three-quarter view of the whole
1318
+ // river; there is no agent to ride and no board to fit, so this rigs the
1319
+ // camera directly rather than asking cameraRigFor for a grid rig.
1320
+ function rigRiverCamera() {
1321
+ cameraState = { mode: "overhead", selectedId: null };
1322
+ cameraRigged = true;
1323
+ overheadOrbited = false;
1324
+ lookOffset.yaw = 0;
1325
+ lookOffset.pitch = 0;
1326
+ cameraTween = null;
1327
+ lookAtTween = null;
1328
+ lookTarget = { x: 0, y: 0, z: 0 };
1329
+ if (!camera3) return;
1330
+ camera3.position.set(0, 7.2, 11);
1331
+ camera3.lookAt(0, 0, 0);
1332
+ if (!orbitControls) return;
1333
+ orbitControls.target.set(0, 0, 0);
1334
+ orbitControls.enabled = true;
1335
+ orbitControls.update();
1336
+ }
1337
+
1027
1338
  // ---- the clicked cell, and the route to it --------------------------------
1028
1339
  // The line follows the cells the world's own exit search returned, never a
1029
1340
  // straight segment from agent to target: a straight one cuts through
@@ -1103,6 +1414,10 @@ export function mudiiiSceneScript({ canvasId, statusId, gridSize, cellSize } = {
1103
1414
  // made. Tracking the agent as it moves is refreshCameraTween's job below,
1104
1415
  // which leaves the visitor's own look alone.
1105
1416
  function setCamera(state) {
1417
+ // A crossing has no agent to follow and no board to fit. The page still
1418
+ // pushes its own camera state after a chat turn, so this holds the river
1419
+ // rig rather than cutting to a grid overhead of an empty floor.
1420
+ if (riverMode) return;
1106
1421
  var next = { mode: (state && state.mode) || "overhead", selectedId: (state && state.selectedId) || null };
1107
1422
  var changed = !cameraRigged || next.mode !== cameraState.mode || next.selectedId !== cameraState.selectedId;
1108
1423
  cameraState = next;
@@ -1142,12 +1457,7 @@ export function mudiiiSceneScript({ canvasId, statusId, gridSize, cellSize } = {
1142
1457
  return byKind;
1143
1458
  }
1144
1459
 
1145
- async function boot(input) {
1146
- var ok = await ensureThree();
1147
- if (!ok) return;
1148
- if (input && input.gridSize) { GRID_SIZE = Number(input.gridSize) || GRID_SIZE; }
1149
- if (input && input.cellSize) { CELL_SIZE = Number(input.cellSize) || CELL_SIZE; }
1150
- rebuildGround();
1460
+ function clearLiveMeshes() {
1151
1461
  for (var id in agentGroups) if (agentGroups[id].group.parent) agentGroups[id].group.parent.remove(agentGroups[id].group);
1152
1462
  agentGroups = {};
1153
1463
  for (var itemId in itemMeshes) if (itemMeshes[itemId].mesh.parent) itemMeshes[itemId].mesh.parent.remove(itemMeshes[itemId].mesh);
@@ -1158,6 +1468,16 @@ export function mudiiiSceneScript({ canvasId, statusId, gridSize, cellSize } = {
1158
1468
  clearRoute();
1159
1469
  clearFlash();
1160
1470
  removalLog = [];
1471
+ }
1472
+
1473
+ async function boot(input) {
1474
+ var ok = await ensureThree();
1475
+ if (!ok) return;
1476
+ clearRiverStage();
1477
+ if (input && input.gridSize) { GRID_SIZE = Number(input.gridSize) || GRID_SIZE; }
1478
+ if (input && input.cellSize) { CELL_SIZE = Number(input.cellSize) || CELL_SIZE; }
1479
+ rebuildGround();
1480
+ clearLiveMeshes();
1161
1481
  manifestByKind = buildManifestByKind(input && input.assetManifest);
1162
1482
  agentPresentation = (input && input.agentPresentation) || null;
1163
1483
  await placeProps((input && input.propPlacements) || []);
@@ -1168,8 +1488,30 @@ export function mudiiiSceneScript({ canvasId, statusId, gridSize, cellSize } = {
1168
1488
  booted = true;
1169
1489
  }
1170
1490
 
1491
+ /** The crossing's own boot, in place of a town square's. Returns true when
1492
+ * the stage is standing, false when three.js could not be vendored at all —
1493
+ * the page keeps its own flat crossing board for that second case. */
1494
+ async function bootRiver(input) {
1495
+ var ok = await ensureThree();
1496
+ if (!ok) return false;
1497
+ clearRiverStage();
1498
+ clearLiveMeshes();
1499
+ await placeProps([]);
1500
+ manifestByKind = buildManifestByKind(input && input.assetManifest);
1501
+ agentPresentation = (input && input.agentPresentation) || null;
1502
+ buildRiverStage();
1503
+ riverBoatGroup = buildRiverBoat();
1504
+ riverMode = true;
1505
+ var passengers = (input && input.passengers) || [];
1506
+ for (var i = 0; i < passengers.length; i += 1) ensureRiverPassenger(passengers[i]);
1507
+ drag = null;
1508
+ rigRiverCamera();
1509
+ booted = true;
1510
+ return true;
1511
+ }
1512
+
1171
1513
  function applyTick(tick) {
1172
- if (!scene) return;
1514
+ if (!scene || riverMode) return;
1173
1515
  var now = performance.now();
1174
1516
  var agents = (tick && tick.agents) || {};
1175
1517
  var items = (tick && tick.items) || {};
@@ -1204,6 +1546,7 @@ export function mudiiiSceneScript({ canvasId, statusId, gridSize, cellSize } = {
1204
1546
  }
1205
1547
  if (entry.mixer) entry.mixer.update(deltaSec);
1206
1548
  }
1549
+ if (riverMode) stepRiverFrame(ts);
1207
1550
  if (flashMesh) {
1208
1551
  var flashLeft = flashUntil - performance.now();
1209
1552
  if (flashLeft <= 0) clearFlash();
@@ -1238,6 +1581,25 @@ export function mudiiiSceneScript({ canvasId, statusId, gridSize, cellSize } = {
1238
1581
 
1239
1582
  window.mudiiiScene = {
1240
1583
  boot: boot,
1584
+ bootRiver: bootRiver,
1585
+ applyRiver: applyRiver,
1586
+ // Where the crossing currently stands, in world units — an e2e
1587
+ // assertion's read, because a software renderer's canvas pixels say
1588
+ // nothing about which bank a passenger is on. Null off a puzzle scenario.
1589
+ riverSnapshot: function () {
1590
+ if (!riverMode) return null;
1591
+ var out = { banks: riverBankNames.slice(), boat: null, passengers: {} };
1592
+ if (riverBoatGroup) out.boat = { x: riverBoatGroup.position.x, side: riverBoatSide };
1593
+ for (var id in riverPassengers) {
1594
+ var entry = riverPassengers[id];
1595
+ out.passengers[id] = {
1596
+ x: entry.group.position.x, z: entry.group.position.z, aboard: entry.aboard,
1597
+ label: entry.label, kind: entry.kind, parts: entry.group.children.length,
1598
+ visible: entry.group.visible,
1599
+ };
1600
+ }
1601
+ return out;
1602
+ },
1241
1603
  applyTick: applyTick,
1242
1604
  setCamera: setCamera,
1243
1605
  flashCell: flashCell,
@@ -55,8 +55,20 @@ const MUDIII_MARKET_OPEN_RE =
55
55
  /^(?:let'?s\s+)?(?:visit|watch|enter|start|begin)\s+(?:the\s+)?market\s+(?:square|day)(?:\s+game)?[.!?\s]*$/i;
56
56
  const MUDIII_CHAPEL_OPEN_RE =
57
57
  /^(?:let'?s\s+)?(?:visit|watch|enter|start|begin)\s+(?:the\s+)?chapel\s+corner(?:\s+game)?[.!?\s]*$/i;
58
-
59
- /** The layout name an opening line names, or null when the line opens
58
+ // The one puzzle world this lane opens. Same closed style as the three
59
+ // layouts above, with "open" and "solve" alongside the shared verb set —
60
+ // a crossing is something you open and solve, not somewhere you visit.
61
+ const MUDIII_RIVER_OPEN_RE =
62
+ /^(?:let'?s\s+)?(?:visit|watch|enter|start|begin|open|solve)\s+(?:the\s+)?river(?:\s+crossing)?(?:\s+(?:puzzle|game))?[.!?\s]*$/i;
63
+
64
+ // A world the pack ships with no grid layout: a fixed cast on named places,
65
+ // with no roster to mint and nothing that moves on its own. Closed, like
66
+ // every other vocabulary here — a world name absent from both this set and
67
+ // TOWN_SQUARE_LAYOUTS is one this lane does not know.
68
+ const PUZZLE_WORLDS = Object.freeze(new Set(["river-crossing"]));
69
+ const isPuzzleWorld = (world) => PUZZLE_WORLDS.has(world);
70
+
71
+ /** The world name an opening line names, or null when the line opens
60
72
  * nothing this lane recognizes. Shape-only, closed vocabulary — never a
61
73
  * generic "play X" grammar, so a name this pack does not ship (e.g. "play
62
74
  * mudiii") stays unclaimed and falls to chat's own last-resort honest
@@ -66,6 +78,7 @@ function matchMudiiiOpening(line) {
66
78
  if (MUDIII_HEADLINE_OPEN_RE.test(l) || MUDIII_FOX_GOBLIN_OPEN_RE.test(l)) return "town-square";
67
79
  if (MUDIII_MARKET_OPEN_RE.test(l)) return "town-square-market";
68
80
  if (MUDIII_CHAPEL_OPEN_RE.test(l)) return "town-square-chapel";
81
+ if (MUDIII_RIVER_OPEN_RE.test(l)) return "river-crossing";
69
82
  return null;
70
83
  }
71
84
 
@@ -161,6 +174,17 @@ async function openMudiiiGame(world, { planHolder, memoryDir, env, cache, gameCo
161
174
  if (cache) cache.rows = null; // the fact-rows cache predates these writes
162
175
 
163
176
  const layout = layoutNamed(world) ?? TOWN_SQUARE_LAYOUTS[world];
177
+ if (!layout) {
178
+ planHolder.state = { mudiii: { world, turn: 0 } };
179
+ const rows = readFactRows(await loadMemory(memoryDir));
180
+ const opening = payload.meta?.opening ?? WORLD_OPENING_FALLBACK;
181
+ return {
182
+ text: [opening, ...standingLines(rows)].join("\n"),
183
+ goal: "ferry every passenger across the river",
184
+ lane: "game-inform",
185
+ note: `MUDIII — loaded the "${world}" puzzle from the worlds pack into this session's memory (facts + rule rows, provenance ${tag}); no layout, so no cast was minted`,
186
+ };
187
+ }
164
188
  const { started } = await startTownSquareGame(memoryDir, { layout, config: gameConfig?.mudiii, roles: MUDIII_ROLES });
165
189
  planHolder.state = { mudiii: { world, turn: 0 } };
166
190
  const opener = started
@@ -1061,6 +1085,157 @@ async function mudiiiContextAnswer(line, { memoryDir }) {
1061
1085
  return { text: GENERIC_GOAL_TEXT, lane: "game-inform", note: "MUDIII — goal aside: the game's predator/prey/forage objective", goal: "understand the game" };
1062
1086
  }
1063
1087
 
1088
+ // ---- the layout-less puzzle world -------------------------------------------
1089
+ //
1090
+ // A puzzle world ships a fixed party standing on named places, with no grid,
1091
+ // no roster to mint and nothing that moves on its own. The square's own verbs
1092
+ // (tick, the addressed teach-frame, the food channel) have nothing to act on
1093
+ // here, so they decline by name; the orientation asides answer from the
1094
+ // world's own rows and the crossing plan riverPuzzleOutlook already computes.
1095
+
1096
+ const PLACE_PREDICATE = "mgx:currently-in";
1097
+ const PUZZLE_WHERE_RE = /^where(?:'s|\s+is)\s+(?:the\s+)?([a-z][a-z0-9-]*)(?:\s+now)?[?.!\s]*$/i;
1098
+
1099
+ /** "on bank-east: cabbage-1, farmer-1, fox-1, goat-1." — one line per place
1100
+ * anything stands in, read off the world's own `mgx:currently-in` rows and
1101
+ * sorted by place then by individual, so the same fact set reads back the
1102
+ * same way whatever order it arrived in. Empty when nothing is placed. Pure. */
1103
+ function standingLines(rows) {
1104
+ const byPlace = new Map();
1105
+ for (const row of rows || []) {
1106
+ if (row.predicate !== PLACE_PREDICATE) continue;
1107
+ if (!byPlace.has(row.object)) byPlace.set(row.object, new Set());
1108
+ byPlace.get(row.object).add(row.subject);
1109
+ }
1110
+ return [...byPlace.keys()].sort()
1111
+ .map((place) => `on ${place}: ${[...byPlace.get(place)].sort().join(", ")}.`);
1112
+ }
1113
+
1114
+ /** The puzzle's objective in one sentence: where the goal wants everyone,
1115
+ * plus the pairs the world's own drive facts say may not be left alone —
1116
+ * `constraintsFromDrives`, the same derivation the crossing search itself
1117
+ * runs, never a hand-written rule sentence. Pure. */
1118
+ function puzzleGoalText(rows, puzzle) {
1119
+ const target = puzzle?.goalPlace
1120
+ ? `ferry every passenger onto ${puzzle.goalPlace}`
1121
+ : "ferry every passenger across";
1122
+ const constraints = constraintsFromDrives(rows)
1123
+ .map((c) => `never leave ${c.left} alone with ${c.right} unless ${c.guard} is there`);
1124
+ return constraints.length ? `${target} — ${constraints.join("; ")}.` : `${target}.`;
1125
+ }
1126
+
1127
+ /** What may cross right now, counted and named from `puzzle.moves`. Null when
1128
+ * the store carries no crossing action for this world at all. Pure. */
1129
+ function legalCrossingsText(puzzle) {
1130
+ if (!puzzle) return null;
1131
+ if (!puzzle.moves.length) return "no crossing is legal from here.";
1132
+ if (puzzle.moves.length === 1) return `one crossing is legal from here: ${puzzle.moves[0]}.`;
1133
+ return `${puzzle.moves.length} crossings are legal from here: ${puzzle.moves.join("; ")}.`;
1134
+ }
1135
+
1136
+ /** "where is the goat" on a puzzle world: the named individual's own place,
1137
+ * or every placed member of the named class. Null when the term names
1138
+ * nothing placed, so an unrelated "where is X" still reaches the ordinary
1139
+ * lanes. Pure. */
1140
+ function puzzleWhereAnswer(rows, term) {
1141
+ const placed = (rows || []).filter((r) => r.predicate === PLACE_PREDICATE);
1142
+ const named = placed.filter((r) => r.subject === term);
1143
+ const hits = named.length
1144
+ ? named
1145
+ : placed.filter((r) => rows.some((t) => t.subject === r.subject && t.predicate === "rdf:type" && t.object === term));
1146
+ if (!hits.length) return null;
1147
+ const lines = hits.map((r) => `${r.subject} is on ${r.object}`).sort();
1148
+ return {
1149
+ text: `${lines.join("; ")}.`,
1150
+ lane: "game-answer",
1151
+ note: `MUDIII — where-aside: ${term}'s place read off the world's own ${PLACE_PREDICATE} rows`,
1152
+ goal: `find the ${term}`,
1153
+ };
1154
+ }
1155
+
1156
+ /** One turn of an open puzzle world. Returns the same
1157
+ * `{ text, lane, note, goal?, miss? }` shape the square's own turns do, or
1158
+ * null when the line is not this lane's to answer (the drive asks and every
1159
+ * ordinary question fall through untouched). */
1160
+ async function puzzleWorldTurn(line, { planHolder, memoryDir, world, openingWorld }) {
1161
+ const trimmed = String(line).trim();
1162
+
1163
+ if (openingWorld) {
1164
+ return {
1165
+ text: `the ${world} puzzle is already open — say "stop watching" to close it first.`,
1166
+ lane: "game-inform",
1167
+ note: "MUDIII — an opening arrived mid-puzzle; declined, the open puzzle stands",
1168
+ };
1169
+ }
1170
+ if (MUDIII_STOP_RE.test(trimmed)) {
1171
+ planHolder.state = null;
1172
+ return {
1173
+ text: `OK — the ${world} puzzle closes here. Everything the world wrote stays remembered; say "open the river crossing" to pick it back up.`,
1174
+ lane: "game-inform",
1175
+ note: "MUDIII — the puzzle closed on request; the world's facts stay in the store",
1176
+ };
1177
+ }
1178
+ if (MUDIII_TICK_RE.test(trimmed)) {
1179
+ return {
1180
+ text: 'nothing here moves on its own — this world changes only when someone is ferried. Say "what can I do" for the crossings that are legal right now.',
1181
+ lane: "game-inform",
1182
+ note: "MUDIII — tick declined: a puzzle world has no roster to advance",
1183
+ };
1184
+ }
1185
+ if (MUDIII_ADDRESS_LEAD_RE.test(trimmed) || MUDIII_PUT_FOOD_RE.test(trimmed) || MUDIII_DROP_FOOD_RE.test(trimmed)) {
1186
+ return {
1187
+ text: `the ${world} puzzle has no grid and nobody to address — it holds a fixed party on named places. Say "what can I do" for the crossings that are legal right now.`,
1188
+ lane: "game-inform",
1189
+ note: "MUDIII — a town-square board verb arrived on a puzzle world; declined rather than answered against nothing",
1190
+ miss: true,
1191
+ };
1192
+ }
1193
+
1194
+ const asksOptions = MUDIII_OPTIONS_RE.test(trimmed);
1195
+ const asksGoal = MUDIII_GOAL_GENERIC_RE.test(trimmed);
1196
+ const asksWhereMe = MUDIII_WHERE_AM_I_RE.test(trimmed);
1197
+ const whereMatch = trimmed.match(PUZZLE_WHERE_RE);
1198
+ if (!asksOptions && !asksGoal && !asksWhereMe && !whereMatch) return null;
1199
+
1200
+ if (asksWhereMe) {
1201
+ return {
1202
+ text: 'you have no piece here — the party is the world\'s own. Say "what can I do" for the crossings that are legal right now.',
1203
+ lane: "game-inform",
1204
+ note: "MUDIII — where-am-I aside: the watcher stance on a puzzle world",
1205
+ goal: "understand your role",
1206
+ };
1207
+ }
1208
+
1209
+ const memory = await loadMemory(memoryDir);
1210
+ const rows = readFactRows(memory);
1211
+ if (whereMatch) return puzzleWhereAnswer(rows, whereMatch[1].toLowerCase());
1212
+
1213
+ const puzzle = riverPuzzleOutlook(rows, readRuleRows(memory));
1214
+ if (asksGoal) {
1215
+ return {
1216
+ text: puzzleGoalText(rows, puzzle),
1217
+ lane: "game-inform",
1218
+ note: "MUDIII — goal aside: the puzzle's own goal place, with the constraints its drive facts imply",
1219
+ goal: "understand the puzzle",
1220
+ };
1221
+ }
1222
+ const legal = legalCrossingsText(puzzle);
1223
+ if (!legal) {
1224
+ return {
1225
+ text: `this store holds no crossing action for the ${world} puzzle, so there is nothing legal to list.`,
1226
+ lane: "game-inform",
1227
+ note: "MUDIII — options declined: the world's own action rules are not in the store",
1228
+ miss: true,
1229
+ };
1230
+ }
1231
+ return {
1232
+ text: `${legal} Say "stop watching" to close it.`,
1233
+ lane: "game-answer",
1234
+ note: "MUDIII — options aside: the crossings legal from the current arrangement",
1235
+ goal: "see what you can do",
1236
+ };
1237
+ }
1238
+
1064
1239
  // ---- the lane ------------------------------------------------------------
1065
1240
 
1066
1241
  /**
@@ -1113,6 +1288,9 @@ export async function mudiiiTurn(line, { planHolder, memoryDir, env, cache = nul
1113
1288
 
1114
1289
  // A game is live.
1115
1290
  const layout = layoutNamed(mudiii.world);
1291
+ if (!layout && isPuzzleWorld(mudiii.world)) {
1292
+ return puzzleWorldTurn(line, { planHolder, memoryDir, world: mudiii.world, openingWorld });
1293
+ }
1116
1294
  if (!layout) {
1117
1295
  planHolder.state = null;
1118
1296
  return {