乱数でじゃんけんに勝つ
相手の傾向から次の勝利を予想する。
main.py
import random
gu = 0
choki = 0
pa = 0
num = 0
gu_p = 1
choki_p = 1
pa_p = 1
up_p = 0.1
dict = ['gu','cho','pa']
while True :
if num != 0:
res = input("勝or負(w / l) : ")
if res == 'w' or res == 'l':
pass
else:
res = random.choice(['w','l'])
if gu == 1:
gu = 0
if res == 'w':
gu_p += up_p
else:
if gu_p > up_p * 1.1:
gu_p -= up_p
else:
pass
elif choki == 1:
choki = 0
if res == 'w':
choki_p += up_p
else:
if choki_p > up_p * 1.1:
choki_p -= up_p
else:
pass
elif pa == 1:
pa = 0
if res == 'w':
pa_p += up_p
else:
if pa_p > up_p * 1.1:
pa_p -= up_p
else:
pass
else:
pass
w = [gu_p,choki_p,pa_p]
val = random.choices(dict, k = 1, weights = w)
val = val[0]
if val == 'gu':
gu += 1
print('グー')
elif val == 'cho':
choki += 1
print('チョキ')
elif val == 'pa':
pa += 1
print('パー')
else:
pass
#print([gu_p,choki_p,pa_p])
num += 1