Skip to content

Instantly share code, notes, and snippets.

Created September 7, 2013 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6478117 to your computer and use it in GitHub Desktop.
Save anonymous/6478117 to your computer and use it in GitHub Desktop.
Martingale Prediction for sites like just-dice
#!/usr/bin/python
# Martingale Predictor V0.1
# Author: Fabian1291
# 2013/09/07 for bitcointalk.org
from random import *
from time import sleep
totalwin=0
totalloss=0
lines=0
maxgames=raw_input("Number of games to simulate [default: 10000]: ")
if not maxgames:
maxgames=10000.0
else:
maxgames=float(maxgames)
initialbankroll = raw_input("Start bankroll [default: 0.2]: ")
if not initialbankroll:
initialbankroll = 0.2
else:
initialbankroll=float(initialbankroll)
targetbankroll = raw_input("Target bankroll [default: 0.4]: ")
if not targetbankroll:
targetbankroll = 0.4
else:
targetbankroll=float(targetbankroll)
initialbet = raw_input("Initial bet [default: 0.01]: ")
if not initialbet:
initialbet = 0.01
else:
initialbet=float(initialbet)
max_times_to_double = raw_input("Max times to double the bet [default: 20]: ")
if not max_times_to_double:
max_times_to_double = 20.0
else:
max_times_to_double=float(max_times_to_double)
chancetowin = raw_input("Chance to win [default: 50%]: ")
if not chancetowin:
chancetowin = 50.0
else:
chancetowin=float(chancetowin)
houseedge = raw_input("House edge [default: 1%]: ")
if not houseedge:
houseedge = 1.0
else:
houseedge=float(houseedge)
multiplier = float(100/chancetowin)
faktor = float(multiplier - (multiplier*houseedge/100))
maxfaktor = float(initialbet * (2**max_times_to_double))
maxcounter = 0
o=0.0
while o in xrange(int(maxgames)):
if o%((maxgames/100)*5) == 0:
print str(o/(maxgames/100))+"% ..."
o+=1
bankroll = initialbankroll
bet = initialbet
i = 1
end = False
times_maxbet_was_used=0
while bankroll<targetbankroll and bankroll>=initialbet:
lucky = round((random()*100),4)
while lucky == 100.0:
# scale is from 0.0000 to 99.9999 so luck can't be 100 and has to be calculated again
lucky = round((random()*100),4)
i = i + 1
if (lucky <= (chancetowin-0.0001)):
bankroll=(bankroll-bet)+bet*faktor
buff_bet=bet
bet=initialbet
status=' WIN'
else:
bankroll=bankroll-bet
buff_bet=bet
status=' LOSE'
if bet == maxfaktor:
times_maxbet_was_used += 1
bet = initialbet
else:
if (bet*2)<=bankroll:
bet=bet*2
else:
bet = initialbet
#print "bet " + str(buff_bet) + " * factor " + str(faktor) + " = " + str(buff_bet*faktor)
#print str(i)+'. :'+ str(bankroll) + status
#print "guess: "+str(chancetowin-0.0001)+"; lucky: "+str(lucky)
#print "\n\n"
#sleep(1)
if bankroll<initialbet or bankroll>=targetbankroll:
end = True
if bankroll < initialbet:
totalloss+=1
elif bankroll >=targetbankroll:
totalwin+=1
if end:
lines+=i
#print str(i)+status+' '+ str(bankroll)
maxcounter += times_maxbet_was_used
#print str(times_maxbet_was_used)+ ' mal '+str(maxfaktor)+'x'
print "\nBankroll: " + str(initialbankroll) +" - "+ str(targetbankroll) + " (maxgames: " + str(maxgames)+")"
print "Initial bet: " + str(initialbet)
print "Chance to win: " + str(chancetowin) + "%, Payout: " + str(faktor) + "x times of bet"
print "Max. times to double: " + str(max_times_to_double) + " (max. wager:"+ str(maxfaktor) + ", " + str(maxcounter) + "x used)"
print "Average number of bets needed per game: " + str(int(round((lines/maxgames),0)))
print "\nHow many games were won, how many were lost?"
print " WINS: " + str(totalwin) + "x"
print " LOSSES: " + str(totalloss) + "x"
print "Winning probability for this strategy: " + str(float(totalwin*100/maxgames)) + "%\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment