Level lakes at the end of world generation, keeping their water (t96)
Volume-preserving levelling pass for water bodies of 50+ cells; the dock foundation is placed first so it cannot erase levelled water. Seed hashes re-baselined (water and air only). Started by Codex, finished and reviewed by Claude after Codex hit its usage limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+45
-26
@@ -1,9 +1,9 @@
|
||||
// Generated lakes wake without a tool, settle on their own, and have dry tree bases.
|
||||
const { load, suite, ticks } = require('./harness');
|
||||
// Generated lakes start flat, conserve water, and have dry tree bases.
|
||||
const { load, suite, ticks, count, rect } = require('./harness');
|
||||
const { createHash } = require('node:crypto');
|
||||
const { run } = load();
|
||||
const { check, done } = suite();
|
||||
const water = run('WATER');
|
||||
|
||||
function surfacePools() {
|
||||
return run(`(() => {
|
||||
const pools = []; let pool = null;
|
||||
@@ -17,35 +17,54 @@ function surfacePools() {
|
||||
})()`);
|
||||
}
|
||||
for (const [seed, expected] of [
|
||||
[7, '865ac320f743ff5ed573acab3333773b5ebc2e10f15600438dd15f1767acb72e'],
|
||||
[42, '94930e108f7bd948c6f3dbe8b15b2950eed695cb3d57376d05a8ad781c2015b7'],
|
||||
[424242, '8b8a4b44c2cc98d3ab86515eb55f38ce7cb3d6a283e29e0ed758af937ea8e8c8'],
|
||||
[7, '669a4ee87496be27473d2987d9a8935be1a19b29a8f2433d306f32a1616f3bca'],
|
||||
[42, 'efeadd2bff0ce3eaf81e5a08a998ce767e9667e3b27b8623e928f202669f640e'],
|
||||
[424242, '24b5e6ccc4e7d5eb9d54c3ff0fa5dfe84185b83e75b07261ac007b4f920f0640'],
|
||||
[2, null],
|
||||
[1, null],
|
||||
]) {
|
||||
run(`generateWorld(${seed}, 2048, 1024); weather.next = 1e15;`);
|
||||
run(`generateWorld(${seed}, 2048, 1024, (f, label) => {
|
||||
if (f === 0.99 && label === 'Finishing') globalThis.waterBeforeLevel = mat.reduce((n, m) => n + (m === WATER), 0);
|
||||
}); weather.next = 1e15;`);
|
||||
const hash = createHash('sha256');
|
||||
for (const name of ['mat', 'temp']) hash.update(Buffer.from(run(name).buffer));
|
||||
check(`seed ${seed} preserves generated material and temperature bytes`, hash.digest('hex') === expected);
|
||||
const actual = hash.digest('hex');
|
||||
if (expected) check(`seed ${seed} matches levelled generation hash`, actual === expected, actual);
|
||||
check(`seed ${seed} conserves water through levelling`, run('mat.reduce((n, m) => n + (m === WATER), 0) === waterBeforeLevel'));
|
||||
const initial = surfacePools();
|
||||
check(`seed ${seed} starts with flat surface pools`, initial.length > 0 && initial.every(p => p.max - p.min <= 1), JSON.stringify(initial));
|
||||
check(`seed ${seed} restores pinned generation switches`, run('LSTEP === 8 && LFILM === 4 && SORTP === 0.06 && CORNER_SEAL && POWDER_FAN'));
|
||||
check(`seed ${seed} starts every water area awake`, run(`mat.every((m, i) => m !== WATER || awake[((i / W) >> 5) * CW + ((i % W) >> 5)] > 0)`));
|
||||
check(`seed ${seed} has no submerged tree base`, run('treeBases.every(i => !treeHeld(i) || mat[i] !== WATER)'));
|
||||
check(`seed ${seed} retains dry trees`, run('treeBases.filter(i => treeHeld(i)).length > 20'));
|
||||
// Seed 7 reproduces the owner's long slope. No drill, forced wakes, or terrain edits.
|
||||
if (seed === 7) {
|
||||
run('globalThis.lakeSave = serializeWorld();');
|
||||
for (const state of ['fresh', 'reloaded']) {
|
||||
if (state === 'reloaded') run('deserializeWorld(lakeSave.meta, lakeSave.buffers); weather.next = 1e15;');
|
||||
check(`${state} world starts with dry tree bases`, run('treeBases.every(i => !treeHeld(i) || mat[i] !== WATER)'));
|
||||
const before = run('mat.slice(270 * W, 340 * W)');
|
||||
const wakeTicks = state === 'fresh' ? 1 : 171;
|
||||
ticks(run, wakeTicks);
|
||||
check(`${state} lake moves within its startup wake window`, run('mat.subarray(270 * W, 340 * W)').some((m, i) => m !== before[i] && (m === water || before[i] === water)));
|
||||
ticks(run, 6000 - wakeTicks);
|
||||
const pools = surfacePools();
|
||||
check(`${state} lake levels within two grains without disturbance`, pools.length > 0 && pools.every(p => p.max - p.min <= 2), JSON.stringify(pools));
|
||||
// Reload can also thaw mountain snow into new puddles; check the original lake here.
|
||||
const lake = pools.reduce((a, b) => a.width > b.width ? a : b);
|
||||
check(`${state} original lake has no submerged tree base after settling`, run(`treeBases.every(i => i % W < ${lake.x0} || i % W > ${lake.x1} || !treeHeld(i) || mat[i] !== WATER)`));
|
||||
}
|
||||
}
|
||||
ticks(run, 600);
|
||||
const settled = surfacePools();
|
||||
check(`seed ${seed} stays flat after 600 ticks`, settled.length > 0 && settled.every(p => p.max - p.min <= 1), JSON.stringify(settled));
|
||||
for (const lake of initial) check(`seed ${seed} original lake retains dry roots`, run(`treeBases.every(i => i % W < ${lake.x0} || i % W > ${lake.x1} || !treeHeld(i) || mat[i] !== WATER)`));
|
||||
}
|
||||
// A low rim with a much deeper empty basin beyond it must not steal the water.
|
||||
for (const wall of ['STONE', 'SAND']) {
|
||||
run('alloc(64, 64); mat.fill(STONE);');
|
||||
rect(run, 5, 10, 24, 29, run('EMPTY'));
|
||||
rect(run, 26, 10, 55, 45, run('EMPTY'));
|
||||
rect(run, 25, 22, 25, 45, run(wall));
|
||||
rect(run, 25, 10, 25, 21, run('EMPTY'));
|
||||
rect(run, 5, 20, 14, 29, run('WATER'));
|
||||
rect(run, 15, 27, 15, 29, run('WATER'));
|
||||
run('globalThis.beforeLake = mat.slice(); levelWorldWater();');
|
||||
check(`${wall} rim holds all 103 grains`, count(run, run('WATER')) === 103 && count(run, run('WATER'), 26, 0) === 0);
|
||||
check(`${wall} basin fills from bottom upward`, count(run, run('WATER'), 5, 25, 24, 29) === 100);
|
||||
check(`${wall} partial top row fills from the middle outward`, run('[13,14,15].every(x => mat[24 * W + x] === WATER)') && count(run, run('WATER'), 0, 0, 63, 24) === 3);
|
||||
check(`${wall} levelling changes only water and air`, run('mat.every((m,i) => m === beforeLake[i] || ((m === EMPTY || m === WATER) && (beforeLake[i] === EMPTY || beforeLake[i] === WATER)))'));
|
||||
}
|
||||
// Diagonally touching small bodies remain separate; exactly 50 grains is eligible.
|
||||
run('alloc(64,64); mat.fill(STONE);');
|
||||
rect(run, 5, 20, 11, 26, run('WATER'));
|
||||
rect(run, 12, 27, 18, 33, run('WATER'));
|
||||
rect(run, 5, 10, 11, 19, run('EMPTY'));
|
||||
rect(run, 30, 10, 49, 29, run('EMPTY'));
|
||||
rect(run, 30, 20, 34, 29, run('WATER'));
|
||||
run('globalThis.smallBefore = mat.slice(); levelWorldWater();');
|
||||
check('diagonally touching 49-grain pools are left intact', run('mat.every((m,i) => i % W >= 30 || m === smallBefore[i])'));
|
||||
check('50-grain body levels and conserves volume', count(run, run('WATER'), 30, 28, 49, 29) === 40 && count(run, run('WATER'), 30, 0) === 50);
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user