Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # By Hamlet, 10/10/2013
- # as attachment to this post:
- # http://iam.yellingontheinternet.com/2013/10/10/from-dust-to-dust-the-economy-of-hearthstone/
- import random
- import math
- #throughout:
- # 0/1/2/3 = common/rare/epic/legendary
- # 0/1 = normal/gold
- #Parameters
- #Disenchant[rarity][gold]
- Disenchant = [[5, 50], [20, 100], [100, 400], [400, 1600]]
- Craft = [[40, 400], [100, 800], [400, 1600], [1600, 3200]]
- #NeutralCardCount = [40, 36, 10, 24]
- #ClassCardCount = [6, 5, 3, 1] #Currently same for each class
- TotalCardCount = [94, 81, 37, 33]
- Required = [2,2,2,1]
- RarityDist = [0.21, 0.04, 0.01] #set rarity of rare/epic/legendary
- RarityDist = [1-sum(RarityDist)] + RarityDist #insert common
- CumulativeDist = [0]*3 #chance that rarity is <= [index]
- for x in range(3):
- CumulativeDist[x] = sum(RarityDist[:x+1])
- GoldFrequency = [0.02, 0.05, 0.05, 0.05]
- #Options
- #Size of card subset we're trying to complete
- DesiredCardCount = TotalCardCount
- # [46, 41, 13, 1] #
- # [94, 81, 37, 0] #
- ForceDisenchant = 0 # 1 = Disenchant all cards outside desired set
- RequireGold = 0 # 1 = Collect only golden cards
- #Craft cost of desired cards
- TotalDustNeeded = sum([DesiredCardCount[x]*Craft[x][RequireGold]*Required[x] for x in range(4)])
- CardsNeeded = [DesiredCardCount[i]*Required[i] for i in range(4)]
- #Stats collected
- Runs = 100
- PacksOpenedRecord = [0]*Runs
- EndingDustRecord = [0]*Runs
- FoundPercentRecord = [[0]*4 for i in range(Runs)] # FPR[run][rarity]
- #simulation
- for Run in range(Runs): #begin each run
- PacksOpened = 0
- DustNeeded = TotalDustNeeded #Craft value of remaining cards this run
- FoundCardValue = 0
- FoundCards = [0]*4
- CardsCollected = [[[0]*2 for i in range(j)] for j in TotalCardCount]
- #CardsCollected[rarity][index][gold]
- while DustNeeded > 0: #open packs
- PacksOpened += 1
- for Card in range(5): #create cards
- Rarity = 3
- Gold = 0
- CardIndex = 0
- rand = random.random()
- for x in range(3): #determine rarity
- if rand < CumulativeDist[x]:
- Rarity = x
- break
- if random.random() < GoldFrequency[Rarity]:
- Gold = 1
- CardIndex = random.randrange(TotalCardCount[Rarity])
- CardsCollected[Rarity][CardIndex][Gold] += 1
- #disenchant card if not needed
- if (RequireGold and Gold == 0): #if disenchanting any non-gold
- CardsCollected[Rarity][CardIndex][Gold] -= 1
- DustNeeded -= Disenchant[Rarity][Gold]
- elif sum(CardsCollected[Rarity][CardIndex]) > Required[Rarity]:
- #extra card
- if CardsCollected[Rarity][CardIndex][1] > 0: #disenchant gold
- CardsCollected[Rarity][CardIndex][1] -= 1
- DustNeeded -= Disenchant[Rarity][1]
- else:
- CardsCollected[Rarity][CardIndex][0] -= 1
- DustNeeded -= Disenchant[Rarity][0]
- elif CardIndex < DesiredCardCount[Rarity]: #card we care about
- DustNeeded -= Craft[Rarity][RequireGold] #reduce remaining goal
- FoundCardValue += Craft[Rarity][RequireGold]
- FoundCards[Rarity] += 1
- elif ForceDisenchant: #Disenchanting all unwanted cards
- CardsCollected[Rarity][CardIndex][Gold] -= 1
- DustNeeded -= Disenchant[Rarity][Gold]
- #Record once we're done
- PacksOpenedRecord[Run] = PacksOpened
- EndingDustRecord[Run] = TotalDustNeeded - FoundCardValue
- FoundPercentRecord[Run] = map(lambda x,y: 0 if y==0 else x/float(y),FoundCards,CardsNeeded)
- # Outputs
- MeanPacks = sum(PacksOpenedRecord)/float(Runs)
- MeanDust = sum(EndingDustRecord)/float(Runs)
- MeanFoundPercent = [0]*4
- for Run in range(Runs):
- MeanFoundPercent = map(lambda x,y: x+y, MeanFoundPercent, FoundPercentRecord[Run])
- MeanFoundPercent = [x/float(Runs) for x in MeanFoundPercent]
- VarPacks = [(x-MeanPacks)**2 for x in PacksOpenedRecord]
- VarDust = [(x-MeanDust)**2 for x in EndingDustRecord]
- StdDevPacks = math.sqrt(sum(VarPacks)/float(Runs))
- StdDevDust = math.sqrt(sum(VarDust)/float(Runs))
- print("Runs", Runs, "Desired Card Set", DesiredCardCount, "Gold?",
- RequireGold, "Force DE", ForceDisenchant)
- print("Packs Opened", MeanPacks, StdDevPacks)
- print("Dust used to craft", MeanDust, StdDevDust, MeanDust/float(TotalDustNeeded))
- print("% cards found", MeanFoundPercent)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement