Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- # payoff and successProbability are ignored... this started as a generic class but ended up getting pretty elvenar specific.
- class Gambler:
- def __init__(self,startingMoney,costPerTicket,payoff,successProbability):
- self.money = startingMoney
- self.cost = costPerTicket
- self.prob = successProbability
- self.payoff = payoff
- self.plays = 0
- self.buildings = 0
- def scratch(self):
- if self.money >= self.cost:
- self.money -= self.cost
- randNum = random.random()
- #if randNum < self.prob:
- # self.money += self.payoff
- if randNum < 0.1300:
- self.money += 140
- elif randNum >= 0.1300 and randNum < 0.2000:
- self.money += 200
- elif randNum >= 0.2000 and randNum < 0.4500:
- self.buildings += 1
- self.plays += 1
- return True
- else:
- return False
- def canPlay(self):
- if self.money >= self.cost:
- return True
- else:
- return False
- def checkPlayCount(self):
- return self.plays
- def getBuildings(self):
- return self.buildings
- def simulate(startingMoney,costPerTicket,payoff,successProbability,minGamesForSuccess, trials = 10**5):
- successes = 0
- games = 0
- buildings = 0
- gp2 = 0
- #print "Ran Simulator for " + str(trials) + " trials"
- while games < trials:
- addict = Gambler(startingMoney,costPerTicket,payoff,successProbability)
- while addict.canPlay() and (addict.checkPlayCount() < minGamesForSuccess):
- addict.scratch()
- if addict.checkPlayCount() >= minGamesForSuccess:
- successes += 1
- gp2 += 1
- elif addict.checkPlayCount() >= 33:
- gp2 += 1;
- games += 1
- buildings += addict.getBuildings()
- #print successes
- #print games
- #print buildings
- #print gp2
- #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))
- print("%d\t%1.4f\t%1.4f\t%2.1f" % (startingMoney, ((1.0*gp2)/games), (1.0*successes)/games, (1.0*buildings)/games))
- return round((successes*1.0)/games,8)
- #print("#lottery ticket example")
- #print(simulate(100,5,10,.2,30))
- simulate(9000,140,161,.20,73)
- simulate(8500,140,161,.20,73)
- simulate(8000,140,161,.20,73)
- simulate(7500,140,161,.20,73)
- simulate(7000,140,161,.20,73)
- simulate(6750,140,161,.20,73)
- simulate(6500,140,161,.20,73)
- simulate(6250,140,161,.20,73)
- simulate(6000,140,161,.20,73)
- simulate(5750,140,161,.20,73)
- simulate(5500,140,161,.20,73)
- simulate(5250,140,161,.20,73)
- simulate(5000,140,161,.20,73)
- simulate(4500,140,161,.20,73)
- simulate(4000,140,161,.20,73)
- simulate(3500,140,161,.20,73)
- simulate(3000,140,161,.20,73)
- simulate(2500,140,161,.20,73)
- simulate(2000,140,161,.20,73)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement