@hackbuild/agents-views 0.2.9 → 0.2.11
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 +1 -1
- package/dist/yard/scope.js +29 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -176,6 +176,6 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
|
|
|
176
176
|
| `dist/index.js` (main entry, imports external) | 6,346 bytes | 6,663 bytes |
|
|
177
177
|
| `dist/agents-views.iife.js` (single file build) | 6,512 bytes | 6,837 bytes |
|
|
178
178
|
|
|
179
|
-
Measured 2026-
|
|
179
|
+
Measured 2026-12-02 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
|
|
180
180
|
tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
|
|
181
181
|
5 percent from its row.
|
package/dist/yard/scope.js
CHANGED
|
@@ -7,6 +7,7 @@ import * as HGAIT from '@hackbuild/gait';
|
|
|
7
7
|
import * as HTUNE from '@hackbuild/tunables';
|
|
8
8
|
import * as HSENSE from '@hackbuild/senses';
|
|
9
9
|
import * as HDRIVE from '@hackbuild/drives';
|
|
10
|
+
import { wasmBytes as DRIVES_WASM } from '@hackbuild/drives/inline';
|
|
10
11
|
import * as HCAM from '@hackbuild/cameras';
|
|
11
12
|
import * as HWEIGHT from '@hackbuild/weights';
|
|
12
13
|
import * as HBV from '@virgilvox/hackbuild-ui/vanilla';
|
|
@@ -1724,6 +1725,17 @@ function trailDir(p, prev) {
|
|
|
1724
1725
|
}
|
|
1725
1726
|
function puffConc(x, z) { let c = 0; for (const p of puffs) { const s2 = 0.0025 + 0.03 * p.age, dx = x - p.x, dz = z - p.z, d2 = dx * dx + dz * dz; if (d2 < 9 * s2) c += p.m * 0.012 / s2 * Math.exp(-d2 / (2 * s2)); } return c; }
|
|
1726
1727
|
function groundConc(x, z) { const i = tgi(x, z); return i < 0 ? 0 : trail[i] * 0.5; }
|
|
1728
|
+
// what the dog smells where it stands: the stronger of the field under its body and at its nose,
|
|
1729
|
+
// and with `reach` the ground one step around the nose as well, as a sniffing sweep covers. A
|
|
1730
|
+
// chase stops the body about 0.75 m short of the squirrel's trail at its tree (measured), so the
|
|
1731
|
+
// search found that trail on 1 of 6 seeds, and 5 of 6 with the nose and its reach (dog simulator
|
|
1732
|
+
// scenario scent-trail, measured)
|
|
1733
|
+
function smellAt(field, reach = 0) {
|
|
1734
|
+
const n = headWorld(dog.noseL, V3());
|
|
1735
|
+
let m = Math.max(field(dog.pos.x, dog.pos.z), field(n.x, n.z));
|
|
1736
|
+
if (reach) for (let dz = -1; dz <= 1; dz++) for (let dx = -1; dx <= 1; dx++) m = Math.max(m, field(n.x + dx * reach, n.z + dz * reach));
|
|
1737
|
+
return m;
|
|
1738
|
+
}
|
|
1727
1739
|
// scent at a point: the plume model, or the older smooth gaussian field when the layer is off
|
|
1728
1740
|
function scentAt(x, z) {
|
|
1729
1741
|
if (ON('L.plume')) return puffConc(x, z) + groundConc(x, z);
|
|
@@ -1767,7 +1779,7 @@ function sniffRun(B, dt) {
|
|
|
1767
1779
|
}
|
|
1768
1780
|
const S = B.sn || (B.sn = { mode: 'cast', side: RNG() < 0.5 ? 1 : -1, amp: 0.8, wp: null, t: 0 });
|
|
1769
1781
|
const up = V3(-wind.v.x, 0, -wind.v.z); if (up.lengthSq() < 1e-4) up.set(Math.sin(dog.yaw), 0, Math.cos(dog.yaw)); up.normalize();
|
|
1770
|
-
const cross = V3(-up.z, 0, up.x), lr = sniff.cL - sniff.cR, gnd = groundConc
|
|
1782
|
+
const cross = V3(-up.z, 0, up.x), lr = sniff.cL - sniff.cR, gnd = smellAt(groundConc, TGS / TG);
|
|
1771
1783
|
S.t += dt;
|
|
1772
1784
|
// ground trail: a deciding phase of 3 to 5 s at half speed over a few footprints, then follow toward the fresher end (Thesen 1993, Hepper and Wells 2005)
|
|
1773
1785
|
if (gnd > 0.08 && S.mode !== 'decide' && S.mode !== 'trail' && (!S.trailDone || now - S.trailDone > 15)) { S.mode = 'decide'; S.dEnd = now + ORG.exg(3.2, 0.5, 1); S.wp = null; }
|
|
@@ -1778,7 +1790,7 @@ function sniffRun(B, dt) {
|
|
|
1778
1790
|
return;
|
|
1779
1791
|
}
|
|
1780
1792
|
if (S.mode === 'trail') {
|
|
1781
|
-
if (!S.wp || motor.done) { const d = trailDir(dog.pos, S.tdir); if (!d || groundConc
|
|
1793
|
+
if (!S.wp || motor.done) { const d = trailDir(dog.pos, S.tdir); if (!d || smellAt(groundConc) < 0.03) { S.mode = 'cast'; S.trailDone = now; S.wp = null; } else { S.tdir = d; S.wp = dog.pos.clone().addScaledVector(d, 1.5); pushOut(S.wp, 0.4); motor.done = false; } }
|
|
1782
1794
|
if (S.wp) { motor.mode = 'goto'; motor.target.copy(S.wp); motor.speed = 0.9; motor.stopDist = 0.3; }
|
|
1783
1795
|
dog.head.tPitch = 0.9 - dog.bodyPitch + (NG.active ? 0.25 : 0); dog.head.tYaw = Math.sin(now * 2.2) * 0.25;
|
|
1784
1796
|
if (S.t > 24) { B.done = true; B.sn = null; }
|
|
@@ -2227,15 +2239,22 @@ Object.assign(brain, {
|
|
|
2227
2239
|
|
|
2228
2240
|
// ---- yard/dog/drives.js
|
|
2229
2241
|
// dog brain: drives. Hunger, fatigue, play, social, curiosity and prey move with the body clock and
|
|
2230
|
-
// what happens, and each tick turns them into signals for the choice.
|
|
2242
|
+
// what happens, and each tick turns them into signals for the choice. The drive, the reward of an act
|
|
2243
|
+
// and the body clock come from @hackbuild/drives (Keramati and Gutkin 2011 drive reduction; the agents
|
|
2244
|
+
// audit found the library's numbers equal the yard's own to 1.1e-15 over 3,339 states).
|
|
2245
|
+
HDRIVE.loadSync(DRIVES_WASM());
|
|
2246
|
+
const DRIVE_KEYS = ['hunger', 'fatigue', 'play', 'social', 'curiosity', 'prey'];
|
|
2247
|
+
const DRIVES = new HDRIVE.Drives({ hunger: 1, fatigue: 1, play: 0.8, social: 0.9, curiosity: 0.6, prey: 1.1 });
|
|
2248
|
+
// every deficit named, a missing one read as 0, as the yard's own sum did
|
|
2249
|
+
const fullDrives = (h) => { const o = {}; for (const k of DRIVE_KEYS) o[k] = h[k] || 0; return o; };
|
|
2250
|
+
const driveShape = () => DRIVES.setShape(TV('Br.driveN'), TV('Br.driveM'), TV('Br.gain'));
|
|
2251
|
+
ENV.dispose(() => DRIVES.free());
|
|
2231
2252
|
Object.assign(brain, {
|
|
2232
2253
|
memory(id) { const p = percepts[id]; return p && p.seen > -1e8 ? p : null; },
|
|
2233
|
-
driveD(h) {
|
|
2234
|
-
gain(K, scale = 1) {
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
return clamp(1 - (0.6 * day + 0.45 * pk - 0.22 * dip), 0, 1);
|
|
2238
|
-
},
|
|
2254
|
+
driveD(h) { driveShape(); return DRIVES.distance(fullDrives(h)); },
|
|
2255
|
+
gain(K, scale = 1) { driveShape(); DRIVES.set(fullDrives(this.d)); return DRIVES.rewardOf(K, scale); },
|
|
2256
|
+
// sleepiness from the body clock: activity peaks near 7 and 19 with a midday dip (Scientific Reports 2020)
|
|
2257
|
+
bodyClock(h) { return HDRIVE.bodyClock(h); },
|
|
2239
2258
|
tick(dt) {
|
|
2240
2259
|
const d = this.d, tempo = +$('tempo').value, org = ON('L.organic');
|
|
2241
2260
|
const moving = Math.abs(dog.v);
|
|
@@ -2318,7 +2337,7 @@ Object.assign(brain, {
|
|
|
2318
2337
|
const ballMoving = ballP && ballP.vis && ballP.speed > 1.2;
|
|
2319
2338
|
const ballAtYou = ball && !ball.held && bodyPos(ball).distanceTo(V3(YOU.x, bodyPos(ball).y, YOU.z)) < 1.3;
|
|
2320
2339
|
const nearYou = Math.hypot(dog.pos.x - YOU.x, dog.pos.z - YOU.z) < 1.8, youDist = dist2(dog.pos, YOU);
|
|
2321
|
-
const sc = scentAt
|
|
2340
|
+
const sc = smellAt(scentAt), youVis = percepts.you && percepts.you.vis;
|
|
2322
2341
|
const sleepy = ON('L.sleep') ? 0.8 * this.Sp + 0.5 * (this.circ ?? 0.3) : d.fatigue;
|
|
2323
2342
|
if (ON('L.drives')) {
|
|
2324
2343
|
const G = (b, s = 1) => this.gain(EFFECT[b], s);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/agents-views",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
4
4
|
"description": "Views that bind the agents packages to the hackbuild-ui class layer: the behaviour, utility and drive bars, the cues by acts associations table, the eye inset, and Yard, the dog simulator's stage and rack as one view. Each small view ships as a Vue component and as a custom element.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|