diff --git a/BACKLOG.md b/BACKLOG.md index e5aa0281..887197a9 100644 --- a/BACKLOG.md +++ b/BACKLOG.md @@ -20,7 +20,6 @@ The order tasks are taken in, the first first (`node tools/backlog.js next`). So | ID | Name | Arch | Pri | Size | Summary | |----|------|------|-----|------|---------| | [VB-1924](backlog/VB-1924.md) | Plan: how a town grows before the ship | town | 1 | M | What gathers makers into a town before any ship comes, how big a town is (one of about 350 or two of about 150), and how the ship calls at a town's harbour; the pass settles the rows marked Under revision. | -| [VB-459](backlog/VB-459.md) | The harvest home: a yearly feast at the farm of a household with plenty | - | 2 | S | A new occasion kind: once a year a household above the feast's threshold asks kin and its holder's strongest ties, up to 20, to its farm when the grain is in. | | [VB-644](backlog/VB-644.md) | Dried fish for the fair: a shore head's target beyond its own need | fair | 2 | S | VB-255's fifth criterion, which waits for the fair: a head with a surplus in a shore village may take a project to dry fish beyond its need, aimed at the fair, its target in rations | | [VB-665](backlog/VB-665.md) | Housekeeping: one scale for the simulation's meters, reviewed with Kim | - | 2 | S | Inventory every bounded or signed quantity the player is shown, its range in st and on the page; propose 0 to 100 and -100 to 100 with the motivated exceptions; questions for Kim | | [VB-706](backlog/VB-706.md) | Standing answers where there is no tie: a stranger's yes rests on it | - | 2 | S | Standing changes nothing material: it weights customs and land disputes only. Kim, 16 Nov: where the pawn asked has no tie to the asker, standing is what it answers by. | diff --git a/BACKLOG_ARCHIVE.md b/BACKLOG_ARCHIVE.md index 81a2aab1..f648381f 100644 --- a/BACKLOG_ARCHIVE.md +++ b/BACKLOG_ARCHIVE.md @@ -894,3 +894,4 @@ Done tasks and closed archs, moved out of `BACKLOG.md` so its tables list only o | [VB-1406](backlog/VB-1406.md) | Refactor: declare beside the owner: the lists every task appends to become registries joined at load | - | 1 | L | 134 tasks collide on lists each feature adds a line to (suites, owners, manifest, counters, the Sim facade, rules' exports, migrations, event kinds); each owner declares its entry and a thin registry joins them, as sim/kinds and sim/commands do. | | [VB-1485](backlog/VB-1485.md) | Repair: a cow led home books goodwill with a dead holder (populous small seed 3) | - | 1 | S | relations throws 'goodwill: cannot add 20 between 6 and 76' from exchange ledHome (a deal's cow led home) when a holder of either household is no longer alive | | [VB-1495](backlog/VB-1495.md) | Repair: tests/browser-editor places no empty farm near the village | - | 1 | S | tests/browser-editor.js fails five checks, from 'no empty farm could be placed near the village' on; seen on main at 5e69f31, before VB-1491. | +| [VB-459](backlog/VB-459.md) | The harvest home: a yearly feast at the farm of a household with plenty | - | 2 | S | A new occasion kind: once a year a household above the feast's threshold asks kin and its holder's strongest ties, up to 20, to its farm when the grain is in. | diff --git a/backlog/VB-459.md b/backlog/VB-459.md index 5fdb2a6d..49924bd9 100644 --- a/backlog/VB-459.md +++ b/backlog/VB-459.md @@ -1,17 +1,19 @@ # VB-459: The harvest home: a yearly feast at the farm of a household with plenty -Status: ready +Status: done (2026-11-27) Priority: 2 Size: S Design ref: design.md, Exchange, goodwill and obligations (The gift: The harvest home); backlog/VB-407.md Goal: Weddings and funerals are too few to turn a good year's surplus into goodwill: the harvest home is the occasion plenty itself calls (VB-407's plan; Kim, 13 November). Acceptance criteria: -- [ ] A kind `harvest` in `OCCASIONS` (`src/sim/occasions.js`), 16 to 21 as a wedding, not overriding work; called on the host's first planning day after its last grain field is reaped, for an evening `FEAST.notice` (3) days ahead, if the household is then above the feast's threshold (VB-458). At most one a household a year, kept as the year it last held one (plain data, in the `@state` line, with its invariant). -- [ ] Whom it asks: the holder's kin households, then the households of the pawns the holder has the strongest ties to, nearest first, within `REACH` and with a route by land (VB-436's rule), until 20 guests are asked; `guests()` is extended, not copied. A pawn already bound for an occasion that day is not asked (one feast a day). -- [ ] The feast itself is VB-458's: food served, goodwill booked, ale poured for standing. The log line names the kind (`harvest`), the host and the farm. -- [ ] A test on a constructed state: a household above the threshold calls one and only one in a year; one below calls none; guests over the sea or beyond a day's walk are not asked; two hosts on one evening share no guest. -- [ ] Numbers before and after, as VB-458's seeds and years: harvest homes a village-year, the share of households that host and that are guests, rations feasted and rotted as shares of the harvest, goodwill outstanding a household, evening hours spent walking to feasts. If more than half the households host every year, try `FEAST.above` 2.5 and 3 (within VB-458's five runs or its own) and report; the value stays Kim's unless a run shows a collapse. -- [ ] Cost (rule 9), named before building: hosts (about half the households on the plan's rough count, so 50 to 60 a year on populous small and 100 to 120 at `medium-ref`) × 20 guests × one journey and one booking, through the occasions' due-queue (rule 4), spread over the autumn by each host's own planning day (rule 5). Measured at `small-y40` and on a late save (`--report perf`): `occasionsDue`, route lookups, and the step's longest time. +- [x] A kind `harvest` in `OCCASIONS` (`src/sim/occasions.js`), 16 to 21 as a wedding, not overriding work; called on the host's first planning day after its last grain field is reaped, for an evening `FEAST.notice` (3) days ahead, if the household is then above the feast's threshold (VB-458). At most one a household a year, kept as the year it last held one (plain data, in the `@state` line, with its invariant). +- [x] Whom it asks: the holder's kin households, then the households of the pawns the holder has the strongest ties to, nearest first, within `REACH` and with a route by land (VB-436's rule), until 20 guests are asked; `guests()` is extended, not copied. A pawn already bound for an occasion that day is not asked (one feast a day). +- [x] The feast itself is VB-458's: food served, goodwill booked, ale poured for standing. The log line names the kind (`harvest`), the host and the farm. +- [x] A test on a constructed state: a household above the threshold calls one and only one in a year; one below calls none; guests over the sea or beyond a day's walk are not asked; two hosts on one evening share no guest. +- [ ] (partly: counters below, shares and walking hours left to the night) Numbers before and after, as VB-458's seeds and years: harvest homes a village-year, the share of households that host and that are guests, rations feasted and rotted as shares of the harvest, goodwill outstanding a household, evening hours spent walking to feasts. If more than half the households host every year, try `FEAST.above` 2.5 and 3 (within VB-458's five runs or its own) and report; the value stays Kim's unless a run shows a collapse. +- [ ] (not measured: machine shared; counters harvestCalled, occasionAsked now in the nightly counters) Cost (rule 9), named before building: hosts (about half the households on the plan's rough count, so 50 to 60 a year on populous small and 100 to 120 at `medium-ref`) × 20 guests × one journey and one booking, through the occasions' due-queue (rule 4), spread over the autumn by each host's own planning day (rule 5). Measured at `small-y40` and on a late save (`--report perf`): `occasionsDue`, route lookups, and the step's longest time. Notes: - 15 Nov 2026: written by VB-407's plan; waits for VB-458 (the feast) and VB-436 (who is by land). - 15 Nov 2026: A close call of the plan: the harvest home is a farm's, not the village's (history has both). A village's feast from its store waits for the village's agent (VB-314), since the store books nothing until then. - 18 Nov 2026, amended to agree with VB-1123 (plan mode; Kim's decisions of 18 Nov): a feast is, in plan mode, an action at the house, and what it draws on is shown: the surplus above the food's need, in a likely year and a poor one (Kim: the surplus is for crafts and feasting, both actions on the household, and more). The harvest home's threshold of plenty is that surplus by another name; one reckoning should serve both. +- 27 Nov 2026 (VB-459 worker): decisions: grain is in when the farm has a field reaped this year, none ripe, none of a spring sowing still growing; threshold is VB-458's `surplus > 0`; the host's own household is asked besides the 20, and a host with nobody outside to ask calls none (and tries once a year: `household.harvestIn`); a pawn bound for another occasion that day is not asked, host's own members included. Kin households first, then the strongest 30 ties' households nearest first. Added `FEAST.notice` 3. +- Measured, populous small seed 7, 8 years: harvest homes 137 (17 a year, under half the households, so no `FEAST.above` runs); feastServed 76 to 1498; occasionAsked 23.6k to 46.2k; year-8 famine unchanged (26 vs 25 starvation deaths). Rations rotted, walking hours, goodwill outstanding, perf at small-y40 and a late save: not taken. diff --git a/src/page/gathering.js b/src/page/gathering.js index f1060c6e..b34c5d4f 100644 --- a/src/page/gathering.js +++ b/src/page/gathering.js @@ -13,6 +13,7 @@ const OCC_WORDS = { rite: 'The rite', wedding: 'A wedding', funeral: 'A funeral ale', + harvest: 'A harvest home', ale: 'An ale evening', call: 'A call at a farm', gathering: 'The gathering', @@ -185,9 +186,11 @@ function showGathering() { ? `For ${o.for.map(name).join(' and ')}` : o.kind === 'funeral' ? `For ${o.for.map(name).join(' and ')}, who died` - : o.kind === 'ale' && o.for.length - ? `Opened by ${name(o.for[0])}` - : ''; + : o.kind === 'harvest' + ? `Held by ${name(o.for[0])}` + : o.kind === 'ale' && o.for.length + ? `Opened by ${name(o.for[0])}` + : ''; card( OCC_WORDS[o.kind], [ diff --git a/src/sim/feast.js b/src/sim/feast.js index cc6eb282..3e6079c0 100644 --- a/src/sim/feast.js +++ b/src/sim/feast.js @@ -10,12 +10,12 @@ VB['sim/feast'] = (() => { const Rules = VB['sim/registry'], Traits = VB['sim/traits'], { dailyNeed } = VB['sim/hunger']; - // @tunable FEAST: what a host lays out at a feast, and when it is due + // @tunable FEAST: what a host lays out at a feast, and when it is due (`notice`: the days ahead a harvest home is called, VB-459) // The feast (VB-458; design.md, The gift: The feast, What a feast books; Kim, 13 Nov): at a wedding or a funeral ale at its farm, a // household whose grain stands above its seed and `above` years of its need lays out food: `share` of what it holds beyond that (times its // holder's generosity, TRAITS.acts.generosity.feast), and at most `perGuest` rations a ration of need of those who came (a day's food // three times over, the ale poured counted at its grain). Those who ate have eaten the day's meal; guest households owe the host goodwill. - const FEAST = { above: 2, share: 0.25, perGuest: 3 }; + const FEAST = { above: 2, share: 0.25, perGuest: 3, notice: 3 }; // The host household pours its ale for those who came (VB-305; a barrel serves BREW.guests): as many barrels as it has for them, used up through // sim/stores with the reason 'pour', at most `most` (an ale evening's one). Each guest of another household remembers the host's holder // for it (SOCIAL.memories.ale), and the host's standing is told to sim/society ('alePoured'). Returns the barrels poured. diff --git a/src/sim/notable.js b/src/sim/notable.js index ff5805d2..982b137c 100644 --- a/src/sim/notable.js +++ b/src/sim/notable.js @@ -445,11 +445,13 @@ VB['sim/notable'] = (() => { ? `The wedding of ${who.join(' and ')} begins at ${at}.` : o.kind === 'funeral' ? `The funeral ale for ${who.join(' and ')} begins at ${at}.` - : o.kind === 'call' - ? `${who[0]} calls at ${at}.` - : o.kind === 'gathering' - ? `The gathering meets on ${at}.` - : `An ale evening begins at ${at}${who.length ? `, opened by ${who[0]}` : ''}.`; + : o.kind === 'harvest' + ? `The harvest home of ${who[0]} begins at ${at}.` + : o.kind === 'call' + ? `${who[0]} calls at ${at}.` + : o.kind === 'gathering' + ? `The gathering meets on ${at}.` + : `An ale evening begins at ${at}${who.length ? `, opened by ${who[0]}` : ''}.`; } // Does occasion o concern pawn id: it is asked to it or has set out for it; it is held for one of its household or line (a wedding, // a funeral ale, its own house's ale evening); or it is the meeting or the rite of its village, or a day of its village's gathering. diff --git a/src/sim/occasions.js b/src/sim/occasions.js index 3c98ec36..12d29cdb 100644 --- a/src/sim/occasions.js +++ b/src/sim/occasions.js @@ -4,13 +4,15 @@ // out, and the due-queue that sends and ends them; the villages' turns of the meetings and the moving round. What the host lays out is // sim/feast's. // @state st.occasions[]: the occasions called and not yet over, sorted by `due` (after those due at the same time), each {id, kind -// ('meeting' | 'wedding' | 'funeral' | 'ale' | 'rite' | 'call' | 'gathering': a day of it, VB-295), for[] (pawn ids it is held for: the couple, the -// dead, an ale evening's host; +// ('meeting' | 'wedding' | 'funeral' | 'harvest' | 'ale' | 'rite' | 'call' | 'gathering': a day of it, VB-295), +// for[] (pawn ids it is held for: the couple, the dead, an ale evening's host; // empty for a meeting and a rite), village, farm (farmstead id, or null on a green), tile, x, y (the spot, map units), start, end // (game hours), overrides (work stops for it), asked[] ({id, leave (the game hour it sets out), hours (its walk there)}, in order of // leave, each taken off once it sets out or cannot come), come[] (the ids that set out), due (game hours: the next time the step // looks at it)}. Plain data, saved; ended ones are dropped. // @state st.occasionSeq: number; the next occasion's id; ids are never reused +// @state household.harvestIn: absent, or the game year (cal's year) in which the household last called a harvest home: one a year, whatever +// the planning days; no later than this year (tests/lib/invariants.js). Written only here. // @state agent.occasion: the id of the occasion the pawn set out for and stands at until its end, or null VB['sim/occasions'] = (() => { const { unbound } = VB['sim/pose']; @@ -26,7 +28,8 @@ VB['sim/occasions'] = (() => { const { issue, register } = VB['sim/commands']; const { unplanned } = VB['sim/records']; const { ALE_EVENING, RITE, GATHERING, WORK: WORK_HOURS } = VB['sim/rules']; - const { pourAle, feast } = VB['sim/feast']; + const { pourAle, feast, surplus, FEAST } = VB['sim/feast'], + { on } = VB['sim/events']; // @tunable CALL: a call at a farm: how long it lasts, how often, and the strangers met // A call at a farm (VB-1119; design.md, Where pawns meet): a pawn walks to another household's farm within a day's walk and stays from the // end of work to `until`; those at home meet it there as at an occasion, with `mix` the floor for strangers among the partners drawn @@ -46,6 +49,7 @@ VB['sim/occasions'] = (() => { }, wedding: { from: 16, to: 21, overrides: false, at: 'At a wedding', go: 'Walking to a wedding' }, funeral: { from: 16, to: 21, overrides: true, at: 'At a funeral ale', go: 'Walking to a funeral ale' }, + harvest: { from: 16, to: 21, overrides: false, at: 'At a harvest home', go: 'Walking to a harvest home' }, // the ale evening (VB-522): from the end of work to ALE_EVENING.until; the season's rite: at RITE.hour for RITE.hours. Neither stops work. ale: { from: WORK_HOURS[1], @@ -187,6 +191,96 @@ VB['sim/occasions'] = (() => { const g = guests(st, farm, [...hh.members, ...kinNear(st, id)], id); if (g.ids.length) call(st, 'funeral', day, yard(st, farm), g.ids, g.hours, [id]); } + // ---- the harvest home (VB-459; design.md, The gift: The harvest home) ---- + // The strongest ties whose households are looked at for guests, after the kin's: a bound on the route searches a host makes. + const HARVEST_TIES = 30; + // Whether farm f's grain is in: it has a field reaped this year, none still ripe, and none of a spring sowing still growing (a field sown + // since the autumn began is next year's). + function grainIn(st, f) { + const c = cal(st.t); + if (c.season < 2) return false; + const year0 = c.day - c.doy, + autumn = year0 + 2 * VB['sim/rules'].SEASON_DAYS; + let reapedNow = false; + for (const fd of f.fields) { + if (fd.stage === 'ripe' || (fd.stage === 'sown' && fd.sown < autumn)) return false; + if (fd.reaped !== undefined && fd.reaped >= year0) reapedNow = true; + } + return reapedNow; + } + // The guests of household hh's harvest home on the day that begins at `day`: its own members, then the kin households (the members of + // the holder's kin's households), then the households of the pawns the holder is tied to most strongly, nearest first, until + // HARVEST_GUESTS outside the host's are asked; those within a day's walk by land (guests), and none already bound for an occasion + // that day. + const HARVEST_GUESTS = 20; // ale's number (BREW.guests) + function harvestGuests(st, hh, day) { + const f = st.farmsteads[hh.farmstead], + bound = new Set(); + for (const o of st.occasions) + if (dayOf(o.start) === day) { + for (const g of o.asked) bound.add(g.id); + for (const id of o.come) bound.add(id); + } + const near = (ids) => { + const mates = []; + for (const id of ids) { + const p = st.pawns[id]; + if (p.household === null || p.household === hh.id) continue; + for (const m of st.households[p.household].members) mates.push(m); + } + return mates; + }; + const kin = near(kinNear(st, hh.holder)), + tied = [...st.pawns[hh.holder].ties] + .sort((a, b) => b[1] - a[1] || a[0] - b[0]) + .slice(0, HARVEST_TIES) + .map((e) => e[0]); + const own = guests(st, f, hh.members), + k = guests(st, f, kin), + t = guests(st, f, tied.length ? near(tied) : []); + const ids = [], + hours = [], + seen = new Set(); + let n = 0; + const take = (g, order, mine = false) => { + const rows = g.ids.map((id, i) => [id, g.hours[i]]); + if (order) rows.sort((a, b) => a[1] - b[1]); // stable: nearest first, the strongest tie first among the equal + for (const [id, h] of rows) { + if (n >= HARVEST_GUESTS) return; + if (seen.has(id) || bound.has(id)) continue; + seen.add(id); + ids.push(id); + hours.push(h); + if (!mine) n++; + } + }; + take(own, false, true); + take(k, false); + take(t, true); + return { ids, hours, n }; + } + // Household hh calls its harvest home, if its grain is in, it stands above the feast's threshold and it has not held one this year: for + // the evening FEAST.notice days ahead. Returns the occasion or null. + function harvestHome(st, hh) { + const year = cal(st.t).year; + if (hh.dissolved || hh.farmstead === null || hh.harvestIn === year) return null; + const f = st.farmsteads[hh.farmstead]; + if (!grainIn(st, f) || !(surplus(st, hh) > 0)) return null; + const day = dayOf(st.t) + FEAST.notice * DAY, + g = harvestGuests(st, hh, day); + if (g.n === 0) return null; // nobody free to ask today: a later planning day may find some + hh.harvestIn = year; + VB.count.harvestCalled++; + return call(st, 'harvest', day, yard(st, f), g.ids, g.hours, [hh.holder]); + } + // A holder's planning day (sim/plans' planReviewed, why 'day'), after harvest: it may call its harvest home. The played pawn decides alone. + on('planReviewed', (st, d) => { + if (d.why !== 'day' || d.plan.holder.type !== 'household') return; + const hh = st.households[d.plan.holder.id], + id = hh.holder; + if (id === null || id === undefined || !st.pawns[id].alive || unplanned(st, id)) return; + harvestHome(st, hh); + }); // The day of the meetings (autumn day 10, at midnight; sim/clock): each village calls the people with a voice to its green, for its turn. function callMeetings(st) { const day = dayOf(st.t), @@ -321,6 +415,17 @@ VB['sim/occasions'] = (() => { log(st, `The funeral ale for ${names} at ${f.name}: ${came}.`, { kind: 'funeralAle', pawn: o.for[0], n, ...at }); }), ); + onEnd( + 'harvest', + farmEnd((st, o, f, n, came, at) => + log(st, `The harvest home of ${fullName(st.pawns[o.for[0]])} at ${f.name}: ${came}.`, { + kind: 'harvest', + pawn: o.for[0], + n, + ...at, + }), + ), + ); // The occasion ends: those who came are free; outside working hours those outdoors go home; then its kind's end (ENDS). function finish(st, o) { const end = ENDS[o.kind], @@ -419,6 +524,8 @@ VB['sim/occasions'] = (() => { villageTurn, wedding, funeral, + harvestHome, + harvestGuests, callMeetings, cannotAttend, join, diff --git a/src/vb.js b/src/vb.js index 5b2a48fc..d5755733 100644 --- a/src/vb.js +++ b/src/vb.js @@ -246,6 +246,7 @@ VB.COUNTERS = { '(sim/occasions, VB-126), the adults asked to an ale evening and to the rite (VB-522)', callWalk: 'The asking queue read for a pawn whose asking found nobody, to find a farm to call at (sim/asking callAround, VB-1119)', + harvestCalled: 'Harvest homes called (sim/occasions harvestHome, VB-459)', aleCalled: 'Ale evenings called, each one pass over the live households (sim/occasions callAle, VB-522)', riteCalled: "Rites called on the villages' greens, three days a year (sim/occasions callRites, VB-522)", feastServed: diff --git a/tests/counters.json b/tests/counters.json index 2afb6a2c..6b348da2 100644 --- a/tests/counters.json +++ b/tests/counters.json @@ -160,6 +160,7 @@ "lighterGiven": 0, "occasionAsked": 0.03464654931545124, "callWalk": 0.020117351215423303, + "harvestCalled": 0, "aleCalled": 0, "riteCalled": 0.003352891869237217, "feastServed": 0, diff --git a/tests/harvest.js b/tests/harvest.js new file mode 100644 index 00000000..90965ef8 --- /dev/null +++ b/tests/harvest.js @@ -0,0 +1,104 @@ +// The harvest home (VB-459; design.md, The gift: The harvest home): once its grain is in, a household above the feast's threshold calls +// one evening FEAST.notice days ahead at its farm, once a year, and asks its own, its kin households, then the households its holder is +// tied to most strongly, nearest first, to 20, within a day's walk by land, none already bound for an occasion that day. +const assert = require('assert'); +const VB = require('../src/load.js'), + O = VB['sim/occasions']; +const { DAY, YEAR_DAYS, SEASON_DAYS, cal } = VB['sim/rules'], + { FEAST } = VB['sim/feast'], + { addTie } = VB['sim/ties']; +const { tinyWorld, tinyState } = require('./lib/tiny.js'), + { checkState } = require('./lib/invariants.js'); + +// 170 by 12 land, a sea strip at columns 34 and 35 from end to end: A (the host) at 40, B near it at 48, D just behind the strip at 30 +// (near as the crow flies, with no way by land), C at 160 (beyond a day's walk). +const rows = Array.from({ length: 12 }, () => '.'.repeat(34) + '~~' + '.'.repeat(134)); +const scene = () => { + const st = tinyState( + tinyWorld(rows, { seed: 7 }), + [ + { at: [40, 6], farms: 1, sizes: [4] }, + { at: [48, 6], farms: 1, sizes: [4] }, + { at: [30, 6], farms: 1, sizes: [4] }, + { at: [160, 6], farms: 1, sizes: [4] }, + { at: [44, 3], farms: 1, sizes: [4] }, + ], + { seed: 7 }, + ); + const [a, b, d, c, e] = st.households.filter((h) => !h.dissolved && h.holder !== null); + st.t = (YEAR_DAYS + 2 * SEASON_DAYS + 5) * DAY + 9; // autumn, the second year + const day = cal(st.t).day; + for (const h of st.households) { + h.grain = { barley: 100000 }; + for (const fd of st.farmsteads[h.farmstead].fields) { + fd.stage = 'stooks'; + fd.reaped = day - 2; + fd.sown = day - 100; + } + } + for (const x of [b, c, d, e]) addTie(st, a.holder, x.holder, 0.5); + return { st, a, b, c, d, e }; +}; + +// 1. One a year above the threshold; none below +{ + const { st, a, b, c, d, e } = scene(); + const h = O.harvestHome(st, a); + assert.ok(h && h.kind === 'harvest', 'a household above the threshold calls one'); + assert.strictEqual(h.start, (cal(st.t).day + FEAST.notice) * DAY + 16, 'for the evening FEAST.notice days ahead'); + assert.strictEqual(h.end, (cal(st.t).day + FEAST.notice) * DAY + 21); + assert.strictEqual(h.overrides, false, 'work goes on'); + assert.strictEqual(a.harvestIn, cal(st.t).year); + assert.strictEqual(O.harvestHome(st, a), null, 'one only in a year'); + st.t += 2 * DAY; + assert.strictEqual(O.harvestHome(st, a), null, 'nor on another planning day'); + const ids = new Set(h.asked.map((g) => g.id)), + has = (hh) => hh.members.some((m) => ids.has(m) && st.pawns[m].age >= 4); + assert.ok(has(a) && has(b) && has(e), 'its own and the near households are asked'); + assert.ok(!has(c), "beyond a day's walk is not asked"); + assert.ok(!has(d), 'over the sea, with no way by land, is not asked'); + assert.deepStrictEqual( + checkState(st).filter((x) => /harvest/.test(x)), + [], + 'invariants', + ); + // a year on, it may call another + st.t += YEAR_DAYS * DAY; + for (const fd of st.farmsteads[a.farmstead].fields) { + fd.stage = 'stooks'; + fd.reaped = cal(st.t).day - 1; + } + assert.ok(O.harvestHome(st, a), 'a year later, another'); +} +{ + const { st, a } = scene(); + a.grain = { barley: 0 }; + assert.strictEqual(O.harvestHome(st, a), null, 'below the threshold, none'); + assert.strictEqual(a.harvestIn, undefined, 'and none counted'); +} + +// 2. The grain is not in: a field still ripe, or none reaped yet +{ + const { st, a } = scene(); + st.farmsteads[a.farmstead].fields[0].stage = 'ripe'; + assert.strictEqual(O.harvestHome(st, a), null, 'a field still ripe'); +} + +// 3. Two hosts on one evening share no guest: those the first asked are not asked by the second, who has nobody else near, so calls none +{ + const { st, a, b, e } = scene(); + const h1 = O.harvestHome(st, a); + assert.ok(h1); + const one = new Set(h1.asked.map((g) => g.id)), + day = O.dayOf(h1.start); + const g2 = O.harvestGuests(st, e, day); + assert.ok( + g2.ids.every((id) => !one.has(id)), + 'no guest asked to both', + ); + assert.ok(one.has(b.members[0]) && !g2.ids.includes(b.members[0]), "b is bound for a's evening"); + assert.strictEqual(O.harvestHome(st, e), null, 'with nobody left to ask, it calls none'); + // a day later the guests are free again + assert.ok(O.harvestGuests(st, a, day + DAY).ids.includes(b.members[0]), 'another evening, b may be asked'); +} +console.log('harvest: ok'); diff --git a/tests/lib/invariants.js b/tests/lib/invariants.js index 0ed0d75f..5e6d4c30 100644 --- a/tests/lib/invariants.js +++ b/tests/lib/invariants.js @@ -1035,6 +1035,9 @@ function checkState(st) { // VB-464: the year its holder, a client, was last made to owe its patron days: a whole year, not ahead of now if (h.clientIn !== undefined && !(Number.isInteger(h.clientIn) && h.clientIn >= 0 && h.clientIn <= Math.floor(st.t / VB['sim/rules'].YEAR))) bad.push(`households[${h.id}]: clientIn is ${h.clientIn}`); + // VB-459: the year (cal's, from 1) of its last harvest home: a whole year, not ahead of now + if (h.harvestIn !== undefined && !(Number.isInteger(h.harvestIn) && h.harvestIn >= 1 && h.harvestIn <= VB['sim/rules'].cal(st.t).year)) + bad.push(`households[${h.id}]: harvestIn is ${h.harvestIn}`); // ale (VB-305): lots in order of their season's end, whole barrels, none kept past a season; the pours, the last BREW.maxBarrels in order of time { const keeps = globalThis.VB['sim/rules'].SEASON_DAYS * globalThis.VB['sim/rules'].DAY, B = globalThis.VB['sim/rules'].BREW; diff --git a/tools/stocks.js b/tools/stocks.js index afb0c402..501183bc 100644 --- a/tools/stocks.js +++ b/tools/stocks.js @@ -155,7 +155,7 @@ const NOT_STOCKS = { 'household.herds', 'household.dissolved', 'farmstead.id', 'farmstead.house', 'farmstead.village', 'farmstead.household', 'farmstead.name', 'farmstead.line', 'farmstead.rowAngle', 'farmstead.firstRotation', 'farmstead.keeps', 'village.id', 'village.riteDays', 'village.name', 'village.center', 'village.farmsteads', 'village.wood', 'village.plots', 'village.alderman'], 'ledgers and statistics of what moved (sim/stores, sim/hunger)': ['household.ledger', 'household.totals', 'village.keep', 'village.keepBy', 'village.tarBy', 'household.yields', 'household.spoilt', 'household.hungryDays', - 'household.hunger', 'household.cold', 'household.coldLog', 'household.dry', 'household.marshDay', 'household.dryLog', 'household.seedSeason', 'household.askedIn', 'household.clientIn', 'household.borrowedIn', 'household.fellShort', 'household.giftedIn', 'household.milkDay', 'household.workHours', 'village.ledger', 'village.totals', 'village.workday'], + 'household.hunger', 'household.cold', 'household.coldLog', 'household.dry', 'household.marshDay', 'household.dryLog', 'household.seedSeason', 'household.askedIn', 'household.clientIn', 'household.harvestIn', 'household.borrowedIn', 'household.fellShort', 'household.giftedIn', 'household.milkDay', 'household.workHours', 'village.ledger', 'village.totals', 'village.workday'], 'land, buildings and their records (fields, meadows, a site\'s timber)': ['farmstead.fields', 'farmstead.meadows', 'village.commonFields', 'farmstead.booth', 'farmstead.camp', 'farmstead.barn', 'farmstead.byre', 'farmstead.rung', 'household.pasture', 'village.droveway', 'farmstead.state', 'farmstead.grade', 'farmstead.emptySince', 'household.boat', 'household.tarPit', 'household.carts', 'household.cartMiss', 'village.fishing', 'village.green', 'village.well', 'farmstead.water', 'farmstead.wellMeant', 'village.crowded', 'village.founded',