AgentSkillsCN

lenia-core

核心Lenia引擎API、稳定参数、多物种预设,以及生长函数。适用于开发模拟引擎、配置生物体,或调试参数问题的场景。

SKILL.md
--- frontmatter
name: lenia-core
description: Core Lenia engine API, stable parameters, multi-species presets, and growth functions. Use when working on the simulation engine, configuring organisms, or debugging parameter issues.

Lenia Core Engine

Key Parameters (Stable Lenia)

typescript
kernelRadius: 13;
growthCenter: 0.12; // μ - center of growth function
growthWidth: 0.04; // σ - width (NOT 0.015, too narrow)
dt: 0.1;
  • Blob radius: 25 (not 15)
  • FFT auto-activates when kernelRadius >= 16

Engine API

typescript
import { createEngine } from "./core/engine";

const engine = await createEngine({ canvas });

// Lifecycle
engine.start();
engine.stop();
engine.reset(pattern);
engine.stepOnce();

// Paradigm
engine.setParadigm("discrete" | "continuous");

// Multi-channel
engine.enableMultiChannel(config);
engine.disableMultiChannel();

// Sensorimotor
engine.enableSensorimotor();
engine.disableSensorimotor();

// Mass conservation
engine.setConservationConfig({ enabled: true });
engine.getMass(): Promise<number>;

// Boundary conditions
engine.setBoundaryMode("periodic" | "clamped" | "reflected" | "zero");
engine.getBoundaryMode();

Boundary Modes

ModeDescription
periodicToroidal wrap (default)
clampedEdge values repeat
reflectedMirror at boundaries
zeroAbsorbing (values go to 0 at edges)

Seeded Random Number Generator

typescript
import { createSeededRandom, globalRandom, setGlobalSeed } from "./core/random";

// Create independent seeded RNG
const rng = createSeededRandom(12345);
rng.next(); // 0-1 float
rng.nextInt(0, 100); // Integer in range [0, 100)
rng.nextGaussian(); // Normal distribution
rng.shuffle(array); // In-place shuffle
rng.choice(array); // Random element

// Global RNG for convenience
setGlobalSeed(42);
globalRandom.next();

Multi-Species Presets

PresetSpeciesDynamics
single1Standard Lenia
two-species2Competitive inhibition
predator-prey2Predator hunts prey
food-chain3Plants → Herbivores → Predators
symbiosis2Mutual benefit
creature-food2Creature consumes food
pheromone3Chemical trail signaling

Loading Presets

typescript
import { MULTI_SPECIES_PRESETS } from "./core/channels";

const config = MULTI_SPECIES_PRESETS["predator-prey"];
engine.enableMultiChannel(config);

Mass Conservation

typescript
// Enable mass conservation with auto-normalization
engine.setConservationConfig({ enabled: true });

// Conservation pipeline (internal)
pipeline.computeAndNormalize(device, stateTexture, outputTexture);
pipeline.setTargetMass(mass); // Lock target mass
pipeline.getCachedMass(); // Non-blocking mass read

Core Files

FilePurpose
core/engine.tsMain orchestrator
core/channels.tsMulti-species preset configs
core/kernels.tsKernel generation functions
core/growth.tsGrowth function implementations
core/random.tsSeeded RNG (xorshift128+)
core/types.tsTypeScript type definitions