概述
PRD介绍
PRD伪随机算法多用于游戏中,主要用于减弱真随机算法带来的运气成分
代码展示
下面用于展示PRD中概率增量的求解代码
# _*_ coding: utf-8 _*_
# @Author : *******
# @Time : 2022/8/24 9:48
# @File : PseudoRandomDistribution.py
# @Project: TestCase
import math
ENV = "DEBUG"
def log_out(content):
if "DEBUG" == ENV:
print(content)
class PRD:
def __init__(self):
# 精度
self.precision = 0.0000000000001
def sum_arithmetic_sequence(self, N):
"""
等差数列前N项求和
:param N:第N项
:return:和
"""
res = 0
for i in range(N + 1):
res += i
return res
def get_avgp_by_c(self, c):
"""
通过c求得Nmax次操作中的平均概率
:param c:概率增量
:return:平均概率
"""
# 初始化变量
p_sum_pre_success = 0
p_sum = 0
# 计算c值对应的最大操作次数
Nmax = math.ceil(1 / c)
log_out(f"--当前[ c: {c}, Nmax: {Nmax} ]")
for i in range(1, Nmax + 1):
p_curr = min(1, i * c) * (1 - p_sum_pre_success)
p_sum_pre_success += p_curr
p_sum += i * p_curr
log_out(f"{i}: [sum_pre_success_p: {p_sum_pre_success}, curr_p: {p_curr}, sum_p: {p_sum}")
p_avg = 1 / p_sum
log_out(f"--p_avg: {p_avg}n#")
return p_avg
def get_c_by_p(self, p):
"""
通过已知触发某项操作的概率求得概率增量
e.g.已知暴击率为50%,求概率增量c
:param p:触发某项操作的概率
:return:概率增量
"""
min_ = 0
max_ = p
while True:
mid_ = (min_ + max_) / 2
p_avg = self.get_avgp_by_c(mid_)
if abs(p_avg - p) < self.precision:
log_out(f"--FINAL C: {mid_}")
return mid_
if p_avg > p:
max_ = mid_
else:
min_ = mid_
if __name__ == '__main__':
prd = PRD()
prd.get_c_by_p(0.5)
运行日志
D:software_installPythonPython39python.exe D:/projects/project-python/TestCase/game_prob/PseudoRandomDistribution.py
--当前[ c: 0.25, Nmax: 4 ]
1: [sum_pre_success_p: 0.25, curr_p: 0.25, sum_p: 0.25
2: [sum_pre_success_p: 0.625, curr_p: 0.375, sum_p: 1.0
3: [sum_pre_success_p: 0.90625, curr_p: 0.28125, sum_p: 1.84375
4: [sum_pre_success_p: 1.0, curr_p: 0.09375, sum_p: 2.21875
--p_avg: 0.4507042253521127
#
--当前[ c: 0.375, Nmax: 3 ]
1: [sum_pre_success_p: 0.375, curr_p: 0.375, sum_p: 0.375
2: [sum_pre_success_p: 0.84375, curr_p: 0.46875, sum_p: 1.3125
3: [sum_pre_success_p: 1.0, curr_p: 0.15625, sum_p: 1.78125
--p_avg: 0.5614035087719298
#
--当前[ c: 0.3125, Nmax: 4 ]
1: [sum_pre_success_p: 0.3125, curr_p: 0.3125, sum_p: 0.3125
2: [sum_pre_success_p: 0.7421875, curr_p: 0.4296875, sum_p: 1.171875
3: [sum_pre_success_p: 0.98388671875, curr_p: 0.24169921875, sum_p: 1.89697265625
4: [sum_pre_success_p: 1.0, curr_p: 0.01611328125, sum_p: 1.96142578125
--p_avg: 0.5098332088623351
#
--当前[ c: 0.28125, Nmax: 4 ]
1: [sum_pre_success_p: 0.28125, curr_p: 0.28125, sum_p: 0.28125
2: [sum_pre_success_p: 0.685546875, curr_p: 0.404296875, sum_p: 1.08984375
3: [sum_pre_success_p: 0.95086669921875, curr_p: 0.26531982421875, sum_p: 1.88580322265625
4: [sum_pre_success_p: 1.0, curr_p: 0.04913330078125, sum_p: 2.08233642578125
--p_avg: 0.480229797461676
#
--当前[ c: 0.296875, Nmax: 4 ]
1: [sum_pre_success_p: 0.296875, curr_p: 0.296875, sum_p: 0.296875
2: [sum_pre_success_p: 0.71435546875, curr_p: 0.41748046875, sum_p: 1.1318359375
3: [sum_pre_success_p: 0.9687576293945312, curr_p: 0.25440216064453125, sum_p: 1.8950424194335938
4: [sum_pre_success_p: 1.0, curr_p: 0.03124237060546875, sum_p: 2.0200119018554688
--p_avg: 0.4950465881322068
#
--当前[ c: 0.3046875, Nmax: 4 ]
1: [sum_pre_success_p: 0.3046875, curr_p: 0.3046875, sum_p: 0.3046875
2: [sum_pre_success_p: 0.7283935546875, curr_p: 0.4237060546875, sum_p: 1.152099609375
3: [sum_pre_success_p: 0.976658821105957, curr_p: 0.24826526641845703, sum_p: 1.896895408630371
4: [sum_pre_success_p: 1.0, curr_p: 0.02334117889404297, sum_p: 1.990260124206543
--p_avg: 0.502446885126973
#
--当前[ c: 0.30078125, Nmax: 4 ]
1: [sum_pre_success_p: 0.30078125, curr_p: 0.30078125, sum_p: 0.30078125
2: [sum_pre_success_p: 0.721405029296875, curr_p: 0.420623779296875, sum_p: 1.14202880859375
3: [sum_pre_success_p: 0.972793459892273, curr_p: 0.25138843059539795, sum_p: 1.8961941003799438
4: [sum_pre_success_p: 1.0, curr_p: 0.02720654010772705, sum_p: 2.005020260810852
--p_avg: 0.49874807728655524
#
--当前[ c: 0.302734375, Nmax: 4 ]
1: [sum_pre_success_p: 0.302734375, curr_p: 0.302734375, sum_p: 0.302734375
2: [sum_pre_success_p: 0.7249069213867188, curr_p: 0.42217254638671875, sum_p: 1.1470794677734375
3: [sum_pre_success_p: 0.9747473150491714, curr_p: 0.2498403936624527, sum_p: 1.8966006487607956
4: [sum_pre_success_p: 1.0, curr_p: 0.025252684950828552, sum_p: 1.9976113885641098
--p_avg: 0.5005978668948237
#
--当前[ c: 0.3017578125, Nmax: 4 ]
1: [sum_pre_success_p: 0.3017578125, curr_p: 0.3017578125, sum_p: 0.3017578125
2: [sum_pre_success_p: 0.7231578826904297, curr_p: 0.4214000701904297, sum_p: 1.1445579528808594
3: [sum_pre_success_p: 0.9737756978720427, curr_p: 0.25061781518161297, sum_p: 1.8964113984256983
4: [sum_pre_success_p: 1.0, curr_p: 0.026224302127957344, sum_p: 2.0013086069375277
--p_avg: 0.49967306218216634
#
--当前[ c: 0.30224609375, Nmax: 4 ]
1: [sum_pre_success_p: 0.30224609375, curr_p: 0.30224609375, sum_p: 0.30224609375
2: [sum_pre_success_p: 0.7240328788757324, curr_p: 0.4217867851257324, sum_p: 1.1458196640014648
3: [sum_pre_success_p: 0.9742628319654614, curr_p: 0.25022995308972895, sum_p: 1.8965095232706517
4: [sum_pre_success_p: 1.0, curr_p: 0.025737168034538627, sum_p: 1.9994581954088062
--p_avg: 0.5001354878517685
#
--当前[ c: 0.302001953125, Nmax: 4 ]
1: [sum_pre_success_p: 0.302001953125, curr_p: 0.302001953125, sum_p: 0.302001953125
2: [sum_pre_success_p: 0.7235954999923706, curr_p: 0.4215935468673706, sum_p: 1.1451890468597412
3: [sum_pre_success_p: 0.9740195965569001, curr_p: 0.25042409656452946, sum_p: 1.8964613365533296
4: [sum_pre_success_p: 1.0, curr_p: 0.02598040344309993, sum_p: 2.0003829503257293
--p_avg: 0.49990428074642734
#
--当前[ c: 0.3021240234375, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021240234375, curr_p: 0.3021240234375, sum_p: 0.3021240234375
2: [sum_pre_success_p: 0.7238142192363739, curr_p: 0.4216901957988739, sum_p: 1.1455044150352478
3: [sum_pre_success_p: 0.9741412971379759, curr_p: 0.250327077901602, sum_p: 1.8964856487400539
4: [sum_pre_success_p: 1.0, curr_p: 0.025858702862024074, sum_p: 1.9999204601881502
--p_avg: 0.5000198857438166
#
--当前[ c: 0.30206298828125, Nmax: 4 ]
1: [sum_pre_success_p: 0.30206298828125, curr_p: 0.30206298828125, sum_p: 0.30206298828125
2: [sum_pre_success_p: 0.7237048670649529, curr_p: 0.42164187878370285, sum_p: 1.1453467458486557
3: [sum_pre_success_p: 0.9740804675707295, curr_p: 0.2503756005057767, sum_p: 1.8964735473659857
4: [sum_pre_success_p: 1.0, curr_p: 0.025919532429270475, sum_p: 2.0001516770830676
--p_avg: 0.4999620836047572
#
--当前[ c: 0.302093505859375, Nmax: 4 ]
1: [sum_pre_success_p: 0.302093505859375, curr_p: 0.302093505859375, sum_p: 0.302093505859375
2: [sum_pre_success_p: 0.7237595450133085, curr_p: 0.4216660391539335, sum_p: 1.145425584167242
3: [sum_pre_success_p: 0.974110887534664, curr_p: 0.2503513425213555, sum_p: 1.8964796117313085
4: [sum_pre_success_p: 1.0, curr_p: 0.025889112465335984, sum_p: 2.0000360615926525
--p_avg: 0.49999098476438875
#
--当前[ c: 0.3021087646484375, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021087646484375, curr_p: 0.3021087646484375, sum_p: 0.3021087646484375
2: [sum_pre_success_p: 0.7237868825905025, curr_p: 0.421678117942065, sum_p: 1.1454650005325675
3: [sum_pre_success_p: 0.9741260936313338, curr_p: 0.25033921104083134, sum_p: 1.8964826336550615
4: [sum_pre_success_p: 1.0, curr_p: 0.025873906368666155, sum_p: 1.9999782591297262
--p_avg: 0.5000054352766523
#
--当前[ c: 0.30210113525390625, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210113525390625, curr_p: 0.30210113525390625, sum_p: 0.30210113525390625
2: [sum_pre_success_p: 0.7237732139183208, curr_p: 0.4216720786644146, sum_p: 1.1454452925827354
3: [sum_pre_success_p: 0.9741184909067604, curr_p: 0.25034527698843956, sum_p: 1.896481123548054
4: [sum_pre_success_p: 1.0, curr_p: 0.025881509093239607, sum_p: 2.0000071599210125
--p_avg: 0.4999982100261549
#
--当前[ c: 0.3021049499511719, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021049499511719, curr_p: 0.3021049499511719, sum_p: 0.3021049499511719
2: [sum_pre_success_p: 0.7237800482835155, curr_p: 0.4216750983323436, sum_p: 1.1454551466158591
3: [sum_pre_success_p: 0.9741222923499865, curr_p: 0.250342244066471, sum_p: 1.8964818788152722
4: [sum_pre_success_p: 1.0, curr_p: 0.025877707650013515, sum_p: 1.9999927094153263
--p_avg: 0.5000018226528126
#
--当前[ c: 0.30210304260253906, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210304260253906, curr_p: 0.30210304260253906, sum_p: 0.30210304260253906
2: [sum_pre_success_p: 0.7237766311081941, curr_p: 0.42167358850565506, sum_p: 1.1454502196138492
3: [sum_pre_success_p: 0.9741203916486084, curr_p: 0.2503437605404143, sum_p: 1.8964815012350922
4: [sum_pre_success_p: 1.0, curr_p: 0.02587960835139158, sum_p: 1.9999999346406585
--p_avg: 0.5000000163398359
#
--当前[ c: 0.30210208892822266, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210208892822266, curr_p: 0.30210208892822266, sum_p: 0.30210208892822266
2: [sum_pre_success_p: 0.7237749225150765, curr_p: 0.4216728335868538, sum_p: 1.1454477561019303
3: [sum_pre_success_p: 0.9741194412827432, curr_p: 0.25034451876766667, sum_p: 1.8964813124049302
4: [sum_pre_success_p: 1.0, curr_p: 0.025880558717256807, sum_p: 2.0000035472739572
--p_avg: 0.4999991131830836
#
--当前[ c: 0.30210256576538086, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210256576538086, curr_p: 0.30210256576538086, sum_p: 0.30210256576538086
2: [sum_pre_success_p: 0.72377577681209, curr_p: 0.4216732110467092, sum_p: 1.1454489878587992
3: [sum_pre_success_p: 0.9741199164669405, curr_p: 0.2503441396548504, sum_p: 1.8964814068233504
4: [sum_pre_success_p: 1.0, curr_p: 0.025880083533059484, sum_p: 2.0000017409555886
--p_avg: 0.4999995647614817
#
--当前[ c: 0.30210280418395996, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210280418395996, curr_p: 0.30210280418395996, sum_p: 0.30210280418395996
2: [sum_pre_success_p: 0.7237762039602558, curr_p: 0.4216733997762958, sum_p: 1.1454496037365516
3: [sum_pre_success_p: 0.9741201540580906, curr_p: 0.25034395009783483, sum_p: 1.896481454030056
4: [sum_pre_success_p: 1.0, curr_p: 0.025879845941909396, sum_p: 2.0000008377976934
--p_avg: 0.4999997905506644
#
--当前[ c: 0.3021029233932495, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021029233932495, curr_p: 0.3021029233932495, sum_p: 0.3021029233932495
2: [sum_pre_success_p: 0.7237764175342534, curr_p: 0.42167349414100386, sum_p: 1.1454499116752572
3: [sum_pre_success_p: 0.9741202728534286, curr_p: 0.2503438553191752, sum_p: 1.8964814776327827
4: [sum_pre_success_p: 1.0, curr_p: 0.025879727146571385, sum_p: 2.0000003862190683
--p_avg: 0.4999999034452516
#
--当前[ c: 0.3021029829978943, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021029829978943, curr_p: 0.3021029829978943, sum_p: 0.3021029829978943
2: [sum_pre_success_p: 0.7237765243212309, curr_p: 0.42167354132333656, sum_p: 1.1454500656445674
3: [sum_pre_success_p: 0.9741203322510382, curr_p: 0.25034380792980737, sum_p: 1.8964814894339894
4: [sum_pre_success_p: 1.0, curr_p: 0.025879667748961777, sum_p: 2.0000001604298365
--p_avg: 0.4999999598925441
#
--当前[ c: 0.3021030128002167, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021030128002167, curr_p: 0.3021030128002167, sum_p: 0.3021030128002167
2: [sum_pre_success_p: 0.7237765777147143, curr_p: 0.4216735649144976, sum_p: 1.1454501426292119
3: [sum_pre_success_p: 0.9741203619498282, curr_p: 0.250343784235114, sum_p: 1.896481495334554
4: [sum_pre_success_p: 1.0, curr_p: 0.025879638050171794, sum_p: 2.000000047535241
--p_avg: 0.49999998811619
#
--当前[ c: 0.30210302770137787, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210302770137787, curr_p: 0.30210302770137787, sum_p: 0.30210302770137787
2: [sum_pre_success_p: 0.7237766044114546, curr_p: 0.42167357671007677, sum_p: 1.1454501811215314
3: [sum_pre_success_p: 0.9741203767992196, curr_p: 0.25034377238776495, sum_p: 1.8964814982848264
4: [sum_pre_success_p: 1.0, curr_p: 0.02587962320078041, sum_p: 1.999999991087948
--p_avg: 0.500000002228013
#
--当前[ c: 0.30210302025079727, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210302025079727, curr_p: 0.30210302025079727, sum_p: 0.30210302025079727
2: [sum_pre_success_p: 0.7237765910630846, curr_p: 0.4216735708122873, sum_p: 1.1454501618753719
3: [sum_pre_success_p: 0.9741203693745242, curr_p: 0.25034377831143967, sum_p: 1.8964814968096908
4: [sum_pre_success_p: 1.0, curr_p: 0.025879630625475825, sum_p: 2.000000019311594
--p_avg: 0.49999999517210153
#
--当前[ c: 0.30210302397608757, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210302397608757, curr_p: 0.30210302397608757, sum_p: 0.30210302397608757
2: [sum_pre_success_p: 0.7237765977372697, curr_p: 0.4216735737611821, sum_p: 1.1454501714984517
3: [sum_pre_success_p: 0.9741203730868719, curr_p: 0.25034377534960234, sum_p: 1.8964814975472588
4: [sum_pre_success_p: 1.0, curr_p: 0.025879626913128062, sum_p: 2.0000000051997713
--p_avg: 0.4999999987000572
#
--当前[ c: 0.3021030258387327, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021030258387327, curr_p: 0.3021030258387327, sum_p: 0.3021030258387327
2: [sum_pre_success_p: 0.7237766010743621, curr_p: 0.4216735752356294, sum_p: 1.1454501763099916
3: [sum_pre_success_p: 0.9741203749430458, curr_p: 0.2503437738686836, sum_p: 1.8964814979160425
4: [sum_pre_success_p: 1.0, curr_p: 0.02587962505695418, sum_p: 1.9999999981438592
--p_avg: 0.5000000004640353
#
--当前[ c: 0.30210302490741014, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210302490741014, curr_p: 0.30210302490741014, sum_p: 0.30210302490741014
2: [sum_pre_success_p: 0.7237765994058158, curr_p: 0.42167357449840576, sum_p: 1.1454501739042215
3: [sum_pre_success_p: 0.9741203740149589, curr_p: 0.25034377460914303, sum_p: 1.8964814977316506
4: [sum_pre_success_p: 1.0, curr_p: 0.02587962598504112, sum_p: 2.000000001671815
--p_avg: 0.4999999995820462
#
--当前[ c: 0.30210302537307143, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210302537307143, curr_p: 0.30210302537307143, sum_p: 0.30210302537307143
2: [sum_pre_success_p: 0.7237766002400889, curr_p: 0.42167357486701756, sum_p: 1.1454501751071064
3: [sum_pre_success_p: 0.9741203744790023, curr_p: 0.2503437742389134, sum_p: 1.8964814978238467
4: [sum_pre_success_p: 1.0, curr_p: 0.02587962552099765, sum_p: 1.9999999999078373
--p_avg: 0.5000000000230407
#
--当前[ c: 0.3021030251402408, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021030251402408, curr_p: 0.3021030251402408, sum_p: 0.3021030251402408
2: [sum_pre_success_p: 0.7237765998229524, curr_p: 0.42167357468271166, sum_p: 1.145450174505664
3: [sum_pre_success_p: 0.9741203742469806, curr_p: 0.2503437744240282, sum_p: 1.8964814977777487
4: [sum_pre_success_p: 1.0, curr_p: 0.025879625753019386, sum_p: 2.000000000789826
--p_avg: 0.4999999998025435
#
--当前[ c: 0.3021030252566561, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021030252566561, curr_p: 0.3021030252566561, sum_p: 0.3021030252566561
2: [sum_pre_success_p: 0.7237766000315207, curr_p: 0.4216735747748646, sum_p: 1.1454501748063852
3: [sum_pre_success_p: 0.9741203743629915, curr_p: 0.2503437743314708, sum_p: 1.8964814978007976
4: [sum_pre_success_p: 1.0, curr_p: 0.02587962563700852, sum_p: 2.0000000003488316
--p_avg: 0.4999999999127921
#
--当前[ c: 0.30210302531486377, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210302531486377, curr_p: 0.30210302531486377, sum_p: 0.30210302531486377
2: [sum_pre_success_p: 0.7237766001358048, curr_p: 0.4216735748209411, sum_p: 1.1454501749567458
3: [sum_pre_success_p: 0.974120374420997, curr_p: 0.2503437742851921, sum_p: 1.8964814978123221
4: [sum_pre_success_p: 1.0, curr_p: 0.02587962557900303, sum_p: 2.0000000001283342
--p_avg: 0.49999999996791644
#
--当前[ c: 0.3021030253439676, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021030253439676, curr_p: 0.3021030253439676, sum_p: 0.3021030253439676
2: [sum_pre_success_p: 0.7237766001879469, curr_p: 0.4216735748439793, sum_p: 1.1454501750319261
3: [sum_pre_success_p: 0.9741203744499995, curr_p: 0.25034377426205273, sum_p: 1.8964814978180844
4: [sum_pre_success_p: 1.0, curr_p: 0.02587962555000045, sum_p: 2.000000000018086
--p_avg: 0.4999999999954785
#
--当前[ c: 0.3021030253585195, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021030253585195, curr_p: 0.3021030253585195, sum_p: 0.3021030253585195
2: [sum_pre_success_p: 0.723776600214018, curr_p: 0.42167357485549845, sum_p: 1.1454501750695165
3: [sum_pre_success_p: 0.9741203744645011, curr_p: 0.250343774250483, sum_p: 1.8964814978209654
4: [sum_pre_success_p: 1.0, curr_p: 0.02587962553549894, sum_p: 1.9999999999629612
--p_avg: 0.5000000000092597
#
--当前[ c: 0.30210302535124356, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210302535124356, curr_p: 0.30210302535124356, sum_p: 0.30210302535124356
2: [sum_pre_success_p: 0.7237766002009824, curr_p: 0.4216735748497389, sum_p: 1.1454501750507213
3: [sum_pre_success_p: 0.9741203744572503, curr_p: 0.25034377425626786, sum_p: 1.8964814978195248
4: [sum_pre_success_p: 1.0, curr_p: 0.025879625542749696, sum_p: 1.9999999999905236
--p_avg: 0.5000000000023691
#
--当前[ c: 0.3021030253476056, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021030253476056, curr_p: 0.3021030253476056, sum_p: 0.3021030253476056
2: [sum_pre_success_p: 0.7237766001944648, curr_p: 0.42167357484685913, sum_p: 1.145450175041324
3: [sum_pre_success_p: 0.974120374453625, curr_p: 0.2503437742591602, sum_p: 1.8964814978188045
4: [sum_pre_success_p: 1.0, curr_p: 0.025879625546375018, sum_p: 2.0000000000043046
--p_avg: 0.49999999999892386
#
--当前[ c: 0.30210302534942457, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210302534942457, curr_p: 0.30210302534942457, sum_p: 0.30210302534942457
2: [sum_pre_success_p: 0.7237766001977236, curr_p: 0.42167357484829904, sum_p: 1.1454501750460226
3: [sum_pre_success_p: 0.9741203744554376, curr_p: 0.25034377425771404, sum_p: 1.8964814978191646
4: [sum_pre_success_p: 1.0, curr_p: 0.025879625544562357, sum_p: 1.999999999997414
--p_avg: 0.5000000000006465
#
--当前[ c: 0.3021030253485151, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021030253485151, curr_p: 0.3021030253485151, sum_p: 0.3021030253485151
2: [sum_pre_success_p: 0.7237766001960941, curr_p: 0.42167357484757906, sum_p: 1.1454501750436732
3: [sum_pre_success_p: 0.9741203744545313, curr_p: 0.2503437742584372, sum_p: 1.8964814978189848
4: [sum_pre_success_p: 1.0, curr_p: 0.025879625545468743, sum_p: 2.0000000000008598
--p_avg: 0.49999999999978506
#
--当前[ c: 0.3021030253489698, Nmax: 4 ]
1: [sum_pre_success_p: 0.3021030253489698, curr_p: 0.3021030253489698, sum_p: 0.3021030253489698
2: [sum_pre_success_p: 0.7237766001969088, curr_p: 0.42167357484793905, sum_p: 1.1454501750448478
3: [sum_pre_success_p: 0.9741203744549845, curr_p: 0.25034377425807564, sum_p: 1.8964814978190747
4: [sum_pre_success_p: 1.0, curr_p: 0.02587962554501555, sum_p: 1.999999999999137
--p_avg: 0.5000000000002158
#
--当前[ c: 0.30210302534874245, Nmax: 4 ]
1: [sum_pre_success_p: 0.30210302534874245, curr_p: 0.30210302534874245, sum_p: 0.30210302534874245
2: [sum_pre_success_p: 0.7237766001965015, curr_p: 0.421673574847759, sum_p: 1.1454501750442605
3: [sum_pre_success_p: 0.9741203744547579, curr_p: 0.2503437742582564, sum_p: 1.8964814978190296
4: [sum_pre_success_p: 1.0, curr_p: 0.025879625545242146, sum_p: 1.9999999999999982
--p_avg: 0.5000000000000004
#
--FINAL C: 0.30210302534874245
Process finished with exit code 0
保底分析
如代码展示中设定暴击概率为50%,求得概率增量近似为30%,且最多攻击(Nmax=)4次必出暴击
则有如下的表现:
第1次: N1=1 => P(1)=N1*30%=0.3,若本次触发暴击,则N2置为1
第2次: N2=N1 + 1 => P(1)=N2*30%=0.6,若本次触发暴击,则N3置为1
第3次: N3=N2 + 1 => P(3)=N3*30%=0.9,若本次触发暴击,则N4置为1
第4次: N4=N3 + 1 => p(4)=N4*30%=1.2
上面的过程是假设玩家前3次都未触发暴击的情况
那么由于第4次概率大于1,则第4次必然触发暴击
最后
以上就是阳光饼干为你收集整理的Python游戏概率保底算法PRD的实现的全部内容,希望文章能够帮你解决Python游戏概率保底算法PRD的实现所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复