Created
August 30, 2017 18:16
-
-
Save jonnyrobbie/a5bfc6de378bc1a8edc10c8d5f08728f to your computer and use it in GitHub Desktop.
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/bin/python | |
| #python3 | |
| #Gambling simulator based on Looking Glass Universe's https://www.youtube.com/watch?v=t8L9GCophac | |
| import argparse | |
| import logging | |
| from random import random | |
| from matplotlib import pyplot as plt | |
| #argument parser | |
| parser = argparse.ArgumentParser(description='Gambling simulator based on Looking Glass Universe\'s https://www.youtube.com/watch?v=t8L9GCophac.') | |
| parser.add_argument("-p", "--pwin", help="Probability of a player win.", action="store", type=float, default=0.5) | |
| parser.add_argument("-w", "--win", help="Base win payout.", action="store", type=float, default=1) | |
| parser.add_argument("-l", "--lose", help="Base lose payout.", action="store", type=float, default=(-1)) | |
| parser.add_argument("-a", "--add", help="Added bet after lose.", action="store", type=float, default=1) | |
| parser.add_argument("-t", "--limit", help="Bet limit.", action="store", type=float, default=0) | |
| parser.add_argument("-r", "--round", help="Round number limit.", action="store", type=int, default=100) | |
| parser.add_argument("-m", "--matplot", help="Draw plot of bank history.", action="store_true") | |
| parser.add_argument("-v", "--verbose", help="Verbose output.", action="count") | |
| args = parser.parse_args() | |
| #logging setup | |
| vcount = {2: logging.DEBUG, | |
| 1: logging.INFO, | |
| None: logging.WARNING} | |
| logging.basicConfig(level=vcount[args.verbose]) | |
| #main loop | |
| bank = 0 | |
| lose_strike = 0 #length of lose strike | |
| lost_in_strike = 0 #accumulated amount lost in a current lose strike | |
| bet_multiplier = 1 | |
| bank_dic = [] | |
| mult_list = [] | |
| for round in range(args.round): | |
| print("="*5) | |
| print("Round %i:" % (round+1)) | |
| won_round = 0 | |
| while not won_round: | |
| throw = random() | |
| print("Current bets are W%f L%f" % (args.win*bet_multiplier, args.lose*bet_multiplier)) | |
| print("Throw %f: %s" % (throw, "WIN" if throw <= args.pwin else "LOSE")) | |
| if throw <= args.pwin: | |
| bank += args.win*bet_multiplier | |
| lose_strike = 0 | |
| lost_in_strike = 0 | |
| print("Won %f, lose strike %i" % (args.win*bet_multiplier, lose_strike)) | |
| bet_multiplier = 1 | |
| print("Bet multiplier %f" % bet_multiplier) | |
| else: | |
| bank += args.lose*bet_multiplier | |
| lose_strike += 1 | |
| lost_in_strike += args.lose*bet_multiplier | |
| print("Lost %f, lose strike %i (lost %f)" % (args.lose*bet_multiplier, lose_strike, lost_in_strike)) | |
| bet_multiplier = (lost_in_strike-args.add)/args.lose | |
| print("Bet multiplier %f" % bet_multiplier) | |
| print("Bank %f" % bank) | |
| bank_dic.append(bank) | |
| mult_list.append(bet_multiplier) | |
| won_round = throw <= args.pwin | |
| if bet_multiplier*args.win > args.limit and args.limit != 0: | |
| print("Taking loses, resetting strike") | |
| won_round = 1 | |
| lose_strike = 0 | |
| lost_in_strike = 0 | |
| bet_multiplier = 1 | |
| print("-"*5) | |
| print("Bank history: %s" % str(bank_dic)) | |
| print("Bet multiplier history: %s" % str(mult_list)) | |
| #plotting | |
| if args.matplot == 1: | |
| plt.plot(range(len(bank_dic)), bank_dic) | |
| plt.title("Bank History") | |
| plt.ylabel("Bank") | |
| plt.xlabel("Play") | |
| plt.show() |
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/bin/python | |
| #python3 | |
| #Gambling simulator based on Looking Glass Universe's https://www.youtube.com/watch?v=t8L9GCophac | |
| import argparse | |
| import logging | |
| from random import random | |
| from matplotlib import pyplot as plt | |
| #argument parser | |
| parser = argparse.ArgumentParser(description='Gambling simulator based on Looking Glass Universe\'s https://www.youtube.com/watch?v=t8L9GCophac.') | |
| parser.add_argument("-p", "--pwin", help="Probability of a player win.", action="store", type=float, default=0.5) | |
| parser.add_argument("-w", "--win", help="Base win payout.", action="store", type=float, default=1) | |
| parser.add_argument("-l", "--lose", help="Base lose payout.", action="store", type=float, default=(-1)) | |
| parser.add_argument("-a", "--add", help="Added bet after lose.", action="store", type=float, default=1) | |
| parser.add_argument("-t", "--limit", help="Bet limit.", action="store", type=float, default=0) | |
| parser.add_argument("-r", "--round", help="Round number limit.", action="store", type=int, default=100) | |
| parser.add_argument("-m", "--matplot", help="Draw plot of bank history.", action="store_true") | |
| parser.add_argument("-v", "--verbose", help="Verbose output.", action="count") | |
| args = parser.parse_args() | |
| #logging setup | |
| vcount = {2: logging.DEBUG, | |
| 1: logging.INFO, | |
| None: logging.WARNING} | |
| logging.basicConfig(level=vcount[args.verbose]) | |
| #main loop | |
| bank = 0 | |
| lose_strike = 0 #length of lose strike | |
| lost_in_strike = 0 #accumulated amount lost in a current lose strike | |
| bet_multiplier = 1 | |
| bank_dic = [] | |
| mult_list = [] | |
| for round in range(args.round): | |
| print("="*5) | |
| print("Round %i:" % (round+1)) | |
| won_round = 0 | |
| while not won_round: | |
| throw = random() | |
| print("Current bets are W%f L%f" % (args.win*bet_multiplier, args.lose*bet_multiplier)) | |
| print("Throw %f: %s" % (throw, "WIN" if throw <= args.pwin else "LOSE")) | |
| if throw <= args.pwin: | |
| bank += args.win*bet_multiplier | |
| lose_strike = 0 | |
| lost_in_strike = 0 | |
| print("Won %f, lose strike %i" % (args.win*bet_multiplier, lose_strike)) | |
| bet_multiplier = 1 | |
| print("Bet multiplier %f" % bet_multiplier) | |
| else: | |
| bank += args.lose*bet_multiplier | |
| lose_strike += 1 | |
| lost_in_strike += args.lose*bet_multiplier | |
| print("Lost %f, lose strike %i (lost %f)" % (args.lose*bet_multiplier, lose_strike, lost_in_strike)) | |
| bet_multiplier = (lost_in_strike-args.add)/args.lose | |
| print("Bet multiplier %f" % bet_multiplier) | |
| print("Bank %f" % bank) | |
| bank_dic.append(bank) | |
| mult_list.append(bet_multiplier) | |
| won_round = throw <= args.pwin | |
| if bet_multiplier*args.win > args.limit and args.limit != 0: | |
| print("Taking loses, resetting strike") | |
| won_round = 1 | |
| lose_strike = 0 | |
| lost_in_strike = 0 | |
| bet_multiplier = 1 | |
| print("-"*5) | |
| print("Bank history: %s" % str(bank_dic)) | |
| print("Bet multiplier history: %s" % str(mult_list)) | |
| #plotting | |
| if args.matplot == 1: | |
| plt.plot(range(len(bank_dic)), bank_dic) | |
| plt.title("Bank History") | |
| plt.ylabel("Bank") | |
| plt.xlabel("Play") | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment