Ejemplo n.º 1
0
        /// <summary>
        /// 男命柱中辰、巳并见,谓之天罗;女命柱中戌、亥并见,谓之地网
        /// </summary>
        /// <returns></returns>
        private string[] 天罗地网(GanZhi shiyun)
        {
            if (this.性别 == 性别.无)
            {
                throw new Exception("未确定性别,无法计算天罗地网。");
            }

            string[] pattern = this.性别 == 性别.男 ? new string[] { "辰", "巳" } : new string[] { "戌", "亥" };
            var      res     = this.GZ.Select(gz => pattern.Any(p => p == gz.Zhi.Name) ? gz.Zhi.Name : string.Empty);

            res = res.Distinct();
            bool hasTianLuoDiWang = res.Count(b => b != string.Empty) >= 2;

            if (shiyun != null)
            {
                bool 是否符合流年 = pattern.Contains(shiyun.Zhi.Name);
                if (hasTianLuoDiWang)
                {
                    // 原局有天罗地网,流年要再碰到
                    return(是否符合流年 ? new string[0] : null);
                }
                else
                {
                    res = res.Concat(是否符合流年 ? new string[] { shiyun.Zhi.Name } : new string[0]);
                    res = res.Distinct();
                    return(res.Count(b => b != string.Empty) >= 2 ? new string[0] : null);
                }
            }
            else
            {
                return(hasTianLuoDiWang ? new string[0] : null);
            }
        }
Ejemplo n.º 2
0
        private static 忌日 Calc月破(LnDate date)
        {
            var 月 = new GanZhi(date.MonthGZ);
            var 日 = new GanZhi(date.DayGZ);

            return(Math.Abs(月.Zhi.Index - 日.Zhi.Index) == 6 ? LnBase.忌日.月破 : 忌日.百无禁忌);
        }
Ejemplo n.º 3
0
        private static 忌日 Calc岁破(LnDate date)
        {
            var 年 = new GanZhi(date.YearGZ);
            var 日 = new GanZhi(date.DayGZ);

            return(Math.Abs(年.Zhi.Index - 日.Zhi.Index) == 6 ? LnBase.忌日.岁破 : 忌日.百无禁忌);
        }
Ejemplo n.º 4
0
        private BaZiList <GanZhi> InitBaZiFromDateTime(DateTime date, bool 确定时辰)
        {
            this.datetime = new LnDate(date);
            this.time     = 确定时辰 ? date.TimeOfDay : TimeSpan.Zero;

            GanZhi 年 = new GanZhi(this.datetime.YearGZ);
            GanZhi 月 = new GanZhi(this.datetime.MonthGZ);
            GanZhi 日 = new GanZhi(this.datetime.DayGZ);

            LnDate 明天 = this.datetime.Add(1);

            if (date.Hour >= 23)
            {
                日 = 日.Add(1);
                年 = new GanZhi(明天.YearGZ);
                月 = new GanZhi(明天.MonthGZ);
            }

            GanZhi 时 = GanZhi.Zero;

            if (确定时辰)
            {
                Zhi 时支 = Zhi.Get((int)((date.Hour + 1) / 2) % 12);
                时 = 日.Gan.起月时(时支, 柱位.时);
            }

            return(BaZiList.Create(年, 月, 日, 时));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 计算胎元干支
        /// </summary>
        /// <returns></returns>
        private static GanZhi CalcTaiYuan(BaZiList <ShiYun> bazi)
        {
            var gan = (bazi.月.Gan.Index + 1) % 10;
            var zhi = (bazi.月.Zhi.Index + 3) % 12;
            var gz  = new GanZhi(gan, zhi);

            return(gz);
        }
Ejemplo n.º 6
0
 internal string[] Calc(GanZhi gz)
 {
     if (this.CalcSpec == null)
     {
         return(new string[] { Zhi.Get(this.Pattern[this.Fetch(gz)]).Name });
     }
     else
     {
         return(this.CalcSpec(gz));
     }
 }
Ejemplo n.º 7
0
        internal static string[] 贵人(GanZhi gz)
        {
            int[,] pattern = new int[10, 2] {
                { 1, 7 }, { 8, 0 }, { 11, 9 }, { 11, 9 }, { 1, 7 }, { 8, 0 }, { 2, 6 }, { 2, 6 }, { 3, 5 }, { 3, 5 }
            };

            List <int> res = new List <int>();

            res.Add(pattern[gz.Gan.Index, 0]);
            res.Add(pattern[gz.Gan.Index, 1]);

            return(res.Select(i => Zhi.Get(i).Name).ToArray());
        }
Ejemplo n.º 8
0
        public static HuangLi 黄历日(LnDate date)
        {
            HuangLi huanli = new HuangLi();

            huanli.忌日 |= LnBase.Calc岁破(date);
            huanli.忌日 |= LnBase.Calc月破(date);
            huanli.忌日 |= LnBase.Calc上朔(date);
            huanli.忌日 |= LnBase.Calc杨公忌日(date);

            GanZhi yue = new GanZhi(date.MonthGZ);
            GanZhi ri  = new GanZhi(date.DayGZ);

            huanli.建除 = JianChu.Get(yue.Zhi, ri.Zhi);
            return(huanli);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 计算年份下标差值
        /// </summary>
        /// <param name="year">要查找的年干支</param>
        /// <param name="startYear">开始的年份</param>
        /// <param name="forward">方向</param>
        /// <returns></returns>
        private static int CalcYearDiff(GanZhi year, int startYear, 方向 forward)
        {
            LnDate lndate   = new LnDate(startYear, 2, 10);
            int    yearDiff = year.Index - (new GanZhi(lndate.YearGZ)).Index;

            if (forward == 方向.逆行)
            {
                yearDiff = yearDiff < 0 ? yearDiff : (yearDiff - 60);
            }
            else
            {
                yearDiff = yearDiff < 0 ? (yearDiff + 60) : yearDiff;
            }

            return(yearDiff);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 用八字寻找公历时间。
        /// </summary>
        /// <param name="year">年干支</param>
        /// <param name="month">月干支</param>
        /// <param name="day">日干支</param>
        /// <param name="startYear">开始时间</param>
        /// <param name="forward">方向: -1 往以前日子, 1 往后面的日子</param>
        /// <returns></returns>
        public static DateTime 查找八字(string year, string month, string day, int startYear, 方向 forward)
        {
            // 看年月是否匹配
            GanZhi n = new GanZhi(year);
            GanZhi m = new GanZhi(month);

            if (n.Gan.起月时(m.Zhi, 柱位.月) != m)
            {
                throw new ArgumentException($"'{year}'年不存在'{month}'月。");
            }

            // 开始运算
            int yearDiff   = CalcYearDiff(new GanZhi(year), startYear, forward);
            int monthIndex = m.Zhi.Index == 0 ? 12 : m.Zhi.Index;

            startYear += m.Zhi.Index == 1 ? 1 : 0;

            // 上下搜索600年
            for (int periode = 0; periode < 10; periode++)
            {
                int    f      = forward == 方向.顺行 ? 1 : -1;
                LnDate lndate = new LnDate(startYear + yearDiff + f * 60 * periode, monthIndex, 1);
                while (lndate.JieQiTime == TimeSpan.Zero)
                {
                    lndate = lndate.Add(1);
                }

                if (lndate.YearGZ != year || lndate.MonthGZ != month)
                {
                    throw new Exception("计算思路有错误!");
                }

                while (lndate.MonthGZ == month)
                {
                    if (lndate.DayGZ == day)
                    {
                        return(lndate.datetime);
                    }

                    lndate = lndate.Add(1);
                }
            }

            throw new Exception("六百年内找不到结果!");
        }
Ejemplo n.º 11
0
        private IEnumerable <ShiYun> 起小运(DateTime start, DateTime end)
        {
            List <ShiYun> res = new List <ShiYun>();

            for (int year = start.Year; year <= end.Year; year++)
            {
                int diff = year - this.time.DateTime.Year + 1;
                int f    = this.方向 == 方向.顺行 ? 1 : -1;

                GanZhi gz      = this.time.时.Add(f * diff);
                ShiYun xiaoyun = new ShiYun(gz, ShiYun.YunType.小运, this.time.Bazi);
                xiaoyun.Start = new DateTime(year, this.time.DateTime.Month, this.time.DateTime.Day);
                xiaoyun.End   = new DateTime(year + 1, this.time.DateTime.Month, this.time.DateTime.Day);
                res.Add(xiaoyun);
            }

            return(res);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 计算命宫干支
        /// </summary>
        /// <returns></returns>
        private static GanZhi CalcMingGong(BaZiList <ShiYun> bazi)
        {
            if (bazi.时 == GanZhi.Zero)
            {
                return(GanZhi.Zero);
            }

            var sum = bazi.月.Zhi.Index + 1 + bazi.时.Zhi.Index + 1;
            var zhi = sum < 14 ? 14 - sum : 26 - sum;

            zhi = zhi - 1;
            var startGan = bazi.年.Gan.起月干.Index;

            var diff = ((zhi - 2) + 12) % 12;
            var gan  = (startGan + diff) % 10;

            var ganzhi = new GanZhi(gan, zhi);

            return(ganzhi);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 返回神煞的计算结果。
        /// 1. 对于地支类,返回一个字符串数组。
        /// 2. 对于布尔值类型,空数组代表“有”, Null代表“没有”
        /// </summary>
        /// <returns></returns>
        public string[] Calc(GanZhi shiyun = null)
        {
            GanZhi[] gzs = shiyun == null ? this.GZ : new GanZhi[] { shiyun };

            if (!this.ssBase.HasCalcFunc)
            {
                switch (this.Name)
                {
                case "四废":
                    return(this.四废(gzs));

                case "孤辰寡宿":
                    return(this.孤辰寡宿(gzs));

                case "阴差阳错":
                    return(ShenSha.阴差阳错(gzs));

                case "天罗地网":
                    return(this.天罗地网(shiyun));

                case "魁罡":
                    return(ShenSha.魁罡(gzs));
                }

                return(null);
            }
            else
            {
                List <string> res = new List <string>();
                foreach (var gz in gzs)
                {
                    var tmp = this.ssBase.Calc(gz);
                    res.AddRange(tmp);
                }

                return(res.Distinct().ToArray());
            }
        }
Ejemplo n.º 14
0
        public override bool Equals(object obj)
        {
            GanZhi gz = obj as GanZhi;

            return(obj is GanZhi && this.Name == gz.Name);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 甲年癸亥日,乙年己巳日。。。。。。
        /// var arr = ["癸亥", "己巳", "乙亥", "辛巳", "丁亥", "癸巳", "己亥", "乙巳", "辛亥", "丁巳"];
        /// </summary>
        /// <param name="date"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private static 忌日 Calc上朔(LnDate date)
        {
            var 年 = new GanZhi(date.YearGZ);

            return(LnBase.朔Def[年.Gan.Index] == date.DayGZ ? LnBase.忌日.朔 : 忌日.百无禁忌);
        }
Ejemplo n.º 16
0
 private static int 取干(GanZhi gz)
 {
     return(gz.Gan.Index);
 }
Ejemplo n.º 17
0
 internal static int  会局(GanZhi z)
 {
     return((int)(((z.Zhi.Index + 1) % 12) / 3));
 }
Ejemplo n.º 18
0
 public ShiYun(GanZhi gz, YunType type, BaZiList <GanZhi> bz) : this(gz.Index, type, bz)
 {
 }
Ejemplo n.º 19
0
        internal static string[] 旬空(GanZhi gz)
        {
            var index = 10 - (int)(gz.Index / 10) * 2;

            return(new string[] { Zhi.Get(index).Name, Zhi.Get(index + 1).Name });
        }
Ejemplo n.º 20
0
 internal static string[] 天医(GanZhi gz)
 {
     return(new string[] { Zhi.Get((gz.Zhi.Index - 1 + 12) % 12).Name });
 }
Ejemplo n.º 21
0
 internal static int  合局(GanZhi z)
 {
     return((z.Zhi.Index % 12) % 4);
 }