'''
Created on Jul 16, 2014
@author: Brett Paufler
Copyright Brett Paufler
'''
import math
import numpy
import lotto_benchmarks as lotto
import matplotlib.pyplot as plt
from lotto_pickle import initializeALLGames
#print lotto.blackjack()
bj = lotto.blackjack()
ct = lotto.coinToss()
cp = lotto.craps()
rl = lotto.roulette()
games = [ct, rl, cp, bj]
pBJ = float(1.00 / bj.prizes[0].odds)
pCT = float(1.00 / ct.prizes[0].odds)
pCP= float(1.00 / cp.prizes[0].odds)
pRL = float(1.00 / rl.prizes[0].odds)
ride = range(1,11)
def basicOddsChart(games):
'''makes HTML odds table for basic casino games (games)
'''
beg = r'
'
end = r' |
'
mid = r''
print '\n\n'
print "%s%s%s%s%s%s%s%s%s" % (beg, "GAME", mid, "ODDS (1/p)", mid, "CHANCE (p)", mid, "PAYOFF (1 for x)", end)
for g in games:
print "%s%s%s%.4f%s%.4f%s%s%s" % (beg, g.name,
mid, g.prizes[0].odds,
mid, 1.00/g.prizes[0].odds,
mid, g.prizes[0].prize, end)
#basicOddsChart(games)
def letItRideChart(games, ride, PorO="p"):
'''makes HTML p/prize (chance/payoff) table for basic casino games (games)
letting bet ride (ride) number of times
'''
beg = r' | '
end = r' |
'
mid = r''
print '\n\n'
midT = ""
for r in ride:
midT += mid + str(r)
print "%s%s%s%s" % (beg, "Let It Ride X Times", midT, end)
for g in games:
midT = ""
for r in ride:
if PorO.lower() == "o":
midT += mid + ("%d" % g.prizes[0].odds ** r)
elif PorO.lower() == "p":
midT += mid + ("%d" % g.prizes[0].prize ** r)
print "%s%s%s%s" % (beg, g.name, midT, end)
#ride = [1,2,3,4,5,10]
#letItRideChart(games, ride, "p")
def oddsVsPayoff(games, targetOdds):
'''
given x odds, what's the payoff
Ot = o**n, log(Ot) = n*log(o), n = Log(Ot)/Log(o)
Wt = w**n, Log(W) = n*log(w), n = log(Wt)/log(w)
Log(Wt)/log(w) = Log(Ot)/log(o)
Log(Wt) = Log(Ot)*log(w)/log(o)
Wt = 10 ** (Log(Ot)*log(w)/log(o))
'''
plt.rcParams['figure.figsize'] = 20,10
leg = []
for g in games:
o = g.prizes[0].odds
w = g.prizes[0].prize
leg.append(g.name)
winPrize = []
for Ot in targetOdds:
Wt = 10 ** (math.log(Ot,10)*math.log(w,10)/math.log(o,10))
winPrize.append(Wt)
#math.lo
#print len(Wt)
#print len(targetOdds)
plt.plot(targetOdds, winPrize)
#powerBall
plt.plot(175223510,40000000, 'bo', markersize=15, color='r')
#megaMillion:
plt.plot(258890850, 32000000, 'bo', markersize=15, color='b')
#superLotto
plt.plot(41416353, 20000000, 'bo', markersize=15, color='g')
plt.legend(leg, loc='upper left')
g1 = "Odds of Winning Various Prize Levels for Common Gambling Games\n(straight streak odds)\n"
g2 = "As Compared To\nSuperLotto (green), PowerBall (red), & MegaMillions (blue)"
graphTitle = g1 + g2
plt.title(graphTitle)
plt.ylabel("Winnings")
plt.xlabel("Odds")
sN = "./lottery/PrizeAtOdds.png"
print "Working On %s" % sN
plt.savefig(sN)
plt.close('all')
#targetOdds = numpy.linspace(1,300000000)
#print targetOdds
#oddsVsPayoff(games, targetOdds)
#print math.log(5000,2)
def graphGamblersRuin(games, spreads):
'''
def
def gamblersRuin(g, s, f):
given a simple game g (one prize level)
returns the chance (1/odds)
that player will win f before they lose s
That is the odds a player will with bankroll s=start
will increase their money to f=finish
while making $1 bets
'''
plt.rcParams['figure.figsize'] = 20,10
leg = []
for g in games:
print g.name
p = 1.00 / g.prizes[0].odds
w = g.prizes[0].prize - 1
leg.append(g.name)
odds = []
for s in spreads:
oT = float(lotto.gR(p, w, s, 100))
odds.append(oT)
print odds
plt.plot(spreads, odds)
plt.legend(leg, loc='upper right')
plt.ylim(0, 0.55)
graphTitle = "Gambler's Ruin\nChance of Reaching $100\n$1 Bets"
plt.title(graphTitle)
plt.ylabel("Chance of Doubling Money")
plt.xlabel("Starting Capital")
sN = "./lottery/GamblersRuin-%s-%s.png" % (spreads[0],spreads[len(spreads)-1])
print "Working On %s" % sN
plt.savefig(sN)
print "Finished %s" % sN
plt.close('all')
#games = [ct, rl, cp, bj]
#spreads = range(1,21,1) #numpy.linspace(1, 101)
#graphGamblersRuin(games, spreads)
def ruinCharts(games, spreads):
beg = r' | '
end = r' |
'
mid = r''
#print '\n\n'
out = ""
out += beg + "2x Odds"
for s in spreads:
out += mid + str(s)
out += end
for g in games:
out += "\n" + beg + g.name + mid
for s in spreads:
oT = float(1 / lotto.gR(1.0/g.prizes[0].odds, (g.prizes[0].prize -1), s, (s*2)))
print "ODDS THIS GAME = oT:%f" % oT
oT = "%.2f" % oT
out += oT + mid
out += end
print out
#games = [ct, rl, cp, bj]
#spreads = [1,2,3,4,5,10,25,35,50,100,500]
#ruinCharts(games, spreads)
#games = [g.name for g in initializeALLGames() if g.prizes[0].prize < 750]
#print games
|