Opportunities.forPawn and the actor viewStatus: done (2026-11-10)
Priority: 2
Size: M
Arch: life
Phase: implement
Design ref: The player and what they see (What it may do here: Proposed, VB-079); What a pawn knows (Decided: omniscient, read through an actor view); docs/architecture/target-v2.md, sections 4.5 (Opportunities) and 4.7, principles 4, 15 and 16; docs/review-life.md, section 3.
Goal: The player chooses its pawn’s commands from what the pawn may do here, for whom and on what basis; slice 3’s planner will ask the same question for every holder. Build the read-only question for one pawn, on demand, and the actor view it reads through.
Acceptance criteria:
sim/opportunities (@sys line; listed in src/manifest.json after the modules it reads; under 400 lines) with actorView(st, id), the seam that filters nothing for now (it returns what the pawn may read, today the whole state), and forPawn(st, view, id), read-only, writing nothing to st and drawing no random numbers. Exposed as Sim.opportunities(st, id).forPawn lists, each with {verb, target, args, holder, basis, fit, why} (why null when the command would be accepted now):
available (VB-208), matched to the posted job, with the planner’s fit and reasons (explainIdle, src/sim/jobs.js:152), best fit first; basis member, servant or villager;walkable, src/sim/routes.js; VB-168’s note);wantsOut, src/sim/heirs.js:371), claiming each empty farm of its village it may claim (src/sim/farmclaims.js), taking service (src/sim/service.js), each with the rule that bars it now, if one does;tests/opportunities.js, in npm test): on a tiny map over a game day, every open job a pawn would bid for in planRound is listed as work with why null, and every work item listed with why null is a job it would bid for (the list and the planner agree); forPawn leaves st unchanged (hash before and after) and draws nothing.medium-y60 (stress), for a holder and for a landless adult; no loop over all pawns, households or the record (the village’s farms and households only).npm run verify passes; node tests/dependencies.js passes (the module reads only earlier ones).
Notes:docs/review-life.md): a pawn may take 1.5 open jobs on average at 10:00 at small-y40, at most 7, and 1.3 at medium-y5, at most 48.forHolder for every holder is slice 3’s (VB-164): its cache and cadence are that plan’s design, not this task’s.sim/opportunities (124 lines, after sim/service in the manifest), with actorView(st, id) and forPawn(st, view, id, near), on Sim as opportunities(st, id, near). No state. It reads households, farms, villages, jobs, the culture’s practice and st.demand; it writes nothing. New coupling: it calls the kinds’ available (sim/kinds), the planner’s fit (sim/jobs), the verbs’ checks (sim/commands) and the round’s rules (sim/heirs, sim/farmclaims, sim/service), all earlier modules.staysWhy beside wantsOut (sim/heirs), barred beside free (sim/farmclaims), unfit and handsLeft, which takeServants now uses (sim/service), and fit, the row explainIdle built (sim/jobs).kind (a job’s kind, to tell the work in words) and when (now, or round for the moving round’s acts).available for the pawn’s farm and village, as refreshJobs asks it, then the posted jobs of the two are added, since a plot’s steps and a claimed farm’s restoration are asked island-wide. Work that is available but not posted (outside working hours) is listed with the reason “not given out yet”.near, as in target-v2’s signature): there is no list of every open tile.dropCause, which does not exist yet (VB-211 issues causes). The player’s queue refuses it until then.leave carries no party or site, which the round reckons.st.demand) is not asked again; any other is checked against the first heirs of its own village’s farms only, and only once the cheaper bars pass. An heir to a farm in another village, or one who became an heir since the last round, is found at the round, which decides in any case.guardian and claimOf scan the live households and the farmsteads for one id each (a few microseconds), as they do for the round; the criterion’s “no loop over all households” holds for everything written here.Cost, a call at 10:00, the best of three, over every such adult of the save (the bench has no medium-y60 since 8 November, so medium-ref stands in):
| Save | Holder: mean, worst | Landless, wanting out: mean, worst | Other adults: mean, worst | Most items |
|---|---|---|---|---|
small-y40 |
0.019 ms, 0.052 | 0.157 ms, 0.42 | 0.042 ms, 1.67 | 51 |
medium-y5 |
0.019 ms, 0.043 | 0.048 ms, 0.091 | 0.024 ms, 0.23 | 49 |
medium-ref |
0.013 ms, 0.034 | 0.051 ms, 0.118 | 0.022 ms, 0.34 | 49 |
The criterion’s two cases are under 1 ms. One adult of 168 at small-y40 took 1.67 ms: neither holder nor counted as wanting out, in a village of 16 farms, whose heirs were ranked. Before the heir ranking was made lazy a holder’s call took 0.6 ms on average and 1.6 at worst there.
npm test (82 scripts) and npm run verify (95 scripts) pass; node tests/dependencies.js passes. tests/opportunities.js: over a game day on a tiny map of 4 farms, 5,760 asks, the work offered equals the jobs the pawn would bid for, both ways (15,577 offered, 15,408 barred), and each of 454 jobs a pawn set out for was on its list; asking leaves the state’s hash and the random streams as they were; own acts, causes and the round’s acts are checked against the rules. tests/golden.json: apiKeys.Sim only (the new opportunities). Counters unchanged.