126 lines
4.1 KiB
TypeScript
126 lines
4.1 KiB
TypeScript
import { Stem, Branch, getXunKong, BRANCH_ELEMENT, BRANCHES, branchIndex } from './ganzhi.js';
|
|
import { buildPlate, getYueJiang, formatPlate } from './plate.js';
|
|
import { assignGenerals, formatGenerals, getNoblemanBranch, isDaytime } from './tianjiang.js';
|
|
import { buildSiKe, STEM_JIGONG } from './sike.js';
|
|
import { buildSanChuan } from './sanchuan.js';
|
|
import { buildEvidence, formatEvidenceText } from './evidence.js';
|
|
|
|
// CLI 参数解析
|
|
const args = process.argv.slice(2);
|
|
function getArg(name: string): string | undefined {
|
|
const found = args.find(a => a.startsWith(`--${name}=`));
|
|
return found ? found.split('=')[1] : undefined;
|
|
}
|
|
|
|
const dayStem = (getArg('dayStem') || '甲') as Stem;
|
|
const dayBranch = (getArg('dayBranch') || '子') as Branch;
|
|
const hourBranch = (getArg('hourBranch') || '子') as Branch;
|
|
const month = parseInt(getArg('month') || String(new Date().getMonth() + 1));
|
|
const question = getArg('question') || undefined;
|
|
const outputFormat = getArg('output') || 'text'; // json | text
|
|
|
|
try {
|
|
// 1. 月将
|
|
const yueJiang = getYueJiang(month);
|
|
|
|
// 2. 天地盘
|
|
const plate = buildPlate(yueJiang, hourBranch);
|
|
|
|
// 3. 天盘支数组(按地盘顺序)
|
|
const heavenBranches = plate.map(p => p.heavenBranch);
|
|
|
|
// 4. 四课
|
|
const sike = buildSiKe(dayStem, dayBranch, heavenBranches);
|
|
|
|
// 5. 三传
|
|
const sanchuan = buildSanChuan(sike, dayStem);
|
|
|
|
// 6. 十二天将
|
|
const generals = assignGenerals(plate, dayStem, hourBranch);
|
|
|
|
// 7. 旬空
|
|
const xunKong = getXunKong(dayStem, dayBranch);
|
|
|
|
// 8. 贵人
|
|
const noblemanBranch = getNoblemanBranch(dayStem, hourBranch);
|
|
|
|
if (outputFormat === 'json') {
|
|
console.log(JSON.stringify({
|
|
dayStem, dayBranch, hourBranch, month,
|
|
yueJiang,
|
|
plate: plate.map(p => ({ earth: p.earthBranch, heaven: p.heavenBranch })),
|
|
sike: sike.lessons,
|
|
sanchuan,
|
|
noblemanBranch,
|
|
xunKong,
|
|
question,
|
|
timestamp: new Date().toISOString(),
|
|
}, null, 2));
|
|
} else {
|
|
console.log(formatAsText(dayStem, dayBranch, hourBranch, month, yueJiang, plate, heavenBranches, sike, sanchuan, generals, noblemanBranch, xunKong, question));
|
|
|
|
// 证据链
|
|
const evidence = buildEvidence({
|
|
dayStem, dayBranch, hourBranch, month, yueJiang,
|
|
plate, heavenBranches, sike, sanchuan,
|
|
generals, noblemanBranch, xunKong, question,
|
|
});
|
|
console.log(formatEvidenceText(evidence));
|
|
}
|
|
} catch (e: any) {
|
|
console.error('排盘错误:', e.message);
|
|
process.exit(1);
|
|
}
|
|
|
|
function formatAsText(
|
|
dayStem: Stem, dayBranch: Branch, hourBranch: Branch, month: number,
|
|
yueJiang: Branch, plate: any[], heavenBranches: Branch[],
|
|
sike: any, sanchuan: any, generals: Map<Branch, any>,
|
|
noblemanBranch: Branch, xunKong: Branch[], question?: string
|
|
): string {
|
|
let text = `═══════════════════════════════════
|
|
大 六 壬 排 盘
|
|
═══════════════════════════════════
|
|
|
|
【占时】${month}月 ${dayStem}${dayBranch}日 ${hourBranch}时
|
|
${question ? `【问事】${question}` : ''}
|
|
【月将】${yueJiang}
|
|
【昼夜】${isDaytime(hourBranch) ? '昼' : '夜'}
|
|
【贵人】${noblemanBranch}
|
|
【旬空】${xunKong.join('、')}
|
|
|
|
`;
|
|
|
|
// 天地盘
|
|
text += `═══ 天 地 盘 ═══\n`;
|
|
text += `天盘:`;
|
|
for (const b of heavenBranches) text += `${b} `;
|
|
text += `\n地盘:`;
|
|
for (const b of BRANCHES) text += `${b} `;
|
|
text += `\n\n`;
|
|
|
|
// 天将
|
|
text += formatGenerals(generals) + '\n';
|
|
|
|
// 四课
|
|
text += sike.text + '\n';
|
|
|
|
// 三传
|
|
text += sanchuan.text + '\n';
|
|
|
|
// 综合提示
|
|
text += `═══ 综 合 提 示 ═══\n`;
|
|
text += `初传${sanchuan.initial}为事之开始,`;
|
|
text += `中传${sanchuan.middle}为事之过程,`;
|
|
text += `末传${sanchuan.final}为事之结果。\n`;
|
|
|
|
if (xunKong.includes(sanchuan.initial)) {
|
|
text += `⚠️ 初传${sanchuan.initial}旬空:事之初有虚象,需待填实。\n`;
|
|
}
|
|
if (xunKong.includes(sanchuan.final)) {
|
|
text += `⚠️ 末传${sanchuan.final}旬空:事之结果有落空之虞。\n`;
|
|
}
|
|
|
|
return text;
|
|
}
|