-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
331 lines (294 loc) · 8.26 KB
/
utils.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
from GUA import GUA
from XIANG import XIANG
from YAO import YAO
from enums import Earth, PropertyPair, Reps, Sky, Soul
# 本卦推变卦
def deriveChange(xiang:XIANG):
if xiang.flag == 1:
change = GUA()
xiang.change = change
change.yaos = [YAO() for _ in range(6)]
for i in range(len(xiang.base.yaos)):
if xiang.base.yaos[i].feature == 0:
change.yaos[i].feature = 0
change.yaos[i].essence = (xiang.base.yaos[i].essence+1)%2
else:
change.yaos[i].feature = 1
change.yaos[i].essence = xiang.base.yaos[i].essence
# 寻世应
def seekForEgo(xiang:XIANG):
base = xiang.base
yaos = base.yaos
s = False
h = False
e = False
if yaos[0].essence == yaos[3].essence:
e = True
if yaos[1].essence == yaos[4].essence:
h = True
if yaos[2].essence == yaos[5].essence:
s = True
if s and h and e:
yaos[5].ego = 1
yaos[2].other = 1
if not (s or h or e):
yaos[2].ego = 1
yaos[5].other = 1
if s and not h and not e:
yaos[1].ego = 1
yaos[4].other = 1
if not s and h and e:
yaos[4].ego = 1
yaos[1].other = 1
if not s and not h and e:
yaos[3].ego = 1
yaos[0].other = 1
if s and h and not e:
yaos[0].ego = 1
yaos[3].other = 1
if not s and h and not e:
yaos[3].ego = 1
yaos[0].other = 1
if s and not h and e:
yaos[2].ego = 1
yaos[5].other = 1
# 纳甲
def matchSkyandEarch(xiang:XIANG):
base = xiang.base
innerMatch(base)
outerMatch(base)
if xiang.flag == 1:
change = xiang.change
innerMatch(change)
outerMatch(change)
def innerMatch(g:GUA):
sum = 0
yaos = g.yaos
# 计算卦宫
for i in range(3):
if yaos[i].essence == 1:
sum += 2**i
starting_point = getStartingPoint(sum, 0)
jia = sort(starting_point, sum)
yaos[0].najia = jia[0]
yaos[1].najia = jia[1]
yaos[2].najia = jia[2]
def outerMatch(g:GUA):
sum = 0
yaos = g.yaos
# 计算卦宫
for i in range(3,6):
if yaos[i].essence == 1:
sum += 2**(i-3)
starting_point = getStartingPoint(sum, 1)
jia = sort(starting_point, sum)
yaos[3].najia = jia[0]
yaos[4].najia = jia[1]
yaos[5].najia = jia[2]
def getStartingPoint(sum, in_or_out):
# in=0, out=1
# 乾7坎2艮4震1巽6离5坤0兑3
match sum:
case 0:
if in_or_out == 0:
return [Sky.YI, Earth.WEI]
else:
return [Sky.GUI, Earth.CHOU]
case 1:
if in_or_out == 0:
return [Sky.GENG, Earth.ZI]
else:
return [Sky.GENG, Earth.WU]
case 2:
if in_or_out == 0:
return [Sky.WU, Earth.YIN]
else:
return [Sky.WU, Earth.SHEN]
case 3:
if in_or_out == 0:
return [Sky.DING, Earth.SI]
else:
return [Sky.DING, Earth.HAI]
case 4:
if in_or_out == 0:
return [Sky.BING, Earth.CHEN]
else:
return [Sky.BING, Earth.XU]
case 5:
if in_or_out == 0:
return [Sky.JI, Earth.MAO]
else:
return [Sky.JI, Earth.YOU]
case 6:
if in_or_out == 0:
return [Sky.XIN, Earth.CHOU]
else:
return [Sky.XIN, Earth.WEI]
case 7:
if in_or_out == 0:
return [Sky.JIA, Earth.ZI]
else:
return [Sky.REN, Earth.WU]
case _:
return [Sky.REN, Earth.WU]
def sort(starting_point, sum):
jia1 = [starting_point[0]]
jia2 = [starting_point[0]]
jia = [starting_point, jia1, jia2]
earth = starting_point[1]
enum = list(Earth.__members__.values())
starting_index = enum.index(earth)
# 7\2\4\1顺序,6\5\0\3逆序
if sum in [1,2,4,7]:
e1 = (starting_index + 2)%12
e2 = (starting_index + 4)%12
else:
e1 = (starting_index - 2)%12
e2 = (starting_index - 4)%12
earth1 = Earth(enum[e1])
earth2 = Earth(enum[e2])
jia1.append(earth1)
jia2.append(earth2)
return jia
# 寻六亲
def seekForReps(xiang:XIANG):
xiang.origin = seekForOrigin(xiang.base)
property = 5
# 乾、兑属金
if xiang.origin in [7, 3]:
property = 0
# 坎属水
elif xiang.origin in [2]:
property = 1
# 艮、坤属土
elif xiang.origin in [4, 0]:
property = 2
# 震、巽属木
elif xiang.origin in [1, 6]:
property = 3
# 离属火
else:
property = 4
for yao in xiang.base.yaos:
findReps(property, yao)
if xiang.flag == 1:
for yao in xiang.change.yaos:
findReps(property, yao)
def seekForOrigin(g:GUA):
yaos = g.yaos
s = (yaos[2].essence==yaos[5].essence)
h = (yaos[1].essence==yaos[4].essence)
e = (yaos[0].essence==yaos[3].essence)
# 乾7坎2艮4震1巽6离5坤0兑3
sum = 0
if s and not h and e:
for i in range(3):
if yaos[i].essence == 1:
sum += 2**i
else:
ego = 0
for i in range(6):
if yaos[i].ego == 1:
ego = i
break
if ego <= 2:
for i in range(3):
if yaos[i+3].essence == 1:
sum += 2**i
else:
for i in range(3):
if yaos[i].essence == 0:
sum += 2**i
return sum
def findReps(property, yao:YAO):
# 金0木3水1火4土2
earth = yao.najia[1]
pair = [property, earth]
if pair in PropertyPair.GUAN.value:
yao.representation = Reps.GUAN
elif pair in PropertyPair.QI.value:
yao.representation = Reps.QI
elif pair in PropertyPair.XIONG.value:
yao.representation = Reps.XIONG
elif pair in PropertyPair.FU.value:
yao.representation = Reps.FU
else:
yao.representation = Reps.ZI
# 缺六亲
def seekForDefects(xiang:XIANG):
base = xiang.base
reps_set = set()
for y in base.yaos:
reps_set.add(y.representation)
all_reps = {Reps.FU, Reps.GUAN, Reps.XIONG, Reps.ZI, Reps.QI}
xiang.defects = list(all_reps-reps_set)
# 寻六神
def seekForSouls(xiang:XIANG):
sky = xiang.day[0]
origin_soul = None
if sky in [Sky.JIA, Sky.YI]:
origin_soul = Soul.LONG
elif sky in [Sky.BING, Sky.DING]:
origin_soul = Soul.QUE
elif sky in [Sky.WU]:
origin_soul = Soul.CHEN
elif sky in [Sky.JI]:
origin_soul = Soul.SHE
elif sky in [Sky.GENG, Sky.XIN]:
origin_soul = Soul.HU
else:
origin_soul = Soul.WU
enum = list(Soul.__members__.values())
starting_index = enum.index(origin_soul)
yaos = xiang.base.yaos
yaos[0].soul = origin_soul
for i in range(1, 6):
yaos[i].soul = Soul(enum[(starting_index+i)%6])
# 输出
def show(xiang:XIANG):
showDate(xiang)
base = xiang.base
showGUA(base)
if xiang.flag == 1:
print('')
print('~~~~~~~~~~')
print('')
change = xiang.change
showGUA(change)
print('缺六亲:'+str([d.value for d in xiang.defects]))
def showDate(xiang:XIANG):
year = xiang.year
month = xiang.month
day = xiang.day
hour = xiang.hour
lacks = xiang.lacks
date = ''
date += year[0].value + year[1].value + '年,'
date += month[0].value + month[1].value + '月,'
date += day[0].value + day[1].value + '日,'
date += hour[0].value + hour[1].value + '时 '
date += '空亡:' + lacks[0].value + lacks[1].value
print(date)
def showGUA(g:GUA):
for i in range(5, -1, -1):
y = g.yaos[i]
showYAO(y)
def showYAO(y:YAO):
line = ''
if y.soul != None:
line += y.soul.value
line += ' '
line += y.representation.value
line += y.najia[0].value
line += y.najia[1].value
if y.essence == 0:
line += '---- ----'
else:
line += '----------'
if y.feature == 0:
line += ' 变'
if y.ego == 1:
line += ' 世'
if y.other == 1:
line += ' 应'
print(line)