Diagonal screw tubes, laid by a 45° drag (t35)
- Tubes run in eight directions: a drag at about 45° lays a diagonal run, R cycles all eight. - Diagonal runs carry grains at the straight rate (120 grains/s), join straight tubes and belts, keep grains in at the corners, pass water, and carry bars level. - New part ids 11-14 (saved ids are never renumbered); tube checks use an IS_TUBE table. - New test/t_diag_tubes.js (85 checks). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -695,6 +695,23 @@ with sync_playwright() as p:
|
||||
check('square wall drag can also place a diagonal', ev(f'Array.from({{length:4}}, (_,k)=>blockP[({bby}-12+k)*BW+{bbx}-5+k]).every(c=>c===BP_WALL)'))
|
||||
pg.keyboard.press('Control+z'); settle(60)
|
||||
|
||||
# Diagonal tubes use real mouse placement, preview arrows, R and picking.
|
||||
check('select screw tube', select('3', "piece().id === 'tube'"))
|
||||
ev('GAME.pieceDir.tube = 0')
|
||||
directions = []
|
||||
for _ in range(8):
|
||||
directions.append(ev('GAME.pieceDir.tube'))
|
||||
pg.keyboard.press('r'); settle(40)
|
||||
check('R cycles eight tube directions', directions == list(range(8)) and ev('GAME.pieceDir.tube') == 0)
|
||||
drag(lambda: blk(bbx - 5, bby - 12), lambda: blk(bbx - 2, bby - 9))
|
||||
check('diagonal tube drag places four down-right blocks', ev(f'Array.from({{length:4}}, (_,k)=>[blockP[({bby}-12+k)*BW+{bbx}-5+k],blockV[({bby}-12+k)*BW+{bbx}-5+k]]).every(([c,v])=>c===BP_TUBE && v===5)'))
|
||||
pg.mouse.move(*blk(bbx - 4, bby - 11)); settle(60)
|
||||
check('diagonal hover names its direction', ev(f"hoverInfo(({bbx}-4)*4+1,({bby}-11)*4+1).t1.includes('down-right')"))
|
||||
pg.mouse.click(*blk(bbx - 4, bby - 11), button='middle'); settle(60)
|
||||
check('picking a diagonal tube keeps its direction', ev("piece().id === 'tube' && GAME.pieceDir.tube === 5"))
|
||||
pg.screenshot(path=str(out / '04-diagonal-tubes.png'))
|
||||
pg.keyboard.press('Control+z'); settle(60)
|
||||
|
||||
# 6. ingot mold: click to place, pour, bars drop below, vacuum them
|
||||
ok = select('3', "piece().id === 'ingotmold'")
|
||||
check('E cycles to the ingot mold', ok)
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
// Diagonal screws: sealed four-lane corner transfers, bars, joins and persistence.
|
||||
const { load, suite, flatWorld, rect, ticks, count } = require('./harness');
|
||||
const fs = require('fs');
|
||||
const { run } = load();
|
||||
const { check, done } = suite();
|
||||
function fresh() { flatWorld(run, 256, 192, 176); run('RS=7; nextPowerBuild=0; money=10000; AMB.fill(20); temp.fill(20); hot.fill(0);'); }
|
||||
function line(v, chain = false) {
|
||||
fresh();
|
||||
const [dx, dy] = run(`TUBE_DIRS[${v}]`), bx = dx > 0 ? 16 : 36, by = dy < 0 ? 32 : 12;
|
||||
run(`for(let k=0;k<10;k++) placeBlock(BP_TUBE,${v},${bx}+k*${dx},${by}+k*${dy},true);`);
|
||||
let tail = bx, head = bx + 9 * dx;
|
||||
if (chain) {
|
||||
run(`for(let k=1;k<=3;k++) { placeBlock(BP_TUBE,${dx > 0 ? 1 : 3},${bx}-k*${dx},${by},true); placeBlock(BP_TUBE,${dx > 0 ? 1 : 3},${head}+k*${dx},${by + 9 * dy},true); }`);
|
||||
tail -= 3 * dx; head += 3 * dx;
|
||||
}
|
||||
return { dx, dy, bx, by, tail, head, hy: by + 9 * dy };
|
||||
}
|
||||
function drain(s, steps, feed = false) {
|
||||
return run(`(() => {
|
||||
let out=0, leaks=0, added=0;
|
||||
for(let k=0;k<${steps};k++) {
|
||||
${feed ? `for(let l=0;l<4;l++) { const i=(${s.by}*4+l)*W+${s.tail}*4+${s.dx > 0 ? 0 : 3}; if(mat[i]===EMPTY) {setCell(i,SAND,20,0);added++;} }` : ''}
|
||||
simTick();
|
||||
for(let i=0;i<N;i++) if(mat[i]===SAND && !IS_TUBE[part[i]]) {
|
||||
const x=i%W; if(${s.dx}>0 ? x>=${(s.head + 1) * 4} : x<${s.head * 4}) out++; else leaks++;
|
||||
setCell(i,EMPTY,20,0);
|
||||
}
|
||||
for(const f of flyers) if(f.m===SAND) {
|
||||
if(${s.dx}>0 ? f.x>=${(s.head + 1) * 4} : f.x<${s.head * 4}) out++; else leaks++;
|
||||
}
|
||||
flyers=flyers.filter(f=>f.m!==SAND);
|
||||
}
|
||||
return {out,leaks,added,inside:mat.reduce((n,m)=>n+(m===SAND),0)};
|
||||
})()`);
|
||||
}
|
||||
for (const v of [4, 5, 6, 7]) {
|
||||
const s = line(v);
|
||||
check(`direction ${v} uses appended part ids and marks power`,run(`part[${s.by * 4}*W+${s.bx * 4}]===${v + 7} && blockV[${s.by}*BW+${s.bx}]===${v} && pcells.size===160`));
|
||||
// Fill every lane, in every block: a corner or side leak is counted before it can fall away.
|
||||
run('for(let i=0;i<N;i++) if(IS_TUBE[part[i]]) setCell(i,SAND,20,0);');
|
||||
const r = drain(s, 300);
|
||||
check(`direction ${v} carries sand through ten blocks and out the head`, r.out === 160, JSON.stringify(r));
|
||||
check(`direction ${v} has no corner or side spills and conserves grains`, r.leaks === 0 && r.out+r.inside === 160,JSON.stringify(r));
|
||||
run('rebuildPower();');
|
||||
check(`direction ${v} joins corner-touching power networks`,run('nets.length===2 && nets[1].nt===160'));
|
||||
const c = line(v, true);
|
||||
rect(run,c.tail*4,c.by*4,c.tail*4+3,c.by*4+3,run('SAND'));
|
||||
const joined = drain(c,500);
|
||||
check(`direction ${v}: straight to diagonal to straight`,joined.out===16 && joined.leaks===0,JSON.stringify(joined));
|
||||
}
|
||||
// A saturated ten-block line: 80 warmup ticks, then 600 measured ticks at 60 Hz.
|
||||
const rates = [];
|
||||
for (const v of [0, 4, 5]) {
|
||||
let s;
|
||||
if (v) s=line(v);
|
||||
else {
|
||||
fresh();run('for(let by=23;by<=32;by++) placeBlock(BP_TUBE,0,16,by,true);');
|
||||
s={dx:0,tail:16,by:32,head:16};
|
||||
}
|
||||
const result = v ? (drain(s,80,true),drain(s,600,true)) : run(`(() => {
|
||||
let out=0;
|
||||
for(let k=0;k<680;k++) {
|
||||
for(let l=0;l<4;l++) {const i=131*W+64+l;if(mat[i]===EMPTY)setCell(i,SAND,20,0);}
|
||||
simTick();
|
||||
if(k>=80) out+=flyers.filter(f=>f.m===SAND).length;
|
||||
flyers=[];
|
||||
}return {out};
|
||||
})()`);
|
||||
rates.push(result.out/10);
|
||||
}
|
||||
console.log('Saturated throughput, ten blocks, grains/s: straight/up-diagonal/down-diagonal '+rates.join('/'));
|
||||
check('diagonals match straight throughput per block',rates.every(n=>n===120),rates);
|
||||
// A belt's last carrying cell feeds the tail side of an upward diagonal screw.
|
||||
const belt=line(4);
|
||||
run('for(let bx=10;bx<16;bx++)placeBlock(BP_BELT,1,bx,33,true);');
|
||||
rect(run,39,100,39,131,run('STONE'));
|
||||
rect(run,40,120,55,131,run('SAND'));
|
||||
const beltOut=run(`(()=>{let out=0;for(let k=0;k<1000;k++){simTick();for(let f=flyers.length-1;f>=0;f--)if(flyers[f].m===SAND && flyers[f].x>=104){out++;flyers.splice(f,1);}}return out;})()`);
|
||||
check('a belt feeds sand into a diagonal tail and out its head',beltOut>150,beltOut);
|
||||
for(const v of [4,5,6,7]) {
|
||||
const s=line(v);
|
||||
rect(run,s.bx*4,s.by*4-8,s.bx*4+3,s.by*4-1,run('WATER'));
|
||||
ticks(run,400);
|
||||
check(`water flows freely through diagonal ${v}`,count(run,run('WATER'),0,0,255,172)===0 && count(run,run('WATER'))===32,count(run,run('WATER')));
|
||||
}
|
||||
// Bars keep their horizontal shape, with no saved ride state.
|
||||
function putBar(x,y) {
|
||||
run(`{ const e=spawnBar(BARCU,20,20,0,0); entMark(e,0); e.x=e.ix=${x}; e.y=e.iy=${y}; entMark(e,1); }`);
|
||||
}
|
||||
function watchBars(s, n=600) {
|
||||
return run(`(()=>{let out=0,overlap=false;for(let k=0;k<${n};k++){
|
||||
simTick();
|
||||
for(let a=0;a<ents.length;a++)for(let b=0;b<a;b++) {
|
||||
const e=ents[a],f=ents[b];if(e.ix<f.ix+4 && f.ix<e.ix+4 && e.iy<f.iy+2 && f.iy<e.iy+2)overlap=true;
|
||||
}
|
||||
if(mat.some((m,i)=>occ[i] && (PH[m]===PH_SOLID || PH[m]===PH_POWDER)))overlap=true;
|
||||
for(let a=ents.length-1;a>=0;a--) {const e=ents[a];if(${s.dx}>0 ? e.ix>=${(s.head + 1) * 4} : e.ix+4<=${s.head * 4}) {out++;removeEnt(e);} }
|
||||
}return {out,overlap,left:ents.length};})()`);
|
||||
}
|
||||
for(const v of [4,5,6,7]) for(const chain of [false,true]) {
|
||||
const s=line(v,chain);
|
||||
putBar(s.tail*4,s.by*4);
|
||||
putBar(s.tail*4,s.by*4+2); // a queued bar must wait for the first one
|
||||
const r=watchBars(s);
|
||||
check(`bars travel diagonal ${v}${chain?' and both straight joins':''} without overlap`,r.out===2 && !r.overlap,JSON.stringify(r));
|
||||
}
|
||||
// Vertical straight joins reach the same tails and heads too.
|
||||
for (const v of [4,5,6,7]) {
|
||||
const s=line(v), vv=s.dy<0?0:2;
|
||||
run(`for(let k=1;k<=3;k++){placeBlock(BP_TUBE,${vv},${s.bx},${s.by}-k*${s.dy},true);placeBlock(BP_TUBE,${vv},${s.head},${s.hy}+k*${s.dy},true);}`);
|
||||
putBar(s.bx*4,(s.by-3*s.dy)*4+1);
|
||||
const r=run(`(()=>{let out=false;for(let k=0;k<500;k++){simTick();if(${s.dy}<0?ents[0].iy+2<=${(s.hy-3)*4}:ents[0].iy>=${(s.hy+4)*4})out=true;}return {out,overlap:mat.some((m,i)=>occ[i] && PH[m]===PH_SOLID)};})()`);
|
||||
check(`a bar crosses vertical joins at diagonal ${v}`,r.out && !r.overlap,JSON.stringify(r));
|
||||
// Sand from the vertical intake exits the far vertical head; no outside grains are left behind.
|
||||
run('for(const e of ents.slice())removeEnt(e);');
|
||||
rect(run,s.bx*4,(s.by-3*s.dy)*4,s.bx*4+3,(s.by-3*s.dy)*4+3,run('SAND'));
|
||||
const grain=run(`(()=>{let out=0,leak=0;for(let k=0;k<500;k++){simTick();for(const f of flyers)if(f.m===SAND){if(${s.dy}<0?f.y<${(s.hy-3)*4}:f.y>=${(s.hy+4)*4})out++;else leak++;}flyers=[];}return {out,leak};})()`);
|
||||
check(`sand crosses vertical joins at diagonal ${v}`,grain.out===16 && !grain.leak,JSON.stringify(grain));
|
||||
}
|
||||
for(const v of [4,5]) {
|
||||
const s=line(v);
|
||||
run('for(let bx=10;bx<16;bx++)placeBlock(BP_BELT,1,bx,'+(s.by+1)+',true);spawnBar(BARCU,44,'+(s.by*4+2)+',0,0);');
|
||||
check(`a belt feeds a bar into diagonal ${v}`,watchBars(s).out===1);
|
||||
// An ascending screw discharges above the receiving belt; a descending one lands on its top.
|
||||
const b=line(v), beltY=v===4?b.hy:b.hy+1;
|
||||
run(`for(let k=1;k<=8;k++)placeBlock(BP_BELT,1,${b.head}+k,${beltY},true);`);
|
||||
rect(run,b.bx*4,b.by*4,b.bx*4+3,b.by*4+3,run('SAND'));
|
||||
const onBelt=run(`(()=>{let seen=false;for(let k=0;k<300;k++){simTick();for(let x=${(b.head+2)*4};x<${(b.head+8)*4};x++)if(mat[${beltY*4-1}*W+x]===SAND)seen=true;}return seen;})()`);
|
||||
check(`diagonal ${v} unloads sand onto a belt`,onBelt);
|
||||
run('for(let i=0;i<N;i++)if(mat[i]===SAND)setCell(i,EMPTY,20,0);flyers=[];');
|
||||
putBar(b.bx*4,b.by*4+1);
|
||||
check(`diagonal ${v} unloads a bar onto a belt`,run(`(()=>{for(let k=0;k<400;k++){simTick();if(ents[0].ix>=${(b.head+2)*4} && ents[0].iy===${beltY*4-2})return true;}return false;})()`));
|
||||
}
|
||||
const savedRide=line(4);
|
||||
putBar(savedRide.bx*4,savedRide.by*4+1);ticks(run,24);
|
||||
run('globalThis.rideSave=serializeWorld();deserializeWorld(rideSave.meta,rideSave.buffers);');
|
||||
check('a bar saved mid-diagonal resumes its ride',watchBars(savedRide).out===1);
|
||||
// Mouth obstruction must hold the bar, and clearing it must resume transport.
|
||||
const blocked=line(4);
|
||||
putBar(blocked.bx*4,blocked.by*4+1);
|
||||
rect(run,(blocked.head+1)*4,(blocked.hy-1)*4,(blocked.head+2)*4-1,blocked.hy*4-1,run('STONE'));
|
||||
ticks(run,300);
|
||||
check('a blocked diagonal mouth holds its bar without wall overlap',run('ents.length===1 && entTubeAt(ents[0].ix,ents[0].iy) && !mat.some((m,i)=>m===STONE && occ[i])'));
|
||||
rect(run,(blocked.head+1)*4,(blocked.hy-1)*4,(blocked.head+2)*4-1,blocked.hy*4-1,run('EMPTY'));
|
||||
check('the diagonal bar resumes after the mouth clears',watchBars(blocked).out===1);
|
||||
for(const v of [4,5,6,7]) {
|
||||
fresh(); run(`placeBlock(BP_TUBE,${v},20,20,true);`);
|
||||
run('globalThis.saved=serializeWorld();deserializeWorld(saved.meta,saved.buffers);');
|
||||
check(`save/load keeps direction ${v} and power`,run(`blockV[20*BW+20]===${v} && part[80*W+80]===${v+7} && isPow[80*W+80]`));
|
||||
run('globalThis.clip=copyRegion(80,80,83,83);bot.x=100;bot.y=80;undoRecord(\'paste\',()=>pasteGhost(clip,24,20));ghostTick();');
|
||||
check(`copy/paste keeps direction ${v}`,run(`blockV[20*BW+24]===${v} && blockIntegrity(20*BW+24)===16`));
|
||||
run('undoLast();');
|
||||
check(`undo removes pasted diagonal ${v}`,run('blockP[20*BW+24]===0'));
|
||||
run('globalThis.flipped=flipBlueprint(clip);');
|
||||
check(`flip maps direction ${v}`,run('flipped.blocks[0][3]')===[7,6,5,4][v-4]);
|
||||
run('undoRecord(\'cut\',()=>cutRegion(80,80,83,83));undoLast();');
|
||||
check(`cut and undo restore direction ${v}`,run(`blockV[20*BW+20]===${v} && blockIntegrity(20*BW+20)===16`));
|
||||
run('money=100;removeBlock(20,20);');
|
||||
check(`diagonal ${v} refunds the straight tube price`,run('money')===125);
|
||||
}
|
||||
// Exercise the actual UI functions without starting a browser or simulating a replacement.
|
||||
run(fs.readFileSync('src/ui/selection.js','utf8'));
|
||||
run(fs.readFileSync('src/ui/actions.js','utf8'));
|
||||
run('globalThis.GAME={pieceDir:{tube:0}};globalThis.hudDirty=false;globalThis.toolId=()=>\'build\';globalThis.piece=()=>PIECE_BY_ID.tube;globalThis.playSfx=()=>{};');
|
||||
const cycle=run('(()=>{const ds=[];for(let k=0;k<8;k++){ds.push(GAME.pieceDir.tube);rotate();}return ds;})()');
|
||||
check('R cycles all eight tube directions then wraps',cycle.join(',')==='0,1,2,3,4,5,6,7' && run('GAME.pieceDir.tube')===0,cycle);
|
||||
for(const [dx,dy,v] of [[5,-4,4],[4,5,5],[-5,4,6],[-4,-5,7]]) {
|
||||
check(`a diagonal drag picks direction ${v}`,run(`dragDirFor(PIECE_BY_ID.tube,{bx:20,by:20},{bx:${20+dx},by:${20+dy}})`)===v);
|
||||
check(`direction ${v} lays a corner-touching diagonal run`,run(`blockLine(20,20,${20+dx},${20+dy},true).every(([x,y],k)=>x===20+k*${Math.sign(dx)} && y===20+k*${Math.sign(dy)})`));
|
||||
}
|
||||
done();
|
||||
Reference in New Issue
Block a user