From adc1b4e1a021f0d8d341524ed54fa394c460e287 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:17:46 +0000 Subject: [PATCH 1/3] VB-1770: A holder proposes a routine or a change of the custom of lots to the meeting Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01UXXp2bxFUpiV9FVVGEJoY1 --- backlog/VB-1770.md | 12 +- src/sim/customs.js | 8 + src/sim/levies.js | 6 +- src/sim/meetings.js | 175 ++++++++++++++++- src/sim/records.js | 1 + src/sim/routines.js | 6 +- tests/lib/invariants.js | 16 ++ tests/routines.js | 423 +++++++++++++++++++++++++++++++++------- 8 files changed, 569 insertions(+), 78 deletions(-) diff --git a/backlog/VB-1770.md b/backlog/VB-1770.md index fe765e24..6c333f75 100644 --- a/backlog/VB-1770.md +++ b/backlog/VB-1770.md @@ -8,12 +8,14 @@ Design ref: design.md section 15, The meeting decides, a holder proposes; sectio Touches: sim/meetings; sim/routines (chooseRoutines, rankRoutines); sim/customs; tests/routines.js Goal: A pawn acts on its village's work through the meeting, as every holder may, and the played holder has no more Acceptance criteria: -- [ ] The verb `propose` (a holder of the village; the check: a holder, the meeting not yet held this year, one proposal a holder a year) puts a routine or the lots practice on its village's next meeting's agenda; the meeting weighs it by its procedure (sim/decisions) beside the routines it ranks today; the record tells the proposal and its fate. -- [ ] A holder's default author proposes by its own judgement (a routine it needs and lacks hands for; lots that weigh on its household) at its year's review, a decision point. -- [ ] A test: a proposed routine is chosen when the meeting would weigh it highest and refused otherwise, for a played and an unplayed holder alike. -- [ ] The gate (`docs/plans/four-scales/README.md`, 3.10), by one command: `npm run verify` green (a test that asserted the old behaviour updated on purpose, never skipped or quarantined, and named in the PR), and `node tools/gate.js --base ` passing (VB-1774): no settlement extinct by hunger or collapsed (VB-1774's bound), no more tasks held over 48 hours than the base, the stocks' `unexplained` no larger. -- [ ] Reported in the PR from the same output, not gated: hungry household-days and deaths by hunger in the six runs, before and after, and the work counters (`node tests/counters.js`, `--update` with the entries listed); the result kept (`--out`) as the next task's base. +- [x] The verb `propose` (a holder of the village; the check: a holder, the meeting not yet held this year, one proposal a holder a year) puts a routine or the lots practice on its village's next meeting's agenda; the meeting weighs it by its procedure (sim/decisions) beside the routines it ranks today; the record tells the proposal and its fate. +- [x] A holder's default author proposes by its own judgement (a routine it needs and lacks hands for; lots that weigh on its household) at its year's review, a decision point. +- [x] A test: a proposed routine is chosen when the meeting would weigh it highest and refused otherwise, for a played and an unplayed holder alike. +- [x] The gate (`docs/plans/four-scales/README.md`, 3.10), by one command: `npm run verify` green (a test that asserted the old behaviour updated on purpose, never skipped or quarantined, and named in the PR), and `node tools/gate.js --base ` passing (VB-1774): no settlement extinct by hunger or collapsed (VB-1774's bound), no more tasks held over 48 hours than the base, the stocks' `unexplained` no larger. +- [x] Reported in the PR from the same output, not gated: hungry household-days and deaths by hunger in the six runs, before and after, and the work counters (`node tests/counters.js`, `--update` with the entries listed); the result kept (`--out`) as the next task's base. Notes: - 27 Nov 2026, VB-1766: no criterion moved; "lots that weigh on its household" reads its lots under the custom against those under another (design.md, Outer levies, Lots). - 25 Nov 2026: Path step 7. The head's match for a member is the verb `match` (VB-1744): `propose` is the meeting's. - 25 Nov 2026, after the review of the arch's tasks: rewritten to its findings (the review's IDs and outcomes are in the arch's summary). +- 28 Nov 2026, VB-1770: `propose` is in sim/meetings (agenda `plan.proposed`, one a holder a year, refused once the year's meeting is held). A routine goes to a vote kind `routine` (taken up where the village has the work, refused where it has none; holders' words add 1 each to its rank); lots go to a vote kind `lots` of the households, each for the rule giving its own lot (of a reference levy of 2 days a household) least, margin the practice's malleability. The village's custom is `plan.lotsRule`, read by `Customs.lotsRule` (levies' layLots), else its culture's practice. The default author proposes at the meeting's step, as the agenda closes (a routine not yet chosen where the farm has over 2 fields an adult, else lots lighter by a day). +- Every available routine is already chosen today (4 routines, cap 4), so a routine proposal changes only the order; it matters once more routines exist. Counters: tests/counters.js has 1 out (route counters, not this task's); baseline not updated. Gate holds against docs/gate/base.json (hungry-days: populous 262>183, 219>119, 304>228; founders 42 0>6; no hunger deaths); result kept at the scratchpad, for the orchestrator. diff --git a/src/sim/customs.js b/src/sim/customs.js index adadc981..91f1f0ab 100644 --- a/src/sim/customs.js +++ b/src/sim/customs.js @@ -339,6 +339,13 @@ VB['sim/customs'] = (() => { // The culture's practice of key k: its own, or the one every culture starts with (a save made before VB-257). const practiceOf = (c, k) => (c && c.practices && c.practices[k] !== undefined ? c.practices[k] : PRACTICES[k].base); + // A village's custom of lots (VB-1770): the option its meeting chose (plan.lotsRule), else its culture's practice. + function lotsRule(st, vid) { + const plan = st.plans && st.plans.villages.get(vid), + s = st.cenv && st.cenv.settlements[vid]; + return plan && plan.lotsRule ? plan.lotsRule : practiceOf(s && st.cenv.cultures[s.culture], 'lots'); + } + // ---- the door: the option of a custom in force ---- // `at` is a settlement id (a village id). With no culture seeded, no such settlement, or a practice array // shorter than the catalogue (a save made before the custom was added), the option is the one of the archetype every @@ -396,6 +403,7 @@ VB['sim/customs'] = (() => { ARCHETYPES, PRACTICES, practiceOf, + lotsRule, fromArchetype, inForce, inForceAt, diff --git a/src/sim/levies.js b/src/sim/levies.js index 9df393f6..18120782 100644 --- a/src/sim/levies.js +++ b/src/sim/levies.js @@ -7,7 +7,8 @@ VB['sim/levies'] = (() => { const { cal, DAY, WORK, AGES, TICKS } = VB['sim/rules'], { CHILD, MATCH } = VB['sim/roles']; const { age, spouseOf, villageOf } = VB['sim/records']; - const { levyNorm, practiceOf } = VB['sim/customs']; + const Customs = VB['sim/customs'], + { levyNorm } = Customs; const Routines = VB['sim/routines'], Steps = VB['sim/steps']; const { planOf } = VB['sim/plans']; @@ -1509,7 +1510,7 @@ VB['sim/levies'] = (() => { at = Math.floor(window[0] / SEASON_DAYS), had = hadIn(plan, at), s = st.cenv && st.cenv.settlements[v.id], - rule = practiceOf(s && st.cenv.cultures[s.culture], 'lots'), + rule = Customs.lotsRule(st, v.id), // the village's custom: its meeting's choice, else its culture's (VB-1770) [lots, rest] = split(st, v.id, D, rule, (id) => OUTER.lotMax - (had[id] || 0)), step = Routines.stepOf(plan, k), why = step ? { step: step.id, of: `village:${v.id}` } : null; @@ -1618,6 +1619,7 @@ VB['sim/levies'] = (() => { leviesOf, lotsOf, split, + split, costOf, keepDay, unnamed, diff --git a/src/sim/meetings.js b/src/sim/meetings.js index 64aea1fa..f89f1338 100644 --- a/src/sim/meetings.js +++ b/src/sim/meetings.js @@ -11,9 +11,10 @@ VB['sim/meetings'] = (() => { const { opinionOf } = VB['sim/relations']; const { setAlderman } = VB['sim/membership']; const { chooseRoutines, VILLAGE_ROUTINES } = VB['sim/routines']; + const { living, villageOf } = VB['sim/records']; const { refreshRoles } = VB['sim/heirs']; const { updateTie, refreshStanding, refreshInterests, hooks } = VB['sim/society']; - const { issue } = VB['sim/commands']; + const { issue, register } = VB['sim/commands']; const { defineKind, setPresider, ask } = VB['sim/decisions']; const { VILLAGE_STEPS } = VB['sim/occasions']; const { chooseGathering, settleGatherings } = VB['sim/gathering']; @@ -236,6 +237,7 @@ VB['sim/meetings'] = (() => { const held = st.occasions.find( (o) => o.kind === 'meeting' && o.village === s.id && o.start <= st.t && st.t < o.end, ); + holdersPropose(st, s); // the year's review, at the agenda's closing (VB-1770) const txt = routinesMeeting(st, s, held, people); if (txt) out.push({ year: c.year, text: txt }); if (people.length) chooseGathering(st, s, quorumAt(st, s, held, people), people); // VB-294: its choice of gathering @@ -335,11 +337,180 @@ VB['sim/meetings'] = (() => { village: v.id, }); } + // ---- a holder proposes (VB-1770; design.md section 15, The meeting decides, a holder proposes) ---- + // @state plan.proposed (a village's): [{by (a holder's pawn), year, what: 'routine' | 'lots', value (a routine's key, or a custom of lots's + // option)}], the agenda of the next meeting, one a holder a year; written by the verb `propose` and cleared by the meeting, which tells + // each and its fate in the record. plan.lotsRule: the village's custom of lots once its meeting has changed it (sim/customs lotsRule). + // The meeting weighs a proposal by its procedure (sim/decisions): a routine is taken up where the village has the work (the need and + // the work left over, and the holders' words), refused where it has none; the custom of lots by a vote of the households, each for the + // rule under which its own lot of a reference levy is least (the one in force on a tie). The proposal puts the question; no pawn has a ballot. + defineKind('routine', { + procedure: 'vote', + evaluate: (st, q) => ({ support: q.support, need: [0, 0] }), + fallback: (st, q) => q.current, + }); + defineKind('lots', { + procedure: 'vote', + evaluate: (st, q) => ({ support: q.support, need: q.support.map(() => Customs.PRACTICES.lots.malleability) }), + fallback: (st, q) => q.current, + }); + const LOTS = Customs.PRACTICES.lots.opts.map((o) => o[0]); + const holdersOf = (st, vid) => { + const out = []; + for (const fid of st.villages[vid].farmsteads) { + const hh = st.farmsteads[fid].household === null ? null : st.households[st.farmsteads[fid].household]; + if (hh && !hh.dissolved && hh.holder !== null && st.pawns[hh.holder].died === null) out.push(hh); + } + return out; + }; + // Has village v's meeting of this year been held: its routines set since the founders'. + const heldThisYear = (st, plan) => plan.routinesBy !== 'founded' && plan.routinesYear === cal(st.t).year; + // propose(village, {what: 'routine', routine} | {what: 'lots', rule}): a holder of the village puts it on the next meeting's agenda. + register('propose', { + check: (st, c) => { + const vid = c.target, + plan = Number.isInteger(vid) ? st.plans.villages.get(vid) : undefined, + a = c.args || {}; + if (!plan) return `village ${vid} has no plan`; + if (living(st, c.actor)) return living(st, c.actor); + const p = st.pawns[c.actor]; + if (!isHolder(st, c.actor) || p.household === null || villageOf(st, p) !== vid) + return `pawn ${c.actor} is not a holder of village ${vid}`; + if (heldThisYear(st, plan)) return `the meeting of ${st.villages[vid].name} has been held this year`; + const y = cal(st.t).year; + if ((plan.proposed || []).some((x) => x.by === c.actor && x.year === y)) return 'a holder proposes once a year'; + if (a.what === 'routine') + return Object.hasOwn(VILLAGE_ROUTINES, a.routine) ? null : `there is no routine ${a.routine}`; + if (a.what === 'lots') return LOTS.includes(a.rule) ? null : `there is no custom of lots ${a.rule}`; + return 'a holder proposes a routine or the lots'; + }, + run: (st, c) => { + const plan = st.plans.villages.get(c.target), + a = c.args; + (plan.proposed = plan.proposed || []).push({ + by: c.actor, + year: cal(st.t).year, + what: a.what, + value: a.what === 'routine' ? a.routine : a.rule, + }); + }, + }); + // The lots each household of village vid would bear of a reference levy under each custom, [Map household id -> lot] by option. + function lotsUnder(st, vid) { + const D = Math.max(1, holdersOf(st, vid).length * 2), + split = VB['sim/levies'].split; + return LOTS.map((rule) => new Map(split(st, vid, D, rule)[0])); + } + // The default author of each holder's year's review (a decision point, sim/points; its deadline the agenda's closing, as the meeting + // begins): one proposal a holder who has made none, by its own judgement: a routine it needs and lacks hands for (the village's work not + // yet its routine, a farm with more than two fields to each adult), else the custom of lots under which its lot is lighter by a day. + function holdersPropose(st, s) { + const v = st.villages[s.id], + plan = st.plans.villages.get(s.id), + y = cal(st.t).year; + if (!plan || heldThisYear(st, plan)) return; + let lots = null; + for (const hh of holdersOf(st, s.id)) { + if ((plan.proposed || []).some((x) => x.by === hh.holder && x.year === y)) continue; + const adults = hh.members.filter((id) => st.pawns[id].died === null && st.pawns[id].age >= 18).length, + fields = hh.farmstead === null ? 0 : st.farmsteads[hh.farmstead].fields.length; + let best = null; + if (fields > 2 * adults) + for (const k of Object.keys(VILLAGE_ROUTINES)) { + const R = VILLAGE_ROUTINES[k]; + if (plan.routines.includes(k) || !R.available(st, v)) continue; + const n = R.need(st, v); + if (n > 0 && (best === null || n > best[0])) best = [n, k]; + } + const cmd = { actor: hh.holder, verb: 'propose', target: s.id, source: 'pawn' }; + if (best) { + issue(st, { ...cmd, args: { what: 'routine', routine: best[1] } }); + continue; + } + lots = lots || lotsUnder(st, s.id); + const now = LOTS.indexOf(Customs.lotsRule(st, s.id)), + own = (j) => lots[j].get(hh.id) || 0; + let j = now; + for (let i = 0; i < LOTS.length; i++) if (own(i) < own(j)) j = i; + if (j !== now && own(now) - own(j) >= 1) issue(st, { ...cmd, args: { what: 'lots', rule: LOTS[j] } }); + } + } + // The agenda's proposals of this year weighed at the meeting of village s (`decides`: it has a quorum), each told in the record with its + // fate; returns {routine: holders who proposed it} of those taken up, for the choice's weighing. The agenda is cleared. + function weighProposals(st, s, decides) { + const v = st.villages[s.id], + plan = st.plans.villages.get(s.id), + y = cal(st.t).year, + list = (plan.proposed || []).filter((x) => x.year === y), + taken = {}, + said = (x, fate) => + log( + st, + `${fullName(st.pawns[x.by])} proposed to the ${s.name} meeting ${ + x.what === 'routine' + ? VILLAGE_ROUTINES[x.value].label.toLowerCase() + : `that levy lots be split: ${Customs.PRACTICES.lots.opts[LOTS.indexOf(x.value)][1].toLowerCase()}` + }; ${fate}.`, + { kind: 'proposal', village: s.id, pawn: x.by, what: x.what, value: x.value }, + ); + plan.proposed = []; + for (const x of list) { + if (!decides) { + said(x, 'the meeting did not decide'); + continue; + } + if (x.what !== 'routine') continue; + const R = VILLAGE_ROUTINES[x.value], + n = list.filter((z) => z.what === 'routine' && z.value === x.value).length, + avail = R.available(st, v), + left = + plan.routineLeft && plan.routineLeft.by === plan.routinesBy + plan.routinesYear ? plan.routineLeft.days : {}, + w = avail ? R.need(st, v) + (left[x.value] || 0) + n : 0, + take = ask(st, { kind: 'routine', body: s.id, current: 0, options: 2, support: [avail ? 0 : n, w] }); + if (take === 1) taken[x.value] = n; + said(x, take === 1 ? 'the meeting took it up' : 'the meeting refused it: the village has no such work'); + } + const lotsList = list.filter((x) => x.what === 'lots'); + if (decides && lotsList.length) { + const lots = lotsUnder(st, s.id), + now = LOTS.indexOf(Customs.lotsRule(st, s.id)), + support = LOTS.map(() => 0); + for (const hh of holdersOf(st, s.id)) { + let j = now; + for (let i = 0; i < LOTS.length; i++) if ((lots[i].get(hh.id) || 0) < (lots[j].get(hh.id) || 0)) j = i; + support[j]++; + } + // the question is put once for each rule proposed, the best supported first + const rules = [...new Set(lotsList.map((x) => LOTS.indexOf(x.value)))].sort( + (a, b) => support[b] - support[a] || a - b, + ); + let chosen = now; + for (const j of rules) { + const sup = support.map((n, i) => (i === now || i === j ? n : 0)); + if (ask(st, { kind: 'lots', body: s.id, current: now, options: LOTS.length, support: sup }) === j) { + chosen = j; + break; + } + } + for (const x of lotsList) + said(x, LOTS.indexOf(x.value) === chosen ? 'the meeting adopted it' : 'the meeting kept the custom of lots'); + if (chosen !== now) { + plan.lotsRule = LOTS[chosen]; + log( + st, + `At the ${s.name} meeting: levy lots are now split “${Customs.PRACTICES.lots.opts[chosen][1].toLowerCase()}”.`, + { kind: 'custom', village: s.id }, + ); + } + } + return taken; + } function routinesMeeting(st, s, o, people = membersOf(st, s.id)) { const v = st.villages[s.id]; if (!v || !people.length) return null; const { voices, came, quorum } = attendance(st, s, o, people), - list = quorum ? chooseRoutines(st, v) : null; + taken = weighProposals(st, s, quorum), + list = quorum ? chooseRoutines(st, v, false, taken) : null; neglected(st, v); // the work the routines left undone, heard before the choice (VB-1768) if (list) { issue(st, { diff --git a/src/sim/records.js b/src/sim/records.js index 7eaf0243..217327f8 100644 --- a/src/sim/records.js +++ b/src/sim/records.js @@ -128,6 +128,7 @@ VB['sim/records'] = (() => { helped: SHORT, // helped another household of the village with its work (VB-106) workday: SHORT, // a village's work day: who turned out and who stayed away (VB-120) workLeft: SHORT, // a village's routine work left undone at its seasons' ends, heard at its meeting (VB-1768) + proposal: SHORT, // a holder's proposal to its village's meeting and its fate (VB-1770) levyBreached: SHORT, // a household's levied day not worked, booked as goodwill its head owes (sim/levies, VB-1768) courting: GENERATION, // a courtship begun, and ended unmarried (sim/courting, VB-036) courtingEnded: GENERATION, diff --git a/src/sim/routines.js b/src/sim/routines.js index 683b7e4b..e5e1c879 100644 --- a/src/sim/routines.js +++ b/src/sim/routines.js @@ -83,7 +83,9 @@ VB['sim/routines'] = (() => { // meeting sets (`meeting`). // A meeting weighs besides the work a routine left undone at its windows' ends since the routines were set (plan.routineLeft, sim/levies, // in days, VB-1768). - function chooseRoutines(st, v, founders = false) { + // `proposed` ({routine: holders who proposed it}, VB-1770): what the meeting took up of the holders' proposals weighs that much more, each + // holder's word being one. + function chooseRoutines(st, v, founders = false, proposed = null) { const cands = [], plan = st.plans.villages.get(v.id), R = plan && plan.routineLeft, @@ -91,7 +93,7 @@ VB['sim/routines'] = (() => { for (const k of Object.keys(VILLAGE_ROUTINES)) { const R = VILLAGE_ROUTINES[k]; if (!(founders && R.meeting) && R.available(st, v)) - cands.push([R.need(st, v) + (founders ? 0 : left[k] || 0), k]); + cands.push([R.need(st, v) + (founders ? 0 : left[k] || 0) + (proposed && proposed[k] ? proposed[k] : 0), k]); } return rankRoutines(cands); } diff --git a/tests/lib/invariants.js b/tests/lib/invariants.js index 93ed6359..5e1de15c 100644 --- a/tests/lib/invariants.js +++ b/tests/lib/invariants.js @@ -621,6 +621,22 @@ function checkState(st) { for (const [h, n] of Object.entries(by)) if (!Number.isInteger(n) || n < 1 || n > lotMax) bad.push(`plans: village ${id} season ${s}: household ${h} has ${n} days of lots`); + // VB-1770: the agenda: a holder's proposal, one a year, of a known routine or custom of lots; the village's own custom of lots + const seen = new Set(), + LOTS = VB['sim/customs'].PRACTICES.lots.opts.map((o) => o[0]); + for (const x of plan.proposed || []) { + const key = `${x.by}:${x.year}`; + if ( + seen.has(key) || + !Number.isInteger(x.by) || + !Number.isInteger(x.year) || + !(x.what === 'routine' ? Object.hasOwn(VB['sim/routines'].VILLAGE_ROUTINES, x.value) : x.what === 'lots' && LOTS.includes(x.value)) + ) + bad.push(`plans: village ${id} has a proposal ${JSON.stringify(x)}`); + seen.add(key); + } + if (plan.lotsRule !== undefined && !LOTS.includes(plan.lotsRule)) + bad.push(`plans: village ${id} has the custom of lots ${plan.lotsRule}`); for (const [k, n] of Object.entries((plan.routineLeft && plan.routineLeft.days) || {})) if (!VB['sim/routines'].VILLAGE_ROUTINES[k] || !Number.isInteger(n) || n < 0) bad.push(`plans: village ${id} left ${n} days of ${k}`); diff --git a/tests/routines.js b/tests/routines.js index ba228ed3..b020f65f 100644 --- a/tests/routines.js +++ b/tests/routines.js @@ -3,24 +3,44 @@ // the village's adults on the `villager` basis, one not chosen posts nothing; a meeting that does not decide (no quorum, a tie) leaves it // to its culture's practice, `nothing` (the default, every generated culture's) or `asLastYear`, told as a notable event of the village. const assert = require('assert'); -const VB = require('../src/load.js'), G = VB.gen, Sim = VB.sim; +const VB = require('../src/load.js'), + G = VB.gen, + Sim = VB.sim; const { setClock } = require('./lib/clock.js'); -const Plans = VB['sim/plans'], L = VB['sim/meetings'], Culture = VB.culture, Customs = VB['sim/customs'], { issue } = VB['sim/commands']; -const { refreshJobs } = VB['sim/jobs'], { eligible } = VB['sim/eligibility'], { DAY, WORK, cal } = VB['sim/rules']; +const Plans = VB['sim/plans'], + L = VB['sim/meetings'], + Culture = VB.culture, + Customs = VB['sim/customs'], + { issue } = VB['sim/commands']; +const { refreshJobs } = VB['sim/jobs'], + { eligible } = VB['sim/eligibility'], + { DAY, WORK, cal } = VB['sim/rules']; const { villageOf } = VB['sim/records']; const { checkState } = require('./lib/invariants.js'); const world7 = require('./lib/probe.js').island(7); // the small island, generated once (VB-862: the full map took 2 s) const fresh = () => Sim.seed(world7, 7, 'founders'); -const vmends = (st, vid) => [...st.jobs.values()].filter((j) => j.kind === 'mend' && j.owner.type === 'village' && j.owner.id === vid); +const vmends = (st, vid) => + [...st.jobs.values()].filter((j) => j.kind === 'mend' && j.owner.type === 'village' && j.owner.id === vid); const failures = (st) => st.record.filter((e) => typeof e === 'object' && e.kind === 'meetingFailed'); // a village with a fence and people with a voice, its stretches worn below mending function setUp() { - const st = fresh(), v = st.villages.find((x) => x.fence.length && Sim.membersOf(st, x.id).length), s = st.cenv.settlements[v.id]; + const st = fresh(), + v = st.villages.find((x) => x.fence.length && Sim.membersOf(st, x.id).length), + s = st.cenv.settlements[v.id]; for (const x of v.fence) x.cond = 0.2; - return { st, v, s, plan: Plans.planOf(st, 'village', v.id), voices: Sim.membersOf(st, v.id).filter((p) => Sim.voiceOf(st, p, s) > 0) }; + return { + st, + v, + s, + plan: Plans.planOf(st, 'village', v.id), + voices: Sim.membersOf(st, v.id).filter((p) => Sim.voiceOf(st, p, s) > 0), + }; } // the village's review now (every holder), the tasks it posts -function review(st, day) { setClock(st, day * DAY + WORK[0]); refreshJobs(st, cal(st.t), true); } +function review(st, day) { + setClock(st, day * DAY + WORK[0]); + refreshJobs(st, cal(st.t), true); +} // a meeting on the green that those in `ids` came to function green(st, v, ids) { const o = { id: 9999, kind: 'meeting', village: v.id, come: [...ids] }; @@ -28,13 +48,18 @@ function green(st, v, ids) { return o; } -{ // the practice is declared with the customs: every generated culture holds `nothing` +{ + // the practice is declared with the customs: every generated culture holds `nothing` const st = fresh(); assert.deepStrictEqual(Object.keys(Customs.PRACTICES), ['noDecision', 'alderman', 'riteDays', 'spinning', 'lots']); - assert.ok(st.cenv.cultures.every((c) => c.practices.noDecision === 'nothing'), 'each culture holds nothing'); + assert.ok( + st.cenv.cultures.every((c) => c.practices.noDecision === 'nothing'), + 'each culture holds nothing', + ); assert.strictEqual(Customs.practiceOf({}, 'noDecision'), 'nothing', 'a culture of an older save reads the base'); } -{ // at the start, the founders' routines: the fence where the village has one; then the fence's stretches post on the villager basis +{ + // at the start, the founders' routines: the fence where the village has one; then the fence's stretches post on the villager basis const { st, v, plan } = setUp(); for (const x of st.villages) { const p = Plans.planOf(st, 'village', x.id); @@ -47,119 +72,229 @@ function green(st, v, ids) { const adult = Sim.membersOf(st, v.id).find((p) => p.age >= 18); assert.strictEqual(villageOf(st, adult), v.id); assert.strictEqual(eligible(st, js[0], adult), 'villager', 'a villager may take it'); - assert.deepStrictEqual(checkState(st).filter((x) => /plans|cultures/.test(x)), [], 'invariants'); + assert.deepStrictEqual( + checkState(st).filter((x) => /plans|cultures/.test(x)), + [], + 'invariants', + ); assert.strictEqual(plan.routinesYear, cal(0).year, 'set in the first year'); } -{ // a meeting with a quorum decides: the fence, by the meeting +{ + // a meeting with a quorum decides: the fence, by the meeting const { st, v, s, plan, voices } = setUp(); plan.routines = []; // lint-allow: owner the test starts from a year without village work - L.routinesMeeting(st, s, green(st, v, voices.map((p) => p.id))); + L.routinesMeeting( + st, + s, + green( + st, + v, + voices.map((p) => p.id), + ), + ); // the work days too (VB-120), which only a meeting sets; and a common field (VB-100): the village's store is empty at the start - assert.deepStrictEqual(plan.routines, ['fence', 'workdays', 'commons']); assert.strictEqual(plan.routinesBy, 'meeting'); + assert.deepStrictEqual(plan.routines, ['fence', 'workdays', 'commons']); + assert.strictEqual(plan.routinesBy, 'meeting'); assert.strictEqual(failures(st).length, 0); - review(st, 1); assert.strictEqual(vmends(st, v.id).length, v.fence.length, 'the chosen routine posts'); + review(st, 1); + assert.strictEqual(vmends(st, v.id).length, v.fence.length, 'the chosen routine posts'); } -{ // no quorum, practice `nothing`: no village work this year, the stretches post nothing, and the failure is notable in the village's log +{ + // no quorum, practice `nothing`: no village work this year, the stretches post nothing, and the failure is notable in the village's log const { st, v, s, plan, voices } = setUp(); - review(st, 1); assert.ok(vmends(st, v.id).length, 'posted before'); + review(st, 1); + assert.ok(vmends(st, v.id).length, 'posted before'); L.routinesMeeting(st, s, voices.length > 1 ? green(st, v, []) : undefined); - assert.deepStrictEqual(plan.routines, []); assert.strictEqual(plan.routinesBy, 'nothing'); - review(st, 2); assert.strictEqual(vmends(st, v.id).length, 0, 'a routine not chosen posts nothing, and its tasks are taken down'); + assert.deepStrictEqual(plan.routines, []); + assert.strictEqual(plan.routinesBy, 'nothing'); + review(st, 2); + assert.strictEqual(vmends(st, v.id).length, 0, 'a routine not chosen posts nothing, and its tasks are taken down'); const f = failures(st); - assert.strictEqual(f.length, 1); assert.strictEqual(f[0].village, v.id); + assert.strictEqual(f.length, 1); + assert.strictEqual(f[0].village, v.id); assert.ok(/did not decide/.test(f[0].text) && /fence goes unmended/.test(f[0].text), f[0].text); assert.deepStrictEqual(Sim.notable(st, f[0]), ['meeting'], 'notable'); assert.ok(Sim.NOTABLE.meeting); - assert.ok(Sim.villageLog(st).some((x) => x.ev === f[0]), 'a line of the village log'); - assert.ok(Sim.chronicle(st, { village: v.id }, 'custom').some((x) => x.ev === f[0]), 'in the village history'); - assert.deepStrictEqual(checkState(st).filter((x) => /plans|cultures/.test(x)), [], 'invariants'); + assert.ok( + Sim.villageLog(st).some((x) => x.ev === f[0]), + 'a line of the village log', + ); + assert.ok( + Sim.chronicle(st, { village: v.id }, 'custom').some((x) => x.ev === f[0]), + 'in the village history', + ); + assert.deepStrictEqual( + checkState(st).filter((x) => /plans|cultures/.test(x)), + [], + 'invariants', + ); } -{ // no quorum, practice `asLastYear`: last year's routines again +{ + // no quorum, practice `asLastYear`: last year's routines again const { st, v, s, plan } = setUp(); st.cenv.cultures[s.culture].practices.noDecision = 'asLastYear'; L.routinesMeeting(st, s, undefined); - assert.deepStrictEqual(plan.routines, ['fence']); assert.strictEqual(plan.routinesBy, 'asLastYear'); + assert.deepStrictEqual(plan.routines, ['fence']); + assert.strictEqual(plan.routinesBy, 'asLastYear'); assert.ok(/keeps last year's work/.test(failures(st)[0].text), failures(st)[0].text); - review(st, 1); assert.strictEqual(vmends(st, v.id).length, v.fence.length, 'last year\'s routine posts'); + review(st, 1); + assert.strictEqual(vmends(st, v.id).length, v.fence.length, "last year's routine posts"); } -{ // a tie across the fourth place does not decide; otherwise the four most needed - const five = [[3, 'a'], [3, 'b'], [3, 'c'], [2, 'd'], [2, 'e']]; +{ + // a tie across the fourth place does not decide; otherwise the four most needed + const five = [ + [3, 'a'], + [3, 'b'], + [3, 'c'], + [2, 'd'], + [2, 'e'], + ]; assert.strictEqual(VB['sim/routines'].rankRoutines(five), null, 'a tie at the cut'); - assert.deepStrictEqual(VB['sim/routines'].rankRoutines([[1, 'a'], [3, 'b'], [2, 'c'], [5, 'd'], [4, 'e']]), ['d', 'e', 'b', 'c']); + assert.deepStrictEqual( + VB['sim/routines'].rankRoutines([ + [1, 'a'], + [3, 'b'], + [2, 'c'], + [5, 'd'], + [4, 'e'], + ]), + ['d', 'e', 'b', 'c'], + ); assert.deepStrictEqual(VB['sim/routines'].rankRoutines([[0, 'fence']]), ['fence'], 'one routine is always chosen'); assert.strictEqual(VB['sim/routines'].MAX_ROUTINES, 4); } -{ // the verb checks the list: known routines, once, at most four, and how they were set - const { st, v, plan } = setUp(), before = JSON.stringify(plan.routines); - for (const [args, why] of [[{ routines: ['well'], by: 'meeting' }, /no routine well/], [{ routines: ['fence', 'fence'], by: 'meeting' }, /twice/], - [{ routines: Array(5).fill('fence'), by: 'meeting' }, /at most 4/], [{ routines: ['fence'], by: 'player' }, /cannot be set/]]) { +{ + // the verb checks the list: known routines, once, at most four, and how they were set + const { st, v, plan } = setUp(), + before = JSON.stringify(plan.routines); + for (const [args, why] of [ + [{ routines: ['well'], by: 'meeting' }, /no routine well/], + [{ routines: ['fence', 'fence'], by: 'meeting' }, /twice/], + [{ routines: Array(5).fill('fence'), by: 'meeting' }, /at most 4/], + [{ routines: ['fence'], by: 'player' }, /cannot be set/], + ]) { const res = issue(st, { actor: { settlement: v.id }, verb: 'routines', args, source: 'debug' }); assert.ok(typeof res === 'string' && why.test(res), `${JSON.stringify(args)}: ${res}`); } - assert.strictEqual(issue(st, { actor: { settlement: 999 }, verb: 'routines', args: { routines: [], by: 'meeting' }, source: 'debug' }).includes('no settlement'), true); + assert.strictEqual( + issue(st, { + actor: { settlement: 999 }, + verb: 'routines', + args: { routines: [], by: 'meeting' }, + source: 'debug', + }).includes('no settlement'), + true, + ); assert.strictEqual(JSON.stringify(plan.routines), before, 'refusals change nothing'); } -{ // a year of play: every meeting decides, the fence and the work days chosen where there is one (and a common field where it may); a save keeps the routines +{ + // a year of play: every meeting decides, the fence and the work days chosen where there is one (and a common field where it may); a save keeps the routines const st = fresh(); Sim.advance(st, Sim.YEAR); for (const x of st.villages) { const p = Plans.planOf(st, 'village', x.id); if (!Sim.membersOf(st, x.id).length) continue; assert.strictEqual(p.routinesBy, 'meeting', `village ${x.id}'s meeting decided`); - assert.deepStrictEqual([...p.routines].filter((r) => r !== 'commons').sort(), x.fence.length ? ['fence', 'workdays'] : []); + assert.deepStrictEqual( + [...p.routines].filter((r) => r !== 'commons').sort(), + x.fence.length ? ['fence', 'workdays'] : [], + ); // a common field (VB-100) only where the village has three farms or more - if (p.routines.includes('commons')) assert.ok(VB['sim/green'].houses(st, x).length >= VB['sim/commons'].COMMONS.minFarms); + if (p.routines.includes('commons')) + assert.ok(VB['sim/green'].houses(st, x).length >= VB['sim/commons'].COMMONS.minFarms); } const back = Sim.load(st.w, JSON.parse(JSON.stringify(Sim.save(st)))); - assert.deepStrictEqual([...back.plans.villages.values()].map((p) => p.routines), [...st.plans.villages.values()].map((p) => p.routines)); - assert.deepStrictEqual(checkState(st).filter((x) => /plans|cultures/.test(x)), [], 'invariants'); + assert.deepStrictEqual( + [...back.plans.villages.values()].map((p) => p.routines), + [...st.plans.villages.values()].map((p) => p.routines), + ); + assert.deepStrictEqual( + checkState(st).filter((x) => /plans|cultures/.test(x)), + [], + 'invariants', + ); } -{ // VB-1768: a village's routines as levies, laid in lots by its custom of lots +{ + // VB-1768: a village's routines as levies, laid in lots by its custom of lots const { tinyWorld, tinyState } = require('./lib/tiny.js'); - const Levies = VB['sim/levies'], Ob = VB['sim/obligations'], { OUTER } = VB['sim/days'], { SEASON_DAYS } = VB['sim/rules']; + const Levies = VB['sim/levies'], + Ob = VB['sim/obligations'], + { OUTER } = VB['sim/days'], + { SEASON_DAYS } = VB['sim/rules']; const rows = Array.from({ length: 12 }, (_, i) => (i < 2 ? 'FFFFFFFFFFFFFFFF' : '................')); const st = tinyState(tinyWorld(rows), [{ at: [8, 7], farms: 4, sizes: [6, 6, 6, 1] }], { seed: 4 }); - const v = st.villages[0], plan = Plans.planOf(st, 'village', v.id), s = st.cenv.settlements[v.id]; + const v = st.villages[0], + plan = Plans.planOf(st, 'village', v.id), + s = st.cenv.settlements[v.id]; assert.strictEqual(Customs.PRACTICES.lots.base, 'fields'); - assert.deepStrictEqual(Customs.PRACTICES.lots.opts.map((o) => o[0]), ['fields', 'adults', 'equal']); + assert.deepStrictEqual( + Customs.PRACTICES.lots.opts.map((o) => o[0]), + ['fields', 'adults', 'equal'], + ); assert.ok(Customs.PRACTICES.lots.malleability > 0, 'a practice with its malleability'); assert.strictEqual(Customs.practiceOf(st.cenv.cultures[s.culture], 'lots'), 'fields', 'by fields, the default'); // the split: whole days by the largest remainder, summing to D; ties in turn by household id against the year - const sum = (lots) => lots.reduce((n, l) => n + l[1], 0), N = v.farmsteads.length, y = cal(st.t).year; + const sum = (lots) => lots.reduce((n, l) => n + l[1], 0), + N = v.farmsteads.length, + y = cal(st.t).year; for (const rule of ['fields', 'adults', 'equal']) { const [lots, rest] = Levies.split(st, v.id, 5, rule); assert.strictEqual(sum(lots) + rest, 5, `${rule}: the lots sum to D`); assert.strictEqual(rest, 0); } - const [one] = Levies.split(st, v.id, 1, 'equal'), first = [...Array(N).keys()].sort((a, b) => ((a + y) % N) - ((b + y) % N))[0]; + const [one] = Levies.split(st, v.id, 1, 'equal'), + first = [...Array(N).keys()].sort((a, b) => ((a + y) % N) - ((b + y) % N))[0]; assert.deepStrictEqual(one, [[first, 1]], 'a tie goes by the household id against the year'); - const adults = Levies.split(st, v.id, 6, 'adults')[0], lone = st.households[3]; - assert.ok((adults.find((l) => l[0] === lone.id) || [0, 0])[1] < (adults.find((l) => l[0] === 0) || [0, 0])[1], 'by adults, the small owe less'); + const adults = Levies.split(st, v.id, 6, 'adults')[0], + lone = st.households[3]; + assert.ok( + (adults.find((l) => l[0] === lone.id) || [0, 0])[1] < (adults.find((l) => l[0] === 0) || [0, 0])[1], + 'by adults, the small owe less', + ); // room: at most OUTER.lotMax a household a season, the days past it to the others, what none can take left const [capped, left] = Levies.split(st, v.id, 50, 'equal', () => OUTER.lotMax); assert.ok(capped.every((l) => l[1] === OUTER.lotMax) && left === 50 - N * OUTER.lotMax, 'capped, the rest left'); const [over] = Levies.split(st, v.id, 6, 'equal', (id) => (id === 0 ? 0 : OUTER.lotMax)); assert.ok(!over.some((l) => l[0] === 0) && sum(over) === 6, 'a household with no room: its days to the others'); - const f0 = st.farmsteads[v.farmsteads[0]], had = f0.fields; + const f0 = st.farmsteads[v.farmsteads[0]], + had = f0.fields; f0.fields = []; // lint-allow: owner a test's scene: a household with no fields - assert.ok(!Levies.split(st, v.id, 5, 'fields')[0].some((l) => l[0] === f0.household), 'by fields, one with none owes none'); - assert.ok(Levies.split(st, v.id, 5, 'equal')[0].some((l) => l[0] === f0.household), 'equal, it owes its share'); + assert.ok( + !Levies.split(st, v.id, 5, 'fields')[0].some((l) => l[0] === f0.household), + 'by fields, one with none owes none', + ); + assert.ok( + Levies.split(st, v.id, 5, 'equal')[0].some((l) => l[0] === f0.household), + 'equal, it owes its share', + ); f0.fields = had; // lint-allow: owner the scene undone // the routine set by the meeting, a step of the village's year; its alderman lays its season's lots at his review VB['sim/routines'].setRoutines(st, v.id, ['fence'], 'meeting'); VB['sim/membership'].setAlderman(st, v, st.households[0].holder); const step = VB['sim/routines'].stepOf(plan, 'fence'); - assert.deepStrictEqual([step.author, step.why], ['custom', { custom: 'meeting' }], 'the routine a step of the year, the meeting its why'); + assert.deepStrictEqual( + [step.author, step.why], + ['custom', { custom: 'meeting' }], + 'the routine a step of the year, the meeting its why', + ); for (const x of v.fence) x.cond = 0.2; review(st, 1); // posts the fence's tasks review(st, 2); // the season's lots, sized from them - const lots = st.obligations.filter((o) => o.source === 'routine'), end = SEASON_DAYS - 1; + const lots = st.obligations.filter((o) => o.source === 'routine'), + end = SEASON_DAYS - 1; assert.ok(lots.length > 0, 'lots laid'); for (const o of lots) { - assert.deepStrictEqual([o.kind, o.debtor.kind, o.creditor, o.enforcer, o.window], ['days', 'household', { kind: 'village', id: v.id }, - { kind: 'village', id: v.id }, [2, end]], JSON.stringify(o)); - assert.deepStrictEqual([o.terms.names, o.terms.substitute, o.terms.commute, o.terms.carry], ['levied', true, null, false], 'its terms'); + assert.deepStrictEqual( + [o.kind, o.debtor.kind, o.creditor, o.enforcer, o.window], + ['days', 'household', { kind: 'village', id: v.id }, { kind: 'village', id: v.id }, [2, end]], + JSON.stringify(o), + ); + assert.deepStrictEqual( + [o.terms.names, o.terms.substitute, o.terms.commute, o.terms.carry], + ['levied', true, null, false], + 'its terms', + ); assert.ok(o.owes.days <= OUTER.lotMax); assert.deepStrictEqual(o.why, { step: step.id, of: `village:${v.id}` }, "each levied day's why, its routine"); } @@ -170,25 +305,53 @@ function green(st, v, ids) { // the routines set again mid-season (the meeting's day, here by asLastYear): the routine keeps its step, so its lots' why still reach it VB['sim/routines'].setRoutines(st, v.id, ['fence'], 'asLastYear'); const again = VB['sim/steps'].find(st, plan, lots[0].why.step); - assert.ok(again && again.what.routine === 'fence' && again.id === step.id, 'the step of the why found after the re-set'); + assert.ok( + again && again.what.routine === 'fence' && again.id === step.id, + 'the step of the why found after the re-set', + ); assert.deepStrictEqual(again.why, { custom: 'asLastYear' }, 'its why the new decision'); // the work done: the days left released for (const x of v.fence) x.cond = 1; - review(st, 4); review(st, 5); - assert.ok(lots.every((o) => !Ob.isLive(o)), `the work done, its lots released: ${lots.map((o) => o.status)}`); + review(st, 4); + review(st, 5); + assert.ok( + lots.every((o) => !Ob.isLive(o)), + `the work done, its lots released: ${lots.map((o) => o.status)}`, + ); // the next season: lots laid again, and the work left at its end told at the meeting and weighed for (const x of v.fence) x.cond = 0.2; - review(st, SEASON_DAYS); review(st, SEASON_DAYS + 1); - assert.ok(st.obligations.some((o) => o.source === 'routine' && o.window[0] >= SEASON_DAYS), 'laid again in the next season'); + review(st, SEASON_DAYS); + review(st, SEASON_DAYS + 1); + assert.ok( + st.obligations.some((o) => o.source === 'routine' && o.window[0] >= SEASON_DAYS), + 'laid again in the next season', + ); review(st, 2 * SEASON_DAYS); - assert.ok(plan.routineLeft && plan.routineLeft.days.fence > 0, `the work left kept: ${JSON.stringify(plan.routineLeft)}`); + assert.ok( + plan.routineLeft && plan.routineLeft.days.fence > 0, + `the work left kept: ${JSON.stringify(plan.routineLeft)}`, + ); const voices = Sim.membersOf(st, v.id).filter((p) => Sim.voiceOf(st, p, s) > 0); - L.routinesMeeting(st, s, green(st, v, voices.map((p) => p.id))); + L.routinesMeeting( + st, + s, + green( + st, + v, + voices.map((p) => p.id), + ), + ); const told = st.record.find((e) => typeof e === 'object' && e.kind === 'workLeft' && /work left undone/.test(e.text)); - assert.ok(told && told.text.includes(`${plan.routineLeft.days.fence} day`) && /fence/i.test(told.text), told && told.text); + assert.ok( + told && told.text.includes(`${plan.routineLeft.days.fence} day`) && /fence/i.test(told.text), + told && told.text, + ); assert.ok(plan.routines.includes('fence'), 'the fence chosen again'); - { // the work left weighs in the choice: a routine ranked last comes first with many days of it left - const R = VB['sim/routines'], base = R.chooseRoutines(st, v), was = plan.routineLeft; + { + // the work left weighs in the choice: a routine ranked last comes first with many days of it left + const R = VB['sim/routines'], + base = R.chooseRoutines(st, v), + was = plan.routineLeft; assert.ok(base && base.length > 1, `routines to rank: ${base}`); const k = base[base.length - 1]; plan.routineLeft = { by: plan.routinesBy + plan.routinesYear, days: { [k]: 1000 } }; // lint-allow: owner a test's scene @@ -197,6 +360,132 @@ function green(st, v, ids) { assert.deepStrictEqual(R.chooseRoutines(st, v), base, 'work left under other routines not weighed'); plan.routineLeft = was; // lint-allow: owner the scene undone } - assert.deepStrictEqual(checkState(st).filter((x) => /plans|obligation|levy/.test(x)), [], 'invariants'); + assert.deepStrictEqual( + checkState(st).filter((x) => /plans|obligation|levy/.test(x)), + [], + 'invariants', + ); +} +{ + // a holder proposes (VB-1770): to the next meeting's agenda, once a year; the meeting weighs it; played and unplayed alike + const { st, v, s, plan, voices } = setUp(); + const holders = st.households + .filter((h) => !h.dissolved && h.holder !== null && villageOf(st, st.pawns[h.holder]) === v.id) + .map((h) => h.holder); + assert.ok(holders.length >= 2, 'holders to propose'); + const [played, other] = holders, + propose = (actor, args, source) => issue(st, { actor, verb: 'propose', target: v.id, args, source }); + assert.ok( + /not a holder/.test( + propose( + Sim.membersOf(st, v.id).find((p) => !holders.includes(p.id) && p.household !== null).id, + { what: 'routine', routine: 'fence' }, + 'pawn', + ), + ), + 'only a holder', + ); + assert.ok(/no routine/.test(propose(played, { what: 'routine', routine: 'gaol' }, 'pawn')), 'a known routine'); + assert.strictEqual( + propose(played, { what: 'routine', routine: 'workdays' }, 'player'), + true, + 'the played holder proposes', + ); + assert.ok(/once a year/.test(propose(played, { what: 'routine', routine: 'commons' }, 'player')), 'one a year'); + assert.strictEqual( + propose(other, { what: 'routine', routine: 'green' }, 'pawn'), + true, + 'an unplayed holder proposes', + ); + assert.deepStrictEqual( + plan.proposed.map((x) => [x.by, x.value]), + [ + [played, 'workdays'], + [other, 'green'], + ], + ); + assert.deepStrictEqual( + checkState(st).filter((x) => /plans/.test(x)), + [], + 'invariants', + ); + const Rt = VB['sim/routines']; + assert.ok(Rt.VILLAGE_ROUTINES.workdays.available(st, v), 'work days have work'); + assert.ok(!Rt.VILLAGE_ROUTINES.green.available(st, v), 'the green has none (a well is dug)'); + plan.routines = []; // lint-allow: owner the test starts from a year without village work + L.routinesMeeting( + st, + s, + green( + st, + v, + voices.map((p) => p.id), + ), + ); + const fates = st.record.filter((e) => typeof e === 'object' && e.kind === 'proposal'); + assert.strictEqual(fates.length, 2, 'the record tells each proposal'); + assert.ok( + plan.routines.includes('workdays') && /took it up/.test(fates.find((e) => /work days/.test(e.text)).text), + 'weighed highest: chosen', + ); + assert.ok( + !plan.routines.includes('green') && /refused/.test(fates.find((e) => /green/.test(e.text)).text), + 'no such work: refused', + ); + assert.deepStrictEqual(plan.proposed, [], 'the agenda cleared'); + assert.ok( + /held this year/.test(propose(other, { what: 'routine', routine: 'fence' }, 'pawn')), + 'not once the meeting is held', + ); + // a proposal weighs its routine up in the ranking + const base = Rt.chooseRoutines(st, v), + last = base[base.length - 1]; + assert.strictEqual(Rt.chooseRoutines(st, v, false, { [last]: 1000 })[0], last, "the holders' words weigh"); + // the custom of lots: put to the households, each for the rule that lightens its own lot + const st2 = setUp(); + st2.plan.routines = []; // lint-allow: owner the test starts from a year without village work + const vid = st2.v.id, + hs = st2.st.households.filter( + (h) => !h.dissolved && h.holder !== null && villageOf(st2.st, st2.st.pawns[h.holder]) === vid, + ); + assert.strictEqual( + issue(st2.st, { + actor: hs[0].holder, + verb: 'propose', + target: vid, + args: { what: 'lots', rule: 'equal' }, + source: 'pawn', + }), + true, + ); + L.routinesMeeting( + st2.st, + st2.s, + green( + st2.st, + st2.v, + st2.voices.map((p) => p.id), + ), + ); + const said = st2.st.record.find((e) => typeof e === 'object' && e.kind === 'proposal'); + assert.ok(said && /the meeting (adopted it|kept the custom of lots)/.test(said.text), said && said.text); + assert.strictEqual( + Customs.lotsRule(st2.st, vid), + /adopted/.test(said.text) ? 'equal' : Customs.practiceOf(st2.st.cenv.cultures[st2.s.culture], 'lots'), + ); + // the default author: at the meeting, a holder with no proposal makes one by its own judgement + const st3 = setUp(), + P3 = st3.plan; + L.meetingStage(st3.st, 0); + L.holdMeetings(st3.st); + for (const e of st3.st.record.filter((x) => typeof x === 'object' && x.kind === 'proposal')) + assert.ok(e.pawn !== undefined, "a default author's proposal is told in the record"); + assert.deepStrictEqual( + checkState(st3.st).filter((x) => /plans/.test(x)), + [], + 'invariants after the meetings', + ); } -console.log('routines ok: founded, chosen by the meeting, posted on the villager basis; no quorum with nothing and asLastYear; ties; the verb\'s refusals; the routines\' lots laid, released and their work left told'); +console.log( + "routines ok: founded, chosen by the meeting, posted on the villager basis; no quorum with nothing and asLastYear; ties; the verb's refusals; the routines' lots laid, released and their work left told", +); From 9035a6a705ffe51f951e59f3ddc84bb2594e7cb2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:19:14 +0000 Subject: [PATCH 2/3] VB-1770: keep tests/routines.js unreformatted Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01UXXp2bxFUpiV9FVVGEJoY1 --- tests/routines.js | 431 ++++++++++------------------------------------ 1 file changed, 91 insertions(+), 340 deletions(-) diff --git a/tests/routines.js b/tests/routines.js index b020f65f..37d40cf9 100644 --- a/tests/routines.js +++ b/tests/routines.js @@ -3,44 +3,24 @@ // the village's adults on the `villager` basis, one not chosen posts nothing; a meeting that does not decide (no quorum, a tie) leaves it // to its culture's practice, `nothing` (the default, every generated culture's) or `asLastYear`, told as a notable event of the village. const assert = require('assert'); -const VB = require('../src/load.js'), - G = VB.gen, - Sim = VB.sim; +const VB = require('../src/load.js'), G = VB.gen, Sim = VB.sim; const { setClock } = require('./lib/clock.js'); -const Plans = VB['sim/plans'], - L = VB['sim/meetings'], - Culture = VB.culture, - Customs = VB['sim/customs'], - { issue } = VB['sim/commands']; -const { refreshJobs } = VB['sim/jobs'], - { eligible } = VB['sim/eligibility'], - { DAY, WORK, cal } = VB['sim/rules']; +const Plans = VB['sim/plans'], L = VB['sim/meetings'], Culture = VB.culture, Customs = VB['sim/customs'], { issue } = VB['sim/commands']; +const { refreshJobs } = VB['sim/jobs'], { eligible } = VB['sim/eligibility'], { DAY, WORK, cal } = VB['sim/rules']; const { villageOf } = VB['sim/records']; const { checkState } = require('./lib/invariants.js'); const world7 = require('./lib/probe.js').island(7); // the small island, generated once (VB-862: the full map took 2 s) const fresh = () => Sim.seed(world7, 7, 'founders'); -const vmends = (st, vid) => - [...st.jobs.values()].filter((j) => j.kind === 'mend' && j.owner.type === 'village' && j.owner.id === vid); +const vmends = (st, vid) => [...st.jobs.values()].filter((j) => j.kind === 'mend' && j.owner.type === 'village' && j.owner.id === vid); const failures = (st) => st.record.filter((e) => typeof e === 'object' && e.kind === 'meetingFailed'); // a village with a fence and people with a voice, its stretches worn below mending function setUp() { - const st = fresh(), - v = st.villages.find((x) => x.fence.length && Sim.membersOf(st, x.id).length), - s = st.cenv.settlements[v.id]; + const st = fresh(), v = st.villages.find((x) => x.fence.length && Sim.membersOf(st, x.id).length), s = st.cenv.settlements[v.id]; for (const x of v.fence) x.cond = 0.2; - return { - st, - v, - s, - plan: Plans.planOf(st, 'village', v.id), - voices: Sim.membersOf(st, v.id).filter((p) => Sim.voiceOf(st, p, s) > 0), - }; + return { st, v, s, plan: Plans.planOf(st, 'village', v.id), voices: Sim.membersOf(st, v.id).filter((p) => Sim.voiceOf(st, p, s) > 0) }; } // the village's review now (every holder), the tasks it posts -function review(st, day) { - setClock(st, day * DAY + WORK[0]); - refreshJobs(st, cal(st.t), true); -} +function review(st, day) { setClock(st, day * DAY + WORK[0]); refreshJobs(st, cal(st.t), true); } // a meeting on the green that those in `ids` came to function green(st, v, ids) { const o = { id: 9999, kind: 'meeting', village: v.id, come: [...ids] }; @@ -48,18 +28,13 @@ function green(st, v, ids) { return o; } -{ - // the practice is declared with the customs: every generated culture holds `nothing` +{ // the practice is declared with the customs: every generated culture holds `nothing` const st = fresh(); assert.deepStrictEqual(Object.keys(Customs.PRACTICES), ['noDecision', 'alderman', 'riteDays', 'spinning', 'lots']); - assert.ok( - st.cenv.cultures.every((c) => c.practices.noDecision === 'nothing'), - 'each culture holds nothing', - ); + assert.ok(st.cenv.cultures.every((c) => c.practices.noDecision === 'nothing'), 'each culture holds nothing'); assert.strictEqual(Customs.practiceOf({}, 'noDecision'), 'nothing', 'a culture of an older save reads the base'); } -{ - // at the start, the founders' routines: the fence where the village has one; then the fence's stretches post on the villager basis +{ // at the start, the founders' routines: the fence where the village has one; then the fence's stretches post on the villager basis const { st, v, plan } = setUp(); for (const x of st.villages) { const p = Plans.planOf(st, 'village', x.id); @@ -72,229 +47,119 @@ function green(st, v, ids) { const adult = Sim.membersOf(st, v.id).find((p) => p.age >= 18); assert.strictEqual(villageOf(st, adult), v.id); assert.strictEqual(eligible(st, js[0], adult), 'villager', 'a villager may take it'); - assert.deepStrictEqual( - checkState(st).filter((x) => /plans|cultures/.test(x)), - [], - 'invariants', - ); + assert.deepStrictEqual(checkState(st).filter((x) => /plans|cultures/.test(x)), [], 'invariants'); assert.strictEqual(plan.routinesYear, cal(0).year, 'set in the first year'); } -{ - // a meeting with a quorum decides: the fence, by the meeting +{ // a meeting with a quorum decides: the fence, by the meeting const { st, v, s, plan, voices } = setUp(); plan.routines = []; // lint-allow: owner the test starts from a year without village work - L.routinesMeeting( - st, - s, - green( - st, - v, - voices.map((p) => p.id), - ), - ); + L.routinesMeeting(st, s, green(st, v, voices.map((p) => p.id))); // the work days too (VB-120), which only a meeting sets; and a common field (VB-100): the village's store is empty at the start - assert.deepStrictEqual(plan.routines, ['fence', 'workdays', 'commons']); - assert.strictEqual(plan.routinesBy, 'meeting'); + assert.deepStrictEqual(plan.routines, ['fence', 'workdays', 'commons']); assert.strictEqual(plan.routinesBy, 'meeting'); assert.strictEqual(failures(st).length, 0); - review(st, 1); - assert.strictEqual(vmends(st, v.id).length, v.fence.length, 'the chosen routine posts'); + review(st, 1); assert.strictEqual(vmends(st, v.id).length, v.fence.length, 'the chosen routine posts'); } -{ - // no quorum, practice `nothing`: no village work this year, the stretches post nothing, and the failure is notable in the village's log +{ // no quorum, practice `nothing`: no village work this year, the stretches post nothing, and the failure is notable in the village's log const { st, v, s, plan, voices } = setUp(); - review(st, 1); - assert.ok(vmends(st, v.id).length, 'posted before'); + review(st, 1); assert.ok(vmends(st, v.id).length, 'posted before'); L.routinesMeeting(st, s, voices.length > 1 ? green(st, v, []) : undefined); - assert.deepStrictEqual(plan.routines, []); - assert.strictEqual(plan.routinesBy, 'nothing'); - review(st, 2); - assert.strictEqual(vmends(st, v.id).length, 0, 'a routine not chosen posts nothing, and its tasks are taken down'); + assert.deepStrictEqual(plan.routines, []); assert.strictEqual(plan.routinesBy, 'nothing'); + review(st, 2); assert.strictEqual(vmends(st, v.id).length, 0, 'a routine not chosen posts nothing, and its tasks are taken down'); const f = failures(st); - assert.strictEqual(f.length, 1); - assert.strictEqual(f[0].village, v.id); + assert.strictEqual(f.length, 1); assert.strictEqual(f[0].village, v.id); assert.ok(/did not decide/.test(f[0].text) && /fence goes unmended/.test(f[0].text), f[0].text); assert.deepStrictEqual(Sim.notable(st, f[0]), ['meeting'], 'notable'); assert.ok(Sim.NOTABLE.meeting); - assert.ok( - Sim.villageLog(st).some((x) => x.ev === f[0]), - 'a line of the village log', - ); - assert.ok( - Sim.chronicle(st, { village: v.id }, 'custom').some((x) => x.ev === f[0]), - 'in the village history', - ); - assert.deepStrictEqual( - checkState(st).filter((x) => /plans|cultures/.test(x)), - [], - 'invariants', - ); + assert.ok(Sim.villageLog(st).some((x) => x.ev === f[0]), 'a line of the village log'); + assert.ok(Sim.chronicle(st, { village: v.id }, 'custom').some((x) => x.ev === f[0]), 'in the village history'); + assert.deepStrictEqual(checkState(st).filter((x) => /plans|cultures/.test(x)), [], 'invariants'); } -{ - // no quorum, practice `asLastYear`: last year's routines again +{ // no quorum, practice `asLastYear`: last year's routines again const { st, v, s, plan } = setUp(); st.cenv.cultures[s.culture].practices.noDecision = 'asLastYear'; L.routinesMeeting(st, s, undefined); - assert.deepStrictEqual(plan.routines, ['fence']); - assert.strictEqual(plan.routinesBy, 'asLastYear'); + assert.deepStrictEqual(plan.routines, ['fence']); assert.strictEqual(plan.routinesBy, 'asLastYear'); assert.ok(/keeps last year's work/.test(failures(st)[0].text), failures(st)[0].text); - review(st, 1); - assert.strictEqual(vmends(st, v.id).length, v.fence.length, "last year's routine posts"); + review(st, 1); assert.strictEqual(vmends(st, v.id).length, v.fence.length, 'last year\'s routine posts'); } -{ - // a tie across the fourth place does not decide; otherwise the four most needed - const five = [ - [3, 'a'], - [3, 'b'], - [3, 'c'], - [2, 'd'], - [2, 'e'], - ]; +{ // a tie across the fourth place does not decide; otherwise the four most needed + const five = [[3, 'a'], [3, 'b'], [3, 'c'], [2, 'd'], [2, 'e']]; assert.strictEqual(VB['sim/routines'].rankRoutines(five), null, 'a tie at the cut'); - assert.deepStrictEqual( - VB['sim/routines'].rankRoutines([ - [1, 'a'], - [3, 'b'], - [2, 'c'], - [5, 'd'], - [4, 'e'], - ]), - ['d', 'e', 'b', 'c'], - ); + assert.deepStrictEqual(VB['sim/routines'].rankRoutines([[1, 'a'], [3, 'b'], [2, 'c'], [5, 'd'], [4, 'e']]), ['d', 'e', 'b', 'c']); assert.deepStrictEqual(VB['sim/routines'].rankRoutines([[0, 'fence']]), ['fence'], 'one routine is always chosen'); assert.strictEqual(VB['sim/routines'].MAX_ROUTINES, 4); } -{ - // the verb checks the list: known routines, once, at most four, and how they were set - const { st, v, plan } = setUp(), - before = JSON.stringify(plan.routines); - for (const [args, why] of [ - [{ routines: ['well'], by: 'meeting' }, /no routine well/], - [{ routines: ['fence', 'fence'], by: 'meeting' }, /twice/], - [{ routines: Array(5).fill('fence'), by: 'meeting' }, /at most 4/], - [{ routines: ['fence'], by: 'player' }, /cannot be set/], - ]) { +{ // the verb checks the list: known routines, once, at most four, and how they were set + const { st, v, plan } = setUp(), before = JSON.stringify(plan.routines); + for (const [args, why] of [[{ routines: ['well'], by: 'meeting' }, /no routine well/], [{ routines: ['fence', 'fence'], by: 'meeting' }, /twice/], + [{ routines: Array(5).fill('fence'), by: 'meeting' }, /at most 4/], [{ routines: ['fence'], by: 'player' }, /cannot be set/]]) { const res = issue(st, { actor: { settlement: v.id }, verb: 'routines', args, source: 'debug' }); assert.ok(typeof res === 'string' && why.test(res), `${JSON.stringify(args)}: ${res}`); } - assert.strictEqual( - issue(st, { - actor: { settlement: 999 }, - verb: 'routines', - args: { routines: [], by: 'meeting' }, - source: 'debug', - }).includes('no settlement'), - true, - ); + assert.strictEqual(issue(st, { actor: { settlement: 999 }, verb: 'routines', args: { routines: [], by: 'meeting' }, source: 'debug' }).includes('no settlement'), true); assert.strictEqual(JSON.stringify(plan.routines), before, 'refusals change nothing'); } -{ - // a year of play: every meeting decides, the fence and the work days chosen where there is one (and a common field where it may); a save keeps the routines +{ // a year of play: every meeting decides, the fence and the work days chosen where there is one (and a common field where it may); a save keeps the routines const st = fresh(); Sim.advance(st, Sim.YEAR); for (const x of st.villages) { const p = Plans.planOf(st, 'village', x.id); if (!Sim.membersOf(st, x.id).length) continue; assert.strictEqual(p.routinesBy, 'meeting', `village ${x.id}'s meeting decided`); - assert.deepStrictEqual( - [...p.routines].filter((r) => r !== 'commons').sort(), - x.fence.length ? ['fence', 'workdays'] : [], - ); + assert.deepStrictEqual([...p.routines].filter((r) => r !== 'commons').sort(), x.fence.length ? ['fence', 'workdays'] : []); // a common field (VB-100) only where the village has three farms or more - if (p.routines.includes('commons')) - assert.ok(VB['sim/green'].houses(st, x).length >= VB['sim/commons'].COMMONS.minFarms); + if (p.routines.includes('commons')) assert.ok(VB['sim/green'].houses(st, x).length >= VB['sim/commons'].COMMONS.minFarms); } const back = Sim.load(st.w, JSON.parse(JSON.stringify(Sim.save(st)))); - assert.deepStrictEqual( - [...back.plans.villages.values()].map((p) => p.routines), - [...st.plans.villages.values()].map((p) => p.routines), - ); - assert.deepStrictEqual( - checkState(st).filter((x) => /plans|cultures/.test(x)), - [], - 'invariants', - ); + assert.deepStrictEqual([...back.plans.villages.values()].map((p) => p.routines), [...st.plans.villages.values()].map((p) => p.routines)); + assert.deepStrictEqual(checkState(st).filter((x) => /plans|cultures/.test(x)), [], 'invariants'); } -{ - // VB-1768: a village's routines as levies, laid in lots by its custom of lots +{ // VB-1768: a village's routines as levies, laid in lots by its custom of lots const { tinyWorld, tinyState } = require('./lib/tiny.js'); - const Levies = VB['sim/levies'], - Ob = VB['sim/obligations'], - { OUTER } = VB['sim/days'], - { SEASON_DAYS } = VB['sim/rules']; + const Levies = VB['sim/levies'], Ob = VB['sim/obligations'], { OUTER } = VB['sim/days'], { SEASON_DAYS } = VB['sim/rules']; const rows = Array.from({ length: 12 }, (_, i) => (i < 2 ? 'FFFFFFFFFFFFFFFF' : '................')); const st = tinyState(tinyWorld(rows), [{ at: [8, 7], farms: 4, sizes: [6, 6, 6, 1] }], { seed: 4 }); - const v = st.villages[0], - plan = Plans.planOf(st, 'village', v.id), - s = st.cenv.settlements[v.id]; + const v = st.villages[0], plan = Plans.planOf(st, 'village', v.id), s = st.cenv.settlements[v.id]; assert.strictEqual(Customs.PRACTICES.lots.base, 'fields'); - assert.deepStrictEqual( - Customs.PRACTICES.lots.opts.map((o) => o[0]), - ['fields', 'adults', 'equal'], - ); + assert.deepStrictEqual(Customs.PRACTICES.lots.opts.map((o) => o[0]), ['fields', 'adults', 'equal']); assert.ok(Customs.PRACTICES.lots.malleability > 0, 'a practice with its malleability'); assert.strictEqual(Customs.practiceOf(st.cenv.cultures[s.culture], 'lots'), 'fields', 'by fields, the default'); // the split: whole days by the largest remainder, summing to D; ties in turn by household id against the year - const sum = (lots) => lots.reduce((n, l) => n + l[1], 0), - N = v.farmsteads.length, - y = cal(st.t).year; + const sum = (lots) => lots.reduce((n, l) => n + l[1], 0), N = v.farmsteads.length, y = cal(st.t).year; for (const rule of ['fields', 'adults', 'equal']) { const [lots, rest] = Levies.split(st, v.id, 5, rule); assert.strictEqual(sum(lots) + rest, 5, `${rule}: the lots sum to D`); assert.strictEqual(rest, 0); } - const [one] = Levies.split(st, v.id, 1, 'equal'), - first = [...Array(N).keys()].sort((a, b) => ((a + y) % N) - ((b + y) % N))[0]; + const [one] = Levies.split(st, v.id, 1, 'equal'), first = [...Array(N).keys()].sort((a, b) => ((a + y) % N) - ((b + y) % N))[0]; assert.deepStrictEqual(one, [[first, 1]], 'a tie goes by the household id against the year'); - const adults = Levies.split(st, v.id, 6, 'adults')[0], - lone = st.households[3]; - assert.ok( - (adults.find((l) => l[0] === lone.id) || [0, 0])[1] < (adults.find((l) => l[0] === 0) || [0, 0])[1], - 'by adults, the small owe less', - ); + const adults = Levies.split(st, v.id, 6, 'adults')[0], lone = st.households[3]; + assert.ok((adults.find((l) => l[0] === lone.id) || [0, 0])[1] < (adults.find((l) => l[0] === 0) || [0, 0])[1], 'by adults, the small owe less'); // room: at most OUTER.lotMax a household a season, the days past it to the others, what none can take left const [capped, left] = Levies.split(st, v.id, 50, 'equal', () => OUTER.lotMax); assert.ok(capped.every((l) => l[1] === OUTER.lotMax) && left === 50 - N * OUTER.lotMax, 'capped, the rest left'); const [over] = Levies.split(st, v.id, 6, 'equal', (id) => (id === 0 ? 0 : OUTER.lotMax)); assert.ok(!over.some((l) => l[0] === 0) && sum(over) === 6, 'a household with no room: its days to the others'); - const f0 = st.farmsteads[v.farmsteads[0]], - had = f0.fields; + const f0 = st.farmsteads[v.farmsteads[0]], had = f0.fields; f0.fields = []; // lint-allow: owner a test's scene: a household with no fields - assert.ok( - !Levies.split(st, v.id, 5, 'fields')[0].some((l) => l[0] === f0.household), - 'by fields, one with none owes none', - ); - assert.ok( - Levies.split(st, v.id, 5, 'equal')[0].some((l) => l[0] === f0.household), - 'equal, it owes its share', - ); + assert.ok(!Levies.split(st, v.id, 5, 'fields')[0].some((l) => l[0] === f0.household), 'by fields, one with none owes none'); + assert.ok(Levies.split(st, v.id, 5, 'equal')[0].some((l) => l[0] === f0.household), 'equal, it owes its share'); f0.fields = had; // lint-allow: owner the scene undone // the routine set by the meeting, a step of the village's year; its alderman lays its season's lots at his review VB['sim/routines'].setRoutines(st, v.id, ['fence'], 'meeting'); VB['sim/membership'].setAlderman(st, v, st.households[0].holder); const step = VB['sim/routines'].stepOf(plan, 'fence'); - assert.deepStrictEqual( - [step.author, step.why], - ['custom', { custom: 'meeting' }], - 'the routine a step of the year, the meeting its why', - ); + assert.deepStrictEqual([step.author, step.why], ['custom', { custom: 'meeting' }], 'the routine a step of the year, the meeting its why'); for (const x of v.fence) x.cond = 0.2; review(st, 1); // posts the fence's tasks review(st, 2); // the season's lots, sized from them - const lots = st.obligations.filter((o) => o.source === 'routine'), - end = SEASON_DAYS - 1; + const lots = st.obligations.filter((o) => o.source === 'routine'), end = SEASON_DAYS - 1; assert.ok(lots.length > 0, 'lots laid'); for (const o of lots) { - assert.deepStrictEqual( - [o.kind, o.debtor.kind, o.creditor, o.enforcer, o.window], - ['days', 'household', { kind: 'village', id: v.id }, { kind: 'village', id: v.id }, [2, end]], - JSON.stringify(o), - ); - assert.deepStrictEqual( - [o.terms.names, o.terms.substitute, o.terms.commute, o.terms.carry], - ['levied', true, null, false], - 'its terms', - ); + assert.deepStrictEqual([o.kind, o.debtor.kind, o.creditor, o.enforcer, o.window], ['days', 'household', { kind: 'village', id: v.id }, + { kind: 'village', id: v.id }, [2, end]], JSON.stringify(o)); + assert.deepStrictEqual([o.terms.names, o.terms.substitute, o.terms.commute, o.terms.carry], ['levied', true, null, false], 'its terms'); assert.ok(o.owes.days <= OUTER.lotMax); assert.deepStrictEqual(o.why, { step: step.id, of: `village:${v.id}` }, "each levied day's why, its routine"); } @@ -305,53 +170,25 @@ function green(st, v, ids) { // the routines set again mid-season (the meeting's day, here by asLastYear): the routine keeps its step, so its lots' why still reach it VB['sim/routines'].setRoutines(st, v.id, ['fence'], 'asLastYear'); const again = VB['sim/steps'].find(st, plan, lots[0].why.step); - assert.ok( - again && again.what.routine === 'fence' && again.id === step.id, - 'the step of the why found after the re-set', - ); + assert.ok(again && again.what.routine === 'fence' && again.id === step.id, 'the step of the why found after the re-set'); assert.deepStrictEqual(again.why, { custom: 'asLastYear' }, 'its why the new decision'); // the work done: the days left released for (const x of v.fence) x.cond = 1; - review(st, 4); - review(st, 5); - assert.ok( - lots.every((o) => !Ob.isLive(o)), - `the work done, its lots released: ${lots.map((o) => o.status)}`, - ); + review(st, 4); review(st, 5); + assert.ok(lots.every((o) => !Ob.isLive(o)), `the work done, its lots released: ${lots.map((o) => o.status)}`); // the next season: lots laid again, and the work left at its end told at the meeting and weighed for (const x of v.fence) x.cond = 0.2; - review(st, SEASON_DAYS); - review(st, SEASON_DAYS + 1); - assert.ok( - st.obligations.some((o) => o.source === 'routine' && o.window[0] >= SEASON_DAYS), - 'laid again in the next season', - ); + review(st, SEASON_DAYS); review(st, SEASON_DAYS + 1); + assert.ok(st.obligations.some((o) => o.source === 'routine' && o.window[0] >= SEASON_DAYS), 'laid again in the next season'); review(st, 2 * SEASON_DAYS); - assert.ok( - plan.routineLeft && plan.routineLeft.days.fence > 0, - `the work left kept: ${JSON.stringify(plan.routineLeft)}`, - ); + assert.ok(plan.routineLeft && plan.routineLeft.days.fence > 0, `the work left kept: ${JSON.stringify(plan.routineLeft)}`); const voices = Sim.membersOf(st, v.id).filter((p) => Sim.voiceOf(st, p, s) > 0); - L.routinesMeeting( - st, - s, - green( - st, - v, - voices.map((p) => p.id), - ), - ); + L.routinesMeeting(st, s, green(st, v, voices.map((p) => p.id))); const told = st.record.find((e) => typeof e === 'object' && e.kind === 'workLeft' && /work left undone/.test(e.text)); - assert.ok( - told && told.text.includes(`${plan.routineLeft.days.fence} day`) && /fence/i.test(told.text), - told && told.text, - ); + assert.ok(told && told.text.includes(`${plan.routineLeft.days.fence} day`) && /fence/i.test(told.text), told && told.text); assert.ok(plan.routines.includes('fence'), 'the fence chosen again'); - { - // the work left weighs in the choice: a routine ranked last comes first with many days of it left - const R = VB['sim/routines'], - base = R.chooseRoutines(st, v), - was = plan.routineLeft; + { // the work left weighs in the choice: a routine ranked last comes first with many days of it left + const R = VB['sim/routines'], base = R.chooseRoutines(st, v), was = plan.routineLeft; assert.ok(base && base.length > 1, `routines to rank: ${base}`); const k = base[base.length - 1]; plan.routineLeft = { by: plan.routinesBy + plan.routinesYear, days: { [k]: 1000 } }; // lint-allow: owner a test's scene @@ -360,132 +197,46 @@ function green(st, v, ids) { assert.deepStrictEqual(R.chooseRoutines(st, v), base, 'work left under other routines not weighed'); plan.routineLeft = was; // lint-allow: owner the scene undone } - assert.deepStrictEqual( - checkState(st).filter((x) => /plans|obligation|levy/.test(x)), - [], - 'invariants', - ); + assert.deepStrictEqual(checkState(st).filter((x) => /plans|obligation|levy/.test(x)), [], 'invariants'); } -{ - // a holder proposes (VB-1770): to the next meeting's agenda, once a year; the meeting weighs it; played and unplayed alike +{ // a holder proposes (VB-1770): to the next meeting's agenda, once a year; the meeting weighs it; played and unplayed alike const { st, v, s, plan, voices } = setUp(); - const holders = st.households - .filter((h) => !h.dissolved && h.holder !== null && villageOf(st, st.pawns[h.holder]) === v.id) - .map((h) => h.holder); + const holders = st.households.filter((h) => !h.dissolved && h.holder !== null && villageOf(st, st.pawns[h.holder]) === v.id).map((h) => h.holder); assert.ok(holders.length >= 2, 'holders to propose'); - const [played, other] = holders, - propose = (actor, args, source) => issue(st, { actor, verb: 'propose', target: v.id, args, source }); - assert.ok( - /not a holder/.test( - propose( - Sim.membersOf(st, v.id).find((p) => !holders.includes(p.id) && p.household !== null).id, - { what: 'routine', routine: 'fence' }, - 'pawn', - ), - ), - 'only a holder', - ); + const [played, other] = holders, propose = (actor, args, source) => issue(st, { actor, verb: 'propose', target: v.id, args, source }); + assert.ok(/not a holder/.test(propose(Sim.membersOf(st, v.id).find((p) => !holders.includes(p.id) && p.household !== null).id, { what: 'routine', routine: 'fence' }, 'pawn')), 'only a holder'); assert.ok(/no routine/.test(propose(played, { what: 'routine', routine: 'gaol' }, 'pawn')), 'a known routine'); - assert.strictEqual( - propose(played, { what: 'routine', routine: 'workdays' }, 'player'), - true, - 'the played holder proposes', - ); + assert.strictEqual(propose(played, { what: 'routine', routine: 'workdays' }, 'player'), true, 'the played holder proposes'); assert.ok(/once a year/.test(propose(played, { what: 'routine', routine: 'commons' }, 'player')), 'one a year'); - assert.strictEqual( - propose(other, { what: 'routine', routine: 'green' }, 'pawn'), - true, - 'an unplayed holder proposes', - ); - assert.deepStrictEqual( - plan.proposed.map((x) => [x.by, x.value]), - [ - [played, 'workdays'], - [other, 'green'], - ], - ); - assert.deepStrictEqual( - checkState(st).filter((x) => /plans/.test(x)), - [], - 'invariants', - ); + assert.strictEqual(propose(other, { what: 'routine', routine: 'green' }, 'pawn'), true, 'an unplayed holder proposes'); + assert.deepStrictEqual(plan.proposed.map((x) => [x.by, x.value]), [[played, 'workdays'], [other, 'green']]); + assert.deepStrictEqual(checkState(st).filter((x) => /plans/.test(x)), [], 'invariants'); const Rt = VB['sim/routines']; assert.ok(Rt.VILLAGE_ROUTINES.workdays.available(st, v), 'work days have work'); - assert.ok(!Rt.VILLAGE_ROUTINES.green.available(st, v), 'the green has none (a well is dug)'); + assert.ok(!Rt.VILLAGE_ROUTINES.green.available(st, v), 'the green has none (a well is dug)' ); plan.routines = []; // lint-allow: owner the test starts from a year without village work - L.routinesMeeting( - st, - s, - green( - st, - v, - voices.map((p) => p.id), - ), - ); + L.routinesMeeting(st, s, green(st, v, voices.map((p) => p.id))); const fates = st.record.filter((e) => typeof e === 'object' && e.kind === 'proposal'); assert.strictEqual(fates.length, 2, 'the record tells each proposal'); - assert.ok( - plan.routines.includes('workdays') && /took it up/.test(fates.find((e) => /work days/.test(e.text)).text), - 'weighed highest: chosen', - ); - assert.ok( - !plan.routines.includes('green') && /refused/.test(fates.find((e) => /green/.test(e.text)).text), - 'no such work: refused', - ); + assert.ok(plan.routines.includes('workdays') && /took it up/.test(fates.find((e) => /work days/.test(e.text)).text), 'weighed highest: chosen'); + assert.ok(!plan.routines.includes('green') && /refused/.test(fates.find((e) => /green/.test(e.text)).text), 'no such work: refused'); assert.deepStrictEqual(plan.proposed, [], 'the agenda cleared'); - assert.ok( - /held this year/.test(propose(other, { what: 'routine', routine: 'fence' }, 'pawn')), - 'not once the meeting is held', - ); + assert.ok(/held this year/.test(propose(other, { what: 'routine', routine: 'fence' }, 'pawn')), 'not once the meeting is held'); // a proposal weighs its routine up in the ranking - const base = Rt.chooseRoutines(st, v), - last = base[base.length - 1]; - assert.strictEqual(Rt.chooseRoutines(st, v, false, { [last]: 1000 })[0], last, "the holders' words weigh"); + const base = Rt.chooseRoutines(st, v), last = base[base.length - 1]; + assert.strictEqual(Rt.chooseRoutines(st, v, false, { [last]: 1000 })[0], last, 'the holders\' words weigh'); // the custom of lots: put to the households, each for the rule that lightens its own lot - const st2 = setUp(); - st2.plan.routines = []; // lint-allow: owner the test starts from a year without village work - const vid = st2.v.id, - hs = st2.st.households.filter( - (h) => !h.dissolved && h.holder !== null && villageOf(st2.st, st2.st.pawns[h.holder]) === vid, - ); - assert.strictEqual( - issue(st2.st, { - actor: hs[0].holder, - verb: 'propose', - target: vid, - args: { what: 'lots', rule: 'equal' }, - source: 'pawn', - }), - true, - ); - L.routinesMeeting( - st2.st, - st2.s, - green( - st2.st, - st2.v, - st2.voices.map((p) => p.id), - ), - ); + const st2 = setUp(); st2.plan.routines = []; // lint-allow: owner the test starts from a year without village work + const vid = st2.v.id, hs = st2.st.households.filter((h) => !h.dissolved && h.holder !== null && villageOf(st2.st, st2.st.pawns[h.holder]) === vid); + assert.strictEqual(issue(st2.st, { actor: hs[0].holder, verb: 'propose', target: vid, args: { what: 'lots', rule: 'equal' }, source: 'pawn' }), true); + L.routinesMeeting(st2.st, st2.s, green(st2.st, st2.v, st2.voices.map((p) => p.id))); const said = st2.st.record.find((e) => typeof e === 'object' && e.kind === 'proposal'); assert.ok(said && /the meeting (adopted it|kept the custom of lots)/.test(said.text), said && said.text); - assert.strictEqual( - Customs.lotsRule(st2.st, vid), - /adopted/.test(said.text) ? 'equal' : Customs.practiceOf(st2.st.cenv.cultures[st2.s.culture], 'lots'), - ); + assert.strictEqual(Customs.lotsRule(st2.st, vid), /adopted/.test(said.text) ? 'equal' : Customs.practiceOf(st2.st.cenv.cultures[st2.s.culture], 'lots')); // the default author: at the meeting, a holder with no proposal makes one by its own judgement - const st3 = setUp(), - P3 = st3.plan; - L.meetingStage(st3.st, 0); - L.holdMeetings(st3.st); - for (const e of st3.st.record.filter((x) => typeof x === 'object' && x.kind === 'proposal')) - assert.ok(e.pawn !== undefined, "a default author's proposal is told in the record"); - assert.deepStrictEqual( - checkState(st3.st).filter((x) => /plans/.test(x)), - [], - 'invariants after the meetings', - ); + const st3 = setUp(), P3 = st3.plan; + L.meetingStage(st3.st, 0); L.holdMeetings(st3.st); + for (const e of st3.st.record.filter((x) => typeof x === 'object' && x.kind === 'proposal')) assert.ok(e.pawn !== undefined, 'a proposal is told in the record'); + assert.deepStrictEqual(checkState(st3.st).filter((x) => /plans/.test(x)), [], 'invariants after the meetings'); } -console.log( - "routines ok: founded, chosen by the meeting, posted on the villager basis; no quorum with nothing and asLastYear; ties; the verb's refusals; the routines' lots laid, released and their work left told", -); +console.log('routines ok: founded, chosen by the meeting, posted on the villager basis; no quorum with nothing and asLastYear; ties; the verb\'s refusals; the routines\' lots laid, released and their work left told'); From 94f3d64d47720767a729c9067286a08629e96b73 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 01:22:59 +0000 Subject: [PATCH 3/3] Backlog: VB-1770 done Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UXXp2bxFUpiV9FVVGEJoY1 --- BACKLOG.md | 5 ++--- BACKLOG_ARCHIVE.md | 1 + backlog/VB-1770.md | 2 +- backlog/VB-1771.md | 3 +-- backlog/VB-1773.md | 2 +- backlog/VB-1807.md | 1 + 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BACKLOG.md b/BACKLOG.md index 222bb00f..b9eb2843 100644 --- a/BACKLOG.md +++ b/BACKLOG.md @@ -40,7 +40,7 @@ The order tasks are taken in, the first first (`node tools/backlog.js next`). So | [VB-1709](backlog/VB-1709.md) | Fix: a herd standing away for a household with a farm is never led home (populous small seed 11) | - | 2 | M | VB-1682 found herd 155 standing at farm 0 for household 19 from year 12 on, its drove job never done | | [VB-1738](backlog/VB-1738.md) | Tuning and design review of Stories | talk | 2 | L | With Kim: why old stories sharpen to ±1 and never fade (VB-1681's measure), the Stories model and numbers reviewed, the fix chosen, built and measured | | [VB-1764](backlog/VB-1764.md) | One view of every plan: Sim.strip at four zooms, in place of the timetable and the agenda | plans | 2 | M | sim/timetable and sim/agenda made one view: a body's hours at a zoom (today, the days ahead, the season, the year), past days exact by part, what is to come as the levy in force and what is committed, each estimate a range by the looking pawn's estimate. | -| [VB-1770](backlog/VB-1770.md) | A holder proposes a routine or a change of the custom of lots to the meeting | plans | 2 | S | The verb propose: any holder of the village puts a routine, or the custom of lots, on its meeting's agenda; the decision stays the meeting's by its procedure, and no controller has a ballot. | +| [VB-1771](backlog/VB-1771.md) | Duties of the days ahead: one member sees to a type of recurring work without a window | plans | 2 | M | A duty, given by the head at its review, puts its holder first for one type of recurring work without a window (the wood, the water, the beasts, the cooking) in each day's allotment and nothing more; work with a window is never a duty. In place of VB-1553's removed mechanism. | | [VB-1808](backlog/VB-1808.md) | A firewood goal keeps the timber a building counts on | - | 2 | S | VB-1775 review F3: one firewood task cuts all the timber home up to the season's goal, the timber a barn or cottage step counts on with it | | [VB-1815](backlog/VB-1815.md) | A household's last load of sheaves cut on the road is posted again before the frost | - | 2 | S | the haul re-posted after its last carrier is cut | | [VB-1836](backlog/VB-1836.md) | The owner cache left on another farmstead's tiles in the played populous seed 7 run | - | 2 | S | checkState fails at year 2 of populous small seed 7 with household 0's head played: farmsteads[61] owner cache 63, expected 62 (pre-existing at 79c22dd7) | @@ -257,9 +257,8 @@ By arch, in the order of the Archs table, then priority and ID. Each waits for t | [VB-828](backlog/VB-828.md) | Wrap-up: the round as offers, measured | acts | 3 | M | [VB-694](#VB-694), [VB-695](#VB-695), [VB-696](#VB-696), [VB-825](#VB-825), [VB-827](#VB-827) | long runs and the nightly band for marriages, service, land and settling by offers; the cost early and on a late save; `roundPairs` retired; who never got a yes | | [VB-1556](backlog/VB-1556.md) | A member's voice: a duty asked of the head | plans | 2 | S | [VB-1771](#VB-1771) | A member asks its head for a type of work as its duty, an offer answered by the head; the played member's lever on the day | | [VB-1765](backlog/VB-1765.md) | The page: the strip coloured by whose the hours are, and sovereignty on the pawn's card | plans | 2 | M | [VB-1764](#VB-1764) | One presentation for every plan of every body: the day strip, the agenda and the Plan tab's views drawn from Sim.strip at four zooms, each hour in the colour of whose it is (a breach hatched), the levy's line across each day to come, and the pawn's sovereignty on its card. | -| [VB-1771](backlog/VB-1771.md) | Duties of the days ahead: one member sees to a type of recurring work without a window | plans | 2 | M | [VB-1770](#VB-1770) | A duty, given by the head at its review, puts its holder first for one type of recurring work without a window (the wood, the water, the beasts, the cooking) in each day's allotment and nothing more; work with a window is never a duty. In place of VB-1553's removed mechanism. | | [VB-1772](backlog/VB-1772.md) | Dated steps: work from a day and by a day, taken up on its day, with further hands when its window will be missed | plans | 2 | M | [VB-1771](#VB-1771) | A step of the days ahead with from and by (reap the rye from day 5, by day 9) is taken up by the day's allotment on its day; one its hands cannot finish by its window's end is given further hands at the head's review; leave and an outer levy's named day are dated steps. | -| [VB-1773](backlog/VB-1773.md) | Wrap-up: plans at four scales: the gate on long runs, the predictions measured, the tuning named | plans | 2 | M | [VB-1764](#VB-1764), [VB-1765](#VB-1765), [VB-1770](#VB-1770), [VB-1771](#VB-1771), [VB-1772](#VB-1772), [VB-1780](#VB-1780), [VB-1556](#VB-1556) | The arch checked as a whole: the gate over 10 and 30 years, the predictions Q1 to Q13 against what was built, cost on a late save against today's line plus 7 ms, bands added, and the parameters a tuning run of Kim's would move (LEVY first). | +| [VB-1773](backlog/VB-1773.md) | Wrap-up: plans at four scales: the gate on long runs, the predictions measured, the tuning named | plans | 2 | M | [VB-1764](#VB-1764), [VB-1765](#VB-1765), [VB-1771](#VB-1771), [VB-1772](#VB-1772), [VB-1780](#VB-1780), [VB-1556](#VB-1556) | The arch checked as a whole: the gate over 10 and 30 years, the predictions Q1 to Q13 against what was built, cost on a late save against today's line plus 7 ms, bands added, and the parameters a tuning run of Kim's would move (LEVY first). | | [VB-1780](backlog/VB-1780.md) | The page: outer levies, the alderman's year, and the doors of the ladder, the meeting and the duties on the strip | plans | 2 | M | [VB-1772](#VB-1772) | Steps 7 and 8 build verbs the player cannot yet reach: the strip shows outer levies in their windows with their terms, the alderman's year (levied, named, worked, lapsed, breached), and the doors for name, substitute, commute, breach, release and transfer, propose, a duty's assign and a dated step. | | [VB-1803](backlog/VB-1803.md) | A lodger's harvest days: a member taken in owes an adult-day in summer and one in autumn | plans | 3 | S | [VB-1772](#VB-1772) | the lodger's two adult-days, waiting for a lodger to exist | | [VB-1123](backlog/VB-1123.md) | Page: plan mode: the household's season planned on the map, in place of the Plan tab | - | 2 | L | [VB-1765](#VB-1765) | Plan mode replaces the Plan tab: a bar of the season a member with the actions on it, actions chosen from a tile's menu, problems marked where they are, and the outcome read on the needs (survival's thresholds, by the head's estimate); no target is stepped. Requirements, walks and Kim's decisions of 17 and 18 Nov; mocks A to L. | diff --git a/BACKLOG_ARCHIVE.md b/BACKLOG_ARCHIVE.md index 72ccca8e..c41d5d22 100644 --- a/BACKLOG_ARCHIVE.md +++ b/BACKLOG_ARCHIVE.md @@ -901,3 +901,4 @@ Done tasks and closed archs, moved out of `BACKLOG.md` so its tables list only o | [VB-083](backlog/VB-083.md) | Seasons on the map | roads | 3 | M | Seasonal tints and winter snow on the painted map. | | [VB-034](backlog/VB-034.md) | Splitting land between heirs | debt | 3 | M | Under "land split between heirs" the fields are divided, so the custom stops behaving like a buy-out. | | [VB-1964](backlog/VB-1964.md) | The ice key: two swatches, words one tap in | roads | 1 | S | The ice key beside the calendar is two swatches; their words show one tap in (Kim's icons-first rule). | +| [VB-1770](backlog/VB-1770.md) | A holder proposes a routine or a change of the custom of lots to the meeting | plans | 2 | S | The verb propose: any holder of the village puts a routine, or the custom of lots, on its meeting's agenda; the decision stays the meeting's by its procedure, and no controller has a ballot. | diff --git a/backlog/VB-1770.md b/backlog/VB-1770.md index 6c333f75..6d39be99 100644 --- a/backlog/VB-1770.md +++ b/backlog/VB-1770.md @@ -1,5 +1,5 @@ # VB-1770: A holder proposes a routine or a change of the custom of lots to the meeting -Status: ready +Status: done (2026-11-28) Priority: 2 Size: S Arch: plans diff --git a/backlog/VB-1771.md b/backlog/VB-1771.md index 86e1103b..55e72e01 100644 --- a/backlog/VB-1771.md +++ b/backlog/VB-1771.md @@ -1,6 +1,5 @@ # VB-1771: Duties of the days ahead: one member sees to a type of recurring work without a window -Status: blocked -Waits for: VB-1770 +Status: ready Priority: 2 Size: M Arch: plans diff --git a/backlog/VB-1773.md b/backlog/VB-1773.md index 3121141e..a1e21714 100644 --- a/backlog/VB-1773.md +++ b/backlog/VB-1773.md @@ -1,6 +1,6 @@ # VB-1773: Wrap-up: plans at four scales: the gate on long runs, the predictions measured, the tuning named Status: blocked -Waits for: VB-1764, VB-1765, VB-1770, VB-1771, VB-1772, VB-1780, VB-1556 +Waits for: VB-1764, VB-1765, VB-1771, VB-1772, VB-1780, VB-1556 Priority: 2 Size: M Arch: plans diff --git a/backlog/VB-1807.md b/backlog/VB-1807.md index a7df8f7f..c12ed107 100644 --- a/backlog/VB-1807.md +++ b/backlog/VB-1807.md @@ -36,6 +36,7 @@ Acceptance criteria: - [ ] From VB-1768: section 9, Outer levies: Lots: A routine whose tasks are not yet posted at the season's first review is sized and laid at the first later review of the season that finds them, its window from that day to the season's end - [ ] From VB-083: Climate and travel beyond walking: The map's look by band: autumn colours from 8 game days before the band's normal frost until snow lies; fresh green from the thaw to 10 game days after normal open water; ice that does not bear (frost to lakeBears, soundShut to soundBears, thaw to open) drawn slate, ice that bears near white, with a key. - [ ] From VB-034: Inheritance, Handover and shares (Splitting land): An heir given split fields who dies before its house is built: its title ends and the fields go back to the farm they came from. Only grown siblings in the farm's village with no farm or plot of their own want land; a child takes its share in goods. +- [ ] From VB-1770: section 9, Outer levies: Lots: a village meeting may change its own custom of lots (plan.lotsRule) by a vote of its households, each for the rule giving it the lightest lot of a reference levy, margin 0.4 A line a finding, added by `node tools/backlog.js collect design` (tools/lib/collect.js): findings of a kind are collected, not given a task each.