forked from shanzhengliu/MeihuaPredict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredict.py
302 lines (241 loc) · 8.27 KB
/
predict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# -*- coding: utf-8 -*-
CODES = ['UTF-8', 'UTF-16', 'GB18030', 'BIG5']
UTF_8_BOM = b'\xef\xbb\xbf'
def string_encoding(b):
for code in CODES:
try:
b.decode(encoding=code)
if 'UTF-8' == code and b.startswith(UTF_8_BOM):
return 'UTF-8-SIG'
return code
except Exception:
continue
return '未知的字符编码类型'
def get_key(dict, value):
return [k for k, v in dict.items() if v == value]
def change_str(str,pos):
l=list(str);
if(l[pos]=="0"):
l[pos]="1";
else:
l[pos] = "0";
newStr ="".join(l);
return newStr;
def wuhangshengkepanduan(wuhangshuA,wuhangshuB):
wuhangzifu = wuhangshuA+wuhangshuB;
shengkejieguo = wuhangshengke[wuhangzifu];
return shengkejieguo;
def baguaguaci(baguashuA,baguashuB):
guaxiang = str(baguashuA)+str(baguashuB);
result = baguaguaxiang[guaxiang];
return result;
baguashu = {
"乾":1,
"兑":2,
"离":3,
"震":4,
"巽":5,
"坎":6,
"艮":7,
"坤":0
}
baguaguaxiang = {
"11":"乾为天:乾卦:刚健中正",
"12":"天泽履:履卦:脚踏实地",
"13":"天火同人:同人卦:上下和同",
"14":"天雷无妄:无妄卦:无妄而得",
"15":"天风姤:姤卦:天下有风",
"16":"天水讼:讼卦:慎争戒讼",
"17":"天山遁:遁卦:遁世救世",
"10":"天地否:否卦:不交不通",
"21":"泽天夬:夬卦:决而能和",
"22":"兑为泽:兑卦:刚内柔外",
"23":"泽火革:革卦:顺天应人",
"24":"泽雷随:随卦:随时变通",
"25":"泽风大过:大过卦:非常行动",
"26":"泽水困:困卦:困境求通",
"27":"泽山咸:咸卦:相互感应",
"20":"泽地萃:萃卦:荟萃聚集",
"31":"火天大有:大有卦:顺天依时",
"32":"火泽睽:睽卦:异中求同",
"33":"离卦:离为火:附和依托",
"34":"火雷噬嗑:噬嗑卦:刚柔相济",
"35":"火风鼎:鼎卦:稳重图变",
"36":"火水未济:未济卦:事业未竟",
"37":"火山旅:旅卦:依义顺时",
"30":"地火晋:晋卦:求进发展",
"41":"雷天大壮:大壮卦:状勿妄动",
"42":"雷泽归妹:归妹卦:立家兴业",
"43":"雷火丰:丰卦:日中则斜",
"44":"震为雷:震卦:临危不乱",
"45":"雷风恒:恒卦:恒心有成",
"46":"雷水解:解卦:柔道致治",
"47":"雷山小过:小过卦:行动有度",
"40":"雷地豫:豫卦:顺时依势",
"51":"风天小畜:小畜卦:蓄养待进",
"52":"风泽中孚:中孚卦:诚信立身",
"53":"风火家人:家人卦:诚威治业",
"54":"风雷益:益卦:损上益下",
"55":"巽为风:巽卦:谦逊受益",
"56":"风水涣:涣卦:拯救涣散",
"57":"风山渐:渐卦:渐进蓄德",
"50":"风地观:观卦:观下瞻上",
"61":"水天需:需卦:守正待机",
"62":"水泽节:节卦:万物有节",
"63":"水火既济:既济卦:盛极将衰",
"64":"水雷屯:屯卦:起始维艰",
"65":"水风井:井卦:求贤若渴",
"66":"坎为水:坎卦:行险用险",
"67":"水山蹇: 蹇卦:险阻在前",
"60":"水地比:比卦:诚信团结",
"71":"山天大畜:大畜卦:止而不止",
"72":"山泽损:损卦:损益制衡",
"73":"山火贲: 贲卦:饰外扬质",
"74":"山雷颐: 颐卦:纯正以养",
"75":"山风蛊:蛊卦:振疲起衰",
"76":"山水蒙:蒙卦:启蒙奋发",
"77":"艮为山:艮卦:动静适时",
"70":"山地剥:剥卦:顺势而止",
"01":"地天泰:泰卦:应时而变",
"02":"地泽临:临卦:教民保民",
"03":"地火明夷:明夷卦:晦而转明",
"04":"地雷复:复卦:寓动于顺",
"05":"地风升:升卦:柔顺谦虚",
"06":"地水师:师卦:行险而顺",
"07":"地山谦:谦卦:内高外低",
"00":"坤为地:坤卦:柔顺伸展",
}
bagua = {
"乾": "111",
"兑": "011",
"离": "101",
"震": "001",
"巽": "110",
"坎": "010",
"艮": "100",
"坤": "000"
}
wuhangbagua = {
"乾": "金",
"兑": "金",
"离": "火",
"震": "木",
"巽": "木",
"坎": "水",
"艮": "土",
"坤": "土"
}
wuhangshu = {
"金":"1",
"木":"2",
"水":"3",
"土":"4",
"火":"5"
}
wuhangshengke = {
"11":"比和",
"12":"克",
"13":"生",
"14":"被生",
"15":"被克",
"21":"被克",
"22":"比和",
"23":"被生",
"24":"克",
"25":"生",
"31":"被生",
"32":"生",
"33":"比和",
"34":"被克",
"35":"克",
"41":"生",
"42":"被克",
"43":"克",
"44":"比和",
"45":"被生",
"51":"克",
"52":"被生",
"53":"被克",
"54":"生",
"55":"比和"
}
yuanshubagua = {
"乾": "天",
"兑": "泽",
"离": "火",
"震": "雷",
"巽": "风",
"坎": "水",
"艮": "山",
"坤": "地"
}
shanggua = input("输入上卦数:")
xiagua =input("输入下卦数:")
dongyao = input("请输入动爻数:")
shanggua = shanggua%8;
xiagua = xiagua%8;
dongyao = dongyao%6;
shangbenguawuhang = wuhangbagua[get_key(baguashu,shanggua)[0]];
xiabenguawuhang = wuhangbagua[get_key(baguashu,xiagua)[0]];
shangbengua = get_key(baguashu,shanggua)[0]+" 五行为:" +shangbenguawuhang;
xiabengua = get_key(baguashu,xiagua)[0]+" 五行为:" +xiabenguawuhang;
bengua = bagua[get_key(baguashu, shanggua)[0]] + bagua[get_key(baguashu, xiagua)[0]];
# bagua[get_key(bagua,get_key(baguashu,xiagua)[0])[0]];
shanghuguawuhang = wuhangbagua[get_key(bagua, bengua[1:4])[0]];
xiahuguawuhang = wuhangbagua[get_key(bagua, bengua[2:5])[0]];
shanghuguaguaming = get_key(bagua, bengua[1:4])[0];
xiahuguaguaming = get_key(bagua, bengua[2:5])[0]
shanghugua = get_key(bagua, bengua[1:4])[0]+" 五行为:"+shanghuguawuhang;
xiahugua = get_key(bagua, bengua[2:5])[0]+" 五行为:"+xiahuguawuhang;
changpos = 6-dongyao;
if(changpos==6):
changpos=0;
biangua = change_str(bengua, changpos);
shangbianguawuhang = wuhangbagua[get_key(bagua, biangua[0:3])[0]];
xiabianguawuhang = wuhangbagua[get_key(bagua, biangua[3:6])[0]];
shangbianguaguaming = get_key(bagua, biangua[0:3])[0];
xiabianguaguaming =get_key(bagua, biangua[3:6])[0];
shangbiangua = get_key(bagua, biangua[0:3])[0]+" 五行为:"+shangbianguawuhang;
xiabiangua = get_key(bagua, biangua[3:6])[0]+" 五行为:"+xiabianguawuhang;
shangtiyong = "";
if(shangbengua == shangbiangua):
shangtiyong = "体";
xiatiyong = "用";
print "上体下用"
else:
shangtiyong = "用";
xiatiyong = "体";
print "下体上用"
dingbenguawuhang = "";
dingbengua = "";
Yongbengua = "";
Yongbenguawuhang = "";
if (shangtiyong == "体"):
dingbenguawuhang = shangbenguawuhang;
dingbengua = shangbengua;
Yongbengua = xiabengua;
Yongbenguawuhang = xiabenguawuhang;
else:
dingbenguawuhang = xiabenguawuhang;
dingbengua = xiabengua;
Yongbengua = shangbengua;
Yongbenguawuhang = shangbenguawuhang;
print "本卦如下:";
print "上卦为:"+shangbengua+" "+shangtiyong;
print "下卦为:"+xiabengua+" "+xiatiyong;
print "体用关系:"+wuhangshengkepanduan(wuhangshu[dingbenguawuhang],wuhangshu[Yongbenguawuhang])
print "六十四卦卦辞:"+baguaguaci(shanggua,xiagua)+"\n"
print "互卦如下:";
print "上互卦为:"+shanghugua+" "+"用";
print "体用关系: "+wuhangshengkepanduan(wuhangshu[dingbenguawuhang],wuhangshu[shanghuguawuhang]);
print "下互卦为:"+xiahugua+" "+"用";
print "体用关系: "+wuhangshengkepanduan(wuhangshu[dingbenguawuhang],wuhangshu[xiahuguawuhang]);
print "六十四卦卦辞:"+baguaguaci(baguashu[shanghuguaguaming],baguashu[xiahuguaguaming])+"\n"
print "变卦如下: ";
print "上变卦为:"+shangbiangua+" "+shangtiyong;
if(shangtiyong == "用"):
print "体用关系: "+wuhangshengkepanduan(wuhangshu[dingbenguawuhang],wuhangshu[shangbianguawuhang]);
print "下变卦为:"+xiabiangua+" "+xiatiyong;
if(xiatiyong == "用"):
print "体用关系: "+wuhangshengkepanduan(wuhangshu[dingbenguawuhang],wuhangshu[xiabianguawuhang]);
print "六十四卦卦辞:"+baguaguaci(baguashu[shangbianguaguaming],baguashu[xiabianguaguaming])+"\n"