// 终端里把盘面画成字符图,方便设计时看形状。只给工具用。 import type { Board } from '../src/board'; import { clueLabel, hasClue } from '../src/clue'; /** * 每个单位格 4 字符宽。1×1 显示 id(或线索),大格用同一个标记铺满,空洞是 '.'。 * 传 path 时改为显示步号。 */ export function renderAscii(board: Board, path?: number[]): string { const stepOf = new Map(); path?.forEach((c, i) => stepOf.set(c, i + 1)); const lines: string[] = []; for (let y = 0; y < board.rows; y++) { let line = ''; for (let x = 0; x < board.cols; x++) { const ci = board.cellAtUnit(x, y); if (ci < 0) { line += ' . '; continue; } const c = board.cells[ci]; let label: string; if (path) { const s = stepOf.get(ci); label = s === undefined ? '?' : String(s); } else if (hasClue(c)) { label = `[${clueLabel(c)}]`; } else { label = c.id; } const big = c.w > 1 || c.h > 1; const [ax, ay] = board.anchorUnit(ci); const isOrigin = x === ax && y === ay; const text = big && !isOrigin ? (path ? '·' : '·') : label; line += text.padStart(3, ' ') + ' '; } lines.push(line.replace(/\s+$/, '')); } return lines.join('\n'); } export function pathToIds(board: Board, path: number[]): string { return path.map((c) => board.cells[c].id).join(' → '); }