Advertisement
makispaiktis

Roulette - Automatic double bet

Jan 15th, 2021 (edited)
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.05 KB | None | 0 0
  1. from random import randrange
  2. from matplotlib import pyplot as plt
  3.  
  4.  
  5. # Function 1 - Simulate the 2x-bet
  6. def betx2(money, target, DIAIRETIS):
  7.     if money >= target:
  8.         print("Error while uging the function '" + betx2.__name__ +"'")
  9.         return -1000
  10.     initialMoney = money
  11.     tries = 0
  12.     wins = 0
  13.     losses = 0
  14.     lossStreak = 0
  15.     bets = list()
  16.     stats01 = list()
  17.     firstBet = int(money / DIAIRETIS)
  18.  
  19.     # I will simulate the simulation with another way: red will be if my number is between 1 and 18,
  20.     # black will be if my number is between 19 and 36 and "0" will be number 37
  21.  
  22.  
  23.     while money > 0 and money < target:
  24.         tries += 1
  25.         # HERE I MUST CHECK IF I CAN DOUBLE MY MONEY
  26.         # There is a possibility to happen this: money = 10, but next bet must be sth like 80 in order to win
  27.         # So, bet will be all the remaining money
  28.         print("************************ Try ", tries, "************************")
  29.         canIDouble = (money > (firstBet)* (2**lossStreak))
  30.  
  31.         if canIDouble == True:
  32.             # The bet will be determined by the lossStreak
  33.             bet = firstBet * (2**lossStreak)
  34.             bets.append(bet)
  35.         else:
  36.             bet = money
  37.             bets.append(bet)
  38.         money = money - bet
  39.         # We will suppose that our user ALWAYS bets 'red', so we want the random generated number to be
  40.         # between 1 and 18
  41.         randomNumber = randrange(0, 37)
  42.         print("Bet =", bet, ", randomNumber =", randomNumber)
  43.         if randomNumber >= 1 and randomNumber <= 18:
  44.             wins += 1
  45.             lossStreak = 0
  46.             money += 2 * bet
  47.             stats01.append(1)
  48.             print("You won, because 1 <=", randomNumber, "<= 18")
  49.             print("Current money: ", money)
  50.         elif randomNumber >= 19 and randomNumber <= 36:
  51.             losses += 1
  52.             lossStreak += 1
  53.             stats01.append(0)
  54.             print("You lost, because 19 <=", randomNumber, "<= 36")
  55.             print("Current money: ", money)
  56.         else:
  57.             stats01.append(0)
  58.             losses += 1
  59.             lossStreak += 1
  60.             print("You lost, because randomNumber = 0 ----> green color")
  61.             print("Current money: ", money)
  62.         print("*******************************************************")
  63.         print()
  64.  
  65.  
  66.     # Now, the basic process has finished. The remaining stuff is to show the stats in the user and the plot of his luck
  67.     print()
  68.     print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
  69.     print("Here, I will present you the stats of your gameplay.")
  70.     print("Tries =", tries, ", wins =", wins, ", losses =", tries - wins)
  71.     winPercentage = wins / tries
  72.     winPercentage = round(10000 * winPercentage) / 10000
  73.     print("Win percentage  = ", str(wins), "/", str(tries), "=", 100 * winPercentage, "%")
  74.     print()
  75.     gain = money - initialMoney
  76.     gainPercentage = gain / initialMoney
  77.     gainPercentage = round(10000 * gainPercentage) / 10000
  78.     print("Initial money =", initialMoney, ", Final Money =", money, "(", 100 * gainPercentage, "%)")
  79.     # Plotting our data
  80.     plt.plot(stats01, 'ro')
  81.     plt.title("0 = Loss, 1 = Win")
  82.     plt.xlabel("Rounds")
  83.     plt.ylabel("Win/Loss")
  84.     plt.show()
  85.     plt.plot(bets, 'bx')
  86.     plt.title("Bets value per round")
  87.     plt.xlabel("Rounds")
  88.     plt.ylabel("Bet")
  89.     plt.show()
  90.  
  91.  
  92. # **********************************************************************************************************
  93. # ********************************** MAIN FUNCTION *********************************************************
  94. # **********************************************************************************************************
  95. print("Welcome to the Roulette game. Rules are simple. You can only bet in red color")
  96. money = int(input("Money here: "))
  97. while money < 0:
  98.     money = int(input("Money here: "))
  99. target = int(input("Target money here: "))
  100. while target <= money:
  101.     target = int(input("Target money here: "))
  102. DIAIRETIS = 50
  103. betx2(money, target, DIAIRETIS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement