feat: 奇门遁甲排盘算法层 v1.0
- qimen-data.ts: 九宫/八门/九星/八神/三奇六仪/五行生克 - plate.ts: 时家奇门排盘(阴阳遁/局数/天地盘/八门/九星/八神/空亡/驿马) - run-qimen.ts: CLI入口(九宫格式化输出) - duangua-prompt.md: 断局分析提示词 - SKILL.md: 完整文档
This commit is contained in:
commit
bd3f86dda6
9 files changed
+757
No files matched your search
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
dist/
|
||||
@@ -0,0 +1,84 @@
|
||||
---
|
||||
name: qimen
|
||||
description: 奇门遁甲排盘与断局。时家奇门转盘法,九宫/八门/九星/八神/三奇六仪/值符值使,输出JSON+文本+HTML海报。
|
||||
---
|
||||
|
||||
# 奇门遁甲 Skill
|
||||
|
||||
## 何时触发
|
||||
|
||||
用户场景:
|
||||
- "帮我起个奇门局" / "奇门遁甲排盘" / "奇门看看"
|
||||
- 提供日干支、时辰、月份要求排盘
|
||||
- 询问方位吉凶、出行择时
|
||||
|
||||
**不触发**:八字/紫微(见 bazi-ziwei)、六爻(见 liuyao-skill)、梅花(见 meihua-yishu)、大六壬(见 daliuren)。
|
||||
|
||||
---
|
||||
|
||||
## 必需输入
|
||||
|
||||
```
|
||||
日干支: 天干+地支(如"甲子")
|
||||
时辰: 天干+地支(如"甲子时")
|
||||
月份: 数字 1-12
|
||||
问事: 事业/财运/感情/健康/出行 等(可选)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 执行流程
|
||||
|
||||
### Step 0 — 确认信息
|
||||
|
||||
> "奇门遁甲排盘需要:
|
||||
> 1. **日干支** — 如'甲子日'
|
||||
> 2. **时干支** — 如'甲子时'(注意:时干需要,不只是地支)
|
||||
> 3. **月份** — 如'8月'
|
||||
> 4. **问事** — 可选"
|
||||
|
||||
### Step 1 — 排盘(算法层)
|
||||
|
||||
```bash
|
||||
cd calculator
|
||||
node dist/run-qimen.js --dayStem=甲 --dayBranch=子 --hourStem=甲 --hourBranch=子 --month=8 --question="事业" --output=text > qimen.txt
|
||||
```
|
||||
|
||||
### Step 2 — 断局分析
|
||||
|
||||
读取 `prompts/duangua-prompt.md`,喂入 `qimen.txt`,输出断局长文。
|
||||
|
||||
---
|
||||
|
||||
## 关键约束
|
||||
|
||||
1. **排盘必须走算法层**:不要徒手算九宫排布
|
||||
2. **一事一局**:每次只问一件事
|
||||
3. **用神选宫**:根据问事类型选择对应宫位
|
||||
4. **空亡必标**:旬空宫位必须在分析中标注
|
||||
5. **不替用户做决策**
|
||||
6. **免责声明**:末尾必带
|
||||
|
||||
---
|
||||
|
||||
## 文件清单
|
||||
|
||||
```
|
||||
qimen/
|
||||
├── SKILL.md
|
||||
├── calculator/
|
||||
│ ├── src/
|
||||
│ │ ├── qimen-data.ts ← 基础数据(九宫/八门/九星/八神/三奇六仪)
|
||||
│ │ ├── plate.ts ← 排盘算法(天地盘/八门/九星/八神排布)
|
||||
│ │ └── run-qimen.ts ← CLI入口
|
||||
│ └── package.json
|
||||
├── prompts/
|
||||
│ ├── duangua-prompt.md ← 断局分析提示词
|
||||
│ └── duangua-poster.md ← 海报版JSON输出
|
||||
└── templates/
|
||||
└── qimen-poster.html ← 海报HTML模板
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
*本分析基于传统奇门遁甲理论框架,仅供文化研究与娱乐参考,不构成任何决策依据。*
|
||||
Generated
+47
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "qimen-calculator",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "qimen-calculator",
|
||||
"version": "1.0.0",
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.0.0",
|
||||
"typescript": "^5.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.20.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.1.tgz",
|
||||
"integrity": "sha512-EANqOCF9QFyra+4pfxUcX9STKJpCLjMbObVzljIJomAWSnuSIEAvyzEU53GaajbXJEgdh0iEcPL+DGvpUd4k1Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.21.0"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.17"
|
||||
}
|
||||
},
|
||||
"node_modules/undici-types": {
|
||||
"version": "6.21.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
||||
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "qimen-calculator",
|
||||
"version": "1.0.0",
|
||||
"description": "奇门遁甲排盘算法层",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"start": "node dist/run-qimen.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.3.0",
|
||||
"@types/node": "^22.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
// 奇门遁甲排盘核心算法
|
||||
// 时家奇门:以时辰定局,转盘法排布
|
||||
|
||||
import { Stem, Branch, STEMS, BRANCHES, PALACES, Palace, YANGDUN_ORDER, YINDUN_ORDER,
|
||||
EIGHT_GATES, NINE_STARS, EIGHT_SPIRITS, GATE_ORIGIN_PALACE, STAR_ORIGIN_PALACE,
|
||||
getRelation } from './qimen-data.js';
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 节气→局数映射
|
||||
// ═══════════════════════════════════
|
||||
// 阳遁:冬至后,一局→九局(冬至/小寒/大寒各1-3局)
|
||||
// 阴遁:夏至后,九局→一局(夏至/小暑/大暑各9-7局)
|
||||
|
||||
// 简化版:按月份和日干支判断阴阳遁和局数
|
||||
function getYinYangDun(month: number, dayBranch: Branch): '阳' | '阴' {
|
||||
// 冬至(11月)到夏至(5月)前为阳遁
|
||||
// 夏至(5月)到冬至(11月)前为阴遁
|
||||
if (month >= 1 && month <= 5) return '阳';
|
||||
if (month >= 7 && month <= 11) return '阴';
|
||||
// 6月和12月看具体日子(简化:6月阴遁,12月阳遁)
|
||||
return month === 6 ? '阴' : '阳';
|
||||
}
|
||||
|
||||
// 获取局数(简化版:用日干支取局)
|
||||
function getJuNumber(dayStem: Stem, dayBranch: Branch, yinYang: '阳' | '阴'): number {
|
||||
// 甲子旬头取局法:用日干支的旬首
|
||||
const stemIdx = STEMS.indexOf(dayStem);
|
||||
const branchIdx = BRANCHES.indexOf(dayBranch);
|
||||
// 旬首地支 = 日支 - 日干索引
|
||||
const xunFirstBranchIdx = ((branchIdx - stemIdx) % 12 + 12) % 12;
|
||||
|
||||
if (yinYang === '阳') {
|
||||
// 阳遁:按旬首取局(子=1局,丑=2局...亥=12局→12%9+1=4局)
|
||||
return (xunFirstBranchIdx % 9) + 1;
|
||||
} else {
|
||||
// 阴遁:逆序(子=9局,丑=8局...)
|
||||
return 9 - (xunFirstBranchIdx % 9);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 地盘排布(固定,三奇六仪按局数落宫)
|
||||
// ═══════════════════════════════════
|
||||
function buildEarthPlate(juNumber: number, yinYang: '阳' | '阴'): Map<number, Stem> {
|
||||
const result = new Map<number, Stem>();
|
||||
const order = yinYang === '阳' ? YANGDUN_ORDER : YINDUN_ORDER;
|
||||
|
||||
// 局数决定戊的起始宫位
|
||||
// 阳遁1局:戊在坎1宫,2局:戊在坤2宫...
|
||||
// 阴遁9局:戊在离9宫,8局:戊在艮8宫...
|
||||
const startPalace = juNumber;
|
||||
|
||||
for (let i = 0; i < 9; i++) {
|
||||
const palaceNum = yinYang === '阳'
|
||||
? ((startPalace - 1 + i) % 9) + 1
|
||||
: ((startPalace - 1 - i + 9) % 9) + 1;
|
||||
const stem = order[i];
|
||||
result.set(palaceNum, stem);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 天盘排布(值符随时干,天盘星跟随)
|
||||
// ═══════════════════════════════════
|
||||
function buildHeavenPlate(
|
||||
earthPlate: Map<number, Stem>,
|
||||
hourStem: Stem,
|
||||
yinYang: '阳' | '阴'
|
||||
): Map<number, Stem> {
|
||||
const result = new Map<number, Stem>();
|
||||
|
||||
// 找时干在地盘的位置
|
||||
let hourPalace = 0;
|
||||
for (const [palace, stem] of earthPlate) {
|
||||
if (stem === hourStem) {
|
||||
hourPalace = palace;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hourPalace === 0) hourPalace = 1; // fallback
|
||||
|
||||
// 天盘旋转:值符(甲所在宫的星)飞到时干宫
|
||||
// 简化:天盘 = 地盘整体旋转,使甲(或值符)移到时干位置
|
||||
// 找甲(戊)在地盘的位置
|
||||
let jiaPalace = 0;
|
||||
for (const [palace, stem] of earthPlate) {
|
||||
if (stem === '戊') {
|
||||
jiaPalace = palace;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 旋转量 = 时干宫 - 甲宫
|
||||
const offset = hourPalace - jiaPalace;
|
||||
|
||||
for (let i = 1; i <= 9; i++) {
|
||||
const sourcePalace = ((i - 1 - offset + 9) % 9) + 1;
|
||||
const stem = earthPlate.get(sourcePalace);
|
||||
if (stem) {
|
||||
result.set(i, stem);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 八门排布(值使随时支)
|
||||
// ═══════════════════════════════════
|
||||
function buildGatePlate(
|
||||
juNumber: number,
|
||||
hourBranch: Branch,
|
||||
yinYang: '阳' | '阴'
|
||||
): Map<number, string> {
|
||||
const result = new Map<number, string>();
|
||||
const gates = EIGHT_GATES.map(g => g.name);
|
||||
|
||||
// 值使门(与值符同宫的门)随时支转动
|
||||
// 简化:按局数和时辰排布
|
||||
const hourIdx = BRANCHES.indexOf(hourBranch);
|
||||
|
||||
// 阳遁顺排,阴遁逆排
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const gatePalace = yinYang === '阳'
|
||||
? ((juNumber - 1 + i) % 9) + 1
|
||||
: ((juNumber - 1 - i + 9) % 9) + 1;
|
||||
if (gatePalace !== 5) { // 中五宫无门
|
||||
result.set(gatePalace, gates[i % 8]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 九星排布(值符随时干)
|
||||
// ═══════════════════════════════════
|
||||
function buildStarPlate(
|
||||
juNumber: number,
|
||||
hourStem: Stem,
|
||||
yinYang: '阳' | '阴'
|
||||
): Map<number, string> {
|
||||
const result = new Map<number, string>();
|
||||
const stars = NINE_STARS.map(s => s.name);
|
||||
|
||||
// 值符星(局数对应的星)飞到时干宫
|
||||
const stemIdx = STEMS.indexOf(hourStem);
|
||||
|
||||
for (let i = 0; i < 9; i++) {
|
||||
const palaceNum = yinYang === '阳'
|
||||
? ((juNumber - 1 + i) % 9) + 1
|
||||
: ((juNumber - 1 - i + 9) % 9) + 1;
|
||||
const starIdx = (i + (juNumber - 1)) % 9;
|
||||
result.set(palaceNum, stars[starIdx]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 八神排布(值符起,阳顺阴逆)
|
||||
// ═══════════════════════════════════
|
||||
function buildSpiritPlate(
|
||||
juNumber: number,
|
||||
yinYang: '阳' | '阴'
|
||||
): Map<number, string> {
|
||||
const result = new Map<number, string>();
|
||||
const spirits = EIGHT_SPIRITS.map(s => s.name);
|
||||
|
||||
for (let i = 0; i < 8; i++) {
|
||||
const palaceNum = yinYang === '阳'
|
||||
? ((juNumber - 1 + i) % 9) + 1
|
||||
: ((juNumber - 1 - i + 9) % 9) + 1;
|
||||
if (palaceNum !== 5) { // 中五宫无神
|
||||
result.set(palaceNum, spirits[i % 8]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 空亡判断
|
||||
// ═══════════════════════════════════
|
||||
function getXunKong(dayStem: Stem, dayBranch: Branch): Branch[] {
|
||||
const si = STEMS.indexOf(dayStem);
|
||||
const bi = BRANCHES.indexOf(dayBranch);
|
||||
const xunFirstBranchIdx = ((bi - si) % 12 + 12) % 12;
|
||||
return [BRANCHES[(xunFirstBranchIdx + 10) % 12], BRANCHES[(xunFirstBranchIdx + 11) % 12]];
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 马星(驿马)
|
||||
// ═══════════════════════════════════
|
||||
function getHorse(dayBranch: Branch): Branch {
|
||||
// 申子辰→寅,寅午戌→申,巳酉丑→亥,亥卯未→巳
|
||||
const bi = BRANCHES.indexOf(dayBranch);
|
||||
const group = bi % 4; // 0=子组, 1=丑组, 2=寅组, 3=卯组
|
||||
const horses: Record<number, Branch> = { 0: '寅', 1: '亥', 2: '申', 3: '巳' };
|
||||
return horses[group];
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 主排盘函数
|
||||
// ═══════════════════════════════════
|
||||
export interface QiMenInput {
|
||||
dayStem: Stem;
|
||||
dayBranch: Branch;
|
||||
hourStem: Stem;
|
||||
hourBranch: Branch;
|
||||
month: number;
|
||||
question?: string;
|
||||
}
|
||||
|
||||
export interface QiMenResult {
|
||||
// 基本信息
|
||||
yinYang: '阳' | '阴';
|
||||
juNumber: number;
|
||||
dayStem: Stem;
|
||||
dayBranch: Branch;
|
||||
hourStem: Stem;
|
||||
hourBranch: Branch;
|
||||
|
||||
// 九宫排布
|
||||
earthPlate: Map<number, Stem>; // 地盘:宫位→天干
|
||||
heavenPlate: Map<number, Stem>; // 天盘:宫位→天干
|
||||
gatePlate: Map<number, string>; // 八门:宫位→门名
|
||||
starPlate: Map<number, string>; // 九星:宫位→星名
|
||||
spiritPlate: Map<number, string>; // 八神:宫位→神名
|
||||
|
||||
// 神煞
|
||||
xunkong: Branch[];
|
||||
horse: Branch;
|
||||
|
||||
// 元信息
|
||||
month: number;
|
||||
question?: string;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export function calculateQiMen(input: QiMenInput): QiMenResult {
|
||||
const { dayStem, dayBranch, hourStem, hourBranch, month } = input;
|
||||
|
||||
// 1. 阴阳遁
|
||||
const yinYang = getYinYangDun(month, dayBranch);
|
||||
|
||||
// 2. 局数
|
||||
const juNumber = getJuNumber(dayStem, dayBranch, yinYang);
|
||||
|
||||
// 3. 地盘
|
||||
const earthPlate = buildEarthPlate(juNumber, yinYang);
|
||||
|
||||
// 4. 天盘
|
||||
const heavenPlate = buildHeavenPlate(earthPlate, hourStem, yinYang);
|
||||
|
||||
// 5. 八门
|
||||
const gatePlate = buildGatePlate(juNumber, hourBranch, yinYang);
|
||||
|
||||
// 6. 九星
|
||||
const starPlate = buildStarPlate(juNumber, hourStem, yinYang);
|
||||
|
||||
// 7. 八神
|
||||
const spiritPlate = buildSpiritPlate(juNumber, yinYang);
|
||||
|
||||
// 8. 神煞
|
||||
const xunkong = getXunKong(dayStem, dayBranch);
|
||||
const horse = getHorse(dayBranch);
|
||||
|
||||
return {
|
||||
yinYang, juNumber, month,
|
||||
dayStem, dayBranch, hourStem, hourBranch,
|
||||
earthPlate, heavenPlate, gatePlate, starPlate, spiritPlate,
|
||||
xunkong, horse,
|
||||
question: input.question,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// 奇门遁甲基础数据层
|
||||
// 九宫、八门、九星、八神、三奇六仪
|
||||
|
||||
// 十天干
|
||||
export const STEMS = ['甲','乙','丙','丁','戊','己','庚','辛','壬','癸'] as const;
|
||||
export type Stem = typeof STEMS[number];
|
||||
|
||||
// 十二地支
|
||||
export const BRANCHES = ['子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥'] as const;
|
||||
export type Branch = typeof BRANCHES[number];
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 九宫(洛书九宫,固定方位)
|
||||
// ═══════════════════════════════════
|
||||
export interface Palace {
|
||||
number: number; // 宫位数 1-9
|
||||
name: string; // 宫名
|
||||
direction: string; // 方位
|
||||
element: string; // 五行
|
||||
trigram: string; // 八卦
|
||||
earthBranch: Branch; // 地盘地支
|
||||
}
|
||||
|
||||
export const PALACES: Palace[] = [
|
||||
{ number: 1, name: '坎一宫', direction: '北', element: '水', trigram: '坎', earthBranch: '子' },
|
||||
{ number: 2, name: '坤二宫', direction: '西南', element: '土', trigram: '坤', earthBranch: '未' },
|
||||
{ number: 3, name: '震三宫', direction: '东', element: '木', trigram: '震', earthBranch: '卯' },
|
||||
{ number: 4, name: '巽四宫', direction: '东南', element: '木', trigram: '巽', earthBranch: '辰' },
|
||||
{ number: 5, name: '中五宫', direction: '中', element: '土', trigram: '中', earthBranch: '中' as any },
|
||||
{ number: 6, name: '乾六宫', direction: '西北', element: '金', trigram: '乾', earthBranch: '戌' },
|
||||
{ number: 7, name: '兑七宫', direction: '西', element: '金', trigram: '兑', earthBranch: '酉' },
|
||||
{ number: 8, name: '艮八宫', direction: '东北', element: '土', trigram: '艮', earthBranch: '丑' },
|
||||
{ number: 9, name: '离九宫', direction: '南', element: '火', trigram: '离', earthBranch: '午' },
|
||||
];
|
||||
|
||||
// 洛书飞宫顺序(1→8→3→4→9→2→7→6)
|
||||
export const LUOSHU_ORDER = [1, 8, 3, 4, 9, 2, 7, 6] as const;
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 八门
|
||||
// ═══════════════════════════════════
|
||||
export interface Gate {
|
||||
name: string;
|
||||
element: string;
|
||||
nature: string; // 吉/凶/平
|
||||
attribute: string; // 属性
|
||||
}
|
||||
|
||||
export const EIGHT_GATES: Gate[] = [
|
||||
{ name: '休门', element: '水', nature: '吉', attribute: '休息、贵人' },
|
||||
{ name: '生门', element: '土', nature: '大吉', attribute: '生机、财富' },
|
||||
{ name: '伤门', element: '木', nature: '凶', attribute: '伤害、争斗' },
|
||||
{ name: '杜门', element: '木', nature: '平', attribute: '闭塞、隐藏' },
|
||||
{ name: '景门', element: '火', nature: '平', attribute: '文书、考试' },
|
||||
{ name: '死门', element: '土', nature: '大凶', attribute: '死亡、终结' },
|
||||
{ name: '惊门', element: '金', nature: '凶', attribute: '惊恐、口舌' },
|
||||
{ name: '开门', element: '金', nature: '大吉', attribute: '开启、事业' },
|
||||
];
|
||||
|
||||
// 八门原始宫位(阳遁顺排,阴遁逆排)
|
||||
// 休门在坎一宫,顺时针:休(坎1)→死(坤2)→伤(震3)→杜(巽4)→中(中5寄坤2)→开(乾6)→惊(兑7)→生(艮8)
|
||||
export const GATE_ORIGIN_PALACE: Record<string, number> = {
|
||||
'休门': 1, '死门': 2, '伤门': 3, '杜门': 4,
|
||||
'景门': 9, '开门': 6, '惊门': 7, '生门': 8,
|
||||
};
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 九星
|
||||
// ═══════════════════════════════════
|
||||
export interface Star {
|
||||
name: string;
|
||||
element: string;
|
||||
nature: string; // 吉/凶/平
|
||||
attribute: string;
|
||||
}
|
||||
|
||||
export const NINE_STARS: Star[] = [
|
||||
{ name: '天蓬', element: '水', nature: '凶', attribute: '盗贼、淫邪' },
|
||||
{ name: '天芮', element: '土', nature: '凶', attribute: '疾病、阴人' },
|
||||
{ name: '天冲', element: '木', nature: '平', attribute: '冲杀、武勇' },
|
||||
{ name: '天辅', element: '木', nature: '大吉', attribute: '文运、辅佐' },
|
||||
{ name: '天禽', element: '土', nature: '大吉', attribute: '中央、帝王' },
|
||||
{ name: '天心', element: '金', nature: '大吉', attribute: '智慧、医术' },
|
||||
{ name: '天柱', element: '金', nature: '凶', attribute: '口舌、破损' },
|
||||
{ name: '天任', element: '土', nature: '吉', attribute: '田土、财富' },
|
||||
{ name: '天英', element: '火', nature: '平', attribute: '光明、文书' },
|
||||
];
|
||||
|
||||
// 九星原始宫位(与洛书对应)
|
||||
export const STAR_ORIGIN_PALACE: Record<string, number> = {
|
||||
'天蓬': 1, '天芮': 2, '天冲': 3, '天辅': 4,
|
||||
'天禽': 5, '天心': 6, '天柱': 7, '天任': 8, '天英': 9,
|
||||
};
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 八神
|
||||
// ═══════════════════════════════════
|
||||
export interface Spirit {
|
||||
name: string;
|
||||
nature: string; // 吉/凶/平
|
||||
attribute: string;
|
||||
}
|
||||
|
||||
export const EIGHT_SPIRITS: Spirit[] = [
|
||||
{ name: '值符', nature: '大吉', attribute: '首领、贵人' },
|
||||
{ name: '腾蛇', nature: '凶', attribute: '惊恐、怪异' },
|
||||
{ name: '太阴', nature: '吉', attribute: '阴私、暗助' },
|
||||
{ name: '六合', nature: '吉', attribute: '合作、婚姻' },
|
||||
{ name: '白虎', nature: '大凶', attribute: '凶险、伤灾' },
|
||||
{ name: '玄武', nature: '凶', attribute: '盗贼、暗昧' },
|
||||
{ name: '九地', nature: '吉', attribute: '稳固、土地' },
|
||||
{ name: '九天', nature: '大吉', attribute: '高远、出行' },
|
||||
];
|
||||
|
||||
// ═══════════════════════════════════
|
||||
// 三奇六仪
|
||||
// ═══════════════════════════════════
|
||||
// 三奇:乙(日奇)、丙(月奇)、丁(星奇)
|
||||
// 六仪:戊、己、庚、辛、壬、癸
|
||||
// 排列顺序(阳遁):戊→己→庚→辛→壬→癸→丁→丙→乙
|
||||
// 排列顺序(阴遁):戊→乙→丙→丁→癸→壬→辛→庚→己
|
||||
|
||||
export const YANGDUN_ORDER: Stem[] = ['戊','己','庚','辛','壬','癸','丁','丙','乙'];
|
||||
export const YINDUN_ORDER: Stem[] = ['戊','乙','丙','丁','癸','壬','辛','庚','己'];
|
||||
|
||||
// 天干五行
|
||||
export const STEM_ELEMENT: Record<Stem, string> = {
|
||||
'甲':'木','乙':'木','丙':'火','丁':'火','戊':'土','己':'土','庚':'金','辛':'金','壬':'水','癸':'水'
|
||||
};
|
||||
|
||||
// 地支五行
|
||||
export const BRANCH_ELEMENT: Record<string, string> = {
|
||||
'子':'水','丑':'土','寅':'木','卯':'木','辰':'土','巳':'火',
|
||||
'午':'火','未':'土','申':'金','酉':'金','戌':'土','亥':'水'
|
||||
};
|
||||
|
||||
// 五行生克
|
||||
export const WUXING_SHENG: Record<string, string> = { '木':'火','火':'土','土':'金','金':'水','水':'木' };
|
||||
export const WUXING_KE: Record<string, string> = { '木':'土','土':'水','水':'火','火':'金','金':'木' };
|
||||
|
||||
// 判断五行关系
|
||||
export function getRelation(a: string, b: string): string {
|
||||
if (a === b) return '比和';
|
||||
if (WUXING_SHENG[a] === b) return `${a}生${b}`;
|
||||
if (WUXING_SHENG[b] === a) return `${b}生${a}`;
|
||||
if (WUXING_KE[a] === b) return `${a}克${b}`;
|
||||
if (WUXING_KE[b] === a) return `${b}克${a}`;
|
||||
return '无关系';
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import { Stem, Branch, STEMS, BRANCHES, PALACES, EIGHT_GATES, NINE_STARS, EIGHT_SPIRITS, getRelation } from './qimen-data.js';
|
||||
import { calculateQiMen, QiMenInput } from './plate.js';
|
||||
|
||||
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 hourStem = (getArg('hourStem') || '甲') as Stem;
|
||||
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';
|
||||
|
||||
try {
|
||||
const result = calculateQiMen({ dayStem, dayBranch, hourStem, hourBranch, month, question });
|
||||
|
||||
if (outputFormat === 'json') {
|
||||
const obj: any = {
|
||||
yinYang: result.yinYang, juNumber: result.juNumber,
|
||||
dayStem: result.dayStem, dayBranch: result.dayBranch,
|
||||
hourStem: result.hourStem, hourBranch: result.hourBranch,
|
||||
xunkong: result.xunkong, horse: result.horse,
|
||||
question: result.question, timestamp: result.timestamp,
|
||||
palaces: [] as any[],
|
||||
};
|
||||
for (let i = 1; i <= 9; i++) {
|
||||
obj.palaces.push({
|
||||
palace: i,
|
||||
name: PALACES[i-1].name,
|
||||
direction: PALACES[i-1].direction,
|
||||
earthStem: result.earthPlate.get(i),
|
||||
heavenStem: result.heavenPlate.get(i),
|
||||
gate: result.gatePlate.get(i) || '',
|
||||
star: result.starPlate.get(i) || '',
|
||||
spirit: result.spiritPlate.get(i) || '',
|
||||
});
|
||||
}
|
||||
console.log(JSON.stringify(obj, null, 2));
|
||||
} else {
|
||||
console.log(formatAsText(result));
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error('排盘错误:', e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function formatAsText(r: ReturnType<typeof calculateQiMen>): string {
|
||||
let text = `═══════════════════════════════════
|
||||
奇 门 遁 甲 排 盘
|
||||
═══════════════════════════════════
|
||||
|
||||
【占时】${r.month}月 ${r.dayStem}${r.dayBranch}日 ${r.hourStem}${r.hourBranch}时
|
||||
${r.question ? `【问事】${r.question}` : ''}
|
||||
【遁局】${r.yinYang}遁${r.juNumber}局
|
||||
【旬空】${r.xunkong.join('、')}
|
||||
【驿马】${r.horse}
|
||||
|
||||
`;
|
||||
|
||||
// 九宫排盘表
|
||||
text += `═══ 九 宫 排 盘 ═══\n\n`;
|
||||
|
||||
// 上三宫(4/9/2)
|
||||
text += formatPalaceRow(r, [4, 9, 2]);
|
||||
text += `───────────────────────────────────\n`;
|
||||
// 中三宫(3/5/7)
|
||||
text += formatPalaceRow(r, [3, 5, 7]);
|
||||
text += `───────────────────────────────────\n`;
|
||||
// 下三宫(8/1/6)
|
||||
text += formatPalaceRow(r, [8, 1, 6]);
|
||||
text += `\n`;
|
||||
|
||||
// 汇总
|
||||
text += `═══ 格 局 提 示 ═══\n`;
|
||||
|
||||
// 找值符宫(戊所在宫)
|
||||
for (let i = 1; i <= 9; i++) {
|
||||
if (r.earthPlate.get(i) === '戊') {
|
||||
text += `值符宫:${PALACES[i-1].name}(${PALACES[i-1].direction})\n`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 空亡提示
|
||||
if (r.xunkong.length > 0) {
|
||||
text += `⚠️ 旬空:${r.xunkong.join('、')}落空,事有虚象\n`;
|
||||
}
|
||||
|
||||
// 马星提示
|
||||
text += `🐴 驿马:${r.horse},主动、快、变\n`;
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
function formatPalaceRow(r: ReturnType<typeof calculateQiMen>, palaces: number[]): string {
|
||||
let text = '';
|
||||
for (const p of palaces) {
|
||||
const pal = PALACES[p-1];
|
||||
const earth = r.earthPlate.get(p) || '?';
|
||||
const heaven = r.heavenPlate.get(p) || '?';
|
||||
const gate = r.gatePlate.get(p) || '—';
|
||||
const star = r.starPlate.get(p) || '—';
|
||||
const spirit = r.spiritPlate.get(p) || '—';
|
||||
|
||||
text += `┌─ ${pal.name}(${pal.direction}) ─────────┐\n`;
|
||||
text += `│ 神:${spirit.padEnd(6)} 星:${star.padEnd(6)} │\n`;
|
||||
text += `│ 门:${gate.padEnd(6)} 天盘:${heaven.padEnd(4)} │\n`;
|
||||
text += `│ 地盘:${earth.padEnd(18)} │\n`;
|
||||
text += `└──────────────────────┘\n`;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
# 奇门遁甲 · 断局分析提示词
|
||||
|
||||
你是一位精通奇门遁甲的命理分析师。请根据以下排盘结果,进行专业断局分析。
|
||||
|
||||
## 分析框架
|
||||
|
||||
### 一、格局概述
|
||||
- 阴阳遁/局数
|
||||
- 旬空/驿马
|
||||
- 值符宫位置
|
||||
|
||||
### 二、九宫逐宫分析
|
||||
每个宫位包含:地盘天干、天盘天干、八门、九星、八神
|
||||
- 天盘干代表外在、动态、对方
|
||||
- 地盘干代表内在、静态、己方
|
||||
- 八门代表事件性质
|
||||
- 九星代表天时
|
||||
- 八神代表神助
|
||||
|
||||
### 三、用神分析(根据问事类型选宫)
|
||||
- 事业:看开门(乾六宫)和值符宫
|
||||
- 财运:看生门(艮八宫)和甲子戊
|
||||
- 感情:看六合和乙奇
|
||||
- 健康:看天芮星和死门
|
||||
- 出行:看景门和驿马宫
|
||||
- 官讼:看惊门和白虎
|
||||
- 考试:看景门和天辅星
|
||||
|
||||
### 四、格局分析
|
||||
- 天盘克地盘:外克内,不利
|
||||
- 地盘克天盘:内克外,可守
|
||||
- 天地比和:和谐
|
||||
- 三奇(乙丙丁)落宫:吉
|
||||
- 六仪(戊己庚辛壬癸)落宫:看具体组合
|
||||
- 庚格:庚临用神宫,阻碍
|
||||
- 空亡宫:事有虚象
|
||||
|
||||
### 五、反证分析
|
||||
- 死门/白虎/玄武临用神宫:不利信号
|
||||
- 空亡:事态不明
|
||||
- 驿马:变动信号
|
||||
|
||||
### 六、综合断语
|
||||
- 明确回答问题
|
||||
- 给出建议
|
||||
- 标注置信度
|
||||
|
||||
## 输出格式
|
||||
Markdown 格式,结构清晰。
|
||||
|
||||
## 免责声明(末尾必带)
|
||||
> 本分析基于传统奇门遁甲理论框架,仅供文化研究与娱乐参考,不构成任何决策依据。
|
||||
Reference in new issue
Block a user