用python写了下理想情况下铁血打捞的情况

修改于2020/04/191161 浏览综合
TapTap
本人从池子刷新到现在,共进行了22次打捞,结果18次遇到3个1星,4次遇到2个1星和1个2星,遇到2星打捞成功0次,最终结果如图。
理想情况下指的是所有铁血的出现概率相等,例如有100只铁血,则每只出现的概率均为100%/100。在理想情况下刷出3只1星的概率是:(x*(x-1)*(x-2))/(y*(y-1)*(y-2)),x,y分别代表1星剩余数和总剩余数
代码如下:建议运行方式 python 文件路径\文件名.py>文件路径\输出文件名.txt
from random import randint
N,R,SR=71,28,1
ALL=N+R+SR
Rand_1,Rand_2,Rand_3=0,0,0
temp_msg=''
cost=0
def wave_fresh():
global N,R,SR,ALL
global Rand_1,Rand_2,Rand_3
global temp_msg
global cost
if ALL>=1:
Rand_1=randint(1,ALL)
if Rand_1<=N:
temp_msg +='\n第'+str(cost+1)+'轮 '+'1:☆ '
elif Rand_1<=N+R:
temp_msg += '\n第'+str(cost+1)+'轮 '+'1:☆☆ '
else:
temp_msg += '\n第'+str(cost+1)+'轮 '+'1:☆☆☆ '
if ALL>=2:
Rand_2=randint(1,ALL)
while Rand_2==Rand_1:
Rand_2=randint(1,ALL)
if Rand_2<=N:
temp_msg += '2:☆ '
elif Rand_2<=N+R:
temp_msg += '2:☆☆ '
else:
temp_msg += '2:☆☆☆ '
if ALL>=3:
Rand_3=randint(1,ALL)
while Rand_3==Rand_2 or Rand_3==Rand_1:
Rand_3=randint(1,ALL)
if Rand_3<=N:
temp_msg += '3:☆ '
elif Rand_3<=N+R:
temp_msg += '3:☆☆ '
else:
temp_msg += '3:☆☆☆ '
print(temp_msg)
temp_msg=''
def RST(x):
Result=randint(1,100)
if Result<=x:
return True
else:
return False
def capture(a,b,c):
global N,R,SR,ALL
global temp_result
global cost
wave=[a,b,c]
temp=0
Result=False
#temp=eval(input('选择捕获目标:'))
if a>b and a>c:
temp=1
elif b>a and b>c:
temp=2
else:
temp=3
if temp>0:
try:
if wave[temp-1]<=N:
Result = RST(100);
N-=1
elif wave[temp-1]<=N+R:
Result = RST(50)
if Result==True:
R-=1
else:
Result = RST(25)
if Result==True:
SR-=1
except:
Result=False
if Result==True:
print('捕获成功。')
else:
print('捕获失败。')
cost+=1
ALL = N + R + SR
print('残余 N:',N,' R:',R,' SR:',SR,' ALL:',ALL)
def main():
global ALL
global Rand_1,Rand_2,Rand_3
global temp_result
wave_fresh()
capture(Rand_1,Rand_2,Rand_3)
if ALL>0:
#cont=eval(input('是否继续(1/default):'))
cont=1
if cont==1:
Rand_1,Rand_2,Rand_3=0,0,0
return main()
print('\n花费:',cost)
main()
27
3
20