Advertisement
Guest User

MTGAMonteCarlo

a guest
Apr 13th, 2020
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.54 KB | None | 0 0
  1. def meanOverRange(numTrials, inputRange, step = 1):
  2.  
  3.     for i in arange(0, inputRange, step):
  4.         print("{:.0f}".format(i*100) + "%: " +
  5.               "{:.0f}".format(meanTrial(numTrials, i)) + " gems, " +
  6.               "{:.2f}".format(meanTrial2(numTrials, i)) + " packs")
  7.  
  8.  
  9.  
  10. def meanTrial(numTrials, inputVal):
  11.  
  12.     total = 0
  13.  
  14.     for _ in range(numTrials):
  15.         total = total + MTGAReward(inputVal)
  16.  
  17.     return total/numTrials
  18.  
  19.  
  20. def meanTrial2(numTrials, inputVal):
  21.  
  22.     total = 0
  23.  
  24.     for _ in range(numTrials):
  25.         total = total + MTGARewardPacks(inputVal)
  26.  
  27.     return total/numTrials
  28.  
  29.  
  30. def MTGAReward(winPercent):
  31.     # Best of 3, 3 matches
  32.  
  33.     wins = 0
  34.  
  35.     matchWin = winPercent*winPercent + 2 * winPercent*winPercent * (1-winPercent)
  36.    
  37.     for _ in range(3):
  38.         if(random.random() < matchWin):
  39.             wins = wins + 1
  40.  
  41.     if(wins == 3):
  42.         return 3000
  43.     elif(wins == 2):
  44.         return 1000
  45.     else:
  46.         return 0
  47.  
  48. ##    # Best of 1, go until 7 wins or 3 losses
  49. ##
  50. ##    wins = 0
  51. ##    losses = 0
  52. ##
  53. ##    while(wins < 7 and losses < 3):
  54. ##        if(random.random() < winPercent):
  55. ##            wins = wins + 1
  56. ##        else:
  57. ##            losses = losses + 1
  58. ##
  59. ##    if(wins == 7):
  60. ##        return 2200
  61. ##    elif(wins == 6):
  62. ##        return 1800
  63. ##    elif(wins == 5):
  64. ##        return 1600
  65. ##    elif(wins == 4):
  66. ##        return 1400
  67. ##    elif(wins == 3):
  68. ##        return 1000
  69. ##    elif(wins == 2):
  70. ##        return 250
  71. ##    elif(wins == 1):
  72. ##        return 50
  73. ##    else:
  74. ##        return 0
  75.  
  76.    
  77. def MTGARewardPacks(winPercent):
  78.     # Best of 3, 3 matches
  79.  
  80.     wins = 0
  81.  
  82.     matchWin = winPercent*winPercent + 2 * winPercent*winPercent * (1-winPercent)
  83.  
  84.     for _ in range(3):
  85.         if(random.random() < matchWin):
  86.             wins = wins + 1
  87.  
  88.     if(wins == 3):
  89.         return 6
  90.     elif(wins == 2):
  91.         return 4
  92.     else:
  93.         return 1
  94.  
  95. ##    # Best of 1, go until 7 wins or 3 losses
  96. ##
  97. ##    wins = 0
  98. ##    losses = 0
  99. ##
  100. ##    while(wins < 7 and losses < 3):
  101. ##        if(random.random() < winPercent):
  102. ##            wins = wins + 1
  103. ##        else:
  104. ##            losses = losses + 1
  105. ##
  106. ##    if(wins == 7):
  107. ##        return 6
  108. ##    elif(wins == 6):
  109. ##        return 5
  110. ##    elif(wins == 5):
  111. ##        return 4
  112. ##    elif(wins == 4):
  113. ##        return 3
  114. ##    elif(wins == 3):
  115. ##        return 2
  116. ##    elif(wins == 2):
  117. ##        return 2
  118. ##    elif(wins == 1):
  119. ##        return 1
  120. ##    else:
  121. ##        return 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement