Files
deepgrain-foundry/test/t_bar_stacking.js
T

42 lines
2.2 KiB
JavaScript

// Resting bars snap into pairs of grains and tip off narrow supports.
const { load, suite, flatWorld, rect } = require('./harness');
const { run } = load();
const { check, done } = suite();
function fresh() { flatWorld(run, 240, 160, 100); }
function settle() { run('for (let n = 0; n < 240; n++) entTick();'); }
fresh();
rect(run, 39, 60, 39, 99, run('STONE'));
rect(run, 56, 60, 56, 99, run('STONE'));
for (const x of [49, 41, 52, 45, 45, 52, 41, 49, 52, 49, 45, 41]) {
check('a dropped bar fits above the pit', !!run(`spawnBar(BARCU, ${x}, 64)`)); settle();
}
check('twelve bars fill the bottom six grain rows without gaps', run(`(() => {
for (let y = 94; y < 100; y++) for (let x = 40; x < 56; x++) if (!occ[y * W + x]) return false;
return ents.length === 12;
})()`), run('JSON.stringify(ents.map(e => [e.ix, e.iy]))'));
for (const side of [-1, 1]) {
fresh();
rect(run, side < 0 ? 43 : 40, 80, side < 0 ? 43 : 40, 99, run('STONE'));
run('spawnBar(BARCU, 40, 78)'); settle();
check('one-cell support tips toward the empty side ' + side, run(`ents[0].iy === 98 && ents[0].ix ${side < 0 ? '<' : '>'} 40`));
}
fresh(); rect(run, 40, 80, 41, 99, run('STONE'));
run('spawnBar(BARCU, 40, 78)'); settle();
check('half-supported bar stays on its ledge', run('ents[0].ix === 40 && ents[0].iy === 78'));
fresh(); run('for (const x of [41, 51, 61, 71]) spawnBar(BARCU, x, 70)'); settle();
check('bars settle on even columns on flat ground', run('ents.every(e => !(e.ix & 1) && e.iy === 98)'));
for (const obstacle of ['SAND', 'bar']) {
fresh(); rect(run, 41, 80, 44, 99, run('STONE'));
if (obstacle === 'bar') run('spawnBar(BARFE, 37, 78); spawnBar(BARFE, 45, 78)');
else { rect(run, 40, 78, 40, 79, run('SAND')); rect(run, 45, 78, 45, 79, run('SAND')); }
run('spawnBar(BARCU, 41, 78); entTick()');
check('snap cannot enter ' + obstacle, run('ents.find(e => e.m === BARCU).ix === 41'));
}
for (const surface of ['BELTR', 'P_FILTER']) {
fresh();
run(`for (let x = 40; x < 48; x++) ${surface === 'BELTR' ? 'setCell(80 * W + x, BELTR, 20, 0)' : 'part[80 * W + x] = P_FILTER'}; spawnBar(BARCU, 41, 78)`);
run('entTick()');
check('settling leaves transport in control on ' + surface, run(surface === 'BELTR' ? 'ents[0].ix === 42' : 'ents[0].ix === 41'));
}
done();