Files
kidgo/tools/reach-diag.mjs
T

32 lines
1.3 KiB
JavaScript

// 诊断:打印可达站立点范围(按行),找出断连位置
// 用法: node reach-diag.mjs <levelId>
import { setupGlobals, reach, TILE } from './lib-reach.mjs';
setupGlobals();
const { LEVELS } = await import('../js/levels/index.js');
const { Level } = await import('../js/level.js');
const id = process.argv[2] || 'j6';
const d = LEVELS.find(l => l.id === id);
const L = new Level(d);
const byRow = new Map();
const DJSET = (process.env.DJ || '0,6,12,18,24,30').split(',').map(Number);
const RELSET = (process.env.REL || '0,4,5,6,8,14').split(',').map(Number);
const r = reach(L, {
DJSET, RELSET,
onState: s => {
const row = Math.round(s.fy / TILE);
const cur = byRow.get(row) || { max: -1, min: 1e9 };
byRow.set(row, { max: Math.max(cur.max, s.fx), min: Math.min(cur.min, s.fx) });
},
});
console.log(`${id} ${d.name} ${L.w}x${L.h} 状态=${r.states}${r.err ? ' ERR:' + r.err : ''}`);
[...byRow.keys()].sort((a, b) => b - a).forEach(row => {
const v = byRow.get(row);
console.log(` row ${String(row).padStart(2)} (y=${row * TILE}): x ${(v.min / TILE).toFixed(1)} .. ${(v.max / TILE).toFixed(1)} 格`);
});
for (const e of L.entities) if (e.type === 'goal' || e.type === 'save')
console.log(` ${e.type}#${e.no ?? ''} at col ${e.tx}, row ${e.ty}`);