python_apps/TheChanges/main.py
2023-11-03 14:49:12 +09:00

114 lines
3.5 KiB
Python

import random
def byun(hyo):
randmin = (hyo//2) - 10
randmax = (hyo//2) + 10
left = random.randrange(randmin, randmax)
right = hyo - left
human = 1
right = right - human
left_tmp = left % 4
if left_tmp == 0:
left_tmp = 4
human = human + left_tmp
right_tmp = right % 4
if right_tmp == 0:
right_tmp = 4
human = human + right_tmp
return human
def decidehyo(r1,r2,r3):
objList = [r1, r2, r3]
number = (49 - (r1 + r2 + r3))//4
db = [{'name':'소양','values': [[9, 4, 8], [9, 8, 4], [5, 8, 8]]},
{'name':'소음','values': [[5, 4, 8], [5, 8, 4], [9, 4, 4]]},
{'name':'노양','values': [[5, 4, 4]]},
{'name':'노음','values': [[9, 8, 8]]}]
hyoname = ''
for i in range(len(db)):
for j in range(len(db[i]['values'])):
if objList == db[i]['values'][j]:
hyoname = db[i]['name']
shape = {'소양':'=======', '소음': '=== ===',
'노양': 'ㅁㅁㅁㅁㅁ', '노음': 'xxx xxx'}
res = {'name': hyoname, 'remains': objList, 'shape': shape[hyoname], 'number': number}
return res
def findbyunhyo(res):
tmp = 0
for i in range(len(res)):
tmp = tmp + res[i]['number']
no = 55 - tmp
byunhyo = [{'chhyo':0,'noar':[1,12,13]},
{'chhyo':1,'noar':[2,11,14]},
{'chhyo':2,'noar':[3,10,15]},
{'chhyo':3,'noar':[4,9,16]},
{'chhyo':4,'noar':[5,8,17]},
{'chhyo':5,'noar':[6,7,18,19]}]
for i in range(len(byunhyo)):
if no in byunhyo[i]['noar']:
chhyo = byunhyo[i]['chhyo']
return chhyo
def finalizeHyo(res,bynhyo):
numberlist = [res[0]['number'],res[1]['number'],res[2]['number'],res[3]['number'],res[4]['number'],res[5]['number']]
enablech = numberlist.count(6) + numberlist.count(9) #可變之爻
for i in range(len(res)):
if res[i]['number'] == 6:
res[i]['shape'] = '=== ==='
if res[i]['number'] == 9:
res[i]['shape'] = '======='
if enablech in [1, 2]:
if res[bynhyo]['number'] in [6,9]:
for i in range(len(res)):
if res[i]['number'] == 6:
res[i]['shape'] = '======='
if res[i]['number'] == 9:
res[i]['shape'] = '=== ==='
if enablech in [3, 4, 5]:
if res[bynhyo]['number'] in [6, 9]:
for i in range(len(res)):
if res[i]['number'] == 6:
res[i]['shape'] = '======='
if res[i]['number'] == 9:
res[i]['shape'] = '=== ==='
if enablech == 6:
for i in range(len(res)):
if res[i]['number'] == 6:
res[i]['shape'] = '======='
if res[i]['number'] == 9:
res[i]['shape'] = '=== ==='
return res
if __name__ == '__main__':
res = []
for i in range(6):
# 제1변
sangaji = 50
taegeuk = 1
hyo = sangaji - taegeuk
remains1 = byun(hyo)
#제2변
hyo = hyo - remains1
remains2 = byun(hyo)
#제3변
hyo = hyo - remains2
remains3 = byun(hyo)
res.append(decidehyo(remains1,remains2,remains3))
#res.reverse()
#for i in range(len(res)):
# print(res[i])
for i in reversed(res):
print(i)
byunhyo = findbyunhyo(res)
print('宜變之爻 : ' + str(byunhyo + 1))
rres = finalizeHyo(res, byunhyo)
for i in reversed(rres):
print(i)