Advertisement
Guest User

HS Generator

a guest
Jan 9th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 KB | None | 0 0
  1. from random import random, randrange
  2. from collections import Counter
  3.  
  4. # http://www.4shared.com/web/preview/pdf/mCdvUh9Wce
  5. # Chance    Type                Total Chance        Dust
  6. # 70.00%    common              100.00%            5
  7. # 21.51%    rare                 30.00%           20
  8. #  4.28%    epic                  8.49%          100
  9. #  1.47%    golden common             4.21%           50
  10. #  1.27%    golden rare           2.74%          100
  11. #  1.05%    legendary             1.47%          400
  12. #  0.31%    golden epic           0.42%          400
  13. #  0.11%    golden legendary          0.11%         1600
  14.  
  15. qualities = [   'Common',
  16.         'Rare',
  17.         'Epic',
  18.         'Legendary',
  19.         'Golden Common',
  20.         'Golden Rare',
  21.         'Golden Epic',
  22.         'Golden Legendary'  ]
  23.  
  24. class HS_pack:
  25.     def __init__(self, u_chance=.225, g_chance=.0225):
  26.  
  27.         self.qualities = [  'Common',
  28.                     'Rare',
  29.                     'Epic',
  30.                     'Legendary',
  31.                     'Golden Common',
  32.                     'Golden Rare',
  33.                     'Golden Epic',
  34.                     'Golden Legendary'  ]
  35.  
  36.         self.dust_values = [5,20,100,400,50,100,400,1600]
  37.         self.u_chance = u_chance
  38.         self.g_chance = g_chance # stacking (e.g. common = 2.5% chance, rare = 5% chance, etc.)
  39.  
  40.         self.pack = []
  41.  
  42.     def get(self):
  43.         for x in xrange(5):
  44.             q = 0
  45.            
  46.             if x==4 and sum(self.pack)==0:
  47.                 q = 1
  48.            
  49.             while q < 3:
  50.                 roll = random()
  51.                 if roll < self.u_chance:
  52.                     q += 1
  53.                 else:
  54.                     break
  55.  
  56.             #gold roll
  57.             g_roll = random()
  58.             if g_roll < (q+1)*self.g_chance: q += 4
  59.  
  60.             self.pack.append(q)
  61.  
  62.         return self.pack
  63.  
  64.     def value(self):
  65.         return sum([self.dust_values[x] for x in self.pack])
  66.  
  67.     def cards(self):
  68.         return [self.qualities[x] for x in self.pack]
  69.  
  70. cards = []
  71. total_dust = 0
  72. n = 100000
  73.  
  74. for x in xrange(n):
  75.     p = HS_pack()
  76.     cards += p.get()
  77.     total_dust += p.value()
  78.  
  79. print 'Packs: {0:,}, Cards: {1:,}'.format(n,n*5)
  80. print '---'
  81. for q,x in Counter(cards).most_common():
  82.     print '{0:16}{1:8,}{2:8.2%}'.format(qualities[q],cards.count(q),(x+0.0)/(n*5))
  83.  
  84. print '---'
  85. print 'Average Dust:',total_dust/n
  86.  
  87. # https://www.reddit.com/r/hearthstone/comments/2emnxl/drops_chances_rarity_by_11359_hearthstone_expert/
  88. # This strikes me as you not knowing how the card generation process actually works. Cards are not calculated as fixed percentages. The process is actually thus:
  89. # 1) A common in generated
  90. # 2) A "dice" rolled (aka a random number generated). If that roll is above a certain point, the card becomes rare.
  91. # 3) If the card is now rare, that dice is rolled again. If the roll is above a certain point, the card is now epic.
  92. # 4) If the card is now epic, roll the dice one more time for legendary.
  93. # The process surrounding becoming gold is unclear. Either it's a percentage chance at the end of the process, or there is an intermediate step throughout that can make a card gold, at which point it continues to be gold.
  94. # When it comes to the fact that a pack cannot have 5 commons, it is because the 5th card starts its life already in the rare state. Thus, the 5th card itself always has a higher chance of becoming epic or legendary, because its already rare. That is why a pack with 1 epic and 4 common is more common that a pack with 1 epic, 1 rare, and 3 commons.
  95. # FWIW, this is the same process Blizzard uses to generate drops in Diablo 2, 3, and WoW, which is why it is well known.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement