Guest User

packopeningsimulator

a guest
Feb 2nd, 2017
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. format compact
  2. rng('shuffle')
  3. % HEARTHSTONE PACK OPENING SIMULATOR
  4. % Opens packs until every plain card is collected
  5.  
  6. % Set number of trials to run (increases accuracy and run time)
  7. n = 10000;
  8.  
  9. % Pick the set to be run (1 = classic
  10. set = 1; % 2 = goblins vs gnomes
  11. % 3 = the grand tournament
  12. % 4 = whispers of the old gods
  13. % 5 = mean streets of gadgetzan)
  14.  
  15. % Optional: input the current state of the collection
  16. % From the chosen set:
  17. % Number of commons where one is owned
  18. userC = 0;
  19. % Number of commons where two are owned
  20. userC2 = 0;
  21. % Number of rares where one is owned
  22. userR = 0;
  23. % Number of rares where two are owned
  24. userR2 = 0;
  25. % Number of epics where one is owned
  26. userE = 0;
  27. % Number of epics where two are owned
  28. userE2 = 0;
  29. % Number of legendaries owned
  30. userL = 1;
  31. % Current dust total
  32. userD = 0;
  33.  
  34. % DON'T EDIT ANYTHING BELOW HERE
  35. % Store the size of each set
  36. % Rows are different sets, columns are different rarities
  37. setSize = [94 81 37 33;
  38. 40 37 26 20;
  39. 49 36 27 20;
  40. 50 36 27 21;
  41. 49 36 27 20];
  42.  
  43. % Store the probability of each rarity occuring for each individual card
  44. % Rows are plain/golden, columns are common/rare/epic/legendary
  45. % Accurate to within ~1% based on HearthSim pack data
  46. rarity = [0.8809558 00.0185221 0.0770890 0.0045338 0.0146196 0.0006866 0.0033284 0.0002646];
  47. % Manipulate the array based on various pity timers
  48. legendaryDist = [0 rarity(7)/sum(rarity(7:8)) 1];
  49. epicDist = [0 rarity(5)/sum(rarity(5:8)) sum(rarity(5:6))/sum(rarity(5:8)) sum(rarity(5:7))/sum(rarity(5:8)) 1];
  50. rareDist = [0 rarity(3)/sum(rarity(3:8)) sum(rarity(3:4))/sum(rarity(3:8)) sum(rarity(3:5))/sum(rarity(3:8)) sum(rarity(3:6))/sum(rarity(3:8)) sum(rarity(3:7))/sum(rarity(3:8)) 1];
  51. commonDist = [0 rarity(1) sum(rarity(1:2)) sum(rarity(1:3)) sum(rarity(1:4)) sum(rarity(1:5)) sum(rarity(1:6)) sum(rarity(1:7)) 1];
  52.  
  53. % Set an array to store how many packs each trial runs
  54. packsOpened = zeros(1,n);
  55.  
  56. % Run the trial 'n' times
  57. for a = 1:n
  58. % Generate a collection
  59. %common = repmat(2,1,setSize(set,1));
  60. common = [zeros(1,userC2) ones(1,userC) repmat(2,1,(setSize(set,1)-(userC2+userC)))];
  61. rare = [zeros(1,userR2) ones(1,userR) repmat(2,1,(setSize(set,2)-(userR2+userR)))];
  62. epic = [zeros(1,userE2) ones(1,userE) repmat(2,1,(setSize(set,3)-(userE2+userE)))];
  63. legendary = [zeros(1,userL) ones(1,setSize(set,4)-userL)];
  64. % Set the dust count, pack count, and pity timers to zero
  65. dust = userD;
  66. pityEpic = 0;
  67. pityLegendary = 0;
  68.  
  69. % Keep opening packs until either the collection is complete OR enough
  70. % dust is left over to craft the remaining
  71. while (sum(common)+sum(rare)+sum(epic)+sum(legendary) > 0) && (40*sum(common) + 100*sum(rare) + 400*sum(epic) + 1600*sum(legendary) > dust)
  72. % Open a pack
  73. packsOpened(a) = packsOpened(a) + 1;
  74. % Randomly give each card a 'rarity number', then translate it
  75. % 1 = Common, 2 = GCommon, 3 = Rare, 4 = GRare
  76. % 5 = Epic, 6 = GEpic, 7 = Legendary, 8 = GLegendary
  77. cardRand = rand(1,5);
  78. cardRarity = zeros(1,5);
  79.  
  80. % The 'first' card has adjusted rarity, based on pity timer
  81. if pityLegendary >= 40
  82. for b = 1:2
  83. if cardRand(1) >= legendaryDist(b) && cardRand(1) <= legendaryDist(b+1)
  84. cardRarity(1) = b+6;
  85. end
  86. end
  87. elseif pityEpic >= 10
  88. for b = 1:4
  89. if cardRand(1) >= epicDist(b) && cardRand(1) <= epicDist(b+1)
  90. cardRarity(1) = b+4;
  91. end
  92. end
  93. else
  94. for b = 1:6
  95. if cardRand(1) >= rareDist(b) && cardRand(1) <= rareDist(b+1)
  96. cardRarity(1) = b+2;
  97. end
  98. end
  99. end
  100.  
  101. % Generate the other four cards
  102. for c = 2:5
  103. for b = 1:8
  104. if cardRand(c) >= commonDist(b) && cardRand(c) <= commonDist(b+1)
  105. cardRarity(c) = b;
  106. end
  107. end
  108. end
  109.  
  110. % Increase pity timers by one if none were opened
  111. if cardRarity(1) < 5 && cardRarity(2) < 5 && cardRarity(3) < 5 && cardRarity(4) < 5 && cardRarity(5) < 5
  112. pityEpic = pityEpic + 1;
  113. else
  114. pityEpic = 0;
  115. end
  116. if cardRarity(1) < 7 && cardRarity(2) < 7 && cardRarity(3) < 7 && cardRarity(4) < 7 && cardRarity(5) < 7
  117. pityLegendary = pityLegendary + 1;
  118. else
  119. pityLegendary = 0;
  120. end
  121.  
  122. % For each card, dust the golden cards, add the plains to the
  123. % collection if needed, or dust them if already owned
  124. for c = 1:5
  125. if cardRarity(c) == 1
  126. draw = randi(setSize(set,1),1,1);
  127. if common(draw) > 0
  128. common(draw) = common(draw) - 1;
  129. else
  130. dust = dust + 5;
  131. end
  132. elseif cardRarity(c) == 2
  133. dust = dust + 50;
  134. elseif cardRarity(c) == 3
  135. draw = randi(setSize(set,2),1,1);
  136. if rare(draw) > 0
  137. rare(draw) = rare(draw) - 1;
  138. else
  139. dust = dust + 20;
  140. end
  141. elseif cardRarity(c) == 4
  142. dust = dust + 100;
  143. elseif cardRarity(c) == 5
  144. draw = randi(setSize(set,3),1,1);
  145. if epic(draw) > 0
  146. epic(draw) = epic(draw) - 1;
  147. else
  148. dust = dust + 100;
  149. end
  150. elseif cardRarity(c) == 6
  151. dust = dust + 400;
  152. elseif cardRarity(c) == 7
  153. draw = randi(setSize(set,4),1,1);
  154. if legendary(draw) > 0
  155. legendary(draw) = legendary(draw) - 1;
  156. else
  157. dust = dust + 400;
  158. end
  159. else
  160. dust = dust + 1600;
  161. end
  162. end
  163. end
  164. end
  165. maxPacks = max(packsOpened);
  166. avgPacks = ceil(mean(packsOpened));
  167. minPacks = min(packsOpened);
  168. stdPacks = std(packsOpened);
  169. intervallower = ceil(avgPacks - 1.96 * stdPacks / sqrt(n));
  170. intervalupper= ceil(avgPacks + 1.96 * stdPacks / sqrt(n));
  171.  
  172. minPacks
  173. intervallower
  174. avgPacks
  175. intervalupper
  176. maxPacks
Advertisement
Add Comment
Please, Sign In to add comment