Working but slow

This commit is contained in:
2026-07-06 23:11:42 +02:00
parent 09c1fba8e6
commit f93bcfb8d4
15 changed files with 4443 additions and 4205 deletions
+29
View File
@@ -188,6 +188,35 @@ describe('CA engine runtimes', () => {
expect(stepped.cells).toEqual(cells(5, 5, [[0, 2]]))
})
it('uses simulation rng_seed to choose deterministic Naga heads', () => {
const current = cells(6, 6)
const baseParams = {
caClass: { dimensions: 3, states: 7 },
renderer: { id: 'voxel-3d' },
simulation: {
engineId: 'naga-3d',
ruleId: 'naga-3d',
grid: { size: [6, 6, 6], boundary: 'wrap' },
initialCondition: {
type: 'cells',
cells: [[1, 2, 2, 1], [4, 2, 2, 1]]
}
}
} satisfies SceneParams
const leftSeed = stepCaSimulation(current, settings({
...baseParams,
simulation: { ...baseParams.simulation, rng_seed: 'bar' }
}))
const rightSeed = stepCaSimulation(current, settings({
...baseParams,
simulation: { ...baseParams.simulation, rng_seed: 'alpha' }
}))
expect(leftSeed.settings.simulation?.initialCondition?.cells).toEqual([[4, 2, 2, 1], [0, 2, 2, 1]])
expect(rightSeed.settings.simulation?.initialCondition?.cells).toEqual([[1, 2, 2, 1], [3, 2, 2, 1]])
})
it('keeps Naga 3D sparse coordinates in place when fixed boundaries would leave the grid', () => {
const current = cells(5, 5)
const params = settings({
@@ -19,7 +19,7 @@ describe('CA initial condition runtimes', () => {
const input = {
caClass: { dimensions: 2, states: 2 },
settings: { simulation: { grid: { size: [5, 5, 1] } } },
params: { density: 0.35, seed: 'repeatable' }
params: { density: 0.35, ic_seed: 'repeatable' }
}
expect(generateInitialCondition('random-soup', input)).toEqual(generateInitialCondition('random-soup', input))
@@ -29,11 +29,11 @@ describe('CA initial condition runtimes', () => {
const generated = generateInitialCondition('random-soup', {
caClass: { dimensions: 2, states: 2 },
settings: { simulation: { grid: { size: [3, 3, 1] } } },
params: { density: 2, seed: 'full' }
params: { density: 2, ic_seed: 'full' }
})
expect(generated.cells).toHaveLength(9)
expect(generated.generator).toEqual({ kind: 'random-soup', density: 1, seed: 'full' })
expect(generated.generator).toEqual({ kind: 'random-soup', density: 1, ic_seed: 'full' })
})
it('lets custom initial condition runtimes plug into the same contract', () => {
@@ -54,7 +54,7 @@ describe('CA initial condition runtimes', () => {
const generated = generateInitialCondition('naga-markov', {
caClass: { dimensions: 3, states: 7 },
settings: { simulation: { grid: { size: [12, 12, 12] } } },
params: { count: 2, length: 5, sameTypeProbability: 1, seed: 'straight-nagas' }
params: { count: 2, meanLength: 5, lengthStdDev: 0, sameTypeProbability: 1, ic_seed: 'straight-nagas' }
})
expect(generated.cells).toHaveLength(10)
@@ -62,9 +62,10 @@ describe('CA initial condition runtimes', () => {
expect(generated.generator).toMatchObject({
kind: 'naga-markov',
count: 2,
length: 5,
meanLength: 5,
lengthStdDev: 0,
sameTypeProbability: 1,
seed: 'straight-nagas',
ic_seed: 'straight-nagas',
created: 2
})
@@ -93,6 +94,31 @@ describe('CA initial condition runtimes', () => {
}
})
it('samples Naga Markov chain lengths from deterministic mean and deviation settings', () => {
const generated = generateInitialCondition('naga-markov', {
caClass: { dimensions: 3, states: 7 },
settings: { simulation: { grid: { size: [30, 30, 30] } } },
params: { count: 8, meanLength: 7, lengthStdDev: 3, sameTypeProbability: 0.8, ic_seed: 'variable-nagas' }
})
const repeated = generateInitialCondition('naga-markov', {
caClass: { dimensions: 3, states: 7 },
settings: { simulation: { grid: { size: [30, 30, 30] } } },
params: { count: 8, meanLength: 7, lengthStdDev: 3, sameTypeProbability: 0.8, ic_seed: 'variable-nagas' }
})
expect(generated).toEqual(repeated)
expect(generated.generator).toMatchObject({
kind: 'naga-markov',
count: 8,
meanLength: 7,
lengthStdDev: 3,
ic_seed: 'variable-nagas',
created: 8
})
expect(generated.cells.length).not.toBe(56)
})
it('rejects duplicate runtime ids and missing implementations', () => {
expect(() =>
registerInitialConditionRuntime({
+23 -3
View File
@@ -56,11 +56,17 @@ describe('CA Studio API', () => {
default_params: {
ruleId: 'naga-3d',
rendererId: 'voxel-3d',
seed: 'naga',
rng_seed: 'naga',
edgeWrap: true
}
})
expect(naga.params_schema.ruleId.options).toEqual([{ value: 'naga-3d', label: '3D Naga' }])
expect(naga.params_schema.rng_seed).toMatchObject({
type: 'string',
label: 'RNG seed',
default: 'naga',
group: 'Randomness'
})
expect(naga.params_schema.edgeWrap).toMatchObject({
type: 'boolean',
label: 'Edge wrap',
@@ -84,15 +90,29 @@ describe('CA Studio API', () => {
generator_kind: 'naga-markov',
default_params: {
count: 3,
length: 5,
meanLength: 5,
lengthStdDev: 0,
sameTypeProbability: 0.8,
seed: 'naga-markov'
ic_seed: 'naga-markov'
}
})
expect(generator.params_schema.meanLength).toMatchObject({
type: 'range',
default: 5
})
expect(generator.params_schema.lengthStdDev).toMatchObject({
type: 'range',
default: 0
})
expect(generator.params_schema.sameTypeProbability).toMatchObject({
type: 'range',
default: 0.8
})
expect(generator.params_schema.ic_seed).toMatchObject({
type: 'string',
label: 'IC seed',
default: 'naga-markov'
})
})
})