import { HEAVENLY_STEMS, EARTHLY_BRANCHES, HEAVENLY_STEMS_KR, EARTHLY_BRANCHES_KR } from './saju-calculator'; /** * 대운 (大運) 정보 */ export interface DaeunPillar { age: number; // 시작 나이 startYear: number; // 시작 년도 endYear: number; // 끝 년도 stem: string; // 천간 branch: string; // 지지 stemKr: string; // 천간 한글 branchKr: string; // 지지 한글 } /** * 대운 계산 * @param birthYear 생년 * @param birthMonth 생월 * @param birthDay 생일 * @param gender 성별 * @param monthStem 월주 천간 인덱스 * @param monthBranch 월주 지지 인덱스 * @returns 대운 배열 (10년 단위) */ export function calculateDaeun( birthYear: number, birthMonth: number, birthDay: number, gender: 'male' | 'female', monthStem: string, monthBranch: string ): DaeunPillar[] { const monthStemIndex = HEAVENLY_STEMS.indexOf(monthStem as any); const monthBranchIndex = EARTHLY_BRANCHES.indexOf(monthBranch as any); if (monthStemIndex === -1 || monthBranchIndex === -1) { return []; } // 양남음녀(陽男陰女)는 순행, 음남양녀(陰男陽女)는 역행 const yearStemIndex = (birthYear - 1900 + 6) % 10; const isYangYear = yearStemIndex % 2 === 0; // 양년 let isForward: boolean; if (gender === 'male') { isForward = isYangYear; // 양남: 순행, 음남: 역행 } else { isForward = !isYangYear; // 양녀: 역행, 음녀: 순행 } // 대운 시작 나이 계산 (간단화: 평균 8세로 설정) // 실제로는 절입일부터 생일까지의 일수를 계산해야 하지만 복잡하므로 단순화 const startAge = 8; const daeunList: DaeunPillar[] = []; for (let i = 0; i < 8; i++) { const age = startAge + (i * 10); const startYear = birthYear + age; const endYear = startYear + 9; let stemIndex: number; let branchIndex: number; if (isForward) { // 순행: 월주에서 증가 stemIndex = (monthStemIndex + i + 1) % 10; branchIndex = (monthBranchIndex + i + 1) % 12; } else { // 역행: 월주에서 감소 stemIndex = (monthStemIndex - i - 1 + 100) % 10; branchIndex = (monthBranchIndex - i - 1 + 120) % 12; } daeunList.push({ age, startYear, endYear, stem: HEAVENLY_STEMS[stemIndex], branch: EARTHLY_BRANCHES[branchIndex], stemKr: HEAVENLY_STEMS_KR[stemIndex], branchKr: EARTHLY_BRANCHES_KR[branchIndex] }); } return daeunList; } /** * 현재 대운 찾기 * @param daeunList 대운 목록 * @param currentYear 현재 년도 */ export function getCurrentDaeun(daeunList: DaeunPillar[], currentYear: number): DaeunPillar | null { for (const daeun of daeunList) { if (currentYear >= daeun.startYear && currentYear <= daeun.endYear) { return daeun; } } return null; } /** * 대운 해석 * @param daeun 대운 정보 * @param dayStem 일간 */ export function getDaeunDescription(daeun: DaeunPillar, dayStem: string): string { const age = daeun.age; const ganzi = `${daeun.stem}${daeun.branch}`; let description = `${age}세부터 ${age + 9}세까지의 10년은 ${daeun.stemKr}${daeun.branchKr}(${ganzi}) 대운입니다. `; // 대운 천간과 일간의 관계에 따른 기본 해석 const stemIndex = HEAVENLY_STEMS.indexOf(daeun.stem as any); if (age < 20) { description += '청소년기로 학업과 기초를 다지는 시기입니다. '; } else if (age < 40) { description += '성장과 발전의 시기로 사회활동이 왕성한 때입니다. '; } else if (age < 60) { description += '안정과 성숙의 시기로 경험이 쌓이는 때입니다. '; } else { description += '원숙한 시기로 인생의 지혜를 나누는 때입니다. '; } if (stemIndex % 2 === 0) { description += '적극적이고 외향적인 활동이 유리합니다.'; } else { description += '차분하고 내실을 다지는 것이 좋습니다.'; } return description; }