From 7329ddf7f6c41d1e6cf2edc212bb9ee46669ff7c Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 4 Nov 2026 16:44:02 +0100 Subject: [PATCH 1/4] Share the meadow age and hunger reads with the day --- src/app/features/meadow/meadow-engine.ts | 25 ++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/app/features/meadow/meadow-engine.ts b/src/app/features/meadow/meadow-engine.ts index 84c472f..e971a95 100644 --- a/src/app/features/meadow/meadow-engine.ts +++ b/src/app/features/meadow/meadow-engine.ts @@ -327,11 +327,11 @@ function createAnimalIntents( if (willDieOfAge(cell, settings)) { return; } - const age = (cell.age ?? 0) + 1; + const age = animalAge(cell) + 1; const neighbors = getNeighborPositions(source, origin); const prey = cell.species === 'herbivore' ? 'plant' : 'herbivore'; - const isHungry = (cell.energy ?? 0) < hungerEnergyFor(cell.species, settings); + const isHungry = animalIsHungry(cell, settings); const foodChoices = isHungry ? neighbors.filter(({ row: neighborRow, column: neighborColumn }) => { const neighbor = source[neighborRow][neighborColumn]; @@ -409,13 +409,30 @@ function maxAgeFor(species: 'herbivore' | 'predator', settings: SimulationSettin return species === 'herbivore' ? settings.herbivoreMaxAge : settings.predatorMaxAge; } -function hungerEnergyFor(species: 'herbivore' | 'predator', settings: SimulationSettings): number { +export function animalAge(cell: EcosystemCell): number { + return cell.age ?? 0; +} + +export function animalIsHungry( + cell: EcosystemCell, + settings: Pick, +): boolean { + if (!isAnimal(cell)) { + return false; + } + return (cell.energy ?? 0) < hungerEnergyFor(cell.species, settings); +} + +function hungerEnergyFor( + species: 'herbivore' | 'predator', + settings: Pick, +): number { return species === 'herbivore' ? settings.herbivoreHungerEnergy : settings.predatorHungerEnergy; } /** True when this tick's aging makes the animal reach its max age, so it dies this tick. */ function willDieOfAge(cell: EcosystemCell, settings: SimulationSettings): boolean { - return isAnimal(cell) && (cell.age ?? 0) + 1 >= maxAgeFor(cell.species, settings); + return isAnimal(cell) && animalAge(cell) + 1 >= maxAgeFor(cell.species, settings); } function choose(items: T[], random: RandomSource): T | undefined { From a61239eed96a478912d0a63e571f6edfbe76769f Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 4 Nov 2026 16:44:45 +0100 Subject: [PATCH 2/4] Show age and hunger on the meadow animal card --- .../cell-info-popover/cell-info-popover.component.html | 8 ++++++++ .../cell-info-popover/cell-info-popover.component.ts | 2 +- src/app/features/meadow/meadow-ui.types.ts | 2 ++ src/app/features/meadow/meadow.component.ts | 9 ++++++++- src/app/shared/i18n/de.ts | 4 ++++ src/app/shared/i18n/en.ts | 4 ++++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/app/features/meadow/cell-info-popover/cell-info-popover.component.html b/src/app/features/meadow/cell-info-popover/cell-info-popover.component.html index 5616959..f982fa7 100644 --- a/src/app/features/meadow/cell-info-popover/cell-info-popover.component.html +++ b/src/app/features/meadow/cell-info-popover/cell-info-popover.component.html @@ -11,6 +11,14 @@

{{ t('species.' + info().cell.species) }}

{{ t('cellInfo.energy') }}
{{ info().cell.energy ?? '–' }}
+
+
{{ t('cellInfo.age') }}
+
{{ info().age }}
+
+
+
{{ t('cellInfo.hunger') }}
+
{{ info().hungry ? t('cellInfo.hungry') : t('cellInfo.full') }}
+
{{ t('cellInfo.position') }}
{{ t('cellInfo.positionValue', { row: info().position.row + 1, column: info().position.column + 1 }) }}
diff --git a/src/app/features/meadow/cell-info-popover/cell-info-popover.component.ts b/src/app/features/meadow/cell-info-popover/cell-info-popover.component.ts index fe55f37..da62c28 100644 --- a/src/app/features/meadow/cell-info-popover/cell-info-popover.component.ts +++ b/src/app/features/meadow/cell-info-popover/cell-info-popover.component.ts @@ -5,7 +5,7 @@ import { speciesImages } from '../meadow-ui.types'; // Width must match cell-info-popover.component.css; height is measured after render. const cardWidth = 200; -const estimatedCardHeight = 150; +const estimatedCardHeight = 190; const gap = 10; const edge = 8; diff --git a/src/app/features/meadow/meadow-ui.types.ts b/src/app/features/meadow/meadow-ui.types.ts index 18b1850..bda39c7 100644 --- a/src/app/features/meadow/meadow-ui.types.ts +++ b/src/app/features/meadow/meadow-ui.types.ts @@ -17,6 +17,8 @@ export interface CellInspectState extends CellInspectRequest { export interface CellInspection extends CellInspectState { cell: EcosystemCell; + age: number; + hungry: boolean; } export type PresetName = 'balanced' | 'meadow' | 'predator-boom'; diff --git a/src/app/features/meadow/meadow.component.ts b/src/app/features/meadow/meadow.component.ts index dfb39b9..0f9f4d9 100644 --- a/src/app/features/meadow/meadow.component.ts +++ b/src/app/features/meadow/meadow.component.ts @@ -2,7 +2,9 @@ import { Component, computed, inject, OnDestroy, signal } from '@angular/core'; import { I18nService } from '../../shared/i18n/i18n.service'; import { advanceSimulation, + animalAge, animalCell, + animalIsHungry, countPopulations, createBalancedState, defaultSimulationSettings, @@ -65,7 +67,12 @@ export class MeadowComponent implements OnDestroy { const cell = this.world().grid[state.position.row]?.[state.position.column]; if (!cell || cell.species !== state.species) return null; if (cell.species !== 'herbivore' && cell.species !== 'predator') return null; - return { ...state, cell }; + return { + ...state, + cell, + age: animalAge(cell), + hungry: animalIsHungry(cell, this.behaviorSettings()), + }; }); private intervalId?: number; diff --git a/src/app/shared/i18n/de.ts b/src/app/shared/i18n/de.ts index ea9a343..cc6692d 100644 --- a/src/app/shared/i18n/de.ts +++ b/src/app/shared/i18n/de.ts @@ -66,6 +66,10 @@ export const de: Record = { 'population.predators': 'Raubtiere', 'cellInfo.thisAnimal': 'Dieses Tier', 'cellInfo.energy': 'Energie', + 'cellInfo.age': 'Alter', + 'cellInfo.hunger': 'Hunger', + 'cellInfo.hungry': 'hungrig', + 'cellInfo.full': 'satt', 'cellInfo.position': 'Position', 'cellInfo.positionValue': 'Zeile {row}, Spalte {column}', 'cellInfo.hiddenPlant': 'Pflanze darunter', diff --git a/src/app/shared/i18n/en.ts b/src/app/shared/i18n/en.ts index 74e7d0c..a41569e 100644 --- a/src/app/shared/i18n/en.ts +++ b/src/app/shared/i18n/en.ts @@ -62,6 +62,10 @@ export const en = { 'population.predators': 'Predators', 'cellInfo.thisAnimal': 'This animal', 'cellInfo.energy': 'Energy', + 'cellInfo.age': 'Age', + 'cellInfo.hunger': 'Hunger', + 'cellInfo.hungry': 'hungry', + 'cellInfo.full': 'full', 'cellInfo.position': 'Position', 'cellInfo.positionValue': 'Row {row}, column {column}', 'cellInfo.hiddenPlant': 'Plant underneath', From 7d627dccd2be67817af36b90eaf6989a27a1ef78 Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 4 Nov 2026 16:45:39 +0100 Subject: [PATCH 3/4] Test meadow age and hunger card reads --- src/app/features/meadow/meadow-engine.spec.ts | 15 +++++++++++++++ .../features/meadow/meadow.component.spec.ts | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/app/features/meadow/meadow-engine.spec.ts b/src/app/features/meadow/meadow-engine.spec.ts index 69c2134..0225ff9 100644 --- a/src/app/features/meadow/meadow-engine.spec.ts +++ b/src/app/features/meadow/meadow-engine.spec.ts @@ -1,6 +1,8 @@ import { advanceSimulation, + animalAge, animalCell, + animalIsHungry, countPopulations, emptyCell, getNeighborPositions, @@ -259,4 +261,17 @@ describe('ecosystem engine', () => { { row: 1, column: 1 }, ]); }); + + it('reads a missing age as zero and hunger only below the species line', () => { + const line = { herbivoreHungerEnergy: 8, predatorHungerEnergy: 10 }; + + expect(animalAge(animalCell('herbivore', 4))).toBe(0); + expect(animalAge(animalCell('herbivore', 4, false, 3))).toBe(3); + expect(animalIsHungry(animalCell('herbivore', 7), line)).toBe(true); + expect(animalIsHungry(animalCell('herbivore', 8), line)).toBe(false); + expect(animalIsHungry({ species: 'herbivore' }, line)).toBe(true); + expect(animalIsHungry(animalCell('predator', 9), line)).toBe(true); + expect(animalIsHungry(animalCell('predator', 10), line)).toBe(false); + expect(animalIsHungry({ species: 'plant' }, line)).toBe(false); + }); }); diff --git a/src/app/features/meadow/meadow.component.spec.ts b/src/app/features/meadow/meadow.component.spec.ts index 0ed08df..e2703b1 100644 --- a/src/app/features/meadow/meadow.component.spec.ts +++ b/src/app/features/meadow/meadow.component.spec.ts @@ -143,6 +143,24 @@ describe('MeadowComponent', () => { expect(component.inspection()).toBeNull(); }); + it('reads a newborn as age 0 and flips full to hungry when the hunger slider rises', () => { + const anchor = { left: 0, top: 0, right: 40, bottom: 40 }; + component.world.set({ + grid: [[animalCell('herbivore', 8)]], + tick: 0, + }); + + component.pinCellInfo({ position: { row: 0, column: 0 }, anchor }); + + expect(component.inspectedAnimal()?.age).toBe(0); + expect(component.inspectedAnimal()?.hungry).toBe(false); + + component.changeBehavior('herbivoreHungerEnergy', '9'); + + expect(component.world().tick).toBe(0); + expect(component.inspectedAnimal()?.hungry).toBe(true); + }); + it('does not show a pinned card for a different species that moves into the cell', () => { const anchor = { left: 0, top: 0, right: 40, bottom: 40 }; component.world.set({ From 008215636cfeaa4b71bd0205a349d29d74903d11 Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 4 Nov 2026 16:46:29 +0100 Subject: [PATCH 4/4] Record animal age and hunger on the meadow card --- goal-and-requirements.md | 2 +- src/app/features/meadow/SPEC.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/goal-and-requirements.md b/goal-and-requirements.md index 592e5ec..c7ba8e3 100644 --- a/goal-and-requirements.md +++ b/goal-and-requirements.md @@ -19,7 +19,7 @@ Visitors to the public site. They can read the lab in English or German. They do ## Capabilities -- Meadow Makers: paint plants, plant eaters, predators, or erase; run, step, or reset; open a seeded story (balanced, green meadow, or predator boom); change speed and species behavior; read population totals and one animal's energy; see the food-chain clue. Playback stops when no animals remain. +- Meadow Makers: paint plants, plant eaters, predators, or erase; run, step, or reset; open a seeded story (balanced, green meadow, or predator boom); change speed and species behavior; read population totals and one animal's energy, age, and whether it is hungry or full; see the food-chain clue. Playback stops when no animals remain. - Conway's Way of Life: germinate, step, replant, or clear; change speed; toggle wrap-around; plant with brushes; start from a Methuselah seed; read living, sprout, perennial, and withered counts. Playback stops when nothing is alive. The rule is B3/S23, and there is no score. - A page that explains those Conway rules and what the Life page shows. - A language switch that survives reload. diff --git a/src/app/features/meadow/SPEC.md b/src/app/features/meadow/SPEC.md index 36721bf..755b854 100644 --- a/src/app/features/meadow/SPEC.md +++ b/src/app/features/meadow/SPEC.md @@ -34,4 +34,4 @@ Balanced, Green meadow, and Predator boom open from fixed seeds, so each story s Behavior sliders change growth, reproduction chance, food energy, max age, and hunger for the next day. They do not rewrite the current grid. -Inspection shows one animal's energy, position, and whether a plant is hidden under it. Hover previews. A pinned card stays until dismissed, or until that cell no longer holds that animal. +Inspection shows one animal's energy, age, whether it is hungry or full, position, and whether a plant is hidden under it. Age is days lived; a newborn shows 0. Hungry means energy is below that species' hunger line — the same read a day uses to hunt. A missing energy counts as 0, so the animal reads as hungry. The card follows the hunger sliders immediately, because those sliders are the line the next day will use, not a line stored from the previous day. Hover previews. A pinned card stays until dismissed, or until that cell no longer holds that animal.