fork download
  1. import numpy as np
  2.  
  3. def RollD6():
  4. return np.random.randint(1,7)
  5.  
  6. def RollD6():
  7. return np.random.randint(1,7)
  8.  
  9. def RollNDice(n):
  10. diceValues = np.random.randint(1,7,n)
  11. return diceValues
  12.  
  13. def Roll3D6():
  14. return sum(RollNDice(3))
  15.  
  16. def Roll4D6D1():
  17. rolls = RollNDice(4)
  18. rolls = np.delete(rolls, rolls.argmin()) # delete lowest value
  19. return sum(rolls)
  20.  
  21. PointBuyValue = {
  22. 3: -9,
  23. 4: -6,
  24. 5: -4,
  25. 6: -2,
  26. 7: -1,
  27. 8: 0,
  28. 9: 1,
  29. 10: 2,
  30. 11: 3,
  31. 12: 4,
  32. 13: 5,
  33. 14: 7,
  34. 15: 9,
  35. 16: 12,
  36. 17: 15,
  37. 18: 19
  38. }
  39.  
  40. def RollStats4D6D1():
  41. stats = []
  42. for i in range(6):
  43. stats.append(Roll4D6D1())
  44. return stats
  45.  
  46. def RollStats3D6(drop):
  47. stats = []
  48. for stat in range(6+drop):
  49. stats.append(Roll3D6())
  50. stats.sort()
  51. for i in range(drop):
  52. stats.pop(0)
  53. return stats
  54.  
  55. def CalculatePointBuy(stats):
  56. pointBuyTotal = 0
  57. for stat in stats:
  58. pointBuyTotal = pointBuyTotal + PointBuyValue[stat]
  59. return pointBuyTotal
  60.  
  61. def Choose4D6D1():
  62. pb_max = 0
  63. for i in range(4):
  64. pb = CalculatePointBuy(RollStats4D6D1())
  65. if pb > pb_max:
  66. pb_max = pb
  67. return pb_max
  68.  
  69.  
  70. def Choose3D6(drop):
  71. pb_max = 0
  72. for i in range(4):
  73. pb = CalculatePointBuy(RollStats3D6(drop))
  74. if pb > pb_max:
  75. pb_max = pb
  76. return pb_max
  77.  
  78. np.random.seed(42)
  79.  
  80. n_sims = 1000
  81. record_4d6d1 = []
  82. record_3d6 = []
  83. record_pick4d6d1 = []
  84. record_pick3d6 = []
  85.  
  86. for runs in range(n_sims):
  87. record_4d6d1.append(CalculatePointBuy(RollStats4D6D1()))
  88. record_3d6.append(CalculatePointBuy(RollStats3D6(1)))
  89. record_pick4d6d1.append(Choose4D6D1())
  90. record_pick3d6.append(Choose3D6(1))
  91.  
  92. print ("Average Point buy (4d6d1): %.2f" % (np.sum(record_4d6d1)/n_sims))
  93. print ("Average Point buy (3d6): %.2f" % (np.sum(record_3d6)/n_sims))
  94. print ("Average Point buy (Choose 4d6d1): %.2f" %
  95. (np.sum(record_pick4d6d1)/n_sims))
  96. print ("Average Point buy (Choose 3d6): %.2f" %
  97. (np.sum(record_pick3d6)/n_sims))
  98.  
  99. ax = sns.distplot(record_4d6d1)
  100. plt.title("Histogram of %d simulated rolls" % n_sims)
  101. ax.set_xlabel("Point Buy Total")
  102. ax.set_ylabel("Count")
  103.  
  104. sns.distplot(record_3d6)
  105. sns.distplot(record_pick4d6d1)
  106. sns.distplot(record_pick3d6)
  107. plt.legend(labels=['4d6d1', '3d6', 'Choose 4d6d1', 'Choose 3d6'])
Runtime error #stdin #stdout #stderr 1.21s 35920KB
stdin
Standard input is empty
stdout
Average Point buy (4d6d1): 31.36
Average Point buy (3d6): 21.77
Average Point buy (Choose 4d6d1): 43.23
Average Point buy (Choose 3d6): 31.61
stderr
Traceback (most recent call last):
  File "./prog.py", line 99, in <module>
NameError: name 'sns' is not defined