Created
December 9, 2013 11:28
-
-
Save Tafkas/7870870 to your computer and use it in GitHub Desktop.
A simulation of the martingale roulette system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python | |
| # encoding: utf-8 | |
| import random | |
| import time | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| #simulates the martingale roulette system | |
| def simulation(): | |
| print("Here we go") | |
| # maximum money you can put on the table | |
| limit = 1200 | |
| #rounds of games simulated | |
| rounds = 10000 | |
| #get time stamp | |
| before = time.clock() | |
| #simulates games up to the target of 1000..2000 units by 100 | |
| x, y = [], [] | |
| for i in xrange(1000, 2001, 100): | |
| print(i) | |
| won = 0 #games won | |
| for j in xrange(1, rounds): | |
| target = i #if reached target => success | |
| money = 1000 # inital money | |
| bet = 1 #inital bet | |
| while True: | |
| if (money >= target): | |
| won += 1 | |
| break | |
| number = random.randrange(0, 37) # Rien ne va plus! | |
| if (number == 0): # zero always loses | |
| money -= bet | |
| bet *= 2 | |
| else: | |
| if (number % 2) == 0 :# even number == round won | |
| money += bet | |
| bet = 1 | |
| else: # odd number == round lost | |
| money -= bet | |
| bet *= 2 | |
| if (bet > money): # put in all you have | |
| bet = money | |
| if (money <= 0): # poor you | |
| break | |
| if (bet > limit): # cannot go over the limit | |
| bet = limit | |
| #compute statistics | |
| lost = rounds - won | |
| ratio = (100*won/rounds) | |
| x.append(i) | |
| y.append(ratio) | |
| # chart says more than a thousand words | |
| x, y = np.array(x), np.array(y) | |
| line, = plt.plot(x, y, '--', linewidth=2) | |
| plt.xlabel('Winning Target') | |
| plt.ylabel('Probability') | |
| plt.title('Martingale starting with 1000 units and 1200 tabel limit') | |
| plt.ylim(ymin=0) | |
| plt.grid() | |
| plt.show() | |
| print('Target: %d, Games won: %d, Games lost: %d, Ratio: %f' % (target, won, lost, ratio)) | |
| elapsed = time.clock() - before | |
| print("%d rounds took %d seconds" % (rounds, elapsed)) | |
| def main(): | |
| #start the simulation | |
| simulation() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment