Alyssa

Slot_Stats.py

Apr 20th, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.46 KB | None | 0 0
  1. import readline
  2. import math
  3.  
  4. sh = {"a": "apple", "b": "banana", "r": "berry", "c": "cherry", "j": "jackpot", "w": "watermelon"}
  5. fruits = ["apple", "banana", "berry", "cherry", "jackpot", "watermelon"]
  6. #Gathered from the 5-slots, so multiply by 5 to get original values.
  7. #apples might be 500
  8. #bananas might be 375
  9. #no idea on jackpot
  10. rewards = {"cherry": 10, "watermelon": 25, "berry": 40, "apple": 100, "banana": 75, "jackpot": 500}
  11.  
  12. def inits():
  13.     global firsts
  14.     global seconds
  15.     global thirds
  16.     global totals
  17.     global wins
  18.     global win_total
  19.     global losses
  20.     global history
  21.     global win_cash
  22.     firsts = {}
  23.     seconds = {}
  24.     thirds = {}
  25.     totals = {}
  26.     wins = {}
  27.     win_total = 0
  28.     losses = 0
  29.     win_cash = 0
  30.     history = []
  31.     for fruit in fruits:
  32.         firsts[fruit] = 0
  33.         seconds[fruit] = 0
  34.         thirds[fruit] = 0
  35.         totals[fruit] = 0
  36.         wins[fruit] = 0
  37.  
  38. inits()
  39.  
  40. def inc_totals(results):
  41.     r_first = results[0:1].lower()
  42.     r_second = results[1:2].lower()
  43.     r_third = results[2:3].lower()
  44.     firsts[sh[r_first]] += 1
  45.     seconds[sh[r_second]] += 1
  46.     thirds[sh[r_third]] += 1
  47.     totals[sh[r_first]] += 1
  48.     totals[sh[r_second]] += 1
  49.     totals[sh[r_third]] += 1
  50.  
  51. def win_check(results):
  52.     first_char = results[0:1].lower()
  53.     if results.lower() == first_char*3:
  54.         return sh[first_char]
  55.     else:
  56.         return False
  57.  
  58. def parse_results(results):
  59.     global losses
  60.     global win_total
  61.     global wins
  62.     global win_cash
  63.     inc_totals(results)
  64.     win_result = win_check(results)
  65.     if win_result:
  66.         print("WIN: " + win_result)
  67.         win_cash += rewards[win_result]
  68.         wins[win_result] += 1
  69.         win_total += 1
  70.     else:
  71.         losses += 1
  72.     history.append(results)
  73.  
  74. def calc_percent(num, decimals=1):
  75.         num *= (10**(2 + decimals))
  76.         num = round(num)
  77.         num = num / (10 ** decimals)
  78.         return num
  79.  
  80. def display_stats():
  81.     win_rate = calc_percent(win_total / losses)
  82.     total_fruits = (losses + win_total) * 3
  83.     games_played = (losses + win_total)
  84.     fruit_rates = {}
  85.     print("STATS")
  86.     for fruit in fruits:
  87.         fruit_rates[fruit] = calc_percent(totals[fruit] / total_fruits)
  88.         print(fruit + " rate: " + str(fruit_rates[fruit]) + "%")
  89.     print("Win Rate: " + str(win_rate) + "%")
  90.     print("Profit: " + str(round((win_cash / games_played) * 1000)/1000) + "x")
  91.     print("PREDICTIONS")
  92.     fruit_win_rates = {}
  93.     weighted_returns = {}
  94.     loss_rate = 1
  95.     for fruit in fruits:
  96.         fruit_win_rates[fruit] = (totals[fruit] / total_fruits)**3
  97.         weighted_returns[fruit] = fruit_win_rates[fruit] * (100 * (rewards[fruit] -1) )
  98.         loss_rate -= fruit_win_rates[fruit]
  99.         print(fruit + " win rate: " + str(calc_percent(fruit_win_rates[fruit],3)) + "%")
  100.     weighted_returns["bust"] = (loss_rate * -100)
  101.     weighted_sum = 0
  102.     for weight in weighted_returns:
  103.         weighted_sum += weighted_returns[weight]
  104.     multiplied_returns = 1
  105.     multiplied_returns += (weighted_sum / 100)
  106.     print("Expected Win Rate: " + str(calc_percent(1 - loss_rate)) + "%")
  107.     print("Expected Return: " + str(round(multiplied_returns*1000)/1000) + "x")
  108.     print("Data is from " + str(len(history)) + " rolls.")
  109.  
  110. def display_history():
  111.     print(str(history))
  112.  
  113. def import_history(hist):
  114.     global history
  115.     inits()
  116.     hist = eval(hist)
  117.     for roll in hist:
  118.         parse_results(roll)
  119.  
  120. print("Type 'stats' for stats!")
  121. print("Type 'history' for history!")
  122. print("Type 'import []' to import!")
  123. while True:
  124.     results = input()
  125.     if results == "stats":
  126.         display_stats()
  127.     elif results == "history":
  128.         display_history()
  129.     elif results[0:7] == "import ":
  130.         import_history(results[7:])
  131.     else:
  132.         parse_results(results)
Advertisement
Add Comment
Please, Sign In to add comment