Guest User

Card Statistics Generator

a guest
Jun 23rd, 2017
4,924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.18 KB | None | 0 0
  1. import random
  2. import copy
  3. from pprint import pprint
  4.  
  5. # Ungoro Cards
  6.  
  7. #Tier 1: 3 epic 1 legend
  8. #Tier 2: 7 epic 5 legend
  9. #Playable: 10 epic 11 legend
  10. NUM_COMMONS = 49
  11. NUM_RARES = 36
  12. NUM_EPICS = 27
  13. NUM_LEGENDARIES = 23
  14. META_LEGENDARIES = 1
  15. META_EPICS = 3
  16. dust_value = {'Common': 5,
  17. 'Rare': 20,
  18. 'Epic': 100,
  19. 'Legendary': 400,
  20. 'Golden Common': 50,
  21. 'Golden Rare': 100,
  22. 'Golden Epic': 400,
  23. 'Golden Legendary': 1600}
  24.  
  25. card_collection_template = {'Common': [0 for i in range(NUM_COMMONS)],
  26. 'Rare': [0 for i in range(NUM_RARES)],
  27. 'Epic': [0 for i in range(NUM_EPICS)],
  28. 'Legendary': [0 for i in range(NUM_LEGENDARIES)],
  29. 'Golden Common': [0 for i in range(NUM_COMMONS)],
  30. 'Golden Rare': [0 for i in range(NUM_RARES)],
  31. 'Golden Epic': [0 for i in range(NUM_EPICS)],
  32. 'Golden Legendary': [0 for i in range(NUM_LEGENDARIES)]}
  33.  
  34.  
  35. class Card:
  36.  
  37. def __init__(self, rarity, card_id):
  38. self.rarity = rarity
  39. self.card_id = card_id
  40.  
  41.  
  42. def create_pack():
  43. pack = []
  44.  
  45. for i in range(5):
  46. r = random.random()
  47.  
  48. if r < .701362:
  49. card = Card('Common', random.randint(0, NUM_COMMONS-1))
  50. elif r - .701362 < .209809:
  51. card = Card('Rare', random.randint(0, NUM_RARES - 1))
  52. elif r - .911172 < .043960:
  53. card = Card('Epic', random.randint(0, NUM_EPICS - 1))
  54. elif r - .955132 < .011262:
  55. card = Card('Legendary', random.randint(0, NUM_LEGENDARIES - 1))
  56. elif r - .966394 < .014714:
  57. card = Card('Golden Common', random.randint(0, NUM_COMMONS - 1))
  58. elif r - .981108 < .015441:
  59. card = Card('Golden Rare', random.randint(0, NUM_RARES - 1))
  60. elif r - .996549 < .002361:
  61. card = Card('Golden Epic', random.randint(0, NUM_EPICS - 1))
  62. elif r - .998910 < .001090:
  63. card = Card('Golden Legendary', random.randint(0, NUM_LEGENDARIES - 1))
  64.  
  65. pack.append(card)
  66.  
  67. return pack
  68.  
  69.  
  70. def calc_remaining_dust_custom(card_collection):
  71. remaining_dust = 0
  72.  
  73. for card_type in ['Common', 'Rare', 'Epic', 'Legendary']:
  74. for x, cards in enumerate(card_collection[card_type]):
  75. if card_type == 'Common':
  76. if cards == 0:
  77. remaining_dust += 80
  78. elif cards == 1:
  79. remaining_dust += 40
  80. if card_type == 'Rare':
  81. if cards == 0:
  82. remaining_dust += 200
  83. elif cards == 1:
  84. remaining_dust += 100
  85. if card_type == 'Epic':
  86. if cards == 0:
  87. remaining_dust += 800
  88. elif cards == 1:
  89. remaining_dust += 400
  90. if x == META_EPICS and card_type == 'Epic':
  91. break
  92. if card_type == 'Legendary':
  93. if cards == 0:
  94. remaining_dust += 1600
  95. if x == META_LEGENDARIES and card_type == 'Legendary':
  96. break
  97.  
  98.  
  99. return remaining_dust
  100.  
  101.  
  102. def calc_duplicate_dust(card_collection):
  103.  
  104. collection_dust = 0
  105.  
  106. for card_type in ['Golden Common', 'Golden Rare', 'Golden Epic', 'Golden Legendary']:
  107. for cards in card_collection[card_type]:
  108. collection_dust += (cards) * dust_value[card_type]
  109.  
  110.  
  111. for card_type in ['Common', 'Rare', 'Epic', 'Legendary']:
  112. for x, cards in enumerate(card_collection[card_type]):
  113. if card_type == 'Common':
  114. if cards > 2:
  115. collection_dust += (cards - 2) * 5
  116. if card_type == 'Rare':
  117. if cards > 2:
  118. collection_dust += (cards - 2) * 20
  119. if x >= META_EPICS and card_type == 'Epic':
  120. if cards > 0:
  121. collection_dust += cards * 100
  122. if x < META_EPICS and card_type == 'Epic':
  123. if cards > 2:
  124. collection_dust += (cards - 2) * 100
  125. if x >= META_LEGENDARIES and card_type == 'Legendary':
  126. if cards > 0:
  127. collection_dust += cards * 400
  128. if x < META_LEGENDARIES and card_type == 'Legendary':
  129. if cards > 1:
  130. collection_dust += (cards - 1) * 400
  131.  
  132. return collection_dust
  133.  
  134. def calc_collection_value(card_collection):
  135.  
  136. collection_dust = 0
  137.  
  138. for card_type in ['Common', 'Rare', 'Epic', 'Legendary']:
  139. for x, cards in enumerate(card_collection[card_type]):
  140. if card_type == 'Common':
  141. if cards > 2:
  142. collection_dust += 2 * 40
  143. elif card_type == 1:
  144. collection_dust += 40
  145. if card_type == 'Rare':
  146. if cards > 2:
  147. collection_dust += 2 * 100
  148. elif card_type == 1:
  149. collection_dust += 200
  150. if x < META_EPICS and card_type == 'Epic':
  151. if cards > 2:
  152. collection_dust += 2 * 400
  153. elif card_type == 1:
  154. collection_dust += 400
  155. if x == META_EPICS and card_type == 'Epic':
  156. break
  157. if x < META_LEGENDARIES and card_type == 'Legendary':
  158. if cards > 1:
  159. collection_dust += 1600
  160. if x == META_LEGENDARIES and card_type == 'Legendary':
  161. break
  162.  
  163. return collection_dust
  164.  
  165. def count_commons(card_collection):
  166.  
  167. completion = 0
  168.  
  169. for cards in card_collection['Common']:
  170. if cards > 2:
  171. completion += 2
  172. elif cards == 1:
  173. completion += 1
  174.  
  175. return completion
  176.  
  177. def no_dupes(card_collection):
  178.  
  179. dupes=0
  180. zeroindex=[]
  181.  
  182. for i in range(len(card_collection['Legendary'])):
  183. if card_collection['Legendary'][i]==0:
  184. zeroindex.append(i)
  185.  
  186. random.shuffle(zeroindex)
  187.  
  188. for i in range(len(card_collection['Legendary'])):
  189. if card_collection['Legendary'][i]>1:
  190. dupes = dupes + 1
  191. card_collection['Legendary'][i] = 1
  192. card_collection['Legendary'][zeroindex.pop()]=1
  193.  
  194. return card_collection
  195.  
  196. def main():
  197.  
  198. tries = 500
  199. packs_needed = []
  200. pack_dust = []
  201. total_value = []
  202. common_array = []
  203.  
  204. for i in range(tries):
  205. collection_incomplete = True
  206. card_collection = copy.deepcopy(card_collection_template)
  207. pack_counter = 0
  208. while collection_incomplete:
  209. pack_counter += 1
  210. contains_legendary = False
  211. pack = create_pack()
  212. for card in pack:
  213. card_collection[card.rarity][card.card_id] += 1
  214. card_collection = no_dupes(card_collection)
  215. collection_value = calc_collection_value(card_collection)
  216. duplicate_dust = calc_duplicate_dust(card_collection)
  217. remaining_dust = calc_remaining_dust_custom(card_collection)
  218. commons = count_commons(card_collection)
  219. if duplicate_dust >= remaining_dust:
  220. collection_incomplete = False
  221. common_array.append(commons)
  222. total_value.append((duplicate_dust + collection_value) / pack_counter)
  223. pack_dust.append(duplicate_dust / pack_counter)
  224. packs_needed.append(pack_counter)
  225.  
  226. print('Stats Based on ' + str(tries) + ' tries')
  227. print('For a collection comprising ' + str(META_EPICS) + ' epics, and ' + str(META_LEGENDARIES) + ' legendaries')
  228. print('Average Packs required: ' + str(sum(packs_needed) / tries))
  229. print('Average Dust per pack: ' + str(sum(pack_dust) / tries))
  230. print('Average Value per pack: ' + str(sum(total_value) / tries))
  231. print('Average Common completion: ' + str(sum(common_array) / tries))
  232. pprint(card_collection['Legendary'])
  233.  
  234. if __name__ == "__main__":
  235. main()
Advertisement
Add Comment
Please, Sign In to add comment