import sys,time,random,webbrowser,os,datetime
#BaGua = ['乾','坤','坎','離','震','巽','艮','兌']
#GuaXian = ['天','地','水','火','雷','風','山','澤']
#Gua08 = ['☰','☷','☵','☲','☳','☴','☶','☱']
# Guadict = {'111':Gua08[0], '000':Gua08[1], '010':Gua08[2], '101':Gua08[3], '001':Gua08[4], '110':Gua08[5], '100':Gua08[6], '011':Gua08[7] }
Gua64 = {'000000':'䷁地地坤', '100000':'䷖山地剝', '010000':'䷇水地比', '110000':'䷓風地觀', '001000':'䷏雷地豫', '101000':'䷢火地晉', '011000':'䷬澤地萃', '111000':'䷋天地否',
'000100':'䷎地山謙', '100100':'䷳山山艮', '010100':'䷦水山蹇', '110100':'䷴風山漸', '001100':'䷽雷山小過','101100':'䷷火山旅', '011100':'䷞澤山咸', '111100':'䷠天山遯',
'000010':'䷆地水師', '100010':'䷃山水蒙', '010010':'䷜水水坎', '110010':'䷺風水渙', '001010':'䷧雷水解', '101010':'䷿火水未濟','011010':'䷮澤水困', '111010':'䷅天水訟',
'000110':'䷭地風升', '100110':'䷑山風蠱', '010110':'䷯水風井', '110110':'䷸風風巽', '001110':'䷟雷風恆', '101110':'䷱火風鼎', '011110':'䷛澤風大過','111110':'䷫天風姤',
'000001':'䷗地雷復', '100001':'䷚山雷頤', '010001':'䷂水雷屯', '110001':'䷩風雷益', '001001':'䷲雷雷震', '101001':'䷔火雷噬嗑','011001':'䷐澤雷隨', '111001':'䷘天雷无妄',
'000101':'䷣地火明夷','100101':'䷕山火賁', '010101':'䷾水火既濟','110101':'䷤風火家人','001101':'䷶雷火豐', '101101':'䷝火火離', '011101':'䷰澤火革', '111101':'䷌天火同人',
'000011':'䷒地澤臨', '100011':'䷨山澤損', '010011':'䷻水澤節', '110011':'䷼風澤中孚','001011':'䷵雷澤歸妹','101011':'䷥火澤睽', '011011':'䷹澤澤兌', '111011':'䷉天澤履',
'000111':'䷊地天泰', '100111':'䷙山天大畜','010111':'䷄水天需', '110111':'䷈風天小畜','001111':'䷡雷天大壯','101111':'䷍火天大有','011111':'䷪澤天夬', '111111':'䷀天天乾'
}
print('假爾泰筮有常,OOO今以某事,未知可否。爰質所疑於神之靈,吉凶、得失、悔吝、憂虞,惟爾有神,尚明告知。')
global Cho_Total
yao_=''
yao_2=''
Cho_Total=50 # 籌策數為50
Gua_res = []
def buyao():
Cho_amount=Cho_Total-1 #取出一根籌策定作太極
bias1=random.randint(0,9)
bias2=random.randint(0,9)
time.sleep(random.randint(0,1))
Cho_Left= random.randint(Cho_amount//2-bias1,Cho_amount//2+bias2) #把籌策分成左右兩堆
Cho_Right=Cho_amount-Cho_Left
Cho_Left=Cho_Left-1 #從左邊的籌策中取出一根
Cho_Left_Quotient= Cho_Left//4 #左邊組數
Cho_Left_Remainder= Cho_Left%4 #左邊餘下籌策數
Cho_Right_Quotient= Cho_Right//4 #右邊組數
Cho_Right_Remainder= Cho_Right%4 #右邊餘下籌策數
if Cho_Left_Remainder == 0:
Cho_Left_Remainder=4 #若整除須取4根
Cho_Left_Quotient=Cho_Left_Quotient-1 #且組數少1
if Cho_Right_Remainder == 0:
Cho_Right_Remainder=4 #若整除須取4根
Cho_Right_Quotient=Cho_Right_Quotient-1 #且組數少1
#將餘下的籌策數放在左前方
Cho_amount=Cho_amount-(Cho_Left_Remainder+Cho_Right_Remainder+1)
bias1=random.randint(0,9)
bias2=random.randint(0,9)
time.sleep(random.randint(0,1))
Cho_Left= random.randint(Cho_amount//2-bias1,Cho_amount//2+bias2) #把籌策分成左右兩堆
Cho_Right=Cho_amount-Cho_Left
Cho_Left=Cho_Left-1 #從左邊的籌策中取出一根
Cho_Left_Quotient= Cho_Left//4 #左邊組數
Cho_Left_Remainder= Cho_Left%4 #左邊餘下籌策數
Cho_Right_Quotient= Cho_Right//4 #右邊組數
Cho_Right_Remainder= Cho_Right%4 #右邊餘下籌策數
if Cho_Left_Remainder == 0:
Cho_Left_Remainder=4 #若整除須取4根
Cho_Left_Quotient=Cho_Left_Quotient-1 #且組數少1
if Cho_Right_Remainder == 0:
Cho_Right_Remainder=4 #若整除須取4根
Cho_Right_Quotient=Cho_Right_Quotient-1 #且組數少1
#將餘下的籌策數放在左前方
Cho_amount=Cho_amount-(Cho_Left_Remainder+Cho_Right_Remainder+1)
bias1=random.randint(0,9)
bias2=random.randint(0,9)
time.sleep(random.randint(0,1))
Cho_Left= random.randint(Cho_amount//2-bias1,Cho_amount//2+bias2) #把籌策分成左右兩堆
Cho_Right=Cho_amount-Cho_Left
Cho_Left=Cho_Left-1 #從左邊的籌策中取出一根
Cho_Left_Quotient= Cho_Left//4 #左邊組數
Cho_Left_Remainder= Cho_Left%4 #左邊餘下籌策數
Cho_Right_Quotient= Cho_Right//4 #右邊組數
Cho_Right_Remainder= Cho_Right%4 #右邊餘下籌策數
if Cho_Left_Remainder == 0:
Cho_Left_Remainder=4 #若整除須取4根
Cho_Left_Quotient=Cho_Left_Quotient-1 #且組數少1
if Cho_Right_Remainder == 0:
Cho_Right_Remainder=4 #若整除須取4根
Cho_Right_Quotient=Cho_Right_Quotient-1 #且組數少1
res=str(int(Cho_Left_Quotient+Cho_Right_Quotient))
return res
TimeStamp=datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')
for i in range(6) :
print('請卜第'+str(i+1)+'個爻:') #模擬用籌策卜爻
keystroke=input()
yao=buyao()
if yao=='9' :
sign=' *'
yao_r='1'
yao_r2='0'
elif yao=='6' :
sign=' *'
yao_r='0'
yao_r2='1'
elif int(yao)%2==0:
sign=' '
yao_r='0'
yao_r2='0'
elif int(yao)%2==1:
sign=' '
yao_r='1'
yao_r2='1'
print('第'+str(i+1)+'個爻是'+yao+sign)
yao_=yao_r+yao_
yao_2=yao_r2+yao_2
result_o=str(Gua64.get(yao_,0))
result_v=str(Gua64.get(yao_2,0))
print('主卦是: '+result_o+' 之卦是: '+result_v) #印出結果
recfile=open('C:\\PythonLab\\rec\\rec.csv','a',encoding='utf8') #留下歷史紀錄檔案
recfile.write(TimeStamp+','+result_o+','+result_v+'\n')
recfile.close()
webbrowser.open('http://zh.wikisource.org/wiki/周易/'+result_o[3:9].rstrip()) #查詢正卦解釋
webbrowser.open('http://zh.wikisource.org/wiki/周易/'+result_v[3:9].rstrip()) #查詢之卦解釋
沒有留言:
張貼留言