From f9f520f732001f27a80640fc2d5a7b03a3e72d44 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 15:23:52 +0000 Subject: [PATCH 1/3] fix(anatomy): per-mouth intake, sniffer over grown kinds, carcass yields may be zero (ADR 0026) Three fixes found while planning hard diets, none of which changes the default diet table: - A bite takes in the yield of the mouth that bites, not the blend over all the body's mouths (a sprout beside a jaw took half the sprout's yield). A body with one mouth keeps the exact value it had. - A sniffer's selectivity is spread over the food kinds a world grows, not the carcass kind that predation appends last: the nectar sipper's 0.875 landed on nectar with four kinds and on carrion with five. - predation.carcass.yields may be zero (a form that cannot digest meat), and with food kinds on every mouth form must list a yield for every kind (an unlisted kind used to be edible by everyone). Goldens: 18 of 52 entries move, all evolving-body worlds (the intake fix moves 16, the sniffer fix 2). With both fixes reverted all 52 reproduce, so the rest of the commit is behaviour-inert. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Cn5qp4xBHxLnTrwReNXcf8 --- packages/config/src/anatomy.ts | 27 +++++++ packages/config/src/predation.ts | 3 +- packages/config/tests/anatomy.test.ts | 23 ++++++ packages/config/tests/ecology.test.ts | 12 +++- packages/config/tests/predation.test.ts | 8 ++- .../src/development/capabilities.ts | 7 +- .../src/systems/InteractionSystem.ts | 11 ++- .../tests/anatomy/diet-fixes.test.ts | 70 +++++++++++++++++++ .../simulation/tests/feeding/bites.test.ts | 40 ++++++++++- .../simulation/tests/golden/state-hashes.json | 36 +++++----- packages/simulation/tests/support/ecology.ts | 25 +++++++ 11 files changed, 236 insertions(+), 26 deletions(-) create mode 100644 packages/simulation/tests/anatomy/diet-fixes.test.ts diff --git a/packages/config/src/anatomy.ts b/packages/config/src/anatomy.ts index b146227..889420b 100644 --- a/packages/config/src/anatomy.ts +++ b/packages/config/src/anatomy.ts @@ -246,6 +246,20 @@ const STARTING_GROUP_KEYS = ['archetype', 'share'] const STARTING_BODY_MODES = ['reference', 'archetypes'] const OUTLINE_KEYS = ['count', 'radii', 'angles'] +/** The names of the food kinds when kinds are on, else none. */ +function enabledKindNames(root: PlainObject): string[] { + const ecology = root['ecology'] + const section = isObject(ecology) ? ecology['resourceKinds'] : undefined + if (!isObject(section) || section['enabled'] !== true || !Array.isArray(section['kinds'])) { + return [] + } + const names: string[] = [] + for (const kind of section['kinds'] as unknown[]) { + if (isObject(kind) && typeof kind['name'] === 'string') names.push(kind['name']) + } + return names +} + function checkRange( section: PlainObject, key: string, @@ -361,6 +375,19 @@ export function checkAnatomy(root: PlainObject, errors: string[]): void { } } } + // With food kinds on, every form must say what it yields for every kind: an unlisted kind used + // to be edible by everyone (a yield of 1), which hard diets turn into a trap (ADR 0026). The + // carcass kind is added later, from `predation.carcass.yields`, so it is not listed here. + for (const name of enabledKindNames(root)) { + for (const form of MOUTH_FORMS) { + const kinds = forms[form] + if (isObject(kinds) && kinds[name] === undefined) { + errors.push( + `anatomy.mouthForms.${form} has no yield for the food kind "${name}" (list it, with 0 if the form cannot eat it)` + ) + } + } + } const mandible = forms['mandible'] if (isObject(mandible)) { for (const [kind, value] of Object.entries(mandible)) { diff --git a/packages/config/src/predation.ts b/packages/config/src/predation.ts index f1b2602..580a530 100644 --- a/packages/config/src/predation.ts +++ b/packages/config/src/predation.ts @@ -83,7 +83,8 @@ export function checkPredation(root: PlainObject, errors: string[]): void { ) if (yields) { for (const form of MOUTH_FORMS) { - checkNumber(yields, form, `predation.carcass.yields.${form}`, { positive: true }, errors) + // Zero is allowed: a form that cannot digest meat takes nothing from a carcass (ADR 0026). + checkNumber(yields, form, `predation.carcass.yields.${form}`, { nonnegative: true }, errors) } } } diff --git a/packages/config/tests/anatomy.test.ts b/packages/config/tests/anatomy.test.ts index cee51e7..66c4396 100644 --- a/packages/config/tests/anatomy.test.ts +++ b/packages/config/tests/anatomy.test.ts @@ -217,6 +217,29 @@ describe('feeding config (ADR 0017)', () => { }) }) +describe('mouth forms must say what they yield for every food kind (ADR 0026)', () => { + it('a kind a form does not list is an error with food kinds on, and fine with them off', () => { + const error = errorsFor( + (c) => delete (c.anatomy.mouthForms.sprout as Record)['fungus'] + ).join('\n') + expect(error).toContain('anatomy.mouthForms.sprout has no yield for the food kind "fungus"') + // a new food kind has to be listed for every form + const added = errorsFor((c) => { + c.ecology.resourceKinds.kinds.push({ ...c.ecology.resourceKinds.kinds[0]!, name: 'moss' }) + }).join('\n') + expect(added).toContain('has no yield for the food kind "moss"') + // negative: with kinds off nothing needs listing + expect( + errorsFor((c) => { + c.ecology.resourceKinds.enabled = false + delete (c.anatomy.mouthForms.sprout as Record)['fungus'] + }) + ).toEqual([]) + // and the defaults list every kind for every form + expect(errorsFor(() => undefined)).toEqual([]) + }) +}) + describe('mouth forms (ADR 0017)', () => { it('the mandible is exactly 1 on every kind so the founder is the neutral reference', () => { for (const value of Object.values(DEFAULT_WORLD_CONFIG.anatomy.mouthForms.mandible)) { diff --git a/packages/config/tests/ecology.test.ts b/packages/config/tests/ecology.test.ts index bc14f54..4cc2467 100644 --- a/packages/config/tests/ecology.test.ts +++ b/packages/config/tests/ecology.test.ts @@ -66,7 +66,17 @@ describe('ecology config', () => { toxicity: 0, regions: [] } - const config = resolveWorldConfig({ ecology: { resourceKinds: { kinds: [kind] } } }) + // every mouth form has to say what it yields for the new kind (ADR 0026) + const mouthForms = Object.fromEntries( + ['sprout', 'proboscis', 'mandible', 'radula', 'jaw'].map((f) => [ + f, + { moss: f === 'jaw' ? 0 : 1 } + ]) + ) + const config = resolveWorldConfig({ + ecology: { resourceKinds: { kinds: [kind] } }, + anatomy: { mouthForms } + }) expect(config.ecology.resourceKinds.kinds).toEqual([kind]) }) diff --git a/packages/config/tests/predation.test.ts b/packages/config/tests/predation.test.ts index 67dc8fc..6c25cc4 100644 --- a/packages/config/tests/predation.test.ts +++ b/packages/config/tests/predation.test.ts @@ -90,9 +90,13 @@ describe('predation config', () => { expect(errorsFor((p) => ((p['carcass'] as Loose)['energyFraction'] = 0 as never))).toContain( 'predation.carcass.energyFraction must be greater than zero and at most one' ) + // zero is allowed (a form that cannot digest meat, ADR 0026); a negative is not expect( - errorsFor((p) => (((p['carcass'] as Loose)['yields'] as Loose)['jaw'] = 0 as never)) - ).toContain('predation.carcass.yields.jaw must be greater than zero') + errorsFor((p) => (((p['carcass'] as Loose)['yields'] as Loose)['sprout'] = 0 as never)) + ).toEqual([]) + expect( + errorsFor((p) => (((p['carcass'] as Loose)['yields'] as Loose)['jaw'] = -1 as never)) + ).toContain('predation.carcass.yields.jaw must be nonnegative') expect(errorsFor((p) => ((p['carcass'] as Loose)['maxCount'] = 1.5 as never))).toContain( 'predation.carcass.maxCount must be an integer' ) diff --git a/packages/simulation/src/development/capabilities.ts b/packages/simulation/src/development/capabilities.ts index 063bbf1..62a2b55 100644 --- a/packages/simulation/src/development/capabilities.ts +++ b/packages/simulation/src/development/capabilities.ts @@ -12,6 +12,7 @@ import type { VisionCone } from '@evo/contracts' import { cos, sin } from '../math/trig' +import { CARRION_KIND } from '../world/predationConfig' /** Which food kind a sniffer favors: its selectivity (a gene in `[0, 1]`) spread over the kinds. */ export function sniffedKind(selectivity: number, kindCount: number): number { @@ -220,7 +221,11 @@ export function capabilitiesOf( signal += p * mult(part, 'potency') * effects.pheromoneSignal break case 'sniffer': { - const kind = sniffedKind(part.stats[2] as number, detection.length) + // Selectivity is spread over the food kinds a world grows, not the carcass kind that predation + // appends last: with it counted, the nectar sipper's selectivity (0.875, nectar with four kinds) + // landed on carrion with five (ADR 0026). + const grown = kindNames.filter((name) => name !== CARRION_KIND).length + const kind = sniffedKind(part.stats[2] as number, grown > 0 ? grown : detection.length) detection[kind] = (detection[kind] as number) + p * 0.5 * (mult(part, 'range') + mult(part, 'sensitivity')) break diff --git a/packages/simulation/src/systems/InteractionSystem.ts b/packages/simulation/src/systems/InteractionSystem.ts index 6a69c0e..35abc38 100644 --- a/packages/simulation/src/systems/InteractionSystem.ts +++ b/packages/simulation/src/systems/InteractionSystem.ts @@ -116,7 +116,8 @@ export class InteractionSystem { const c = cos(heading) const s = sin(heading) - for (const mouth of mouthsOf(organism.genome, this.config)) { + const mouths = mouthsOf(organism.genome, this.config) + for (const mouth of mouths) { // The mouth in the world: the body-frame point turned by the heading. const mx = (mouth.x * c - mouth.y * s) * bodyRadius const my = (mouth.x * s + mouth.y * c) * bodyRadius @@ -161,7 +162,13 @@ export class InteractionSystem { const resource = hit.item const kind = this.kindOf(resource.kind) - const yieldPerChunk = body.dietEfficiency[resource.kind] ?? 1 + // What it takes in is what the mouth that bites yields, not the body's blend over all its mouths + // (a sprout beside a jaw bites grass at the sprout's yield, ADR 0026). A body with one mouth keeps + // the exact value it always had. + const yieldPerChunk = + mouths.length === 1 + ? (body.dietEfficiency[resource.kind] ?? 1) + : (this.formYields[mouth.form][resource.kind] ?? 1) // A plant's hub is tougher than its nodes (ADR 0021); free food and nodes are the kind's own. const hardness = resource.slot === HUB_SLOT diff --git a/packages/simulation/tests/anatomy/diet-fixes.test.ts b/packages/simulation/tests/anatomy/diet-fixes.test.ts new file mode 100644 index 0000000..08b0264 --- /dev/null +++ b/packages/simulation/tests/anatomy/diet-fixes.test.ts @@ -0,0 +1,70 @@ +import { describe, expect, it } from 'vitest' +import { resolveWorldConfig } from '@evo/config' +import { developAnatomy } from '../../src/development/develop' +import { capabilitiesOf, sniffedKind } from '../../src/development/capabilities' +import { bodyVectorOf } from '../../src/genetics/BodyGenes' + +// Fixes found while planning hard diets (ADR 0026). + +const config = resolveWorldConfig({}) +const { anatomy } = config +const natural = config.ecology.resourceKinds.kinds.map((k) => k.name) +const withCarrion = [...natural, 'carrion'] +const sipper = anatomy.starters.find((s) => s.name === 'nectar-sipper')! +const body = bodyVectorOf({ parts: sipper.parts, look: sipper.look, outline: sipper.outline }) +const developed = developAnatomy(body, anatomy) + +describe('a sniffer is spread over the food kinds a world grows, not the carcass kind', () => { + const sniffer = developed.parts.find((p) => p.type === 'sniffer') + + it('the nectar sipper has a sniffer tuned to nectar when four kinds are grown', () => { + expect(sniffer).toBeDefined() + expect(natural[sniffedKind(sniffer!.stats[2] as number, natural.length)]).toBe('nectar') + }) + + it('still smells nectar, and not carrion, once predation appends the carcass kind', () => { + const caps = capabilitiesOf(developed, anatomy, 1, withCarrion.length, withCarrion) + const nectar = natural.indexOf('nectar') + const carrion = withCarrion.indexOf('carrion') + // the sniffer boosts the kind it favors above the plain baseline every kind has + expect(caps.foodDetection[nectar] as number).toBeGreaterThan( + caps.foodDetection[carrion] as number + ) + expect(caps.foodDetection[carrion]).toBe(caps.foodDetection[natural.indexOf('grass')]) + }) + + it('negative: counting the carcass kind (the old mapping) puts that selectivity on carrion', () => { + const old = sniffedKind(sniffer!.stats[2] as number, withCarrion.length) + expect(withCarrion[old]).toBe('carrion') + }) + + it('is the same with or without the carcass kind for every selectivity over the grown kinds', () => { + for (let s = 0; s <= 1; s += 0.05) { + const a = capabilitiesOf( + developAnatomy(withSelectivity(s), anatomy), + anatomy, + 1, + natural.length, + natural + ) + const b = capabilitiesOf( + developAnatomy(withSelectivity(s), anatomy), + anatomy, + 1, + withCarrion.length, + withCarrion + ) + natural.forEach((_, i) => expect(b.foodDetection[i]).toBe(a.foodDetection[i])) + // the carcass kind is never the one a sniffer favors: it keeps the baseline + expect(b.foodDetection[withCarrion.length - 1]).toBe(Math.min(...b.foodDetection)) + } + }) +}) + +function withSelectivity(selectivity: number): number[] { + const copy = [...body] + const slot = developed.parts.find((p) => p.type === 'sniffer')!.slot + // stat s2 of the sniffer's slot: 14 genes a slot, field order present..integrity then s0..s5 + copy[slot * 14 + 8 + 2] = selectivity + return copy +} diff --git a/packages/simulation/tests/feeding/bites.test.ts b/packages/simulation/tests/feeding/bites.test.ts index 155a8d2..cc95da7 100644 --- a/packages/simulation/tests/feeding/bites.test.ts +++ b/packages/simulation/tests/feeding/bites.test.ts @@ -17,7 +17,7 @@ import { DigestionSystem } from '../../src/systems/DigestionSystem' import { InteractionSystem } from '../../src/systems/InteractionSystem' import { MovementSystem } from '../../src/systems/MovementSystem' import { organismFor } from '../support/organism' -import { withoutEcology } from '../support/ecology' +import { eats, withoutEcology } from '../support/ecology' /** * Bites (ADR 0017): a working mouth, food in front of it within reach, the intent to interact and a @@ -270,6 +270,7 @@ describe('food has health: it takes several bites', () => { const cfg = resolveWorldConfig({ learning: { controller: 'reflex' }, feeding: FEEDING, + anatomy: eats(['tough']), ecology: { resourceKinds: { enabled: true, @@ -387,11 +388,48 @@ describe('the mouth', () => { }) }) +describe('a body with two mouths', () => { + it('takes the yield of the mouth that bites, not the blend over both (ADR 0026)', () => { + const cfg = resolveWorldConfig( + withoutEcology({ + learning: { controller: 'reflex' }, + feeding: FEEDING, + ecology: { resourceKinds: DEFAULT_WORLD_CONFIG.ecology.resourceKinds } + }) + ) + const sproutMouth = (p: FounderPart): FounderPart => + p.type === 'mouth' ? { ...p, stats: [0.5, 0.5, 0.05, 0.5, 0.5, 0.5] } : p + const intake = (extra: boolean): number => { + const parts = founderOf(cfg).map(sproutMouth) + const mouth = parts.find((p) => p.type === 'mouth')! + // a jaw beside the sprout: it bites nothing off a plant, but used to drag the blended yield down + if (extra) + parts.push({ ...mouth, angle: mouth.angle + 3, stats: [0.5, 0.5, 0.95, 0.5, 0.5, 0.5] }) + const s = scene( + cfg, + (m) => [food(9, m.x + 1, m.y, 30, 0)], + {}, + undefined, + new EcologyModel(cfg, null), + parts + ) + s.interact() + return s.organism.gut + } + expect(intake(false)).toBeCloseTo(12 * 1.3, 12) + // A second mouth doubles the body's bite size (it sums over mouths), so the chunk is 24; what it + // takes in is the sprout's 1.3 of it, not the blend over both mouths (0.65). + expect(intake(true)).toBeCloseTo(24 * 1.3, 12) + expect(intake(true)).not.toBeCloseTo(24 * 0.65, 6) + }) +}) + describe('toxins', () => { it('a whole toxic item adds up to its old damage, split over its bites', () => { const cfg = resolveWorldConfig({ learning: { controller: 'reflex' }, feeding: FEEDING, + anatomy: eats(['toxic']), ecology: { resourceKinds: { enabled: true, diff --git a/packages/simulation/tests/golden/state-hashes.json b/packages/simulation/tests/golden/state-hashes.json index 8946b56..fa8a175 100644 --- a/packages/simulation/tests/golden/state-hashes.json +++ b/packages/simulation/tests/golden/state-hashes.json @@ -292,7 +292,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 100000, - "expectedHash": "9b14b1c9595fbdf716dd831662c74f43" + "expectedHash": "43f483885de7b8f74ce88bde897ba99f" }, { "name": "reflex-default-1k", @@ -707,7 +707,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 6000, - "expectedHash": "a0388ae0a84fc3b80ead1f5e8a3cc2dd" + "expectedHash": "2c06cf6f0fec093bd63e2f53614cc8f6" }, { "name": "anatomy-on-reflex-4k", @@ -748,7 +748,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 4000, - "expectedHash": "3f5ae508e3d5e461ed17ed0cce83b715" + "expectedHash": "b2a40f52021592c05214ee92dc2d7c43" }, { "name": "clusters-small-6k", @@ -879,7 +879,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 12000, - "expectedHash": "ff2654fdb2e6c32d46909bada36c85ca" + "expectedHash": "d2b9cd57ea4c081d5e2b2ded495618b5" }, { "name": "archetypes-reflex-8k", @@ -1043,7 +1043,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 3000, - "expectedHash": "b4d3b87a25bacd3baa3375e0428a93a7" + "expectedHash": "320cdf7945c99f4e7a292305e01288b0" }, { "name": "noise-food-4k", @@ -1073,7 +1073,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 4000, - "expectedHash": "e5b02a027b6c7d306fea0512ff879bae" + "expectedHash": "36b550127d7f1be84248ea73fe810bc0" }, { "name": "noise-reflex-3k", @@ -1134,7 +1134,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 6000, - "expectedHash": "a1851625349fee916fa42c1082d8a60b" + "expectedHash": "93d65e057d0e0fbf4e2fab8e76ae652e" }, { "name": "plants-noise-reflex-5k", @@ -1165,7 +1165,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 5000, - "expectedHash": "895fd03f3a24748838fba9b4622c4694" + "expectedHash": "6bb542d77a8174ce71d3377a3dad40cf" }, { "name": "plants-brain-evolving-8k", @@ -1198,7 +1198,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 8000, - "expectedHash": "4a6d5dee4873b7c856fc66f26ebbf366" + "expectedHash": "68a92946ed3370eb549f0a458541a96a" }, { "name": "food-default-1k", @@ -1220,7 +1220,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 12000, - "expectedHash": "b1fb89450aa5df601208731420041546" + "expectedHash": "00cfbbfd4828b0d76d58b1415a608729" }, { "name": "food-default-reflex-8k", @@ -1252,7 +1252,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 6000, - "expectedHash": "5fcf154ec9c93e980527bd9aa18b8c3d" + "expectedHash": "fe69449e6c2892c9529a857b2b8e0243" }, { "name": "food-lush-4k", @@ -1268,7 +1268,7 @@ "ecology": { "obstacles": { "enabled": false } } }, "steps": 4000, - "expectedHash": "5d687f807cdcefc55e26e090dad7569e" + "expectedHash": "1c08f874f067af38dfb56f0b75d97124" }, { "name": "obstacles-default-1k", @@ -1288,7 +1288,7 @@ "anatomy": { "startingBody": { "groups": [] } } }, "steps": 12000, - "expectedHash": "1ec4c556a39840d57e1aa25c7b85eb9b" + "expectedHash": "84950d17f6782508faadf4f4a40597ae" }, { "name": "obstacles-reflex-8k", @@ -1318,7 +1318,7 @@ "genetics": { "mutationRateScale": 3 } }, "steps": 6000, - "expectedHash": "fce90dd0aeb659e59a7d2e4db69406f8" + "expectedHash": "ad858c84fc69bf2362341ca55a5ab5ca" }, { "name": "obstacles-lush-4k", @@ -1333,7 +1333,7 @@ } }, "steps": 4000, - "expectedHash": "a9ddf72a9c27d340994f78912b347fd0" + "expectedHash": "cd86aa4f8fa2dec7540afac4414bf30c" }, { "name": "predation-default-1k", @@ -1354,7 +1354,7 @@ "seed": 3, "config": { "learning": { "controller": "reflex" } }, "steps": 8000, - "expectedHash": "0fcc26dee9e091850c83b33aff8c5436" + "expectedHash": "77f609256b658658dc66011fadae2aba" }, { "name": "predation-evolving-bodies-6k", @@ -1371,7 +1371,7 @@ "genetics": { "mutationRateScale": 3 } }, "steps": 6000, - "expectedHash": "48d8b7e596b3cbc89a1d1bed1c358bf9" + "expectedHash": "24b72f1bbbc816e9aa563ecfcb0ee4ab" }, { "name": "predation-lush-4k", @@ -1384,7 +1384,7 @@ } }, "steps": 4000, - "expectedHash": "c96e1b5afdd6ffbdd8353f67b03454e7" + "expectedHash": "551cf78d35dcb3cf05c3be08232ced5d" }, { "name": "predation-hunters-only-3k", diff --git a/packages/simulation/tests/support/ecology.ts b/packages/simulation/tests/support/ecology.ts index 93b6656..402d4f9 100644 --- a/packages/simulation/tests/support/ecology.ts +++ b/packages/simulation/tests/support/ecology.ts @@ -1,6 +1,19 @@ import type { EcologyConfigOverrides, WorldConfigOverrides } from '@evo/contracts' import { FREE_FOOD } from './food' +/** + * Mouth yields for food kinds a test makes up (ADR 0026: every form has to say what it yields for every + * kind a world grows): every form takes them whole (1), except the jaw, which eats no plant. + */ +export function eats(names: readonly string[]): NonNullable { + const forms = ['sprout', 'proboscis', 'mandible', 'radula', 'jaw'] as const + return { + mouthForms: Object.fromEntries( + forms.map((form) => [form, Object.fromEntries(names.map((n) => [n, form === 'jaw' ? 0 : 1]))]) + ) as never + } +} + const OFF = { health: { enabled: false }, regions: { enabled: false }, @@ -30,8 +43,20 @@ export function withoutEcology(config: WorldConfigOverrides = {}): WorldConfigOv migration: { ...OFF.migration, ...given.migration }, obstacles: { ...OFF.obstacles, ...given.obstacles } } + // Kinds a test makes up have to be edible by the forms it uses; the defaults already list their own. + const custom = (given.resourceKinds?.kinds ?? []) + .map((k) => k.name) + .filter((n) => !['grass', 'fruit', 'fungus', 'nectar'].includes(n)) + const anatomy = + custom.length === 0 + ? config.anatomy + : { + ...(config.anatomy ?? {}), + mouthForms: { ...eats(custom).mouthForms, ...(config.anatomy?.mouthForms ?? {}) } + } return { ...config, + ...(anatomy === undefined ? {} : { anatomy }), // The Phase 5 food: free food at two a second on a 500 x 500 field (the spawn rate was lowered // when mate seeking arrived, ADR 0010; patches, plants and the bigger field came in ADR 0021). environment: { ...FREE_FOOD.environment, ...(config.environment ?? {}) }, From dba33429e335b75d9aef6095cea058081531b3d0 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 16:37:41 +0000 Subject: [PATCH 2/3] docs(anatomy): ADR 0026, diets measured, hard diets not kept; reusable diet probe, fixed starts probe Records the owner's observation with numbers (jaws get 5 percent of the carrion, herbivore mouths eat every kind), the three fixes kept, and four diet variants measured over 16 seeds and 30,000 ticks plus carrion-for-the-jaw-only at 100,000 ticks: hard plant diets raise extinction (7 of 16 worlds with boosted specialists) and exclusive carrion does not feed the jaw (jaw alive in 2 of 8, one world 72 percent jaws, population about 11 percent lower). The stated criteria were missed by every variant, so no diet table is shipped; the owner decides on jaw-only carrion. tests/probe/diet.probe.ts is committed (who eats what by mouth form and kind); starts.probe.ts no longer overwrites an override's anatomy section. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Cn5qp4xBHxLnTrwReNXcf8 --- docs/anatomy/anatomy.md | 46 +++++----- docs/decisions/0026-diets.md | 59 +++++++++++++ docs/simulation/configuration.md | 4 +- packages/simulation/tests/probe/diet.probe.ts | 86 +++++++++++++++++++ .../simulation/tests/probe/starts.probe.ts | 11 ++- 5 files changed, 177 insertions(+), 29 deletions(-) create mode 100644 docs/decisions/0026-diets.md create mode 100644 packages/simulation/tests/probe/diet.probe.ts diff --git a/docs/anatomy/anatomy.md b/docs/anatomy/anatomy.md index 0cf8999..65b4b2a 100644 --- a/docs/anatomy/anatomy.md +++ b/docs/anatomy/anatomy.md @@ -80,29 +80,29 @@ It uses the engine's own `cos` and `sin`, no randomness, and never modifies its `capabilitiesOf(anatomy, config, bodyScale, kindCount)`. Sums run over functional parts of the named type; `p = strength * size * integrity`; `m(stat)` is the stat's multiplier `0.5 + gene`, exactly 1 at the founder's value, so every line is the founder's at founder stats. Gene tables per type are in [ADR 0016](../decisions/0016-part-stats-and-attachment.md). -| Capability | Formula | -| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| mass | `bodyMass * bodyScale` + `sum(mass * size * massScale)` over **all** parts (`massScale` follows the part's own dimensions) | -| upkeep | `sum(upkeep * size * upkeepScale)` over **all** parts (`upkeepScale` follows force, rate or range; energy per second) | -| thrust strength | flagellum `p * m(force) * sqrt(m(length)) * (0.8 + 0.2 m(thickness))`; cilia `p * m(density) * sqrt(m(length) * m(rate))` | -| forward / lateral thrust | `strength * max(0, fx)` / `strength * abs(fy)` with the push `(fx, fy) = -(cos axis, sin axis)` (a tail trails along its axis) | -| torque | `strength * abs(x * fy - y * fx)`: the moment of the force about the centre, from the part's anchor | -| sense range | `senseFloor + sqrt(sum(p * m(range)))` over eyes (so each extra eye adds less) | -| vision cone, per eye | axis = the eye's facing; half-angle = field of view / 2; reach = sense range `* (1 + effects.visionNarrowing * (sqrt(6.28 / fov) - 1))` (an all-round eye reaches exactly the sense range) | -| food detection, kind `k` | `(1 + sum(p * (m(range) + m(sensitivity)) / 2)) * (1 + 0.25 * sum(p * m(resolution)))`; a sniffer's selectivity stat picks `k`; eye resolution lifts every kind | -| reach | `1 + sum(p * m(reach))` over mouths | -| bite size / bite rate | `sum(p * m(gape))` / `sum(p * m(rate))` over mouths; zero without a working mouth, which then cannot bite (ADR 0017) | -| diet efficiency, kind `k` | power-weighted mean over mouths of the form's yield for that kind (config `anatomy.mouthForms`; the mandible is exactly 1) | -| absorption | `1 + sum(p * (m(absorption) + m(length)) / 2)` over intestines `+ sum(p * m(throughput) / 2)` over stomachs: how fast the gut empties | -| digestion | `1 + sum(p * (m(absorption) + m(length)) / 2)` over intestines `+ sum(p * m(gape) / 2)` over mouths `+ sum(p * m(throughput) / 2)` over stomachs | -| toxin tolerance | `x / (1 + x)` with `x = sum(p * m(filter))` over intestines, in `[0, 1)` | -| gyro torque | `sum(p * m(stability) * effects.gyroTorque)` over gyros, added to the torque above: turning with no thrust | -| eye on an eyestalk | an eye whose parent is a working eyestalk has its range term multiplied by `1 + effects.eyestalkLift * m(length)` | -| mating signal | `min(effects.pheromoneCap, 1 + sum(p * m(potency) * effects.pheromoneSignal))` over pheromone glands: a creature is heard by a searcher out to `mateSenseRadius` times this | -| energy capacity | `1 + sum(p * m(capacity))` over stomachs `+ sum(p * m(reserve) * effects.lipidCapacity)` over lipid stores | -| damage taken | `1 / (1 + sum(p * (m(thickness) + m(coverage) + m(hardness)) / 3))` over armor, in `(0, 1]` | -| temperature tolerance | `1 + sum(p * m(insulation) * (0.8 + 0.2 m(thickness)))` over membranes | -| regeneration | `1 + sum(p * m(rate))` over menders | +| Capability | Formula | +| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| mass | `bodyMass * bodyScale` + `sum(mass * size * massScale)` over **all** parts (`massScale` follows the part's own dimensions) | +| upkeep | `sum(upkeep * size * upkeepScale)` over **all** parts (`upkeepScale` follows force, rate or range; energy per second) | +| thrust strength | flagellum `p * m(force) * sqrt(m(length)) * (0.8 + 0.2 m(thickness))`; cilia `p * m(density) * sqrt(m(length) * m(rate))` | +| forward / lateral thrust | `strength * max(0, fx)` / `strength * abs(fy)` with the push `(fx, fy) = -(cos axis, sin axis)` (a tail trails along its axis) | +| torque | `strength * abs(x * fy - y * fx)`: the moment of the force about the centre, from the part's anchor | +| sense range | `senseFloor + sqrt(sum(p * m(range)))` over eyes (so each extra eye adds less) | +| vision cone, per eye | axis = the eye's facing; half-angle = field of view / 2; reach = sense range `* (1 + effects.visionNarrowing * (sqrt(6.28 / fov) - 1))` (an all-round eye reaches exactly the sense range) | +| food detection, kind `k` | `(1 + sum(p * (m(range) + m(sensitivity)) / 2)) * (1 + 0.25 * sum(p * m(resolution)))`; a sniffer's selectivity stat picks `k`; eye resolution lifts every kind | +| reach | `1 + sum(p * m(reach))` over mouths | +| bite size / bite rate | `sum(p * m(gape))` / `sum(p * m(rate))` over mouths; zero without a working mouth, which then cannot bite (ADR 0017) | +| diet efficiency, kind `k` | power-weighted mean over mouths of the form's yield for that kind (config `anatomy.mouthForms`; the mandible is exactly 1; a bite takes in the yield of the mouth that bites, not the blend over all the body's mouths, ADR 0026) | +| absorption | `1 + sum(p * (m(absorption) + m(length)) / 2)` over intestines `+ sum(p * m(throughput) / 2)` over stomachs: how fast the gut empties | +| digestion | `1 + sum(p * (m(absorption) + m(length)) / 2)` over intestines `+ sum(p * m(gape) / 2)` over mouths `+ sum(p * m(throughput) / 2)` over stomachs | +| toxin tolerance | `x / (1 + x)` with `x = sum(p * m(filter))` over intestines, in `[0, 1)` | +| gyro torque | `sum(p * m(stability) * effects.gyroTorque)` over gyros, added to the torque above: turning with no thrust | +| eye on an eyestalk | an eye whose parent is a working eyestalk has its range term multiplied by `1 + effects.eyestalkLift * m(length)` | +| mating signal | `min(effects.pheromoneCap, 1 + sum(p * m(potency) * effects.pheromoneSignal))` over pheromone glands: a creature is heard by a searcher out to `mateSenseRadius` times this | +| energy capacity | `1 + sum(p * m(capacity))` over stomachs `+ sum(p * m(reserve) * effects.lipidCapacity)` over lipid stores | +| damage taken | `1 / (1 + sum(p * (m(thickness) + m(coverage) + m(hardness)) / 3))` over armor, in `(0, 1]` | +| temperature tolerance | `1 + sum(p * m(insulation) * (0.8 + 0.2 m(thickness)))` over membranes | +| regeneration | `1 + sum(p * m(rate))` over menders | The consequences are the point: a flagellum pushing forward drives speed; pushing sideways it strafes; placed off the axis it turns the body; one at the rear on the axis cannot. Every part costs mass and upkeep, a dormant part costs them for nothing, and armor can reduce damage but never to zero. diff --git a/docs/decisions/0026-diets.md b/docs/decisions/0026-diets.md new file mode 100644 index 0000000..3f6ea7f --- /dev/null +++ b/docs/decisions/0026-diets.md @@ -0,0 +1,59 @@ +# 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). + +## The owner's observation + +After three measured null results on carnivory, the owner pointed at two causes: **predators have only one food source**, and **herbivore mouths do not really matter, they can eat any food regardless: grazers and fungus-scrapers can eat carcasses.** Both are true, and measured (`tests/probe/diet.probe.ts`, default world, 4 seeds x 20,000 ticks, energy taken in credited to the eater's mouth form): + +| eater | grass | fruit | fungus | nectar | carrion | flesh | +| --------------- | ----- | ----- | ------ | ------ | ------- | ----- | +| sprout (grazer) | 173k | 65k | 36k | 47k | 3.5k | 0 | +| proboscis | 50k | 42k | 31k | 44k | 2.6k | 0 | +| mandible | 75k | 30k | 41k | 27k | 20k | 0 | +| radula | 2.2k | 1.4k | 2.2k | 1.8k | 0.5k | 0 | +| jaw | 0 | 0 | 0 | 0 | 1.5k | 2.8k | + +**Jaws got 5 percent of the carrion** (mandibles 71, sprouts 12, proboscis 9, radula 2). A sprout took about a fifth of its intake from fungus and nectar, and a proboscis ate as much grass as fruit. The cause is the specification, not a bug in the code: a form is a 0.5 to 1.5 times multiplier on the yield (`anatomy.mouthForms`), and only an exact 0 stops a mouth eating (the per-mouth gate and the perception filter of ADR 0023 step three). Carcasses were given every form a positive yield (`predation.carcass.yields`: sprout 0.1, proboscis 0.2, mandible 0.8, radula 0.6, jaw 1.2). Jaws that did exist ate as well as anyone (0.146 intake per creature-tick against 0.147 for sprouts). + +## Three fixes, kept + +Found while planning hard diets; each stands on its own. + +1. **A bite takes in the yield of the mouth that bites**, not the power-weighted blend over every mouth of the body (`InteractionSystem`): a sprout beside a jaw took the sprout's grass at half its yield. A body with one mouth keeps the exact value it had (the blend of one mouth is its own yield, but the old path is kept so float rounding cannot move a hash). +2. **A sniffer's selectivity is spread over the food kinds a world grows**, not over the carcass kind that predation appends last. `sniffedKind = floor(selectivity x kindCount)` counted carrion, so the nectar sipper's selectivity (0.875: nectar with four kinds) landed on **carrion** with five. In every default world its nose was tuned to carcasses. +3. **Validation.** `predation.carcass.yields` may be 0 (a form that cannot digest meat; it demanded strictly positive), and with food kinds on every form must list a yield for every kind (an unlisted kind was edible by everyone at 1, which a hard diet turns into a trap). + +**Goldens:** 18 of the 52 entries move, all evolving-body worlds (the intake fix moves 16, the sniffer fix 2; evolved bodies often grow a second mouth). With both fixes reverted all 52 reproduce, so the rest of the commit is behaviour-inert. + +## Hard diets, measured, not kept + +The change the owner pointed at: a form eats only the kinds it is built for (yield exactly 0 elsewhere), carcasses only for the jaw. 16 seeds x 30,000 ticks, the default world (a start drawn from the seed), `longrun.probe.ts`: + +| variant | extinct | mean population (lowest) | worlds with a jaw at the end | 2+ mouth forms | carrion share of intake | +| ---------------------------------------------------------------------------------------------------- | ----------- | ------------------------ | ---------------------------- | -------------- | ----------------------- | +| today (soft) | 0 of 16 | 56.8 (34) | 0 of 16 | 10 of 16 | 5.3% | +| **carrion for the jaw only**, plants soft | 0 of 16 | 50.3 (10) | 1 of 16 | 13 of 16 | 0.7% | +| hard plant diets with low-yield fallbacks | 1 of 16 | 51.2 (16) | 1 of 15 | 7 of 15 | 0.0% | +| hard plant diets, boosted specialist yields | **7 of 16** | 46.8 (0) | 0 of 9 | 4 of 9 | 0.0% | +| first cut of hard diets (sprout grass and fruit, proboscis nectar and fruit, radula fungus), 8 seeds | **3 of 8** | n/a | 0 of 5 | 3 of 8 | 0.0% | + +- **Hard plant diets starve their own starts**: the three extinct worlds of the first cut were the specialist starts (proboscis, radula, radula); the radula lives on a toxic, hard food that is 23 percent of the energy and absent from meadow and desert. +- **Exclusive carrion does not feed the jaw**, because there are almost no jaws: the carrion share of intake fell from 5.3 percent to 0.7 percent, the carcasses rot, and the population lost about 11 percent (the energy the herbivores had been eating). +- **100,000 ticks, carrion for the jaw only, the owner's seed and 1 to 7:** no extinct world; a jaw alive at the end in **2 of 8** (1 of 8 before); in one world (seed 5) the jaws took over, **21 of 29 creatures**, 186 predation deaths in the last window; on the owner's seed 224 predation deaths in the last window with one jaw left. Two or more mouth forms alive in 3 of 8 worlds, as before. + +The criteria stated before the runs (jaw alive in at least 4 of 8 at 100,000 ticks, never above 40 percent of a population, two forms alive in at least 70 percent of worlds, no extinct world) were **missed by every variant**, so no diet table is shipped. + +## What this says + +- **Exclusivity is the wrong lever on its own.** The energy a carnivore can get is bounded by how much dies and by how fast it is found: the carrion flux is about 3.5 energy a second across the world (the intake seen over 4 seeds x 20,000 ticks), which feeds about four creatures at 0.9 a second each even if every carcass were eaten. Giving it all to jaws leaves a niche of about four animals that has to be found by a few jaws spread over a 700 by 700 world. +- **Hard plant diets cost more than they give**: they shrink every specialist's food supply to a fraction of the map, and the generalist mandible (1 on everything, forced by the validation rule that keeps the founder neutral) is the safe choice for evolution. Specialisation needs the foods to be dense enough in each lineage's region, which the Voronoi regions and sparse kinds do not give. +- **The jaw's problem is a second, richer, findable food source**, as the owner said: eggs and nests (stationary, concentrated, renewable) are the next project, not a diet table. + +## 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). + +## Limits + +8 to 16 seeds, 30,000 and 100,000 ticks, one world. The variants are a handful of points in a large table of yields and I did not search it; a table with each specialist's niche widened to two or three kinds might do better, and "hard" then becomes a matter of degree. The `starts.probe.ts` bug (it overwrote the override's anatomy section, so its first hard-diet run was not hard) was found and fixed; the numbers above are from `longrun.probe.ts`, which applies the override whole. A second mouth doubles the body's bite size (it sums over mouths) even when the second mouth is a jaw that takes nothing from a plant: noticed, not changed here. diff --git a/docs/simulation/configuration.md b/docs/simulation/configuration.md index 8b8c86e..034ad69 100644 --- a/docs/simulation/configuration.md +++ b/docs/simulation/configuration.md @@ -93,7 +93,7 @@ Units: time is in **seconds** (one tick advances time by `timestep`), distance i | `anatomy.mutation.continuousStd` | > 0 | Gaussian step of a continuous body gene as a fraction of its range | | `anatomy.parts..mass`, `.upkeep`, `.strength` | >= 0; >= 0; > 0 | Per unit of part `size`: mass added, energy per second, and the capability coefficient, for each of the ten part types | | `anatomy.effects` | `eyestalkLift`, `gyroTorque`, `lipidCapacity`, `pheromoneSignal`, `skeletonBudget` >= 0; `visionNarrowing` in [0, 1]; `pheromoneCap` >= 1 | What the newer parts do: the range gain of an eye on an eyestalk, a gyro's torque, a lipid store's energy capacity, a pheromone gland's signal and the most any body can reach, the structural budget a skeleton adds for the slots after it, and how much reach a narrower eye gains (ADR 0016) | -| `anatomy.mouthForms` | each of sprout, proboscis, mandible, radula, jaw: food kind name to yield >= 0; the mandible is exactly 1 | Energy yield of each mouth form on each kind of food (a kind that is not listed counts as 1); the mandible is the generalist and the founder's, so the founder is neutral (ADR 0017). A yield of 0 means the mouth neither bites nor sees that food: the **jaw is 0 on every plant** (ADR 0023 step three), so it lives on creatures and carrion | +| `anatomy.mouthForms` | each of sprout, proboscis, mandible, radula, jaw: food kind name to yield >= 0; the mandible is exactly 1; with food kinds on every form lists every kind | Energy yield of each mouth form on each kind of food (a kind has to be listed for every form, 0 if the form cannot eat it: an unlisted kind used to count as 1, edible by everyone, ADR 0026); the mandible is the generalist and the founder's, so the founder is neutral (ADR 0017). A yield of 0 means the mouth neither bites nor sees that food: the **jaw is 0 on every plant** (ADR 0023 step three), so it lives on creatures and carrion | | `feeding.enabled` | boolean | `true` (default): organisms bite food with a mouth, food has health and a gut digests it (ADR 0017); `false`: touching food eats it whole at once (the original rule, used by the Classic preset) | | `feeding.biteRadius`, `feeding.biteCone` | > 0 (body radii); > 0, <= pi (radians, half-angle) | How far from a mouth a bite reaches, and the cone in front of it in which food can be bitten | | `feeding.biteSize`, `feeding.biteInterval` | > 0 (energy); > 0 (seconds) | Food energy one bite takes at the founder's mouth (before the kind's `hardness`), and seconds between bites | @@ -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 | +| `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) | | `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/simulation/tests/probe/diet.probe.ts b/packages/simulation/tests/probe/diet.probe.ts new file mode 100644 index 0000000..bf43239 --- /dev/null +++ b/packages/simulation/tests/probe/diet.probe.ts @@ -0,0 +1,86 @@ +import { describe, it } from 'vitest' +import { mkdirSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { mouthFormOf } from '@evo/contracts' +import type { WorldConfigOverrides } from '@evo/contracts' +import { World } from '../../src/index' + +/** + * Who eats what (ADR 0026): the energy taken in, credited to the eater's mouth form and to the kind + * it came from (a plant kind, carrion, or flesh), over seeds, plus how long each form was alive. The + * measurement that showed jaws getting 5 percent of the carrion. A measurement, not a test. + * + * Environment: `DIET_NAME` (label), `DIET_CONFIG` (JSON overrides), `DIET_SEEDS` (default 1..4), + * `DIET_TICKS` (default 20000). Writes `/evo-probe/diet-.txt`. + */ +const NAME = process.env.DIET_NAME ?? 'default' +const CONFIG = JSON.parse(process.env.DIET_CONFIG ?? '{}') as WorldConfigOverrides +const SEEDS = (process.env.DIET_SEEDS ?? '1,2,3,4').split(',').map(Number) +const TICKS = Number(process.env.DIET_TICKS ?? 20000) +describe('diet', () => { + it('measures', () => { + const table = new Map() // form|kind -> intake + const creatureTicks = new Map() + const fleshByForm = new Map() + for (const seed of SEEDS) { + const world = World.create({ seed, config: CONFIG }) + const kinds = world.config.ecology.resourceKinds.kinds.map((k) => k.name) + const formOf = new Map() + const form = (id: number): string => { + let f = formOf.get(id) + if (f === undefined) { + const mouth = (world.anatomyOf(id)?.anatomy.parts ?? []).find( + (p) => p.type === 'mouth' && p.functional + ) + f = mouth ? mouthFormOf(mouth.stats[2] as number) : 'none' + formOf.set(id, f) + } + return f + } + for (let t = 1; t <= TICKS; t++) { + world.step() + for (const e of world.events.eventsThisTick()) { + if (e.type === 'resource-bitten') { + const key = `${form(e.organismId)}|${kinds[e.kind]}` + table.set(key, (table.get(key) ?? 0) + e.intake) + } else if (e.type === 'organism-bitten') { + const f = form(e.predatorId) + fleshByForm.set(f, (fleshByForm.get(f) ?? 0) + e.intake) + } + } + if (t % 50 === 0) { + for (const o of world.snapshot().organisms) { + const f = form(o.id) + creatureTicks.set(f, (creatureTicks.get(f) ?? 0) + 50) + } + } + } + } + const lines: string[] = [] + const forms = ['sprout', 'proboscis', 'mandible', 'radula', 'jaw', 'none'] + const kindsAll = ['grass', 'fruit', 'fungus', 'nectar', 'carrion'] + let carrionTotal = 0 + for (const f of forms) carrionTotal += table.get(`${f}|carrion`) ?? 0 + lines.push( + `seeds ${SEEDS.length} ticks ${TICKS}; creature-ticks per form: ` + + forms.map((f) => `${f} ${creatureTicks.get(f) ?? 0}`).join(', ') + ) + for (const f of forms) { + const row = kindsAll.map((k) => `${k} ${(table.get(`${f}|${k}`) ?? 0).toFixed(0)}`).join(' ') + lines.push(`${f.padEnd(10)} ${row} flesh ${(fleshByForm.get(f) ?? 0).toFixed(0)}`) + } + lines.push( + `carrion intake total ${carrionTotal.toFixed(0)}; share by form: ` + + forms + .map( + (f) => + `${f} ${carrionTotal === 0 ? 0 : (((table.get(`${f}|carrion`) ?? 0) / carrionTotal) * 100).toFixed(0)}%` + ) + .join(', ') + ) + const dir = join(tmpdir(), 'evo-probe') + mkdirSync(dir, { recursive: true }) + writeFileSync(join(dir, `diet-${NAME}.txt`), lines.join('\n') + '\n') + }, 1800000) +}) diff --git a/packages/simulation/tests/probe/starts.probe.ts b/packages/simulation/tests/probe/starts.probe.ts index 25f0a18..40d3fc5 100644 --- a/packages/simulation/tests/probe/starts.probe.ts +++ b/packages/simulation/tests/probe/starts.probe.ts @@ -33,12 +33,15 @@ describe('starting bodies probe', () => { it( `measures ${name}`, () => { + // The override's own anatomy (a mouth-form table, say) is kept: only the start is forced. + const given = (OVERRIDES['anatomy'] ?? {}) as Record const config = { ...OVERRIDES, - anatomy: - name === 'reference' - ? { startingBody: { mode: 'reference' } } - : { startingBody: { mode: 'archetypes', archetype: name } } + anatomy: { + ...given, + startingBody: + name === 'reference' ? { mode: 'reference' } : { mode: 'archetypes', archetype: name } + } } let extinct = 0 let meanSum = 0 From 675773d99bae8f71e1742985c62d2ba7ff33aec3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Nov 2026 17:24:08 +0000 Subject: [PATCH 3/3] fix(predation): make carcasses jaw-only by default Co-authored-by: CodeByBryant <191651927+CodeByBryant@users.noreply.github.com> --- packages/config/src/defaults.ts | 2 +- packages/simulation/tests/predation/carnivore.test.ts | 4 ++-- .../simulation/tests/predation/death-and-carcass.test.ts | 8 +++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/config/src/defaults.ts b/packages/config/src/defaults.ts index ad79872..9371b13 100644 --- a/packages/config/src/defaults.ts +++ b/packages/config/src/defaults.ts @@ -420,7 +420,7 @@ export const DEFAULT_WORLD_CONFIG: Readonly = deepFreeze({ maxCount: 40, radius: 4, hardness: 1, - yields: { sprout: 0.1, proboscis: 0.2, mandible: 0.8, radula: 0.6, jaw: 1.2 } + yields: { sprout: 0, proboscis: 0, mandible: 0, radula: 0, jaw: 1.2 } } }, // Another creature's body hides what is behind it (ADR 0016 "Line of sight"); a creature checks diff --git a/packages/simulation/tests/predation/carnivore.test.ts b/packages/simulation/tests/predation/carnivore.test.ts index 71fc67c..9f70571 100644 --- a/packages/simulation/tests/predation/carnivore.test.ts +++ b/packages/simulation/tests/predation/carnivore.test.ts @@ -138,13 +138,13 @@ describe('what a creature sees as food', () => { } it.each([false, true])( - 'a jaw does not see a plant but sees carrion; a mandible sees both (occluding search: %s)', + 'a jaw sees carrion while a mandible sees plants but not carrion (occluding search: %s)', (occluding) => { const carrion = carrionOf(config()) expect(see(true, GRASS, occluding)).toBeNull() expect(see(true, carrion, occluding)).toBe(7) expect(see(false, GRASS, occluding)).toBe(7) - expect(see(false, carrion, occluding)).toBe(7) + expect(see(false, carrion, 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 7a22e49..1bab726 100644 --- a/packages/simulation/tests/predation/death-and-carcass.test.ts +++ b/packages/simulation/tests/predation/death-and-carcass.test.ts @@ -224,14 +224,12 @@ describe('carcasses', () => { expect(withCarrion(noKinds)).toBe(noKinds) }) - it('makes a mandible eat a carcass well and a sprout hardly at all (the form decides)', () => { + it('makes a mandible get no carcass yield while jaws keep a positive yield', () => { const cfg = full() const kind = cfg.ecology.resourceKinds.kinds.length - 1 const founder = organismFor(cfg, 1) - expect(factorsOf(founder.genome, cfg).dietEfficiency[kind]).toBeCloseTo( - cfg.predation.carcass.yields.mandible, - 9 - ) + expect(factorsOf(founder.genome, cfg).dietEfficiency[kind]).toBeCloseTo(0, 9) + expect(cfg.predation.carcass.yields.jaw).toBeGreaterThan(0) }) function carcasses(extra: WorldConfigOverrides = {}) {