Advertisement
Guest User

Untitled

a guest
Dec 19th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.93 KB | None | 0 0
  1. import random
  2.  
  3. # payoff and successProbability are ignored... this started as a generic class but ended up getting pretty elvenar specific.
  4. class Gambler:
  5.     def __init__(self,startingMoney,costPerTicket,payoff,successProbability):
  6.         self.money = startingMoney
  7.         self.cost = costPerTicket
  8.         self.prob = successProbability
  9.         self.payoff = payoff
  10.         self.plays = 0
  11.         self.buildings = 0
  12.     def scratch(self):
  13.         if self.money >= self.cost:
  14.             self.money -= self.cost
  15.             randNum = random.random()
  16.            
  17.             #if randNum < self.prob:
  18.             #    self.money += self.payoff
  19.            
  20.            
  21.             if randNum < 0.1300:
  22.                 self.money += 140
  23.             elif randNum >= 0.1300 and randNum < 0.2000:
  24.                 self.money += 200
  25.             elif randNum >= 0.2000 and randNum < 0.4500:
  26.                 self.buildings += 1
  27.             self.plays += 1
  28.             return True
  29.         else:
  30.             return False
  31.     def canPlay(self):
  32.         if self.money >= self.cost:
  33.             return True
  34.         else:
  35.             return False
  36.     def checkPlayCount(self):
  37.         return self.plays
  38.     def getBuildings(self):
  39.         return self.buildings
  40.  
  41. def simulate(startingMoney,costPerTicket,payoff,successProbability,minGamesForSuccess, trials = 10**5):
  42.     successes = 0
  43.     games = 0
  44.     buildings = 0
  45.     gp2 = 0
  46.     #print "Ran Simulator for " + str(trials) + " trials"
  47.     while games < trials:
  48.         addict = Gambler(startingMoney,costPerTicket,payoff,successProbability)
  49.         while addict.canPlay() and (addict.checkPlayCount() < minGamesForSuccess):
  50.             addict.scratch()
  51.         if addict.checkPlayCount() >= minGamesForSuccess:
  52.             successes += 1
  53.             gp2 += 1
  54.         elif addict.checkPlayCount() >= 33:
  55.             gp2 += 1;
  56.         games += 1
  57.         buildings += addict.getBuildings()
  58.        
  59.     #print successes
  60.     #print games
  61.     #print buildings
  62.     #print gp2
  63.     #print("With %d flakes, Probability of getting 3rd GP: %1.6f, Daily Exclusive Buildings: %2.2f" % (startingMoney, (1.0*successes)/games, (1.0*buildings)/games))
  64.     print("%d\t%1.4f\t%1.4f\t%2.1f" % (startingMoney, ((1.0*gp2)/games), (1.0*successes)/games, (1.0*buildings)/games))
  65.     return round((successes*1.0)/games,8)
  66.    
  67. #print("#lottery ticket example")
  68. #print(simulate(100,5,10,.2,30))
  69.  
  70. simulate(9000,140,161,.20,73)
  71. simulate(8500,140,161,.20,73)
  72. simulate(8000,140,161,.20,73)
  73. simulate(7500,140,161,.20,73)
  74. simulate(7000,140,161,.20,73)
  75. simulate(6750,140,161,.20,73)
  76. simulate(6500,140,161,.20,73)
  77. simulate(6250,140,161,.20,73)
  78. simulate(6000,140,161,.20,73)
  79. simulate(5750,140,161,.20,73)
  80. simulate(5500,140,161,.20,73)
  81. simulate(5250,140,161,.20,73)
  82. simulate(5000,140,161,.20,73)
  83. simulate(4500,140,161,.20,73)
  84. simulate(4000,140,161,.20,73)
  85. simulate(3500,140,161,.20,73)
  86. simulate(3000,140,161,.20,73)
  87. simulate(2500,140,161,.20,73)
  88. simulate(2000,140,161,.20,73)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement