GeJuLogic.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. import Common
  2. from DataCenter import DataCenter
  3. from LocalModel import BaZi, SiZhuWeiZhi, GeJu, SiZhu, ZhenJia, ShiShenXiongJi, MangPaiGong
  4. def fill_geju(bazi: BaZi, dc: DataCenter):
  5. __fill_lushen(bazi)
  6. __check_zhenjia(bazi, dc)
  7. bazi.gejuInfo.shishen = []
  8. # 坐支
  9. __check_zuozhi(bazi)
  10. # 计算盲派功
  11. __check_mangpaigong(bazi)
  12. # buf
  13. __check_yinluxiangsui(bazi, dc)
  14. __check_shishenzhisha(bazi, dc)
  15. __check_shishangheyin(bazi, dc)
  16. __check_caiheyin(bazi, dc)
  17. __check_guanzhijiecai(bazi, dc)
  18. __check_guanyinxiangsheng(bazi, dc)
  19. __check_shayinxiangsheng(bazi, dc)
  20. __check_zihecaiguan(bazi, dc)
  21. # debuf
  22. __check_jiecaijiancai(bazi, dc)
  23. __check_jiecaiheqisha(bazi, dc)
  24. __check_shangguanjianguan(bazi, dc)
  25. __check_xiaoshenduoshi(bazi, dc)
  26. __check_qishagongshen(bazi, dc)
  27. __check_caisunyin(bazi, dc)
  28. __check_shangguanheqisha(bazi, dc)
  29. __check_shaxiaoxiangsha(bazi, dc)
  30. __check_durenfengchong(bazi, dc)
  31. def __fill_lushen(bazi: BaZi):
  32. for sz in bazi.sizhu_dizhis():
  33. if sz.isLuShen or sz.isBanLu:
  34. info = GeJu()
  35. if sz.weiZhi == SiZhuWeiZhi.nianzhi.value:
  36. info.key = "年禄"
  37. bazi.gejuInfo.nianlu = info
  38. elif sz.weiZhi == SiZhuWeiZhi.yuezhi.value:
  39. info.key = "建禄"
  40. bazi.gejuInfo.jianlu = info
  41. elif sz.weiZhi == SiZhuWeiZhi.rizhi.value:
  42. info.key = "专禄"
  43. bazi.gejuInfo.zhuanlu = info
  44. elif sz.weiZhi == SiZhuWeiZhi.shizhi.value:
  45. info.key = "归禄"
  46. bazi.gejuInfo.guiLu = info
  47. info.tip = Common.get_lushen_tip(info.key)
  48. if sz.findGaoNeng("冲") is not None:
  49. info.isChong = True
  50. if sz.findGaoNeng("穿") is not None:
  51. info.isChuan = True
  52. if sz.findGaoNeng("破") is not None:
  53. info.isPo = True
  54. if sz.findGaoNeng("合") is not None:
  55. info.isBaoHu = True
  56. if sz.isBanLu and bazi.gejuInfo.banlu is None:
  57. info1 = GeJu()
  58. info1.key = "半禄"
  59. info1.tip = Common.get_lushen_tip(info1.key)
  60. bazi.gejuInfo.banlu = info1
  61. def __check_zhenjia(bazi: BaZi, dc: DataCenter):
  62. # 虚实
  63. bazi.gejuInfo.xushi = Common.has_genqi(bazi.riGan.wuXing, bazi.riZhi.wuXing)
  64. # 真假
  65. bazi.gejuInfo.zhenjia = []
  66. for tg in bazi.sizhu_tiangans():
  67. zj = dc.genqi[tg.weiZhi]
  68. zhenjia = ZhenJia()
  69. zhenjia.key = tg.shiShen
  70. zhenjia.zhenValue = zj[0]
  71. zhenjia.jiaValue = zj[1]
  72. tips = Common.get_zhenjia(zhenjia.key)
  73. zhenjia.zhenTip = tips["真"]
  74. zhenjia.jiaTip = tips["假"]
  75. if not bazi.gejuInfo.hasKeyInZhenJiaList(zhenjia.key):
  76. bazi.gejuInfo.zhenjia.append(zhenjia)
  77. def __create_xiongji(key: str):
  78. data = Common.get_xiongji(key)
  79. obj = ShiShenXiongJi()
  80. obj.key = key
  81. obj.eft = data["eft"]
  82. obj.solve = data["solve"]
  83. return obj
  84. def __check_zuozhi(bazi: BaZi):
  85. ss = bazi.riZhi.getCangGanShiShens()
  86. if "劫" in ss:
  87. bazi.gejuInfo.zuozhi = "自坐劫财,易在配偶宫破财。劫财容易见利忘义,可共患难,不能同富贵。"
  88. elif "比" in ss:
  89. bazi.gejuInfo.zuozhi = "自坐比肩,得配偶真心相助。"
  90. def __check_mangpaigong(bazi: BaZi):
  91. bazi.gejuInfo.gong = MangPaiGong()
  92. bazi.gejuInfo.gong.he = bazi.countGaoNeng("合")
  93. bazi.gejuInfo.gong.po = bazi.countGaoNeng("破")
  94. # 计算日柱上自合产生的功
  95. # 注意,这里产生的自合仅用于计算盲派功,因此这个系数是固定的,和藏干那边的系数无关
  96. zihe = 0
  97. if bazi.riGan.text == "甲" and bazi.riZhi.text == "午":
  98. zihe = 0.5
  99. elif bazi.riGan.text == "戊" and bazi.riZhi.text == "子":
  100. zihe = 1
  101. elif bazi.riGan.text == "己" and bazi.riZhi.text == "亥":
  102. zihe = 0.5
  103. elif bazi.riGan.text == "辛" and bazi.riZhi.text == "巳":
  104. zihe = 0.7
  105. elif bazi.riGan.text == "壬" and bazi.riZhi.text == "午":
  106. zihe = 0.5
  107. elif bazi.riGan.text == "癸" and bazi.riZhi.text == "巳":
  108. zihe = 0.5
  109. elif bazi.riGan.text == "丙" and bazi.riZhi.text == "戌":
  110. if bazi.riZhi.muku is not None and bazi.riZhi.muku.isOpen is True:
  111. zihe = 0.2
  112. elif bazi.riGan.text == "壬" and bazi.riZhi.text == "戌":
  113. if bazi.riZhi.muku is not None and bazi.riZhi.muku.isOpen is True:
  114. zihe = 0.6
  115. bazi.gejuInfo.gong.zihe = zihe
  116. bazi.gejuInfo.gong.calcTotal()
  117. def __check_yinluxiangsui(bazi: BaZi, dc: DataCenter):
  118. # 有禄神,并且地支有印或枭
  119. key = "印禄相随"
  120. if dc.lushenAmount > 0 or dc.banluAmount > 0:
  121. if dc.has_shishen_in_dizhi(["印", "枭"]):
  122. xj = __create_xiongji(key)
  123. xj.isGood = True
  124. bazi.gejuInfo.shishen.append(xj)
  125. dc.xiongjiTexts.append(key)
  126. def __check_shishenzhisha(bazi: BaZi, dc: DataCenter):
  127. # 八字中带食神和七杀
  128. key = "食神制杀"
  129. if dc.has_all_shishen(["食", "杀"]):
  130. xj = __create_xiongji(key)
  131. xj.isGood = True
  132. p1 = dc.get_shishen_power("食")
  133. p2 = dc.get_shishen_power("杀")
  134. xj.tip = "食(" + str(p1) + ") 杀(" + str(p2) + ")"
  135. bazi.gejuInfo.shishen.append(xj)
  136. dc.xiongjiTexts.append(key)
  137. def __check_shishangheyin(bazi: BaZi, dc: DataCenter):
  138. # 八字中食伤和印枭相合
  139. key = "食伤合印"
  140. tips = []
  141. found = False
  142. if len(bazi.findGaoNengByGuanXis("食", "印", ["合", "半合", "拱合", "暗合"])) > 0:
  143. tips.append("食神合正印")
  144. found = True
  145. if len(bazi.findGaoNengByGuanXis("伤", "印", ["合", "半合", "拱合", "暗合"])) > 0:
  146. tips.append("伤官合正印")
  147. found = True
  148. if len(bazi.findGaoNengByGuanXis("食", "枭", ["合", "半合", "拱合", "暗合"])) > 0:
  149. tips.append("食神合偏印")
  150. found = True
  151. if len(bazi.findGaoNengByGuanXis("伤", "枭", ["合", "半合", "拱合", "暗合"])) > 0:
  152. tips.append("伤官合偏印")
  153. found = True
  154. if found is True:
  155. xj = __create_xiongji(key)
  156. xj.isGood = True
  157. xj.tip = ""
  158. for tp in tips:
  159. xj.tip += tp + " "
  160. bazi.gejuInfo.shishen.append(xj)
  161. dc.xiongjiTexts.append(key)
  162. def __check_caiheyin(bazi: BaZi, dc: DataCenter):
  163. # 八字中正偏财合正偏印
  164. key = "财合印"
  165. tips = []
  166. found = False
  167. if len(bazi.findGaoNengByGuanXis("财", "印", ["合", "半合", "拱合", "暗合"])) > 0:
  168. tips.append("正财合正印")
  169. found = True
  170. if len(bazi.findGaoNengByGuanXis("才", "印", ["合", "半合", "拱合", "暗合"])) > 0:
  171. tips.append("偏财合正印")
  172. found = True
  173. if len(bazi.findGaoNengByGuanXis("财", "枭", ["合", "半合", "拱合", "暗合"])) > 0:
  174. tips.append("正财合偏印")
  175. found = True
  176. if len(bazi.findGaoNengByGuanXis("才", "枭", ["合", "半合", "拱合", "暗合"])) > 0:
  177. tips.append("偏财合偏印")
  178. found = True
  179. if found is True:
  180. xj = __create_xiongji(key)
  181. xj.isGood = True
  182. xj.tip = ""
  183. for tp in tips:
  184. xj.tip += tp + " "
  185. bazi.gejuInfo.shishen.append(xj)
  186. dc.xiongjiTexts.append(key)
  187. def __check_guanzhijiecai(bazi: BaZi, dc: DataCenter):
  188. key = "官制劫财"
  189. if dc.has_all_shishen(["官", "劫"]):
  190. xj = __create_xiongji(key)
  191. xj.isGood = True
  192. p1 = dc.get_shishen_power("官")
  193. p2 = dc.get_shishen_power("劫")
  194. xj.tip = "官(" + str(p1) + ") 劫(" + str(p2) + ")"
  195. bazi.gejuInfo.shishen.append(xj)
  196. dc.xiongjiTexts.append(key)
  197. def __check_guanyinxiangsheng(bazi: BaZi, dc: DataCenter):
  198. key = "官印相生"
  199. tips = []
  200. found = False
  201. if len(bazi.findGaoNengByGuanXis("官", "印", ["合", "半合", "拱合", "暗合"])) > 0:
  202. tips.append("合正印")
  203. found = True
  204. if len(bazi.findGaoNengByGuanXis("官", "枭", ["合", "半合", "拱合", "暗合"])) > 0:
  205. tips.append("合偏印")
  206. found = True
  207. if found is True:
  208. xj = __create_xiongji(key)
  209. xj.isGood = True
  210. xj.tip = ""
  211. for tp in tips:
  212. xj.tip += tp + " "
  213. bazi.gejuInfo.shishen.append(xj)
  214. dc.xiongjiTexts.append(key)
  215. def __check_shayinxiangsheng(bazi: BaZi, dc: DataCenter):
  216. key = "杀印相生"
  217. tips = []
  218. found = False
  219. if len(bazi.findGaoNengByGuanXis("杀", "印", ["合", "半合", "拱合", "暗合"])) > 0:
  220. tips.append("合正印")
  221. found = True
  222. if len(bazi.findGaoNengByGuanXis("杀", "枭", ["合", "半合", "拱合", "暗合"])) > 0:
  223. tips.append("合偏印")
  224. found = True
  225. if found is True:
  226. xj = __create_xiongji(key)
  227. xj.isGood = True
  228. xj.tip = ""
  229. for tp in tips:
  230. xj.tip += tp + " "
  231. bazi.gejuInfo.shishen.append(xj)
  232. dc.xiongjiTexts.append(key)
  233. def __check_zihecaiguan(bazi: BaZi, dc: DataCenter):
  234. key = "自合财官"
  235. found = False
  236. tip = ""
  237. for gn in bazi.riGan.gaonengs:
  238. if gn.guanxi in ["合", "半合", "拱合", "暗合"]:
  239. if gn.shishen1 in ["官", "财", "才"]:
  240. found = True
  241. tip = "合" + gn.shishen1
  242. break
  243. if gn.shishen2 in ["官", "财", "才"]:
  244. found = True
  245. tip = "合" + gn.shishen2
  246. break
  247. if found is True:
  248. xj = __create_xiongji(key)
  249. xj.isGood = True
  250. xj.tip = tip
  251. bazi.gejuInfo.shishen.append(xj)
  252. dc.xiongjiTexts.append(key)
  253. def __check_jiecaijiancai(bazi: BaZi, dc: DataCenter):
  254. key = "劫财见财"
  255. if dc.has_shishen("劫"):
  256. if dc.has_shishen("财") or dc.has_shishen("才"):
  257. xj = __create_xiongji(key)
  258. xj.isGood = False
  259. if dc.has_xiongji("官制劫财"):
  260. xj.tip = " 官制劫财缓解"
  261. bazi.gejuInfo.shishen.append(xj)
  262. dc.xiongjiTexts.append(key)
  263. def __check_jiecaiheqisha(bazi: BaZi, dc: DataCenter):
  264. key = "劫财合七杀"
  265. lst = bazi.findGaoNengByShiShen("劫", "杀", "合")
  266. if len(lst):
  267. xj = __create_xiongji(key)
  268. xj.isGood = False
  269. xj.tip = ""
  270. if dc.has_xiongji("印禄相随"):
  271. xj.tip += " 印禄相随化解"
  272. if dc.has_xiongji("官制劫财"):
  273. xj.tip += " 官制劫财缓解"
  274. # 食神化杀
  275. bazi.gejuInfo.shishen.append(xj)
  276. dc.xiongjiTexts.append(key)
  277. def __check_shangguanjianguan(bazi: BaZi, dc: DataCenter):
  278. key = "伤官见官"
  279. if bazi.hasShiShen("伤"):
  280. if bazi.hasShiShen("官"):
  281. xj = __create_xiongji(key)
  282. xj.isGood = False
  283. bazi.gejuInfo.shishen.append(xj)
  284. dc.xiongjiTexts.append(key)
  285. def __check_xiaoshenduoshi(bazi: BaZi, dc: DataCenter):
  286. key = "枭神夺食"
  287. if bazi.hasShiShen("枭") and bazi.hasShiShen("食"):
  288. xj = __create_xiongji(key)
  289. xj.isGood = False
  290. p1 = bazi.getPowerOfShiShen("枭")
  291. p2 = bazi.getPowerOfShiShen("食")
  292. xj.tip = "枭(" + str(p1) + ") 食(" + str(p2) + ") "
  293. lst = bazi.findGaoNengByGuanXis("枭", "食", ["合", "半合", "拱合", "暗合"])
  294. if len(lst) > 0:
  295. xj.tip += " ,当前存在枭神合食神"
  296. if dc.has_xiongji("印禄相随"):
  297. xj.tip += " 印禄相随化解"
  298. dc.xiongjiTexts.append(key)
  299. bazi.gejuInfo.shishen.append(xj)
  300. def __check_qishagongshen(bazi: BaZi, dc: DataCenter):
  301. key = "七杀攻身"
  302. found = False
  303. for gn in bazi.riGan.gaonengs:
  304. if gn.shishen1 == "杀" or gn.shishen2 == "杀":
  305. found = True
  306. break
  307. if found is True:
  308. xj = __create_xiongji(key)
  309. xj.isGood = False
  310. p1 = dc.get_shishen_power("印")
  311. p2 = dc.get_shishen_power("食")
  312. p3 = dc.get_shishen_power("伤")
  313. p4 = dc.get_shishen_power("杀")
  314. xj.tip = "印(" + str(p1) + ") 食(" + str(p2) + ") 伤(" + str(p3) + ") 杀(" + str(p4) + ")"
  315. if dc.has_xiongji("印禄相随"):
  316. xj.tip += " 印禄相随化解"
  317. bazi.gejuInfo.shishen.append(xj)
  318. dc.xiongjiTexts.append(key)
  319. def __check_caisunyin(bazi: BaZi, dc: DataCenter):
  320. key = "财损印"
  321. p1 = bazi.getPowerOfShiShen("财")
  322. p2 = bazi.getPowerOfShiShen("才")
  323. p3 = bazi.getPowerOfShiShen("印")
  324. p4 = bazi.getPowerOfShiShen("枭")
  325. if p1 + p2 == 0:
  326. return
  327. if (p1 + p2) < (p3 + p4):
  328. xj = __create_xiongji(key)
  329. xj.isGood = False
  330. xj.tip = "财(" + str(p1) + ") 才(" + str(p2) + ") 印(" + str(p3) + ") 枭(" + str(p4) + ")"
  331. if dc.has_xiongji("财合印"):
  332. xj.tip += " 财合印化解"
  333. bazi.gejuInfo.shishen.append(xj)
  334. dc.xiongjiTexts.append(key)
  335. def __check_shangguanheqisha(bazi: BaZi, dc: DataCenter):
  336. key = "伤官合七杀"
  337. lst = bazi.findGaoNengByGuanXis("伤", "杀", ["合", "半合", "拱合", "暗合"])
  338. if len(lst) > 0:
  339. xj = __create_xiongji(key)
  340. xj.isGood = False
  341. p1 = dc.get_shishen_power("伤")
  342. p2 = dc.get_shishen_power("杀")
  343. xj.tip = "伤(" + str(p1) + ") 杀(" + str(p2) + ")"
  344. if dc.has_xiongji("印禄相随"):
  345. xj.tip += " 印禄相随化解"
  346. bazi.gejuInfo.shishen.append(xj)
  347. dc.xiongjiTexts.append(key)
  348. def __check_shaxiaoxiangsha(bazi: BaZi, dc: DataCenter):
  349. key = "杀枭相杀"
  350. if dc.has_xiongji("枭神夺食") and dc.has_xiongji("七杀攻身"):
  351. xj = __create_xiongji(key)
  352. xj.isGood = False
  353. if dc.has_xiongji("印禄相随"):
  354. xj.tip = " 印禄相随化解"
  355. bazi.gejuInfo.shishen.append(xj)
  356. dc.xiongjiTexts.append(key)
  357. def __check_durenfengchong(bazi: BaZi, dc: DataCenter):
  358. key = "独刃逢冲"
  359. tip = ""
  360. sz: SiZhu = None
  361. found = False
  362. for wz in bazi.shenshaInfo.fenbu:
  363. lst = bazi.shenshaInfo.fenbu[wz]
  364. for dt in lst:
  365. if dt.name == "羊刃":
  366. dz = __get_dizhi_weizhi(wz)
  367. if dz != SiZhuWeiZhi.unknown.value:
  368. gns = bazi.getZhuByWeiZhi(dz).gaonengs
  369. for gn in gns:
  370. if gn.guanxi == "冲":
  371. found = True
  372. sz = bazi.getZhuByWeiZhi(dz)
  373. if dz == SiZhuWeiZhi.nianzhi.value:
  374. tip += "年上犯冲 "
  375. elif dz == SiZhuWeiZhi.yuezhi.value:
  376. tip += "月上犯冲 "
  377. elif dz == SiZhuWeiZhi.rizhi.value:
  378. tip += "坐支犯冲 "
  379. elif dz == SiZhuWeiZhi.shizhi.value:
  380. tip += "时上犯冲 "
  381. if found is True and sz is not None:
  382. xj = __create_xiongji(key)
  383. xj.isGood = False
  384. xj.tip = tip
  385. bazi.gejuInfo.shishen.append(xj)
  386. dc.xiongjiTexts.append(key)
  387. def __get_dizhi_weizhi(zhuWeiZhi: int):
  388. if zhuWeiZhi == SiZhuWeiZhi.nianzhu.value:
  389. return SiZhuWeiZhi.nianzhi.value
  390. if zhuWeiZhi == SiZhuWeiZhi.yuezhu.value:
  391. return SiZhuWeiZhi.yuezhi.value
  392. if zhuWeiZhi == SiZhuWeiZhi.rizhu.value:
  393. return SiZhuWeiZhi.rizhi.value
  394. if zhuWeiZhi == SiZhuWeiZhi.shizhu.value:
  395. return SiZhuWeiZhi.shizhi.value
  396. return SiZhuWeiZhi.unknown.value