Advertisement
Guest User

Untitled

a guest
May 14th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.74 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import random
  4.  
  5. # Standard game result multipliers
  6. STD_DOUBLE = 2
  7. STD_GREEN = 14
  8.  
  9. # Enhanced "0%-edge" game result multipliers (for $MONK bets)
  10. HOUSE_EDGE = 0
  11. ZERO_EDGE_DOUBLE = (1 - HOUSE_EDGE) / (7 / 15) # 2.14
  12. ZERO_EDGE_GREEN = (1 - HOUSE_EDGE) / (1 / 15) # 15
  13. print(f"Enhanced 0%-edge 2x red/black multiplier: {ZERO_EDGE_DOUBLE:.2f}x")
  14. print(f"Enhanced 0%-edge 14x green multiplier: {ZERO_EDGE_GREEN:.2f}x")
  15.  
  16. def generate_balance_history_graph(std_balance_history, zero_edge_balance_history):
  17.     plt.figure(figsize=(10, 5))
  18.     plt.plot(std_balance_history, marker='.', color='green')
  19.     plt.plot(zero_edge_balance_history, marker='|', color='blue')
  20.     plt.title('Roulette user balance history')
  21.     plt.xlabel('Bet #')
  22.     plt.ylabel('Balance')
  23.     plt.show()
  24.  
  25. def plot_frequency_bar_chart(frequency_array):
  26.     plt.figure(figsize=(10, 5))
  27.     roulette_results = range(len(frequency_array))
  28.     plt.bar(roulette_results, frequency_array, color='blue')
  29.     plt.title('Game result distribution')
  30.     plt.xlabel('Roulette numbers')
  31.     plt.ylabel('Frequency')
  32.     plt.xticks(roulette_results)
  33.     plt.show()
  34.  
  35. # red: 1-7, black: 8-14, green: 15
  36. def gen_result(result_idx):
  37.     if result_idx >= 1 and result_idx <= 7:
  38.         return STD_DOUBLE, ZERO_EDGE_DOUBLE, 'red', result_idx
  39.     if result_idx >= 8 and result_idx <= 14:
  40.         return STD_DOUBLE, ZERO_EDGE_DOUBLE, 'black', result_idx
  41.     if result_idx == 15:
  42.         return STD_GREEN, ZERO_EDGE_GREEN, 'green', result_idx
  43.  
  44. NUM_SIMS = 10000
  45. START_BALANCE = 100
  46. BET_AMOUNT = 1
  47.  
  48. def simulate_bets(results, is_theoretical = False):
  49.     result_distribution = np.zeros(15)
  50.  
  51.     std_balance_history = np.zeros(NUM_SIMS)
  52.     zero_edge_balance_history = np.zeros(NUM_SIMS)
  53.  
  54.     std_balance = START_BALANCE
  55.     zero_edge_balance = START_BALANCE
  56.  
  57.     std_total_wagered = 0
  58.     zero_edge_total_wagered = 0
  59.  
  60.     default_bet_color = 'black' # (only for theoretical scenario)
  61.  
  62.     for i in range(len(results)):
  63.         multiplier, zero_edge_multiplier, color, idx = results[i]
  64.         result_distribution[idx - 1] += 1
  65.  
  66.         std_balance_history[i] = std_balance
  67.         zero_edge_balance_history[i] = zero_edge_balance
  68.  
  69.         random_color = ['red', 'green', 'black'][random.randint(0, 2)]
  70.         user_bet_color = random_color if not is_theoretical else default_bet_color
  71.         bet_won = user_bet_color == color
  72.  
  73.         if bet_won:
  74.             if (std_balance > 0):
  75.                 std_balance += (BET_AMOUNT * multiplier) - BET_AMOUNT
  76.                 std_total_wagered += BET_AMOUNT
  77.             if (zero_edge_balance > 0):
  78.                 zero_edge_balance += (BET_AMOUNT * zero_edge_multiplier) - BET_AMOUNT
  79.                 zero_edge_total_wagered += BET_AMOUNT
  80.         else:
  81.             if (std_balance > 0):
  82.                 std_balance -= BET_AMOUNT
  83.                 std_total_wagered += BET_AMOUNT
  84.             if (zero_edge_balance > 0):
  85.                 zero_edge_balance -= BET_AMOUNT
  86.                 zero_edge_total_wagered += BET_AMOUNT
  87.     generate_balance_history_graph(std_balance_history, zero_edge_balance_history)
  88.     # plot_frequency_bar_chart(result_distribution)
  89.     print('Standard total wagered:', zero_edge_total_wagered)
  90.     print('Zero edge total wagered:', zero_edge_total_wagered)
  91.  
  92. # User bets on a random color; game outcome is random
  93. def simulated():
  94.     results = list(map(lambda x: gen_result(x), np.random.randint(1, 15 + 1, NUM_SIMS)))
  95.     simulate_bets(results)
  96.  
  97. # User bets on constant color; game outcomes matches theoretical expected distribution
  98. def theoretical():
  99.     results = [gen_result((i % 15) + 1) for i in range(NUM_SIMS)]
  100.     simulate_bets(results, True)
  101.  
  102. theoretical()
  103. simulated()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement