feat: 大六壬排盘算法层 v1.0
- ganzhi.ts: 天干地支/五行/藏干/合冲刑害/旬空 - plate.ts: 天地盘排布(月将加时旋转法) - tianjiang.ts: 十二天将(贵人起法/昼夜分/顺逆排布) - sike.ts: 四课算法(天干寄宫→干上神/支上神→四课结构) - sanchuan.ts: 三传算法(九宗门:贼克/比用/涉害/遥克/昴星/别责等) - run-liuren.ts: CLI入口(JSON/文本双格式输出) - duangua-prompt.md: 断课分析提示词 - SKILL.md: 完整文档
This commit is contained in:
commit
59a5593361
12 files changed
+1078
No files matched your search
@@ -0,0 +1,116 @@
|
||||
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';
|
||||
|
||||
// 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));
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
Reference in new issue
Block a user