SomeoneEvil

Divine Favor/Smite

Jun 12th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. import _random
  2. import math
  3.  
  4. rnd = _random.Random()
  5. def getrandint(m):
  6.     return math.ceil(rnd.random()*m)
  7. def d(N):
  8.     return getrandint(N)
  9.  
  10. def nodmg():
  11.     return 0
  12. def warhammer():
  13.     return d(8)
  14. def favour():
  15.     return d(4)
  16. def smite():
  17.     return d(8) + d(8)
  18.  
  19. def killNrounds(rounds, hp, eAC, weapon, modif, favor=nodmg, smite=nodmg):
  20.     hasSmited=False
  21.     killcount = 0
  22.     currenthp = hp
  23.     for i in range(rounds):
  24.         d20 = d(20)
  25.         if d20 == 20:
  26.             if not hasSmited:
  27.                 currenthp -= weapon() + weapon() + modif + favor() + favor() + smite() + smite()
  28.                 hasSmited = True
  29.             else:
  30.                 currenthp -= weapon() + weapon() + modif + favor() + favor()
  31.         elif d20 >= eAC:
  32.             if not hasSmited:
  33.                 currenthp -= weapon() + modif + favor() + smite()
  34.                 hasSmited = True
  35.             else:
  36.                 currenthp -= weapon() + modif + favor()
  37.         if currenthp <= 0:
  38.             currenthp = hp
  39.             killcount+=1
  40.     return killcount + (hp-currenthp)/hp
  41.  
  42. def simkillrounds(tries, *prm):
  43.     tests = [0]*tries
  44.     for i in range(tries):
  45.         tests[i] = killNrounds(*prm)
  46.     return sum(tests)/tries
  47.  
  48. favourtest = [ 8, warhammer, 4, favour]
  49. smitetest = [8, warhammer, 4, nodmg, smite]
  50. # hps = [5, 10, 15, 20]
  51. # hps = [5, 7, 9, 12, 15, 18, 22, 26, 30, 35]
  52. #hps = [6, 8]
  53. # hps = [40,50,60,70,80,90,100,120]
  54. hps = [5, 6, 7, 8, 9, 10, 12, 15, 18, 22, 26, 30, 35, 40, 50,60,70,80,90,100,120]
  55. testtries = 1000000
  56.  
  57. def runfor(testtries, testprm, hps, filepath='paladin/output.txt'):
  58.     f = open(filepath, 'a+')
  59.     f.write(str(testprm)+'\n')
  60.     f.write('r\t' + '\t'.join(map(str,hps)))
  61.     for i in range(1, 11):
  62.         f.write('\n' + str(i) + '\t')
  63.         for hp in hps:
  64.             f.write(str(simkillrounds(testtries, i, hp, *testprm))+'\t')
  65.     f.write('\n')
  66.     f.close()
  67.  
  68. runfor(testtries, favourtest, hps)
  69. runfor(testtries, smitetest, hps)
Add Comment
Please, Sign In to add comment