// t105: same belt feed, open sink, central single-grain/bar travel. Run with node. const {load,flatWorld}=require('../../test/harness'); const fs=require('node:fs'); const {run}=load(); run(fs.readFileSync('test/fixtures/t105-transport.js','utf8')); const kinds=['belt','filter','uphill','downhill','screen','screw-right','screw-up','screw-down','screw-up-right','screw-down-right']; function fresh(kind,reverse){flatWorld(run,256,224,208);return run(`globalThis.ts=transportFixture(${JSON.stringify(kind)},${reverse});ts`);} function speed(kind,reverse,bar=false){ fresh(kind,reverse); return run(`(()=>{let [x,y]=ts.start;if(${bar}&&ts.kind.startsWith('screw')){x=x&~3;y=(y&~3)+2;}if(${bar}&&ts.diagonal&&!ts.kind.startsWith('screw')){let face=H;for(let xx=x;xx>2)*BW+(xx>>2);if(isSlopeBelt(blockP[b])&&beltFaceY(blockP[b],xx>>2,yy>>2,xx)===yy)face=Math.min(face,yy);}y=face-1;}if(${bar}){spawnBar(BARCU,20,40,0,0);const e=ents[0];entMark(e,0);e.x=e.ix=x;e.y=e.iy=y-1;entMark(e,1);}else setCell(y*W+x,SAND,20,0); let begin=-1,first=0; for(let k=0;k<180;k++){simTick();let px,py; if(${bar}){px=ents[0].ix;py=ents[0].iy;}else{const i=mat.indexOf(SAND);if(i<0)continue;px=i%W;py=(i/W)|0;} const p=ts.axis?(py-y)*ts.sign:(px-x)*(ts.reverse?-1:1); if(begin<0&&p>=4){begin=k;first=p;} if(begin>=0&&p>=20)return (p-first)*60/(k-begin)*(ts.diagonal?Math.SQRT2:1); }return 0;})()`); } function throughput(kind,reverse,depth){fresh(kind,reverse);return run(`(()=>{let out=0;for(let k=0;k<2400;k++){transportFeed(ts,${depth});simTick();const n=transportCollect(ts);if(k>=1200)out+=n;}return out/20;})()`);} function chain(){flatWorld(run,320,256,240);run('globalThis.ts=transportChainFixture();');return run(`(()=>{let out=0,total=0,added=0,early;for(let k=0;k<4800;k++){added+=transportFeed(ts,16);simTick();const n=transportCollect(ts);total+=n;if(k>=3600)out+=n;if(k===3599)early=transportPiles(ts);}return {heavy:out/20,added,accounted:total+mat.reduce((n,m)=>n+(m===SAND),0)+flyers.filter(f=>f.m===SAND).length,early,late:transportPiles(ts),joined:endJoin(51,32,1)>=0&&endJoin(57,27,1)>=0,stray:mat.reduce((n,m,i)=>n+(m===SAND&&i/W>=200),0)};})()`);} function measure(){const rows=[];for(const kind of kinds)for(const reverse of [false,true]){const row={piece:kind+(reverse?' mirrored':''),speed:speed(kind,reverse),normal:throughput(kind,reverse,1),heavy:throughput(kind,reverse,16),bar:speed(kind,reverse,true)};rows.push(row);console.log(JSON.stringify(row));}return rows;} if(require.main===module){measure();console.log(JSON.stringify({piece:'chain',...chain()}));} module.exports={fresh,speed,throughput,kinds,chain,run};