Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion goal-and-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/meadow/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ <h2>{{ t('species.' + info().cell.species) }}</h2>
<dt>{{ t('cellInfo.energy') }}</dt>
<dd>{{ info().cell.energy ?? '–' }}</dd>
</div>
<div>
<dt>{{ t('cellInfo.age') }}</dt>
<dd>{{ info().age }}</dd>
</div>
<div>
<dt>{{ t('cellInfo.hunger') }}</dt>
<dd>{{ info().hungry ? t('cellInfo.hungry') : t('cellInfo.full') }}</dd>
</div>
<div>
<dt>{{ t('cellInfo.position') }}</dt>
<dd>{{ t('cellInfo.positionValue', { row: info().position.row + 1, column: info().position.column + 1 }) }}</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 15 additions & 0 deletions src/app/features/meadow/meadow-engine.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
advanceSimulation,
animalAge,
animalCell,
animalIsHungry,
countPopulations,
emptyCell,
getNeighborPositions,
Expand Down Expand Up @@ -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);
});
});
25 changes: 21 additions & 4 deletions src/app/features/meadow/meadow-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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<SimulationSettings, 'herbivoreHungerEnergy' | 'predatorHungerEnergy'>,
): boolean {
if (!isAnimal(cell)) {
return false;
}
return (cell.energy ?? 0) < hungerEnergyFor(cell.species, settings);
}

function hungerEnergyFor(
species: 'herbivore' | 'predator',
settings: Pick<SimulationSettings, 'herbivoreHungerEnergy' | 'predatorHungerEnergy'>,
): 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<T>(items: T[], random: RandomSource): T | undefined {
Expand Down
2 changes: 2 additions & 0 deletions src/app/features/meadow/meadow-ui.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
18 changes: 18 additions & 0 deletions src/app/features/meadow/meadow.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
9 changes: 8 additions & 1 deletion src/app/features/meadow/meadow.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions src/app/shared/i18n/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export const de: Record<TranslationKey, string> = {
'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',
Expand Down
4 changes: 4 additions & 0 deletions src/app/shared/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading