From 21e3290528144b409c48c656bcccba739064e8ce Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 18:06:14 +0000 Subject: [PATCH] fix(predation): carcasses jaw-only, goldens and the stability floor that go with it (ADR 0026) PR #143 merged with the one-line carcass change from the Copilot bot but without the parts that make it pass: 4 predation goldens regenerated, the ecology-stability floor 15 to 8 (measured over 12 held-out seeds: means 37.7-77.2, minimum 10 on seed 6, maximum 118, none extinct), tests with negatives (only the jaw bites or sees carrion, a mandible does neither, the old table is still expressible) and the doc updates. Main's determinism shards 1 and 2 failed on both OSes at aed927b for exactly this reason (stale goldens; seed 6 under the floor). Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Cn5qp4xBHxLnTrwReNXcf8 --- docs/decisions/0023-predation.md | 2 +- docs/decisions/0026-diets.md | 6 ++++-- docs/ecology/ecology.md | 2 +- docs/simulation/configuration.md | 2 +- packages/config/src/defaults.ts | 2 ++ packages/simulation/tests/golden/state-hashes.json | 8 ++++---- .../simulation/tests/predation/carnivore.test.ts | 10 +++++++++- .../tests/predation/death-and-carcass.test.ts | 13 ++++++++++--- .../simulation/tests/support/ecology-stability.ts | 7 ++++++- 9 files changed, 38 insertions(+), 14 deletions(-) diff --git a/docs/decisions/0023-predation.md b/docs/decisions/0023-predation.md index 6c6e945..51176b7 100644 --- a/docs/decisions/0023-predation.md +++ b/docs/decisions/0023-predation.md @@ -14,7 +14,7 @@ Owner decisions (2026-11-12): the first hunters are **emergent only** (no seeded 2. **What can be bitten.** A creature that is not itself, not a parent or child (kin are never prey; no species rule, because a species label drifts and would couple behaviour to a post hoc name), alive, no bigger than `maxPreyRatio` (1.5) times the biter's body radius (so the mouth's gape, bite size and size-for-size decide who eats whom), within the mouth's reach, inside the bite cone, and **not behind an obstacle that blocks movement** (the ADR 0022 field; reeds do not stop a bite). 3. **What a bite does.** The victim loses **energy**, at most what it has and what the biter's gut can hold: `min(energy, biteEnergy x gape factor)`. The biter's gut gains that times `trophicYield` (0.6) times the mouth's flesh yield, so **energy moves and is lost on the way, never created**: a drained or tiny victim is poor prey. The victim also takes **health damage** `biteDamage x gape factor x its own damageTaken`, so armor finally matters for something other than hazards. One bite a tick per mouth, the same cooldown and chewing slow-down as for food. An `organism-bitten` event carries both creatures, the damage, the energy taken and the intake. 4. **Death by predation.** `DeathCause` gains `'predation'`: a creature that was bitten within `attackWindow` (3 s) and then starved or was worn down is counted as killed by the bite, not by hunger or the weather (a victim drained to zero energy would otherwise be reported as starved). `organism-died` and the history record carry the killer. Old age stays old age. The bookkeeping (`lastBitten`) only labels deaths, never feeds back into the dynamics, and is **not hashed**. -5. **Carcasses.** With predation on, the world's configuration (`world/predationConfig.ts`, like the cluster scaling) appends a `carrion` food kind that never spawns by itself and gives every mouth form a carrion yield (jaw 1.2, mandible 0.8, radula 0.6, proboscis 0.2, sprout 0.1). Every death, from any cause, leaves one carcass where the creature died, worth `energyFraction` (0.6) of its energy and what was in its gut, if that is at least 5, while fewer than 40 are on the field; carcasses rot after 120 s. Ids come from the shared allocator in death order and nothing is drawn, so a run is the same however it is sliced. A carcass is an ordinary bitable food item, so scavengers need no new mechanism. With predation off, carcasses off or food kinds off, the very same configuration object is used, so those worlds are exactly what they were. +5. **Carcasses.** With predation on, the world's configuration (`world/predationConfig.ts`, like the cluster scaling) appends a `carrion` food kind that never spawns by itself and gives every mouth form a carrion yield (jaw 1.2, mandible 0.8, radula 0.6, proboscis 0.2, sprout 0.1; **since ADR 0026 the jaw's alone, every other form is 0**: jaws had got 5 percent of the carrion). Every death, from any cause, leaves one carcass where the creature died, worth `energyFraction` (0.6) of its energy and what was in its gut, if that is at least 5, while fewer than 40 are on the field; carcasses rot after 120 s. Ids come from the shared allocator in death order and nothing is drawn, so a run is the same however it is sliced. A carcass is an ordinary bitable food item, so scavengers need no new mechanism. With predation off, carcasses off or food kinds off, the very same configuration object is used, so those worlds are exactly what they were. 6. **Reward.** A predator's intake from a bite counts as a meal in its feeding reward; the prey already learn from `organism-damaged`. 7. **Drawn.** A ring effect where a bite lands, carrion as a dull red food dot, and a **Predation** row in the death-causes strip, shown only in a world where something has been killed by a bite. 8. **Constraints.** Predation needs `feeding.enabled` and `ecology.health.enabled` (validated: a bite is damage and eating is biting). It is **off by default** and pinned off for `classic` and `clusters`; the field layout is where it will be turned on. diff --git a/docs/decisions/0026-diets.md b/docs/decisions/0026-diets.md index 3f6ea7f..0a07630 100644 --- a/docs/decisions/0026-diets.md +++ b/docs/decisions/0026-diets.md @@ -1,6 +1,6 @@ # ADR 0026: Diets, what a mouth can eat, three fixes and what hard diets did -Status: accepted. Follows [ADR 0017](0017-feeding.md) (mouth forms and the yield matrix), [ADR 0023](0023-predation.md) (carcasses, the jaw) and [ADR 0025](0025-place-memory.md) (the third null result in a row). +Status: accepted. **Update, same day:** the owner decided carcasses are the jaw's alone (comment on PR #143), so that one change is shipped with its measured cost (below); hard plant diets are not. Follows [ADR 0017](0017-feeding.md) (mouth forms and the yield matrix), [ADR 0023](0023-predation.md) (carcasses, the jaw) and [ADR 0025](0025-place-memory.md) (the third null result in a row). ## The owner's observation @@ -52,7 +52,9 @@ The criteria stated before the runs (jaw alive in at least 4 of 8 at 100,000 tic ## Decision -Keep the three fixes. Do not change the diet table. Carcasses stay edible by every form with their present yields until the owner decides whether the realism of jaw-only carrion is worth a population about 11 percent lower and a predator boom in some worlds (a one-line config change: `predation.carcass.yields` to 0 for the four non-jaw forms, measured above). +Keep the three fixes. **Carcasses are the jaw's alone** (the owner's call, made after seeing the numbers above): `predation.carcass.yields` is 0 for sprout, proboscis, mandible and radula and 1.2 for the jaw, so only a jaw bites a carcass or sees one as food. It is exactly the "carrion for the jaw only" variant measured above, so those numbers are the shipped behaviour: population about 11 percent lower (56.8 to 50.3 over 16 seeds x 30,000 ticks), the carrion share of intake 5.3 to 0.7 percent (the carcasses mostly rot), and a predator boom in some worlds (one of eight at 100,000 ticks: 21 of 29 creatures jaws); a jaw alive at the end in 2 of 8 worlds rather than 1 of 8, which is inside the noise. No plant diet table is shipped: hard plant diets raised extinction in every variant tried and nothing helped the jaw. The owner's other point, that predators need a second food source, is the next project (eggs and nests). + +**Goldens:** 4 more entries move (the predation worlds `predation-ecology-12k`, `-reflex-8k`, `-evolving-bodies-6k`, `-lush-4k`), regenerated in the commit that causes it; the rest do not touch a carcass. ## Limits diff --git a/docs/ecology/ecology.md b/docs/ecology/ecology.md index a5f8c68..70bde99 100644 --- a/docs/ecology/ecology.md +++ b/docs/ecology/ecology.md @@ -106,4 +106,4 @@ Measured (default world, 16 seeds x 30,000 ticks, against the same worlds with o ## Predation (ADR 0023) -With `predation.enabled` a mouth that can bite creatures (only the jaw by default) takes the nearer of the best food and the best creature in its cone: a creature that is not kin, alive, no bigger than `maxPreyRatio` times the biter, within reach and not behind a solid obstacle. A bite moves energy from the victim to the biter's gut at a trophic loss (energy is never created), damages the victim (its armor reduces it) and is remembered for a few seconds so that a victim that then starves or is worn down is counted as **killed by predation**. Every death leaves a **carcass**, a carrion food item worth part of the dead creature's energy and gut that mandibles, radulas and jaws eat well and sprouts hardly at all, so there are scavengers without any new mechanism. On by default since step two, and pinned off for Classic, Clusters and Fixed bodies. A creature **sees** the nearest creature it could bite (prey) and the nearest that could bite it (a threat), through the same eyes and cover as any peer (brain inputs 40 to 47, zero without predation), and its innate prior hunts and flees on those (so does the reflex controller). Carnivory does not take hold from mutation alone, so a world also **starts with a small hunter group** (`anatomy.startingBody.groups`, 10 percent of the founders, a jaw on the grazer's body). **The jaw eats meat only** (step three): its yield on every plant is 0, so it neither bites nor sees plants and lives on creatures and carrion (a future egg food kind is one more yield). In step two it was as good as the mandible on plants; over 100,000 ticks that made jaws omnivores that took over a world (35 of 36 creatures, 82 percent of the energy still from plants) and ate each other. Strict carnivory is a hard niche here: a jaw lineage is alive at 100,000 ticks in about 1 of 8 worlds, because hunters reproduce at about replacement level and a lineage of two to four founders drifts out, whatever the meat yield, bite size, tails or group size tried (ADR 0023). A 20 percent group made 1 to 3 of 16 worlds go extinct, so the default is 10. +With `predation.enabled` a mouth that can bite creatures (only the jaw by default) takes the nearer of the best food and the best creature in its cone: a creature that is not kin, alive, no bigger than `maxPreyRatio` times the biter, within reach and not behind a solid obstacle. A bite moves energy from the victim to the biter's gut at a trophic loss (energy is never created), damages the victim (its armor reduces it) and is remembered for a few seconds so that a victim that then starves or is worn down is counted as **killed by predation**. Every death leaves a **carcass**, a carrion food item worth part of the dead creature's energy and gut that **only a jaw eats** (ADR 0026: every other mouth form yields exactly 0, so it neither bites a carcass nor sees one; carcasses used to be eaten by mandibles, radulas and sprouts too, and jaws got 5 percent of them). On by default since step two, and pinned off for Classic, Clusters and Fixed bodies. A creature **sees** the nearest creature it could bite (prey) and the nearest that could bite it (a threat), through the same eyes and cover as any peer (brain inputs 40 to 47, zero without predation), and its innate prior hunts and flees on those (so does the reflex controller). Carnivory does not take hold from mutation alone, so a world also **starts with a small hunter group** (`anatomy.startingBody.groups`, 10 percent of the founders, a jaw on the grazer's body). **The jaw eats meat only** (step three): its yield on every plant is 0, so it neither bites nor sees plants and lives on creatures and carrion (a future egg food kind is one more yield). In step two it was as good as the mandible on plants; over 100,000 ticks that made jaws omnivores that took over a world (35 of 36 creatures, 82 percent of the energy still from plants) and ate each other. Strict carnivory is a hard niche here: a jaw lineage is alive at 100,000 ticks in about 1 of 8 worlds, because hunters reproduce at about replacement level and a lineage of two to four founders drifts out, whatever the meat yield, bite size, tails or group size tried (ADR 0023). A 20 percent group made 1 to 3 of 16 worlds go extinct, so the default is 10. diff --git a/docs/simulation/configuration.md b/docs/simulation/configuration.md index 034ad69..03fa62b 100644 --- a/docs/simulation/configuration.md +++ b/docs/simulation/configuration.md @@ -104,7 +104,7 @@ Units: time is in **seconds** (one tick advances time by `timestep`), distance i | `predation.biteDamage`, `.biteEnergy`, `.trophicYield`, `.maxPreyRatio`, `.attackWindow` | >= 0; > 0; (0, 1]; > 0; > 0 (seconds) | Health damage of a bite and energy a bite takes from the victim (both at the founder's gape, damage reduced by the victim's armor); the share of the energy taken that reaches the biter's gut (the rest is lost); the biggest prey as a multiple of the biter's body radius; how long after a bite a death by starvation or damage counts as predation | | `predation.fleshYield.
` | >= 0 each | What each mouth form yields from a creature; zero means that form never bites creatures (only the jaw is above zero by default) | | `predation.carcass.enabled`, `.energyFraction`, `.minEnergy`, `.lifespan`, `.maxCount`, `.radius`, `.hardness` | boolean; (0, 1]; >= 0; >= 0 (seconds, 0 never rots); integer >= 0; > 0; > 0 | What a dead creature leaves where it died: a carrion food item worth this share of its energy and gut if at least `minEnergy`, up to `maxCount` on the field. With predation on, a `carrion` food kind is appended to the resource kinds (it never spawns by itself) | -| `predation.carcass.yields.` | >= 0 each | What each mouth form yields from a carcass, per unit bitten; 0 means the form neither bites nor sees carcasses (ADR 0026) | +| `predation.carcass.yields.` | >= 0 each | What each mouth form yields from a carcass, per unit bitten; 0 means the form neither bites nor sees carcasses. Default: **the jaw only (1.2)**, every other form 0 (ADR 0026); before that every form had a positive yield and jaws got 5 percent of the carrion | | `perception.organismsBlockSight`, `perception.maxSightChecks` | boolean; whole number >= 1 | `true` (default): another creature's body hides what is behind it from a viewer, for food and for other creatures; at most this many candidates are checked for something in the way (ADR 0019). `false` is the transparent world of Phase 3 (the Classic preset). | | `ecology.resourceKinds.kinds[].hardness` | > 0, default 1 | How many times harder than the baseline a kind is to bite: a bite takes `biteSize / hardness` | | `anatomy.founderOutline`, `anatomy.outlineDrag` | outline: count 5-16, 16 radii 0.35-1, 16 angles 0-1; >= 0 | The outline every founder starts with, and the extra movement cost per unit of outline roughness above the founder's (ADR 0013); size and drag factors are exactly 1 for the founder outline | diff --git a/packages/config/src/defaults.ts b/packages/config/src/defaults.ts index 9371b13..5f79dd4 100644 --- a/packages/config/src/defaults.ts +++ b/packages/config/src/defaults.ts @@ -420,6 +420,8 @@ export const DEFAULT_WORLD_CONFIG: Readonly = deepFreeze({ maxCount: 40, radius: 4, hardness: 1, + // Meat is the jaw's alone (ADR 0026, the owner's decision): every other mouth form yields exactly 0, so + // it neither bites a carcass nor sees one. It used to be eaten by everyone (jaws got 5 percent of it). yields: { sprout: 0, proboscis: 0, mandible: 0, radula: 0, jaw: 1.2 } } }, diff --git a/packages/simulation/tests/golden/state-hashes.json b/packages/simulation/tests/golden/state-hashes.json index fa8a175..d7cd63c 100644 --- a/packages/simulation/tests/golden/state-hashes.json +++ b/packages/simulation/tests/golden/state-hashes.json @@ -1347,14 +1347,14 @@ "seed": 7, "config": {}, "steps": 12000, - "expectedHash": "82a71ca77694b5cebe72b80fa1779218" + "expectedHash": "bb5365f32f6cf4ad304b19661013b54c" }, { "name": "predation-reflex-8k", "seed": 3, "config": { "learning": { "controller": "reflex" } }, "steps": 8000, - "expectedHash": "77f609256b658658dc66011fadae2aba" + "expectedHash": "ba847deb2c907ffb8c997675e16f2853" }, { "name": "predation-evolving-bodies-6k", @@ -1371,7 +1371,7 @@ "genetics": { "mutationRateScale": 3 } }, "steps": 6000, - "expectedHash": "24b72f1bbbc816e9aa563ecfcb0ee4ab" + "expectedHash": "ff6ecdeb75b3cb03edb09189d52a284d" }, { "name": "predation-lush-4k", @@ -1384,7 +1384,7 @@ } }, "steps": 4000, - "expectedHash": "551cf78d35dcb3cf05c3be08232ced5d" + "expectedHash": "7d816aed7cbf721448662cbb54803ec7" }, { "name": "predation-hunters-only-3k", diff --git a/packages/simulation/tests/predation/carnivore.test.ts b/packages/simulation/tests/predation/carnivore.test.ts index 9f70571..6d81e05 100644 --- a/packages/simulation/tests/predation/carnivore.test.ts +++ b/packages/simulation/tests/predation/carnivore.test.ts @@ -105,6 +105,14 @@ describe('what a mouth bites', () => { expect(events.eventsThisTick().some((e) => e.type === 'resource-bitten')).toBe(true) }) + it("a mandible does not bite carrion: a carcass is the jaw's alone (ADR 0026)", () => { + const cfg = config() + const { organism, food, events } = eat(false, carrionOf(cfg)) + expect(food.remaining).toBe(30) + expect(organism.gut).toBe(0) + expect(events.eventsThisTick().some((e) => e.type === 'resource-bitten')).toBe(false) + }) + it('a mandible still bites the same plant (negative: only the jaw changed)', () => { const { organism, food } = eat(false, GRASS) expect(food.remaining).toBeLessThan(30) @@ -138,7 +146,7 @@ describe('what a creature sees as food', () => { } it.each([false, true])( - 'a jaw sees carrion while a mandible sees plants but not carrion (occluding search: %s)', + 'a jaw sees carrion and not a plant; a mandible sees a plant and not carrion (occluding search: %s)', (occluding) => { const carrion = carrionOf(config()) expect(see(true, GRASS, occluding)).toBeNull() diff --git a/packages/simulation/tests/predation/death-and-carcass.test.ts b/packages/simulation/tests/predation/death-and-carcass.test.ts index 1bab726..f117451 100644 --- a/packages/simulation/tests/predation/death-and-carcass.test.ts +++ b/packages/simulation/tests/predation/death-and-carcass.test.ts @@ -224,12 +224,19 @@ describe('carcasses', () => { expect(withCarrion(noKinds)).toBe(noKinds) }) - it('makes a mandible get no carcass yield while jaws keep a positive yield', () => { + it("makes a carcass the jaw's alone: every other form yields exactly 0 (ADR 0026)", () => { const cfg = full() const kind = cfg.ecology.resourceKinds.kinds.length - 1 + for (const form of ['sprout', 'proboscis', 'mandible', 'radula'] as const) { + expect(cfg.anatomy.mouthForms[form][CARRION_KIND]).toBe(0) + } + expect(cfg.anatomy.mouthForms.jaw[CARRION_KIND]).toBeGreaterThan(0) + // the founder is a mandible: it digests nothing from a carcass const founder = organismFor(cfg, 1) - expect(factorsOf(founder.genome, cfg).dietEfficiency[kind]).toBeCloseTo(0, 9) - expect(cfg.predation.carcass.yields.jaw).toBeGreaterThan(0) + expect(factorsOf(founder.genome, cfg).dietEfficiency[kind]).toBe(0) + // negative: the old table (a mandible at 0.8) is still expressible and gives the old yield + const old = full({ predation: { carcass: { yields: { mandible: 0.8 } } } }) + expect(factorsOf(founder.genome, old).dietEfficiency[kind]).toBeCloseTo(0.8, 9) }) function carcasses(extra: WorldConfigOverrides = {}) { diff --git a/packages/simulation/tests/support/ecology-stability.ts b/packages/simulation/tests/support/ecology-stability.ts index 6a1e8f9..166e0e5 100644 --- a/packages/simulation/tests/support/ecology-stability.ts +++ b/packages/simulation/tests/support/ecology-stability.ts @@ -26,6 +26,11 @@ import { World } from '../../src/index' * means are 43.0-81.5, minimum 16, maximum 123, and no world went extinct. Only the ceiling * moved: 110 became 140 (it was 87 and 85 before bites and plants), still a seventh of * `maxPopulation`; means and the floor of 15 are as they were. + * + * Carcasses for the jaw alone (ADR 0026, the owner's decision) take the carrion energy away from the + * herbivores that were eating it (5 percent of all intake): over these 12 seeds (5-8 and 33-40, same + * sampling) means are 37.7-77.2, minimum 10 (seed 6; the next lowest is 17), maximum 118, and no world + * went extinct. The floor moved from 15 to 8; means and the ceiling hold. */ export function describeStability(seeds: readonly number[]): void { describe('the default ecology keeps held-out worlds alive', () => { @@ -42,7 +47,7 @@ export function describeStability(seeds: readonly number[]): void { expect(world.isExtinct).toBe(false) expect(mean).toBeGreaterThan(25) expect(mean).toBeLessThan(90) - expect(Math.min(...samples)).toBeGreaterThanOrEqual(15) + expect(Math.min(...samples)).toBeGreaterThanOrEqual(8) expect(Math.max(...samples)).toBeLessThanOrEqual(140) expect(world.validate()).toEqual({ ok: true, errors: [] }) // the ecology was actually in play