From 9f9632961fd34754548233d9f348a7ad853cc22d Mon Sep 17 00:00:00 2001 From: NeoLorenzo Date: Wed, 28 Oct 2026 19:31:00 +0000 Subject: [PATCH] Life 15: simple wayfinding [LIFE15-Wayfinding-071] --- CHANGELOG.md | 10 + LAB_NOTES.md | 10 + docs/ARCHITECTURE.md | 2 +- docs/LIFE15_SPEC.md | 78 ++++++-- docs/VALIDATION.md | 2 +- src/valley/fingerprintRuns.ts | 82 ++++----- src/valley/invariants.ts | 20 +- src/valley/routes.ts | 293 +++++++++++++++++++++--------- src/valley/types.ts | 2 +- src/valley/ways.test.ts | 115 ++++++++---- src/valley/ways.ts | 6 +- src/valleyView/valleyViewModel.ts | 4 +- 12 files changed, 442 insertions(+), 182 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 911ce24..4c3d500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to Econ-Engine are documented here. The changelog records what changed in each update. Design rationale, experiments, observations, and lessons are documented separately in [Lab Notes](LAB_NOTES.md). +## [LIFE15-Wayfinding-071] - (2026-10-28) + +- A new route is planned as people find their way: the straight line when every triangle it crosses is known walkable ground, otherwise steered along the chain of pieces, heading in each piece for the crossing nearest the line on to the target, straight where it can and by a search confined to that piece where it cannot. +- The band of chunks, the search over all known ground and `full` walks are removed. Walk plans are now `way`, `joined`, `straight` and `steered`; the panel says "heading straight there" or "finding a way through". +- The checker requires a way remembered from a straight walk to be exactly the triangles its line crosses, and rejects a new way holding a triangle twice. +- The chain of pieces and the fine search reuse typed arrays and one heap instead of maps, sets and a heap per search. +- Trajectories change: new fingerprints are recorded for 21 of the 22 runs; one flat-land run is unchanged. +- New unit fixtures for straight and steered plans, a line through a vertex, the crossing nearest the line, an obstacle inside one piece, and the checker rejecting a straight way off its line. +- The Life 15 specification is revised for update 071. + ## [LIFE15-Lighter-070] - (2026-10-28) - An exchange no longer copies group members who are dead or out of talking distance, and copies back only the views that changed. diff --git a/LAB_NOTES.md b/LAB_NOTES.md index c0dd7ee..090f5fe 100644 --- a/LAB_NOTES.md +++ b/LAB_NOTES.md @@ -6,6 +6,16 @@ Every meaningful model, architecture, experimental, or design update should receive a newest-first entry. Use at most one base update number per Git commit. Refinements completed before that commit keep the same base number with a decimal suffix—for example, `003` and `003.1` belong to the same commit family. Allocate the next base number only for a later commit. Preserve the context, observed problem or research question, rationale, important implementation decisions, trade-offs, findings, and unresolved questions. Distinguish verified observations from hypotheses. If the original rationale is unknown, say so rather than inferring intent from the finished code. +## [LIFE15-Wayfinding-071] - (2026-10-28) + +After update 070, route planning was about 30% of a day: about 80 new plans a day past day 50 at about 1 ms each, each expanding some 3,400 triangles. The owner pointed out that people do not compute so much to find their way and approved a specification that plans as people do: straight at the goal when the ground ahead is known, otherwise steering round what is in the way, piece by piece (Hochmair and Frank 2000; Bailenson et al. 2000). + +**How lifelike the walks are, on the canonical forty, seed 20260813, against the shortest path over each walker's known ground.** Straight walks are within about 0% of it. Steered walks: day 5, 52 walks, median 0.0% longer, longest 101%; day 13, 562 walks, median 1.4%, longest 156%; day 30, 90 walks, median 2.1%, longest 289%; day 55, 84 walks, median 0.9%, longest 50%. The medians meet the specification's 15%; the long tails are walks whose chain of pieces turns away from the line, which people also do when they head the wrong way round an obstacle. Most new walks past day 20 are steered: about 78 a day against 23 straight. + +**Speed, in Node, 12-hour steps, single runs, against update 070's 1,791 ms, 9,083 ms and 172 ms.** Days 1–10 1,878 ms; the hut week, days 11–19, 7,340 ms; days 20–60 about 185–205 ms a day. A straight plan costs about 4 µs and a steered one about 0.5 ms, with a corridor of some 340 triangles. The first steered version took about 206 ms a day at days 50–59: the chain of pieces built maps and sets, and every in-piece search a new heap. Reusing typed arrays and one heap, and reading each chunk's piece labels once instead of per triangle, brought it to 186 ms, the same cost per wake-up as update 070; this run has about 9% more wake-ups past day 50 (about 1,860 a day against 1,705). + +**Findings.** The specification expected ordinary days at roughly 130–150 ms; they are not faster than before. Planning is cheaper per walk, but steered corridors are long, and cutting a route along them, and the garbage it leaves (about a fifth of the time), costs as much as before. The busy hut week is about 20% faster. Next: cheaper route cutting along long corridors, and the remaining speed-ups that change no result. + ## [LIFE15-Lighter-070] - (2026-10-28) The owner asked why 1 month/s (30 simulated days a second) is out of reach and approved any speed-up that leaves the simulation unchanged. The camp wake-up cascade was kept on purpose: who wakes whom will matter for relationships. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index afabd76..b35a5b7 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -89,7 +89,7 @@ The 3D world draws each firm and Government across its plot: `buildingScale` str - **Clock and queue.** `clock.ts` holds the wake-up queue, ordered by minute, then world before people, then person id. `calendar.ts` turns a minute into a day, a season and a year of `daysPerYear` days. `world.ts` owns hourly and midnight work: regrowth, fish growth, fires and daily summaries. `wake.ts` handles a person's wake-up: it settles the task that ended, perceives, chooses the next task by priority and queues the next wake-up. - **Places.** `places.ts` and `layout.ts` place berry and hazel thickets, wood stands and stone outcrops as aggregate stocks, indexed by place id, with their own regrowth (`logRegrowth` keeps each felled tree's schedule). The terrain, water, shore geometry and fish of Life 11 (`terrain.ts`, `water.ts`, `banks.ts`, `fish.ts`) are kept unchanged. - **Ground mesh.** `mesh.ts` builds, once per layout, a constrained Delaunay triangulation (Delaunator and Constrainautor, pinned) over the whole valley: the hydrology's shorelines simplified to within `shoreToleranceCm`, relief vertices from a quadtree of squares from `meshMaxEdgeCm` down to one terrain cell, and refinement until every dry 5 m point is within `meshHeightToleranceCm` of the terrain. Each triangle has an area type (ground, lake or river), neighbours, a chunk and a region; the largest walkable region is the main land, where founders start. The mesh is cached per terrain and checked once by `meshViolations`. -- **Knowledge and routes.** `perception.ts` records what a person sees at a wake-up: mesh triangles, places with their stock, bank points and other people. Triangle knowledge is a bitset shared between a state and its copy until its holder learns something. `routes.ts` runs A\* over known ground triangles, pulls the path straight through the corridor with the funnel algorithm, and cuts it at triangle edges into segments with their slope and walking time. Bank points sit on the ground side of each shore edge. A new route is planned coarse to fine: an A* over the person's pieces, the joined-up patches of known ground within each chunk, linked across chunk borders only where the person knows ground on both sides (`ChunkLinks`, precomputed per mesh), gives a band of chunks, and the triangle search stays inside it. A chain of pieces is joined-up known ground, so the band always holds a path; the search over the whole known ground remains only as a guard, recorded as a `full` walk, which the checker rejects. Pieces are derived from knowledge, cached per knowledge and carried forward at each survey by dropping only the chunks where triangles were learnt. The still landscape is surveyed again only after moving `resurveyCm` (100 m) from the last survey point; stock at the person's place, people and fires are seen at every wake-up. +- **Knowledge and routes.** `perception.ts` records what a person sees at a wake-up: mesh triangles, places with their stock, bank points and other people. Triangle knowledge is a bitset shared between a state and its copy until its holder learns something. `routes.ts` runs A\* over known ground triangles, pulls the path straight through the corridor with the funnel algorithm, and cuts it at triangle edges into segments with their slope and walking time. Bank points sit on the ground side of each shore edge. A new route is planned the way people find their way: first the straight line, kept when every triangle it crosses is known walkable ground (`lineCorridor`, exact side tests; a line through a vertex counts as blocked); otherwise it is steered. Steering takes an A* over the person's pieces, the joined-up patches of known ground within each chunk, linked across chunk borders only where the person knows ground on both sides (`ChunkLinks`, precomputed per mesh), and then crosses each piece toward the crossing into the next whose midpoint is nearest the line on to the target: straight where the line stays in the piece, otherwise by A* confined to that piece. A chain of pieces is joined-up known ground, so a steered plan always arrives; there is no search over the whole known ground. Pieces are derived from knowledge, cached per knowledge and carried forward at each survey by dropping only the chunks where triangles were learnt. The still landscape is surveyed again only after moving `resurveyCm` (100 m) from the last survey point; stock at the person's place, people and fires are seen at every wake-up. - **Ways.** `ways.ts` keeps each person's remembered ways: immutable corridors of triangles between two ends (the hearth, a place, a known bank point), at most `waysRemembered` (64), the least recently used forgotten first. A walk to such an end takes a way that holds the walker's triangle, whole or joined part-way, in either direction; the route is pulled straight along the way's corridor at the walker's current load. A way is planned again once a day has passed and the person has seen new ground since, or at once if it crosses ground no longer known. Walk events record whether the walk used a way, joined one or planned a new one. An idle person with nothing to explore takes one leisure walk a day along the way from home used longest ago (`leisureMinute`), goes home when away, and otherwise rests. - **Tasks and lazy bodies.** `tasks.ts` builds a `TaskRecord` (kind, start and end minute, place, route, reason, starting body and load). `body.ts` gives energy and water at any minute of a task in closed form (`energyAt`, `waterAt`), and `positionAt` gives the position along its route. Nobody is advanced minute by minute. Food, wood, fire, huts, axes, trade and practice (`food.ts`, `work.ts`, `fire.ts`, `huts.ts`, `axes.ts`, `trade.ts`, `practice.ts`, `social.ts`) apply their rules when a task settles or two people meet. - **Checker.** `invariants.ts` checks each interval against the preceding immutable state. `replay.ts` keeps separate stock, fish, body, tool, hut and water ledgers, replays recorded transfers and regrowth, and compares them with the returned state. Geography is checked once. diff --git a/docs/LIFE15_SPEC.md b/docs/LIFE15_SPEC.md index 16cd228..aa9f4d4 100644 --- a/docs/LIFE15_SPEC.md +++ b/docs/LIFE15_SPEC.md @@ -1,6 +1,6 @@ -# [LIFE15-Lighter-070] +# [LIFE15-Wayfinding-071] -**Approved by the owner, 2026-10-28.** This specification replaced the Life 14 specification at update 066 and describes the whole simulation. It is step 15 of the [roadmap](ROADMAP.md), habitual routes, inserted before relationships, and is built under the [Life section](../SIMULATION_DESIGN_RULES.md#life-realism-and-time) of the design rules. Update 068 revised how a new route is planned. Update 069, below, moves the engine off the page's main thread; it changes only the observer. Update 070 makes wake-ups cheaper without changing any result. +**Updates up to 071 approved by the owner, 2026-10-28.** This specification replaced the Life 14 specification at update 066 and describes the whole simulation. It is step 15 of the [roadmap](ROADMAP.md), habitual routes, inserted before relationships, and is built under the [Life section](../SIMULATION_DESIGN_RULES.md#life-realism-and-time) of the design rules. Update 068 revised how a new route is planned. Update 069, below, moves the engine off the page's main thread; it changes only the observer. Update 070 makes wake-ups cheaper without changing any result. Update 071, below, replaces the detailed route search with the simple rules people use to find their way. Forty strangers are dropped on 4 km square of young glacial land in Mesolithic northern Europe: drumlins, moraine fronts, kames, hummocks, kettle hollows and tunnel valleys, with lakes in the hollows and rivers running downhill to the edge. The ground is grass, dirt and stone. People discover drinking banks, drink, pick berries, gather hazelnuts, fish, gather firewood, meet, form groups, exchange wood and axes for food, and build huts around shared fires. Their knowledge comes from observation and memory. Each of them is a woman or a man with a body of their own and a personality of their own. From this step they find their way as people do: they remember the ways they walk, take them again, and plan afresh only for somewhere new, or now and then to notice a shortcut. @@ -9,7 +9,8 @@ Time is one clock in minutes. Nobody is stepped: a person is woken when their ta ## What Life 15 makes possible - **People walk the ways they know.** Until now every walk was planned from nothing, as the best path over all the ground the person had ever seen, as if they studied a perfect map before every step. Real people learn a few routes between the places they use, take them again, and join a familiar route when they find themselves on it (Siegel and White 1975; Golledge 1999). Each person now remembers **ways**: the line of ground they walked from a starting point to a place, a bank or home. A walk to the same place, or back from it, takes the remembered way, or the rest of a way they are standing on. -- **People plan coarsely, then in detail.** When no way is known, a person first picks a chain of pieces of known land, each within a 200 m square, that leads there, then the exact path within that band, as someone thinks "over the ridge, round the lake" before choosing their footing. Because each piece is ground the person knows to be joined up, the chain always holds a path (update 068). +- **People head straight for where they are going.** When no way is known and the straight line there crosses only ground the person knows they can walk, they walk it (update 071). +- **Otherwise they plan coarsely and steer.** A person picks a chain of pieces of known land, each within a 200 m square, that leads there, as someone thinks "over the ridge, round the lake", then heads for each crossing into the next piece in turn, going round what is in the way only within the piece they are crossing. Because each piece is ground the person knows to be joined up, the chain always holds a path (updates 068 and 071). - **People notice shortcuts slowly.** A remembered way is reconsidered at most once a day, and only if the person has seen new ground since they planned it. Until then they keep to it, even if a better path has just come into view. - **People look again only when they have moved.** The still landscape in sight (ground, banks, thickets, stands, outcrops) is surveyed again only once the person has moved 100 m from where they last surveyed it. People, fires, flags and huts, and the stock where the person stands are noticed at every wake-up, as before. - **Why now.** In the canonical run, the engine is about 400 times slower per simulated hour on day 12 than on day 2: in four midday hours of day 12 people searched 1,675 routes, every one planned anew, none repeating an earlier search (update 065). Planning every walk from scratch is both unrealistic and the largest single cost of a late day. Fixing it now, before relationships add more walking, keeps later steps runnable. @@ -17,6 +18,25 @@ Time is one clock in minutes. Nobody is stepped: a person is woken when their ta This step changes how people find and keep their way, and how often they look around. It does not change the map, the ground anyone may walk, walking speeds, the resources, bodies, personality or what people can do. +## Update 071: simple wayfinding + +**The problem.** After update 070 a simulated day past day 50 takes about 195 ms, against about 33 ms for a month a second. Finding routes is the largest part, about 30%. Of about 400 walks a day, about 80 are planned afresh, at about 1 ms each: to find a path about 150 triangles long, the fine A\* expands about 3,400 triangles, more than twenty times the path. It is also not how people find their way. The fine A\* finds the shortest path over every triangle in a band of known ground, as if the walker compared thousands of footings before setting off. + +**How people find their way.** People do not compute shortest paths. They head roughly towards the goal, choosing at each choice point the direction that points most nearly at it (the least-angle strategy, Hochmair and Frank 2000); they prefer routes whose first stretch is long and straight (Bailenson et al. 2000); they keep and reuse familiar routes (Golledge 1999); and they go round an obstacle when they reach it rather than planning the detour from afar. The routes they take are commonly longer than the shortest ones (Zhu and Levinson 2015). + +**The change.** A walk that has no remembered way to take is found by the first of two rules that applies: + +1. **Straight there.** If the straight line from the walker to the target crosses only triangles that are walkable and known to the person, the walk follows it. Checking costs one step per triangle crossed: tens, not thousands. +2. **Steered through pieces.** Otherwise the coarse A\* over the person's pieces of known ground picks the chain as now (update 068). The walker then crosses the chain piece by piece. From where they enter a piece, they head for the crossing into the next piece that is nearest the line to the target, straight if that line stays within the piece, and otherwise by the fine A\* limited to that one piece, never more than one 200 m square. The walk's corridor is these stretches joined, pulled tight as every corridor is. + +The band, the fine A\* over a band and the full search over all known ground are removed. A piece is joined-up known ground, so the search within a piece always succeeds, and a chain of pieces always yields a walk: no guard is needed. + +Remembered ways, joining a way part-way, rechecking a way once a day and forgetting are unchanged; a recheck plans afresh by the two rules above. Ways are now remembered from straight and steered walks. + +**Expected, and measured.** The work of a new plan was expected to fall from about 3,400 triangles expanded to the triangles crossed by straight lines plus small searches within the few pieces where a line is blocked, and a day past day 50 from about 195 ms to roughly 130–150 ms. Measured, it did not. A straight plan costs about 4 µs, but only about one new plan in four is straight past day 20. A steered plan costs about 0.5 ms, and its corridor of some 340 triangles makes the route cut along it no cheaper than before. Over 60 days in 12-hour steps (single runs, against update 070): the hut week, days 11–19, takes 7.3 s instead of 9.1 s; days 1–10 take about the same; days 20–60 take about 185–205 ms a day instead of 172. Per wake-up the cost is the same as before; the run differs from 070's and has about 9% more wake-ups past day 50. So this update makes walks lifelike and the busy first weeks faster, but not ordinary days. The speed-ups that change no result (the inner loops, ground heights at places, the water search for people who know many banks, fewer short-lived objects) remain for separate updates; a month a second needs more still. + +**Who notices.** Paths are less perfect: a steered walk can be a little longer than the shortest path over known ground, going through the crossing nearest the goal rather than the best one, and round the near side of a lake. A median excess within about 15% is expected and examined in the lab notes, not tuned away. Every run's trajectory changes, including on the flat land, where straight lines replace searched paths. The person panel's wording for a new walk changes. Nothing else about people changes. + ## Update 070: lighter wake-ups **The problem.** After update 069, 1 month/s reaches about 4 simulated days a second, against 30 wanted. On the canonical forty past day 50 a simulated day costs about 230 ms of engine time: a thousand wake-ups that end in "keep resting" take 37 ms, four hundred walk decisions 140 ms, and the rest is the step's own copies and about 45 ms of garbage collection over 270 MB of short-lived objects a day. @@ -86,7 +106,7 @@ After the behaviour change and its new fingerprints, each further speed-up must | --- | --- | --- | | Route choice | People rarely take the shortest path. Most commuters keep to habitual routes longer than the shortest one (Zhu and Levinson 2015); pedestrians choose by familiarity and simple rules such as "head roughly the right way" more than by distance (Golledge 1995; Hölscher et al. 2011). | Magnitudes, measured once on the canonical seed: how much longer walks on a remembered way are than the shortest path over the walker's known ground at that minute, as a median and the largest. A median within about 10% is expected; a large excess is examined in the lab notes, not tuned away. | | Reuse | Habit: most trips go between a few familiar places along familiar routes (Golledge 1999). | Recorded once on the canonical seed: the share of walks by how they were found (a remembered way, a joined way, a coarse plan, a full plan), day by day. Most walks to places are expected to use a way after the first days. | -| Coarse planning | Planning by regions before footing gives routes close to the shortest when regions are small against the trip (hierarchical path planning, Botea et al. 2004). | Recorded once on the canonical seed: how much longer coarse plans are than the shortest path over the walker's known ground at that minute, as a median and the largest. From update 068 no plan needs the full search. | +| New routes | People head towards the goal by the direction that points most nearly at it (Hochmair and Frank 2000), prefer a long straight first stretch (Bailenson et al. 2000), and take routes longer than the shortest (Zhu and Levinson 2015). Planning by regions before footing gives routes close to the shortest when regions are small against the trip (Botea et al. 2004). | Recorded once on the canonical seed from update 071: the share of new walks straight and steered, and how much longer each kind is than the shortest path over the walker's known ground at that minute, as a median and the largest. A median excess within about 15% is expected. | | Adult height | Mesolithic Europe, from skeletons: men about 165 cm and women about 154 cm, each with a spread of about 6 cm (Formicola and Giannecchini 1999; Ruff 2018). The forty founders' means lie within 3 cm of these, and the sexes do not overlap much more than real ones. | Magnitudes; checked once on the canonical seed, and by a unit test over 10,000 draws. | | Adult body mass | Mesolithic Europe, estimated from skeletons: men about 62 kg, women about 52 kg (Ruff 2018). | As above. | | Strength | Grip strength, the standard field measure, among forager-horticulturalists (Tsimane, Hadza, Agta): men about 38 kg, women about 24 kg, with women's strength about 60% of men's (Gurven et al. 2006; Apicella 2014). | As above. | @@ -105,16 +125,18 @@ After the behaviour change and its new fingerprints, each further speed-up must | A way is the corridor of triangles a walk crossed, kept with its two end points, the minute it was planned and the person's knowledge revision then. The path is pulled tight afresh along the corridor at each use and timed for the walker's load. | The corridor is what a person remembers ("along the stream, through the gap"); pulling it tight is the walking. Keeping the corridor rather than a timed path keeps a way good under any load: a load changes speed, not the way. | | Ways are kept only for walks to a place, a bank point or the person's hearth, never to a frontier. | Habits form between places used again. Exploring is by definition going somewhere new. | | A way can be walked in either direction, and joined part-way: a walker standing in a triangle of a way with an end at the target walks the rest of it. | Home to thicket is also thicket to home. Joining from part-way is what makes a habit useful when a walk starts from elsewhere, for instance after an interrupted walk. | -| Joining is only from a triangle on the way itself, not from nearby. | Joining from nearby needs a small search to reach the way and a rule for how near. The exact rule is simpler and already covers walks resumed along a way. A join radius is a question for later. | +| Joining is only from a triangle on the way itself, not from nearby. (Update 071 keeps this.) | Joining from nearby needs a small search to reach the way and a rule for how near. The exact rule is simpler and already covers walks resumed along a way. A join radius is a question for later. | | When several ways could serve, the one used most recently wins, ties by lowest way number. | A deterministic, human rule: take the route you took last time. | | A person keeps at most `waysRemembered` (64) ways. A new way to the same two end points replaces the old one; when full, the way used longest ago is forgotten, ties by lowest way number. | Bounds memory and work per person. People forget routes they stop using. | | A remembered way is reconsidered when it is about to be used, if `wayRecheckMinutes` (one day) has passed since it was planned and the person's knowledge has grown since. Otherwise it is used as it is, even if a shorter path is now known. | Rules 2 and 10: local, not optimal, decisions, and learning through experience. People notice a shortcut eventually, not the instant it comes into sight. Once a day bounds re-planning per way. | | A way whose triangles are not all still walkable and known to the person is dropped and planned afresh. | Nothing can block a way in this step, because the ground does not change and knowledge only grows; the rule is for floods, fences and palisades later, and costs one pass over the corridor. | | An idle person who has nothing new to explore no longer tours the places they know. Once a day they walk out along a remembered way from home, the one used longest ago, and otherwise go home and rest. | Foragers spend much of the day resting and in company at camp (Hawkes et al. 1997; Marlowe 2010), and learn the state of patches while out foraging, not by inspecting every one daily. In Life 14 an idle person walked to every known place unchecked for a day, about 210 short walks a day each from day 13, which also made late days slow. A walk along a known way needs no planning, and refreshes the memory of the place at its far end. | -| A new plan is coarse first: an A\* over the person's pieces of known ground, then the fine A\* restricted to triangles whose chunks are on the chain of pieces or next to it. (Update 068; before, the coarse A\* ran over whole chunks, and when the band held no path the fine A\* ran over all known triangles.) | People plan by regions before footing (Golledge 1999). The band keeps a fine search to a few chunks instead of the whole known valley. A chain of joined-up pieces always holds a path, so every target on the person's known ground is reached without searching all of it. | +| A new plan is straight if the line to the target crosses only known walkable ground. (Update 071.) | People head for what they are going to when nothing they know of stands in the way (Hochmair and Frank 2000). One step per triangle crossed. | +| Otherwise a new plan is steered: an A\* over the person's pieces of known ground picks a chain, and the walker crosses it piece by piece, heading for the crossing into the next piece nearest the line to the target, straight where they can and by a fine A\* within the one piece where they cannot. (Update 071; from update 068 to 070 the fine A\* ran over a band of chunks around the whole chain; before, the coarse A\* ran over whole chunks.) | People plan by regions before footing and steer round obstacles as they meet them (Golledge 1999), rather than comparing every footing to the goal. A fine search within one 200 m piece is what a walker can see and judge on the spot. Searching the whole band expanded about twenty times the triangles of the path. | +| The crossing into the next piece is the edge between the two pieces whose midpoint is nearest the straight line from the walker's entry point to the target, ties by the lower triangle id on the walker's side. | The least-angle rule: of the ways onward, take the one pointing most nearly at the goal. It is local, needs no look further ahead, and is deterministic. | | A person's piece is a largest set of their known walkable triangles in one chunk joined to each other by shared edges within that chunk; it is numbered by its lowest triangle id. Two pieces in different chunks are linked when a known walkable triangle in one shares an edge with one in the other. A triangle belongs to the chunk holding its centroid. The coarse cost is the distance between chunk centres, ties by piece number. | It uses only what the person knows (rule 1), and only ground they know to be joined, so the coarse plan never promises a crossing that is not there. Linking whole chunks failed whenever a chunk held two separate patches of known ground, which on day 13 sent a third of all new plans to a search of everything known. | | Pieces are worked out from the person's knowledge when needed and not stored in the state; only the chunks holding newly learnt triangles are worked out again. | They follow from knowledge alone, so keeping them would add state that could disagree with it. Most chunks change rarely once known. | -| The full search over all known ground stays only as a guard: if the band ever held no path, the walk is planned in full and recorded as `full`, and the checker rejects it. | By construction it never runs. A guard that a checked run rejects finds a mistake in the pieces without stopping an unchecked run in the browser. | +| There is no search over all known ground, and no guard. (Update 071; from update 068 to 070 a `full` search was kept as a guard.) | A piece is joined-up known ground, so the search within a piece always succeeds, and a chain of pieces always yields a walk. | | The still landscape is surveyed again only once the person stands `resurveyCm` (100 m) or more from where they last surveyed it. People, people-made places and the stock where the person stands are looked at every wake-up. | Ground, water, thickets and stands do not move; looking again over the same kilometre from the same spot learns almost nothing. 100 m is a tenth of the sight radius: what is missed at the edge of sight is learnt on the next move. | | The route cache by exact end points, knowledge revision and load is removed. | Ways replace it. It was almost never reused, because a start a centimetre away or one newly seen triangle made a new key. | | Travel estimates for choosing targets stay straight-line lower bounds. | A person judges how far a place is before walking; the way is what they then walk. | @@ -311,13 +333,18 @@ When a walk to a target starts, in this order: - if it has a triangle that is no longer walkable or known to the person, it is forgotten and the search goes on to step 2; - if `wayRecheckMinutes` have passed since it was planned and the person's knowledge revision has changed since, it is planned afresh by step 2, and the new way replaces it; - otherwise the walk takes the part of the corridor from the walker's triangle to the target's end, reversed if the target is the way's start. It is a **way** walk if the walker stands at the way's other end, and a **joined** walk otherwise. -2. **A coarse plan.** If start and target lie in different pieces of the person's known ground, an A\* over pieces finds a chain from the start's piece to the target's, moving only between linked pieces, costed by the distance between their chunk centres, with the distance from a piece's chunk centre to the target's as the estimate, ties by piece number. If they lie in the same piece, the chain is that piece. The band is the chain's chunks and every chunk next to one of them, side or corner. The fine A\* then runs over the person's known walkable triangles in the band. It is a **coarse** walk. -3. **The guard.** A chain exists whenever start and target are on one piece of known ground, and the band then always holds a path. If the band's search failed all the same, the fine A\* would run over all the person's known walkable triangles and the walk be recorded as **full**; a checked run rejects it. +2. **Straight.** The straight line from the walker's position to the target is followed through the mesh from the walker's triangle, crossing at each step the edge the line leaves by. If every triangle it crosses is walkable and known to the person, and it reaches the target's triangle, the corridor is those triangles. A line that passes exactly through a vertex of the mesh, or a walker or target standing outside their route triangle (within `NEAR_CM` of it), counts as not clear. It is a **straight** walk. +3. **Steered.** Otherwise, if start and target lie in different pieces of the person's known ground, an A\* over pieces finds a chain from the start's piece to the target's, moving only between linked pieces, costed by the distance between their chunk centres, with the distance from a piece's chunk centre to the target's as the estimate, ties by piece number. If they lie in the same piece, the chain is that piece. The walker then crosses the chain piece by piece: + - The **entry** into the first piece is the walker's position and triangle. + - In each piece but the last, the **exit** is the crossing edge from this piece to the next, among those the mesh lists between the two pieces' chunks, whose midpoint is nearest the straight line from the entry point to the target, ties by the lower triangle id on this side. The entry into the next piece is that edge's midpoint and the triangle on its far side. + - In the last piece, the exit is the target and its triangle. + - Within a piece, the stretch from entry to exit is the straight line between them if every triangle it crosses belongs to this piece and it passes through no vertex; otherwise it is the fine A\* from the entry triangle to the exit triangle over this piece's triangles only. + - The corridor is the stretches joined in order. It is a **steered** walk. 4. If the target is unknown or unreachable, the person walks to the nearest known frontier, or rests with `no known route`, as before. **Leisure.** A person idle at their hearth (priority 9, no frontier in range), who has not set out on a leisure walk this calendar day, takes the remembered way with an end at their hearth that was used longest ago (ties by lowest number) whose far end can be reached and left for home before dusk, less their dusk margin, by the straight-line estimate. They walk it to its far end, `out for a walk`, and the walk's start records the minute in `leisureMinute`. Idle away from their hearth, they walk home, `going home to rest`. Idle at home otherwise, they rest. A person with no such way rests. -The fine A\* is Life 14's: costed by the distance between the midpoints of the edges crossed, ties by triangle id. Before a fine search, the person's known pieces of ground are compared as before; targets on another piece go straight to step 4. A coarse, full or rechecked plan to a place, bank point or hearth is remembered as a way between the walk's start and the target, replacing any way with the same two end points; when the person holds `waysRemembered` ways, the one used longest ago is forgotten first, ties by lowest number. Using a way sets its last-used minute. Walks to a frontier are never remembered. +The fine A\* is Life 14's: costed by the distance between the midpoints of the edges crossed, ties by triangle id; from update 071 it runs within one piece only. Before a new plan, the person's known components of ground are compared as before; targets on another component go straight to step 4. A straight, steered or rechecked plan to a place, bank point or hearth is remembered as a way between the walk's start and the target, replacing any way with the same two end points; when the person holds `waysRemembered` ways, the one used longest ago is forgotten first, ties by lowest number. Using a way sets its last-used minute. Walks to a frontier are never remembered. A person's pieces are found within each chunk: known walkable triangles of the chunk sharing an edge belong to one piece, numbered by its lowest triangle id. Two pieces are linked when one of the mesh's chunk-crossing edges, listed once per layout, joins a triangle of one to a triangle of the other. A triangle's chunk is the chunk holding its centroid. Pieces and links are worked out from the person's knowledge, never stored, and only for chunks where the person has learnt triangles since they were last worked out; they cannot change any result. @@ -437,14 +464,14 @@ The checker replays the events of each `stepValley` interval against the state i - Every decision reads memory only. - Hunger and thirst hysteresis with the person's own levels, death minute and cause, and group dissolution below two living members follow the stated order. -Events are as Life 14; a walk's start records how it was found (`plan`: `way`, `joined`, `coarse`, or `full` only from the guard; a walk to a frontier is coarse), whether a way was dropped and planned again (`rechecked`), and the way it used (`wayId`, −1 for a new plan). An observation records whether it was a survey. Daily summaries and world metrics are as Life 14. +Events are as Life 14; a walk's start records how it was found (`plan`: `way`, `joined`, `straight` or `steered`; a walk to a frontier is straight or steered; from update 068 to 070 `coarse`, or `full` only from the guard), whether a way was dropped and planned again (`rechecked`), and the way it used (`wayId`, −1 for a new plan). An observation records whether it was a survey. Daily summaries and world metrics are as Life 14. ## Observer Label the page **Life 15 · strangers**. Everything else in the settings screen, loading card, header, history panel, group card, playback and landscape is as Life 14, except that from update 069 the engine runs in a worker thread and the page draws from view copies of its states, as described there. - **Ways.** When a person is followed, their remembered ways are drawn as faint lines on the ground, from the corridors pulled tight, the most recently used strongest; the current walk is drawn as before. -- **Person panel.** Adds a "Ways" row ("Knows 23"), and the current walk says how it was found: "on a known way", "joining a known way" or "planning a new way". +- **Person panel.** Adds a "Ways" row ("Knows 23"), and the current walk says how it was found: "on a known way", "joining a known way", "heading straight there" or "finding a way through" (from update 071; before, "planning a new way"). Unchanged from Life 14: @@ -455,8 +482,8 @@ Unchanged from Life 14: ## Code layout - New `src/valley/ways.ts`: a person's ways, finding one for a walk, joining, rechecking, remembering and forgetting. -- `routes.ts`: corridors from a way; the chunk-crossing edges in the nav map, the coarse chunk A\*, and the fine A\* limited to a band; `knownRoute` split into finding a corridor and timing a path along it. -- `forager.ts`: `routeFor` uses ways, coarse and full plans in that order; the route cache and `routeKey` are removed; the idle rule takes a leisure walk or goes home to rest in place of rechecking places, and `exploreAfterHours` is removed. +- `routes.ts`: corridors from a way; the chunk-crossing edges in the nav map, the coarse A\* over pieces, the straight-line corridor, and the fine A\* limited to one piece (update 071); `knownRoute` split into finding a corridor and timing a path along it. +- `forager.ts`: `routeFor` uses ways, straight and steered plans in that order; the route cache and `routeKey` are removed; the idle rule takes a leisure walk or goes home to rest in place of rechecking places, and `exploreAfterHours` is removed. - `wake.ts`: a walk's start remembers its way and records how it was found. - `perception.ts`: the survey point; the still landscape surveyed only after moving `resurveyCm`; people-made places and people every wake-up. - `types.ts`, `config.ts`, `engine.ts`: the person's ways, next way number and survey point, shared between states; the new parameters and their validation. @@ -470,6 +497,8 @@ Update 068 changes `routes.ts` only for behaviour: a person's pieces, worked out Update 069 touches only `src/valleyView/`: a new `engineWorker.ts` that builds the valley, runs towards the goal in slices and posts view copies; a new `engineLink.ts`, the page's end of the worker, which starts it and turns the changes received into states; a new `viewCopy.ts` that makes a view copy, finds its changes from the last one in the worker, and applies them on the page; playback in `valleyViewModel.ts` (`advancePlayback`, `receiveState`, `stepPlayback`, `changeSpeed`) in place of stepping the engine within a frame budget, used by `ValleyApp.tsx`; and `LifePage.tsx` starting the worker before building the page's own valley, so the two builds run at once. The engine is unchanged. +Update 071 changes `routes.ts`: a straight-line corridor through the mesh; the chain of pieces kept as a list of pieces; the crossings between pieces; the fine A\* limited to one piece in place of a band; the band and the full search removed. `ways.ts` and `types.ts` name the plans `straight` and `steered` in place of `coarse` and `full`; `invariants.ts` drops the `full` check and adds the checks below; the panel wording in `valleyViewModel.ts`. `knownRoute`, the shortest path over all known ground, stays for tests and measurement only. + Update 070 changes no result: `wake.ts` skips absent group members in an exchange; `perception.ts` scans nearby chunks without temporary lists and finds route crossings with a reused buffer; `clock.ts` cancels lazily; `engine.ts` adds `advanceValley` and counts known places without copying; the worker advances its state in place, and `viewCopy.ts` snapshots the followed person's memory. ## Tests and implementation acceptance @@ -483,10 +512,10 @@ New unit fixtures: 3. Recheck: on a fixture where new ground opens a shorter path, the way is kept within a day of planning, replaced after a day, and kept after a day when nothing new was seen. 4. Forgetting: with `waysRemembered` ways held, a new way forgets the one used longest ago; a new way between the same end points replaces the old one. 5. Load: the same way walked loaded and unloaded has the same corridor and different times. -6. Coarse planning: on an open fixture the corridor lies in the band of the chain; on a fixture where a strip of unknown ground walls off the straight way, the chain goes round it and the plan is coarse, not full. +6. Replaced at update 071 by its fixtures 1 and 2, below. 7. Pieces and links: a chunk whose known ground is split by unknown or unwalkable ground holds two pieces; two pieces are linked only when the person knows walkable triangles on both sides of a crossing edge; a chain never passes from one piece of a chunk to another inside it. -8. Same chunk, two pieces: a walk between two pieces of one chunk, joined only through a neighbouring chunk, is coarse and goes round. -9. The checker rejects a walk recorded as `full`. +8. Replaced at update 071 by its fixture 6, below. +9. Replaced at update 071 by its fixture 7, below. 10. Survey: a person who has moved less than 100 m learns no new triangles; after moving 100 m they learn what came into sight. 11. The checker rejects a way through an unknown triangle, a corridor with a gap, one way too many, and a survey recorded against the rule. 12. Leisure: an idle person at home with nothing to explore walks out along the way from home used longest ago, once a calendar day; away from home they walk home to rest; with no time to return before dusk they rest. @@ -512,6 +541,18 @@ Life 14 fixtures, kept: **Update 070.** Every fingerprint stays the same. A few fast unit tests: advancing a state in place equals stepping copies of it, minute by minute and across days; and the view-copy tests run on a state advanced in place, checking each copy equals the one made from a pure copy of the run. Measured once and recorded in the lab notes: days 50 to 59 at 1 month/s in Node, before and after. +**Update 071.** `fingerprints.test.ts` passes before the engine is changed. Every trajectory changes, so new fingerprints are recorded once for all 22; the founders, bodies and traits stay the same. Fixtures 6, 8 and 9 above are replaced, and route fixtures elsewhere updated where a straight or steered walk now takes a different path. New unit fixtures: + +1. Straight: on open known ground a walk's corridor is exactly the triangles its line crosses, and the walk is recorded as straight. +2. Blocked line: with a strip of unknown ground across the straight line, the walk is steered round it, and no triangle of its corridor is unknown. +3. A line through a vertex counts as blocked, and the walk is steered. +4. Crossings: between two pieces with two crossing edges, the walker takes the one whose midpoint is nearer the line to the target. +5. Within a piece: where a lake inside one chunk blocks the line between entry and exit, the stretch goes round it within that piece, and the corridor never leaves the chain's pieces. +6. Same chunk, two pieces: a walk between two pieces of one chunk, joined only through a neighbouring chunk, is steered and goes round. +7. The checker rejects a way remembered from a straight walk that is not the triangles its line crosses, and a new way holding a triangle twice. + +Measured once and recorded in the lab notes, on the canonical seed: the walks of each kind on days 5, 13, 30 and 55; the median and largest excess of straight and steered walks over the shortest known path; each of the first 60 days' time in 12-hour steps as the worker runs, against update 070's; and a profile of days 50 to 60. In the browser: a walk steered round a lake, the panel's wording, and the console clean. + Final validation is `npm run agent:check`. Measured once at update 066 and recorded in the lab notes, on the canonical seed: the walks of each kind by day; the median and largest excess of way walks over the shortest known path; the share of new plans needing the full search; the year of forty's time and memory; and a profile of day 12 against update 065's. In the browser: a followed person's ways drawn, the panel's wording during a walk, 1 month/s against the 8 frames a second of update 065, and the console clean. ## Questions for later @@ -520,6 +561,7 @@ Final validation is `npm run agent:check`. Measured once at update 066 and recor - Is once a day the right pace for noticing a shortcut, and should it depend on openness? - Should ways be chosen by expected time, with slopes and ground, rather than distance? - Should the coarse level be landmarks (places, banks, the hearth) rather than pieces of squares of land? +- Joining a remembered way from nearby, rather than only from a triangle on it, and chaining ways through the places they share ("back to camp, then out along the other way"): how near, and does it make walks more lifelike than a steered plan? (Update 071 leaves both out.) - After update 070, which still reaches about 6 days a second at 1 month/s, which way to a month a second: cheaper route planning and water choice, which change no result, or people thinking less often (surveying and replanning less), or a simpler model of daily movement at map speeds? The last two change what people do. - The hut-building week (days 11 to 17 on the canonical run) takes 0.5 to 3.3 s a simulated day against about 0.25 s later, from its many cutting and log-carrying walks. What would make it affordable at a month a second? - Every route ever walked stays in the state, 27,000 by day 45. Should finished routes be dropped once no task or record refers to them? @@ -545,6 +587,8 @@ Trails, shared or taught ways, ways blocked by anything, and sight blocked by re - Golledge, R. (1995), *Path selection and route preference in human navigation: a progress report*; Golledge, R. (ed.) (1999), *Wayfinding Behavior: Cognitive Mapping and Other Spatial Processes*. - Hölscher, C., Tenbrink, T. and Wiener, J. (2011), *Would you follow your own route description? Cognitive strategies in urban route planning*, Cognition. - Zhu, S. and Levinson, D. (2015), *Do people use the shortest path? An empirical test of Wardrop's first principle*, PLoS ONE. +- Hochmair, H. and Frank, A. (2000), *Influence of estimation errors on wayfinding-decisions in unfamiliar street networks: analyzing the least-angle strategy*, Spatial Cognition and Computation. +- Bailenson, J., Shum, M. and Uttal, D. (2000), *The initial segment strategy: a heuristic for route selection*, Memory and Cognition. - Botea, A., Müller, M. and Schaeffer, J. (2004), *Near optimal hierarchical path-finding*, Journal of Game Development. - Formicola, V. and Giannecchini, M. (1999), *Evolutionary trends of stature in Upper Paleolithic and Mesolithic Europe*, Journal of Human Evolution. - Ruff, C. (ed.) (2018), *Skeletal Variation and Adaptation in Europeans: Upper Paleolithic to the Twentieth Century*: stature and body mass estimates. diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index cf72550..af20b03 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -130,6 +130,6 @@ The browser check looks at the settings screen rejecting 7 and 366 days, Start s Life 14 adds bounded-normal moments, integer factorisation and positive-definiteness checks, 10,000 draws per sex for body magnitudes and correlations, and 10,000 trait sets for all ten correlations. Small fixtures verify carrying, loaded speed, energy and thirst, each trait's direction, and checker rejection of damaged bodies, derived quantities, task charges and exchange prices. Rule fixtures explicitly supply a reference-weight/reference-grip body and neutral traits when old numeric assertions need them. `life13-founders.json` freezes starts and born skills on all three fingerprint seeds; those streams must remain unchanged. -`sites.test.ts` checks that an idle person at home with nothing to explore walks out along the way used longest ago, once a day, goes home to rest afterwards, and stays in when there is no time to return before dusk. `ways.test.ts` checks walking a way again and back the other way, joining one part-way and planning afresh from off it, the recheck after a day with new ground, forgetting the least recently used way and replacing one between the same ends, the same corridor at a slower pace under load, a coarse plan staying in its band, a coarse plan going round a wall of unknown ground, a chunk split into two pieces where its known ground is not joined, a plan between two pieces of one chunk going through the next chunk, chunks linked only across known ground, the 100 m survey rule, and the checker rejecting a way through unknown ground, a way with a gap, too many ways, a survey against the rule and a walk that needed the full search. +`sites.test.ts` checks that an idle person at home with nothing to explore walks out along the way used longest ago, once a day, goes home to rest afterwards, and stays in when there is no time to return before dusk. `ways.test.ts` checks walking a way again and back the other way, joining one part-way and planning afresh from off it, the recheck after a day with new ground, forgetting the least recently used way and replacing one between the same ends, the same corridor at a slower pace under load, a straight plan being exactly the triangles its line crosses, a steered plan going round a wall of unknown ground, a line through a vertex counting as blocked, the crossing nearest the line being chosen, a steered stretch round an obstacle inside one piece, a chunk split into two pieces where its known ground is not joined, a plan between two pieces of one chunk going through the next chunk, chunks linked only across known ground, the 100 m survey rule, and the checker rejecting a way through unknown ground, a way with a gap, too many ways, a survey against the rule, a straight way off its line and a way holding a triangle twice. Browser acceptance covers the followed person's remembered ways drawn as lines, the task line naming the kind of walk, the "Ways" row, and the console. Earlier steps' acceptance covered a woman's and a man's person panels, five trait bars, figures scaled by height and weight, minute stepping and an exchange line with its price and gain share. Results and the single canonical year measurement are recorded in update 064's lab notes. diff --git a/src/valley/fingerprintRuns.ts b/src/valley/fingerprintRuns.ts index 7861dc8..a07b120 100644 --- a/src/valley/fingerprintRuns.ts +++ b/src/valley/fingerprintRuns.ts @@ -39,121 +39,121 @@ const RECORDED = [ { config: 'canonical', seed: 20260813, - days: '6dd66e65:66501', - totals: 'f7cf7980:464', + days: 'bba6f543:66620', + totals: '31853532:464', }, { config: 'canonical', seed: 1, - days: '2ac589f6:66317', - totals: '13558877:464', + days: '3a6b437d:66325', + totals: 'f0375bbb:464', }, { config: 'canonical', seed: 2, - days: 'a47a374b:66221', - totals: '55a6f741:463', + days: 'aa551dc9:66250', + totals: '82a6f566:463', }, { config: 'together', seed: 20260813, - days: '6b1d2742:66291', - totals: '5b2a7159:463', + days: 'fc4d9bf5:66366', + totals: 'f0d7ab37:463', }, { config: 'together', seed: 1, - days: 'cd30b991:66129', - totals: 'f36c46d1:464', + days: '709ab523:66147', + totals: '14d50b3e:462', }, { config: 'together', seed: 2, - days: '1e2a7ee5:66146', - totals: '6ddf9c6a:464', + days: '221a3823:66176', + totals: '172354e2:464', }, { config: 'noPractice', seed: 20260813, - days: '7a366264:66580', - totals: 'da4c7848:464', + days: 'adcf6810:66613', + totals: '34c472d6:464', }, { config: 'noPractice', seed: 1, - days: '995b0000:66296', - totals: 'd4f2e53a:464', + days: '585d816d:66340', + totals: 'c457c508:464', }, { config: 'noPractice', seed: 2, - days: '52cd85f9:66238', - totals: '534d359f:462', + days: 'c0ef770a:66227', + totals: '70b8acde:463', }, { config: 'talent', seed: 20260813, - days: 'b874662e:66551', - totals: 'fd049345:464', + days: '9111c80d:66677', + totals: '3fafbe32:464', }, { config: 'talent', seed: 1, - days: 'b93234b4:66380', - totals: '400eb230:464', + days: 'e0d4cca7:66374', + totals: 'ae28e8ed:464', }, { config: 'talent', seed: 2, - days: '16f626b:66282', - totals: 'acfb38c5:463', + days: 'f80778ff:66328', + totals: '1f4f7c0e:463', }, { config: 'twelve', seed: 20260813, - days: '90490841:78530', - totals: '2b986826:468', + days: '45288634:78586', + totals: '3d678e0:468', }, { config: 'twelve', seed: 1, - days: '294277b3:78475', - totals: '68bfeec3:472', + days: 'f1ceeb30:78472', + totals: '7880e101:472', }, { config: 'twelve', seed: 2, - days: 'be666fe7:78187', - totals: 'a3ea33b:470', + days: '91e3f305:78366', + totals: '42626bb:469', }, { config: 'alike', seed: 20260813, - days: '6eead3:66600', - totals: 'deec9194:463', + days: 'ad43b4bc:66607', + totals: '8f48c5c:464', }, { config: 'alike', seed: 1, - days: '9f26e36b:66432', - totals: '797f9a88:464', + days: '4139543d:66429', + totals: 'ef7ad196:464', }, { config: 'alike', seed: 2, - days: '83304d9b:66370', - totals: '87404deb:463', + days: '8f6e59c0:66356', + totals: '375644b8:463', }, { config: 'flat', seed: 20260813, - days: 'a90ffa46:59415', - totals: 'cea4ed8b:437', + days: '8795e744:59414', + totals: '7b9b0885:437', }, { config: 'flat', seed: 1, - days: 'a89f2479:59466', + days: '9f68ec56:59465', totals: 'd41aa245:437', }, { @@ -165,8 +165,8 @@ const RECORDED = [ { config: 'forty', seed: 20260813, - days: '9645b9b3:162512', - totals: '628f4e06:477', + days: 'f78f390:162722', + totals: 'fa9c4b90:477', }, ] as const diff --git a/src/valley/invariants.ts b/src/valley/invariants.ts index a4d1c71..ec95ae5 100644 --- a/src/valley/invariants.ts +++ b/src/valley/invariants.ts @@ -9,6 +9,7 @@ import { positionAlong, chunkOf, knows, + lineCorridor, meshSettings, NEAR_CM, onWalkableGround, @@ -172,7 +173,24 @@ export class ValleyChecker { errors.push(`person ${p.id}: two leisure walks in a day`) leisure = e.minute } - if (e.kind === 'walk' && e.plan === 'full') errors.push(`person ${p.id}: a walk needed the full search`) + const made = e.kind === 'walk' && e.plan !== 'way' && e.plan !== 'joined' + const newWay = made ? p.ways.find((w) => w.id >= before.nextWayId && w.plannedMinute === e.minute) : undefined + if (newWay) { + const c = newWay.corridor + if (new Set(c).size !== c.length) errors.push(`person ${p.id}: way ${newWay.id} holds a triangle twice`) + if (e.kind === 'walk' && e.plan === 'straight') { + const line = lineCorridor( + mesh, + c[0]!, + c[c.length - 1]!, + newWay.a, + newWay.b, + (t) => mesh.area[t] === GROUND_AREA, + ) + if (!line || line.length !== c.length || line.some((t, i) => t !== c[i])) + errors.push(`person ${p.id}: straight way ${newWay.id} is not the line between its ends`) + } + } if (e.kind === 'walk' && (e.plan === 'way' || e.plan === 'joined')) { const way = known.get(e.wayId) if (way) { diff --git a/src/valley/routes.ts b/src/valley/routes.ts index bde2d9f..40a8650 100644 --- a/src/valley/routes.ts +++ b/src/valley/routes.ts @@ -394,33 +394,21 @@ export function cachedHeight(mesh: GroundMesh, x: number, y: number) { return value } -const searchBuffers = new WeakMap< - GroundMesh, - { - costs: Float64Array - parents: Int32Array - px: Float64Array - py: Float64Array - seen: Uint32Array - closed: Uint32Array - stamp: number - } ->() -const length2 = (ax: number, ay: number, bx: number, by: number) => Math.sqrt((ax - bx) ** 2 + (ay - by) ** 2) -/** - * A* over known walkable triangles between their shared edges' midpoints, ties by triangle id. Returns the - * corridor of triangles from `first` to `last`, or null. With a band, only triangles in the band's chunks are crossed. - */ -export function corridorOf( - mesh: GroundMesh, - knowledge: Knowledge, - first: number, - last: number, - from: Point, - to: Point, - band?: Uint8Array, -): number[] | null { - let buffers = searchBuffers.get(mesh) +interface SearchBuffers { + costs: Float64Array + parents: Int32Array + px: Float64Array + py: Float64Array + seen: Uint32Array + closed: Uint32Array + heap: CellHeap + stamp: number +} +/** Reusable per-triangle search arrays: one set for the fine search, one for the chain of pieces. */ +const searchBuffers = new WeakMap(), + chainBuffers = new WeakMap() +function buffersOf(cache: WeakMap, mesh: GroundMesh) { + let buffers = cache.get(mesh) if (!buffers) { const n = mesh.triangles buffers = { @@ -430,14 +418,32 @@ export function corridorOf( py: new Float64Array(n), seen: new Uint32Array(n), closed: new Uint32Array(n), + heap: new CellHeap(), stamp: 0, } - searchBuffers.set(mesh, buffers) + cache.set(mesh, buffers) } - const { costs, parents, px, py, seen, closed } = buffers, + buffers.heap.clear() + return buffers +} +const length2 = (ax: number, ay: number, bx: number, by: number) => Math.sqrt((ax - bx) ** 2 + (ay - by) ** 2) +/** + * A* over known walkable triangles between their shared edges' midpoints, ties by triangle id. Returns the + * corridor of triangles from `first` to `last`, or null. With `within`, only triangles of that one piece are crossed. + */ +export function corridorOf( + mesh: GroundMesh, + knowledge: Knowledge, + first: number, + last: number, + from: Point, + to: Point, + within?: PieceOf, +): number[] | null { + const buffers = buffersOf(searchBuffers, mesh) + const { costs, parents, px, py, seen, closed, heap } = buffers, stamp = ++buffers.stamp const { tv, tn, vx, vy, area } = mesh - const heap = new CellHeap() costs[first] = 0 parents[first] = -1 px[first] = from.x @@ -452,7 +458,7 @@ export function corridorOf( for (let e = 0; e < 3; e++) { const next = tn[3 * t + e]! if (next < 0 || area[next] !== GROUND_AREA || closed[next] === stamp || !knows(knowledge, next)) continue - if (band && !band[mesh.chunk[next]!]) continue + if (within && (mesh.chunk[next] !== within.chunk || within.labels[within.slots[next]!] !== within.id)) continue const a = tv[3 * t + e]!, b = tv[3 * t + ((e + 1) % 3)]!, mx = (vx[a]! + vx[b]!) / 2, @@ -651,71 +657,185 @@ export function carryPieces(nav: NavMap, before: Knowledge, after: Knowledge, ad for (const t of added) chunks.delete(nav.mesh.chunk[t]!) pieceCache.set(after, { revision: after.revision, chunks }) } +/** The one piece a search keeps to: its chunk's piece labels by slot, and its number. */ +export interface PieceOf { + chunk: number + labels: Int32Array + slots: Int32Array + id: number +} +/** A person's pieces: the labels of a chunk by slot, and the piece of a triangle. */ +function pieceLookup(nav: NavMap, knowledge: Knowledge) { + const mesh = nav.mesh, + pieces = piecesOf(knowledge), + slots = slotsOf(mesh), + labels = (c: number) => chunkPieces(mesh, knowledge, pieces, c) + return { labels, slots, piece: (t: number) => labels(mesh.chunk[t]!)[slots[t]!]! } +} /** * The coarse plan: A* over the person's linked pieces, costed between their chunks' centres, ties by piece number. - * Returns the band of the chain's chunks and every chunk touching one of them, side or corner, or null if no chain is - * known. A chain of pieces is joined-up known ground, so the band always holds a path. + * Returns the chain of pieces from the first triangle's to the last's, or null if no chain is known. */ -export function coarseBand(nav: NavMap, knowledge: Knowledge, first: number, last: number): Uint8Array | null { +export function pieceChain(nav: NavMap, knowledge: Knowledge, first: number, last: number): number[] | null { const { mesh, links } = nav, cells = mesh.chunkCells, - pieces = piecesOf(knowledge), - slots = slotsOf(mesh) - const piece = (t: number) => chunkPieces(mesh, knowledge, pieces, mesh.chunk[t]!)[slots[t]!]! + { labels, slots, piece } = pieceLookup(nav, knowledge) const from = piece(first), to = piece(last) if (from < 0 || to < 0) return null + if (from === to) return [from] const gap = (a: number, b: number) => Math.sqrt(((a % cells) - (b % cells)) ** 2 + (Math.floor(a / cells) - Math.floor(b / cells)) ** 2) - const chain: number[] = [mesh.chunk[from]!] - if (from !== to) { - const goal = mesh.chunk[to]!, - costs = new Map([[from, 0]]), - parents = new Map([[from, -1]]), - closed = new Set(), - heap = new CellHeap() - heap.push(from, gap(mesh.chunk[from]!, goal)) - while (heap.length) { - const p = heap.popId() - if (closed.has(p)) continue - closed.add(p) - if (p === to) break - const c = mesh.chunk[p]! + // Pieces are numbered by one of their triangles, so the per-triangle arrays serve. + const buffers = buffersOf(chainBuffers, mesh) + const { costs, parents, seen, closed, heap } = buffers, + stamp = ++buffers.stamp + const goal = mesh.chunk[to]! + costs[from] = 0 + parents[from] = -1 + seen[from] = stamp + heap.push(from, gap(mesh.chunk[from]!, goal)) + while (heap.length) { + const p = heap.popId() + if (closed[p] === stamp) continue + closed[p] = stamp + if (p === to) break + const c = mesh.chunk[p]!, + here = labels(c) + for (let k = links.start[c]!; k < links.start[c + 1]!; k++) { + const n = links.chunk[k]!, + there = labels(n), + cost = costs[p]! + gap(c, n) + for (let j = links.pairStart[k]!; j < links.pairStart[k + 1]!; j++) { + if (here[slots[links.pairs[2 * j]!]!] !== p) continue + const q = there[slots[links.pairs[2 * j + 1]!]!]! + if (q < 0 || closed[q] === stamp) continue + if (seen[q] !== stamp || cost < costs[q]! || (cost === costs[q] && p < parents[q]!)) { + costs[q] = cost + seen[q] = stamp + parents[q] = p + heap.push(q, cost + gap(n, goal)) + } + } + } + } + if (closed[to] !== stamp) return null + const chain: number[] = [] + for (let p = to; p >= 0; p = parents[p]!) chain.push(p) + return chain.reverse() +} +/** + * The triangles the straight line from `from` to `to` crosses, starting in `first` and ending in `last`, each one + * passing `open`; null if one does not, if either point lies outside its triangle, or if the line passes exactly + * through a vertex. Coordinates are whole or half centimetres, so the side tests are exact. + */ +export function lineCorridor( + mesh: GroundMesh, + first: number, + last: number, + from: Point, + to: Point, + open: (t: number) => boolean, +): number[] | null { + const { tv, tn, vx, vy } = mesh + if (triangleDistanceSq(mesh, first, from.x, from.y) > 0) return null + const corridor = [first] + let t = first + while (triangleDistanceSq(mesh, t, to.x, to.y) > 0) { + // Leaving a counter-clockwise triangle across edge a→b, a lies right of the line and b left. + let next = -1 + for (let e = 0; e < 3; e++) { + const a = tv[3 * t + e]!, + b = tv[3 * t + ((e + 1) % 3)]! + if ( + crossXY(from.x, from.y, to.x, to.y, vx[a]!, vy[a]!) < 0 && + crossXY(from.x, from.y, to.x, to.y, vx[b]!, vy[b]!) > 0 + ) { + next = tn[3 * t + e]! + break + } + } + if (next < 0 || !open(next)) return null + corridor.push((t = next)) + } + return t === last ? corridor : null +} +/** The midpoint of the edge `t` shares with its neighbour `u`. */ +function sharedMidpoint(mesh: GroundMesh, t: number, u: number): Point { + const { tv, tn, vx, vy } = mesh + let e = 0 + while (tn[3 * t + e] !== u) e++ + const a = tv[3 * t + e]!, + b = tv[3 * t + ((e + 1) % 3)]! + return { x: (vx[a]! + vx[b]!) / 2, y: (vy[a]! + vy[b]!) / 2 } +} +/** + * A steered corridor along a chain of pieces: in each piece, from where the walker enters it to the crossing into the + * next piece whose midpoint is nearest the line on to the target, straight where the line stays in the piece and + * otherwise by the fine A* within the piece alone. The last piece's stretch ends at the target. + */ +export function steeredCorridor( + nav: NavMap, + knowledge: Knowledge, + chain: readonly number[], + first: number, + last: number, + from: Point, + to: Point, +): number[] { + const { mesh, links } = nav, + { labels, slots } = pieceLookup(nav, knowledge) + const corridor: number[] = [] + let entry = from, + entryTriangle = first + for (let i = 0; i < chain.length; i++) { + const id = chain[i]!, + c = mesh.chunk[id]!, + here = labels(c) + let exit = to, + exitTriangle = last, + across = -1 + if (i + 1 < chain.length) { + const next = chain[i + 1]!, + n = mesh.chunk[next]!, + there = labels(n) + let best = Infinity for (let k = links.start[c]!; k < links.start[c + 1]!; k++) { - const n = links.chunk[k]!, - cost = costs.get(p)! + gap(c, n) + if (links.chunk[k] !== n) continue for (let j = links.pairStart[k]!; j < links.pairStart[k + 1]!; j++) { - if (piece(links.pairs[2 * j]!) !== p) continue - const q = piece(links.pairs[2 * j + 1]!) - if (q < 0 || closed.has(q)) continue - const old = costs.get(q) - if (old === undefined || cost < old || (cost === old && p < parents.get(q)!)) { - costs.set(q, cost) - parents.set(q, p) - heap.push(q, cost + gap(n, goal)) + const t = links.pairs[2 * j]!, + u = links.pairs[2 * j + 1]! + if (here[slots[t]!] !== id || there[slots[u]!] !== next) continue + const m = sharedMidpoint(mesh, t, u), + d = segmentDistanceSq(m.x, m.y, entry.x, entry.y, to.x, to.y) + if (d < best || (d === best && t < exitTriangle)) { + best = d + exit = m + exitTriangle = t + across = u } } } } - if (!closed.has(to)) return null - chain.length = 0 - for (let p = to; p >= 0; p = parents.get(p)!) chain.push(mesh.chunk[p]!) - } - const band = new Uint8Array(cells * cells) - for (const c of chain) { - const x = c % cells, - y = Math.floor(c / cells) - for (let dy = -1; dy <= 1; dy++) - for (let dx = -1; dx <= 1; dx++) - if (x + dx >= 0 && x + dx < cells && y + dy >= 0 && y + dy < cells) band[(y + dy) * cells + x + dx] = 1 + const stretch = + lineCorridor( + mesh, + entryTriangle, + exitTriangle, + entry, + exit, + (t) => mesh.chunk[t] === c && here[slots[t]!] === id, + ) ?? corridorOf(mesh, knowledge, entryTriangle, exitTriangle, entry, exit, { chunk: c, labels: here, slots, id })! + for (const t of stretch) corridor.push(t) + entry = exit + entryTriangle = across } - return band + return corridor } -export type PlanKind = 'coarse' | 'full' +export type PlanKind = 'straight' | 'steered' /** - * A new corridor over known ground, within the band of a coarse plan over pieces. The band always holds a path; the - * search over all known ground is only a guard, recorded as `full`, that the checker rejects. Null when the two points - * are on separate pieces of known ground. + * A new corridor over known ground: the straight line if it crosses only known walkable ground, else a corridor + * steered along the coarse chain of pieces. Null when the two points are on separate pieces of known ground. */ export function planCorridor( nav: NavMap, @@ -725,14 +845,21 @@ export function planCorridor( from: Point, to: Point, ): { corridor: number[]; plan: PlanKind } | null { - // A search between separate pieces of known ground would exhaust the start's piece before failing. + // A plan between separate pieces of known ground could never arrive. const componentOf = knownComponents(nav, knowledge) if (componentOf(first) !== componentOf(last)) return null - const band = coarseBand(nav, knowledge, first, last) - const banded = band && corridorOf(nav.mesh, knowledge, first, last, from, to, band) - if (banded) return { corridor: banded, plan: 'coarse' } - const corridor = corridorOf(nav.mesh, knowledge, first, last, from, to) - return corridor && { corridor, plan: 'full' } + const mesh = nav.mesh + const straight = lineCorridor( + mesh, + first, + last, + from, + to, + (t) => mesh.area[t] === GROUND_AREA && knows(knowledge, t) === 1, + ) + if (straight) return { corridor: straight, plan: 'straight' } + const chain = pieceChain(nav, knowledge, first, last) + return chain && { corridor: steeredCorridor(nav, knowledge, chain, first, last, from, to), plan: 'steered' } } /** The shortest route over everything the person knows, without a coarse plan. */ export function knownRoute( diff --git a/src/valley/types.ts b/src/valley/types.ts index 54a02f3..b6f724c 100644 --- a/src/valley/types.ts +++ b/src/valley/types.ts @@ -578,7 +578,7 @@ export interface Way { usedMinute: number } /** How a walk's corridor was found. */ -export type WalkPlan = 'way' | 'joined' | 'coarse' | 'full' +export type WalkPlan = 'way' | 'joined' | 'straight' | 'steered' export interface Forager extends Hydration, PersonNature { task: TaskRecord | null knowledge: Knowledge diff --git a/src/valley/ways.test.ts b/src/valley/ways.test.ts index 4bdddf1..41bb15c 100644 --- a/src/valley/ways.test.ts +++ b/src/valley/ways.test.ts @@ -2,10 +2,12 @@ import { describe, expect, it } from 'vitest' import { createSurveyedValley } from './ruleFixtures' import { FLAT_LAND } from './config' import { - coarseBand, corridorRoute, + lineCorridor, + pieceChain, pieceOf, planCorridor, + knows, routeTriangle, trianglePoint, type Knowledge, @@ -45,7 +47,7 @@ describe('remembered ways', () => { const { person, go } = fixture() place(person, home) const first = go(thicket) - expect(first.plan).toBe('coarse') + expect(first.plan).toBe('straight') expect(person.ways).toHaveLength(1) const again = go(thicket) expect(again.plan).toBe('way') @@ -68,7 +70,7 @@ describe('remembered ways', () => { expect(joined.corridor).toEqual(corridor.slice(corridor.indexOf(middle))) const off = [0, 1, 2].map((e) => mesh.tn[3 * middle + e]!).find((t) => t >= 0 && !corridor.includes(t))! place(person, trianglePoint(mesh, off)) - expect(walk(thicket).plan).toBe('coarse') + expect(['straight', 'steered']).toContain(walk(thicket).plan) }) it('keeps a way until a day has passed and new ground was seen', () => { const { state, person, go, walk } = fixture() @@ -115,33 +117,75 @@ describe('remembered ways', () => { }) }) -describe('coarse planning', () => { - it('keeps a coarse plan inside the band of its chain', () => { +describe('new plans', () => { + const plan = (state: ValleyState, k: Knowledge, from: Point, to: Point) => { + const nav = state.layout.nav + return planCorridor(nav, k, routeTriangle(nav, k, from), routeTriangle(nav, k, to), from, to)! + } + it('walks straight over open known ground, crossing exactly the triangles of the line', () => { const { state, person } = fixture() const nav = state.layout.nav, k = person.knowledge - const first = routeTriangle(nav, k, home), - last = routeTriangle(nav, k, thicket) - const band = coarseBand(nav, k, first, last)! - const plan = planCorridor(nav, k, first, last, home, thicket)! - expect(plan.plan).toBe('coarse') - for (const t of plan.corridor) expect(band[nav.mesh.chunk[t]!]).toBe(1) - }) - it('goes round a wall of unknown ground in a coarse plan, inside its band', () => { + const straight = plan(state, k, home, thicket) + expect(straight.plan).toBe('straight') + const line = lineCorridor( + nav.mesh, + routeTriangle(nav, k, home), + routeTriangle(nav, k, thicket), + home, + thicket, + () => true, + ) + expect(straight.corridor).toEqual(line) + }) + it('steers round a wall of unknown ground across the line, over known ground only', () => { const { state, person } = fixture() - // A wall inside the first column of chunks, open only far outside the band of the straight chain. + // A wall inside the first column of chunks, open only far from the line. forget(state, person.knowledge, (x, y) => x > 9_000 && x < 11_000 && y < 70_000) + const k = person.knowledge, + mesh = state.layout.nav.mesh + const steered = plan(state, k, { x: 1_000, y: 10_000 }, { x: 30_000, y: 10_000 }) + expect(steered.plan).toBe('steered') + expect(steered.corridor.every((t) => knows(k, t))).toBe(true) + expect(steered.corridor.some((t) => mesh.cy[t]! > 70_000)).toBe(true) + expect(new Set(steered.corridor).size).toBe(steered.corridor.length) + }) + it('counts a line through a vertex as blocked', () => { + const { state, person } = fixture() + const mesh = state.layout.nav.mesh, + t = routeTriangle(state.layout.nav, person.knowledge, { x: 30_000, y: 30_000 }), + v = mesh.tv[3 * t]! + const from = { x: mesh.vx[v]! - 1_500, y: mesh.vy[v]! - 700 }, + to = { x: mesh.vx[v]! + 1_500, y: mesh.vy[v]! + 700 } + expect(plan(state, person.knowledge, from, to).plan).toBe('steered') + }) + it('crosses into the next piece by the crossing nearest the line to the target', () => { + const { state, person } = fixture() + // Unknown ground along the border between the first two chunks, open in two gaps, one nearer the line. + forget( + state, + person.knowledge, + (x, y) => x > 18_000 && x < 22_000 && y < 20_000 && !(y < 4_000) && !(y > 12_000 && y < 16_000), + ) + const mesh = state.layout.nav.mesh + const steered = plan(state, person.knowledge, { x: 5_000, y: 10_000 }, { x: 35_000, y: 10_000 }) + expect(steered.plan).toBe('steered') + const crossing = steered.corridor.filter((t) => mesh.cx[t]! > 18_000 && mesh.cx[t]! < 22_000) + expect(crossing.length).toBeGreaterThan(0) + expect(crossing.every((t) => mesh.cy[t]! > 12_000 && mesh.cy[t]! < 16_000)).toBe(true) + }) + it('goes round an obstacle inside one piece without leaving it', () => { + const { state, person } = fixture() + forget(state, person.knowledge, (x, y) => x > 8_000 && x < 12_000 && y > 8_000 && y < 12_000) const nav = state.layout.nav, k = person.knowledge - const from = { x: 1_000, y: 10_000 }, - to = { x: 30_000, y: 10_000 } - const first = routeTriangle(nav, k, from), - last = routeTriangle(nav, k, to) - const band = coarseBand(nav, k, first, last)! - const plan = planCorridor(nav, k, first, last, from, to)! - expect(plan.plan).toBe('coarse') - for (const t of plan.corridor) expect(band[nav.mesh.chunk[t]!]).toBe(1) - expect(plan.corridor.some((t) => nav.mesh.cy[t]! > 70_000)).toBe(true) + const from = { x: 2_000, y: 10_000 }, + to = { x: 18_000, y: 10_000 } + const first = routeTriangle(nav, k, from) + expect(pieceChain(nav, k, first, routeTriangle(nav, k, to))).toEqual([pieceOf(nav, k, first)]) + const steered = plan(state, k, from, to) + expect(steered.plan).toBe('steered') + expect(steered.corridor.every((t) => pieceOf(nav, k, t) === pieceOf(nav, k, first))).toBe(true) }) it('splits a chunk into pieces where its known ground is not joined', () => { const { state, person } = fixture() @@ -155,7 +199,7 @@ describe('coarse planning', () => { expect(pieceOf(nav, k, left)).not.toBe(pieceOf(nav, k, right)) expect(pieceOf(nav, k, left)).toBe(pieceOf(nav, k, below)) }) - it('plans between two pieces of one chunk through the next chunk', () => { + it('steers between two pieces of one chunk through the next chunk', () => { const { state, person } = fixture() forget(state, person.knowledge, (x, y) => x > 9_000 && x < 11_000 && y < 21_000) const nav = state.layout.nav, @@ -165,16 +209,16 @@ describe('coarse planning', () => { const first = routeTriangle(nav, k, from), last = routeTriangle(nav, k, to) expect(nav.mesh.chunk[first]).toBe(nav.mesh.chunk[last]) - const plan = planCorridor(nav, k, first, last, from, to)! - expect(plan.plan).toBe('coarse') - expect(plan.corridor.some((t) => nav.mesh.chunk[t] !== nav.mesh.chunk[first])).toBe(true) + const steered = plan(state, k, from, to) + expect(steered.plan).toBe('steered') + expect(steered.corridor.some((t) => nav.mesh.chunk[t] !== nav.mesh.chunk[first])).toBe(true) }) it('links chunks only across ground known on both sides', () => { const { state, person } = fixture() forget(state, person.knowledge, (x) => x > 14_000 && x < 26_000) const nav = state.layout.nav, k = person.knowledge - expect(coarseBand(nav, k, routeTriangle(nav, k, home), routeTriangle(nav, k, thicket))).toBeNull() + expect(pieceChain(nav, k, routeTriangle(nav, k, home), routeTriangle(nav, k, thicket))).toBeNull() }) }) @@ -232,11 +276,18 @@ describe('the checker on ways', () => { }) expect(survey.some((e) => e.includes('survey taken against the rule'))).toBe(true) }) - it('rejects a walk that needed the full search', () => { + it('rejects a straight way off its line, and a way holding a triangle twice', () => { const errors = run((s) => { - const e = s.lastInterval.find((r) => r.kind === 'walk')! - if (e.kind === 'walk') e.plan = 'full' + const e = s.lastInterval.find((r) => r.kind === 'walk' && r.plan === 'straight' && r.wayId < 0)! + if (e.kind !== 'walk') return + const p = s.foragers[e.foragerId]!, + w = p.ways.find((way) => way.plannedMinute === e.minute)! + const c = w.corridor + p.ways = p.ways.map((way) => + way === w ? { ...w, corridor: Int32Array.from([c[0]!, c[1]!, c[0]!, ...c.subarray(1)]) } : way, + ) }) - expect(errors.some((e) => e.includes('needed the full search'))).toBe(true) + expect(errors.some((e) => e.includes('holds a triangle twice'))).toBe(true) + expect(errors.some((e) => e.includes('is not the line between its ends'))).toBe(true) }) }) diff --git a/src/valley/ways.ts b/src/valley/ways.ts index fd368f9..deafb44 100644 --- a/src/valley/ways.ts +++ b/src/valley/ways.ts @@ -33,7 +33,7 @@ export function wayPart(way: Way, first: number, target: Point): number[] { } /** * The corridor of a walk to `target`: a remembered way, or the rest of one the walker stands on, unless it is due a - * recheck; otherwise a coarse plan, or a full one. Only walks to places, banks and home (`habitual`) use ways. + * recheck; otherwise a straight or steered plan. Only walks to places, banks and home (`habitual`) use ways. */ export function findWalk( state: ValleyState, @@ -68,7 +68,7 @@ export function findWalk( from, target, }) - if (same(from, target)) return found(null, 'full', null, null) + if (same(from, target)) return found(null, 'straight', null, null) let drop: Way | null = null, rechecked = false const way = habitual ? wayTo(person, first, target) : null @@ -96,7 +96,7 @@ export function rememberWalk(state: ValleyState, person: Forager, walk: WalkFoun let ways = person.ways if (walk.drop) ways = ways.filter((w) => w !== walk.drop) if (walk.way) ways = ways.map((w) => (w === walk.way ? { ...w, usedMinute: minute } : w)) - else if (walk.habitual && walk.corridor && (walk.plan === 'coarse' || walk.plan === 'full')) { + else if (walk.habitual && walk.corridor && (walk.plan === 'straight' || walk.plan === 'steered')) { const { from: a, target: b } = walk ways = ways.filter((w) => !((same(w.a, a) && same(w.b, b)) || (same(w.a, b) && same(w.b, a)))) ways = [ diff --git a/src/valleyView/valleyViewModel.ts b/src/valleyView/valleyViewModel.ts index d614a7d..830d964 100644 --- a/src/valleyView/valleyViewModel.ts +++ b/src/valleyView/valleyViewModel.ts @@ -594,8 +594,8 @@ export function describeActivity(display: Display, foragerId: number) { const WALK_PLANS = { way: 'on a known way', joined: 'joining a known way', - coarse: 'planning a new way', - full: 'planning a new way', + straight: 'heading straight there', + steered: 'finding a way through', } as const /** How a person's current walk was found, in words, from its walk record; null for other tasks or unrecorded walks. */ export function walkWording(state: ValleyState, foragerId: number) {