Advertisement
makispaiktis

Betting Odds - V2 with other algorithm for possibilities

Jul 26th, 2021 (edited)
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.83 KB | None | 0 0
  1. from math import floor
  2. from random import randrange
  3.  
  4. # Function 0
  5. def sort(myList):
  6.     for i in range(len(myList)):
  7.         for j in range(i, len(myList)):
  8.             if myList[i] > myList[j]:
  9.                 myList[i], myList[j] = myList[j], myList[i]
  10.     return myList
  11.  
  12. # Function 1
  13. def findMinOdd(aces, ties, doubles, index):
  14.     array = [aces[index], ties[index], doubles[index]]
  15.     return min(array)
  16.  
  17. # Function 2
  18. def regularize(a, b, c):
  19.     syntelestis = 100 / (a + b + c)
  20.     return [a*syntelestis, b*syntelestis, c*syntelestis]
  21.  
  22. # Function 3
  23. def calculatePossibilities(ace, tie, double):
  24.     aceP = 100 / ace
  25.     tieP = 100 / tie
  26.     doubleP = 100 / double
  27.     # But aceP + .... maybe is over 100 ----> regularization
  28.     # I will return the possibilities in a sorted list, so that the 3rd number
  29.     # is matched with the highest probability and the lowest odd
  30.     acePoss, tiePoss, doublePoss = regularize(aceP, tieP, doubleP)
  31.     possibilities = [acePoss, tiePoss, doublePoss]
  32.     possibilities = sort(possibilities)
  33.     return possibilities
  34.  
  35. # Function 4
  36. def produceResult(p1, p2, p3):
  37.     # p1, p2, p3 have 3 decimal places
  38.     P1 = 1000 * p1
  39.     P2 = 1000 * p2
  40.     P3 = 1000 * p3
  41.     spot1 = P1
  42.     spot2 = P1 + P2
  43.     spot3 = int(P1 + P2 + P3)
  44.     r = randrange(1, spot3+1)
  45.     if r <= spot1:
  46.         return 1
  47.     elif r <= spot2:
  48.         return 2
  49.     else:
  50.         return 3
  51.     # My function returns 1, 2 or 3.
  52.     # 3 means that the 3rd possibility became true. The 3rd possibility is always the highest one,
  53.     # so the 3rd possibility is combined with the result with the lowest odd
  54.  
  55. # Function 5
  56. def simulate1Match(aces, ties, doubles, index):
  57.     if len(aces) != len(ties) or len(aces) != len(doubles) or len(ties) != len(doubles):
  58.         print("Error 1 while using function '" + simulate1Match.__name__ + "'")
  59.         return -1000
  60.     N = len(aces)
  61.     if index >= N:
  62.         print("Error 2 while using function '" + simulate1Match.__name__ + "'")
  63.         return -1000
  64.     ace = aces[index]
  65.     tie = ties[index]
  66.     double = doubles[index]
  67.     p1, p2, p3 = calculatePossibilities(ace, tie, double)
  68.     result = produceResult(p1, p2, p3)
  69.     return result
  70.  
  71. # Function 6
  72. def simulate1Round(aces, ties, doubles, bet):
  73.     if len(aces) != len(ties) or len(aces) != len(doubles) or len(ties) != len(doubles):
  74.         print("Error 1 while using function '" + simulate1Match.__name__ + "'")
  75.         return -1000
  76.     N = len(aces)
  77.     betPerRound = N * bet
  78.     moneyWon = 0
  79.     for index in range(N):
  80.         result = simulate1Match(aces, ties, doubles, index)
  81.         # I will always bet in result = 3, because that means I am betting
  82.         # in the highest possibility and minimum odd
  83.         if result == 3:
  84.             # I will gain money
  85.             apodosi = findMinOdd(aces, ties, doubles, index)
  86.             extraMoney = apodosi * bet
  87.             moneyWon += extraMoney
  88.             # print("index = " + str(index))
  89.             # print("apodosi = " + str(apodosi))
  90.             # print("extra money = " + str(extraMoney))
  91.             # print("Money won = " + str(moneyWon))
  92.             # print()
  93.     print("Bet per round = " + str(N) + " * " + str(bet) + " = " + str(betPerRound))
  94.     print("Money won = " + str(moneyWon))
  95.     return moneyWon, betPerRound
  96.  
  97. # Function 7
  98. def giveOdd(n1, n2):
  99.     if n1 >= n2:
  100.         print("Error while using function '" + selectData.__name__ + "'")
  101.         print("n1 >= n2")
  102.         return -1000
  103.     N1 = int(100 * n1)
  104.     N2 = int(100 * n2)
  105.     N = randrange(N1, N2+1)
  106.     n = N / 100
  107.     return n
  108.  
  109. # Function 8 - Select data vectors
  110. def selectData(caseNumber):
  111.     if caseNumber == 1:
  112.         aces = [17.5, 1.14, 1.85, 4.7, 5.5, 13, 1.75, 1.11, 5.4, 4, 1.28, 1.67, 1.26]
  113.         ties = [7.5, 7.2, 3.35, 3.25, 4.05, 5.3, 3.45, 7.8, 4.8, 3.7, 6, 3.9, 6.35]
  114.         doubles = [1.11, 15.5, 3.95, 1.78, 1.6, 1.22, 4.35, 16.5, 1.44, 1.75, 7.2, 4.85, 8.95]
  115.         return aces, ties, doubles
  116.     elif caseNumber == 2:
  117.         ace1 = 1.05
  118.         ace2 = 1.5
  119.         tie1 = 4.5
  120.         tie2 = 6.5
  121.         double1 = 8.5
  122.         double2 = 10.5
  123.         N = 13
  124.         aces = []
  125.         ties = []
  126.         doubles = []
  127.         for i in range(N):
  128.             aces.append(giveOdd(ace1, ace2))
  129.             ties.append(giveOdd(tie1, tie2))
  130.             doubles.append(giveOdd(double1, double2))
  131.         return aces, ties, doubles
  132.     else:
  133.         print("Error while using function '" + selectData.__name__ + "'")
  134.         print("CaseNumber " + str(caseNumber) + " not valid.")
  135.         return -1000
  136.  
  137.  
  138. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  139. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  141. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142. # MAIN FUNCTION
  143. # Simulation
  144. bet = 10
  145. caseNumber = 1                                  # IMPORTANT! 1 FOR PLAYING WITH REAL DATA, 2 FOR PLAYING UNDER CONDITIONS OF FUNCTION 8
  146. aces, ties, doubles = selectData(caseNumber)
  147. rounds = 10**4
  148. totalEarnings = 0
  149. totalBet = 0
  150. for round in range(1, rounds+1):
  151.     print("Round " + str(round))
  152.     moneyWon, betPerRound = simulate1Round(aces, ties, doubles, bet)
  153.     totalEarnings += moneyWon
  154.     totalBet += betPerRound
  155.     print()
  156. print()
  157.  
  158. print("**************** Total Stats ****************")
  159. print("Aces =", aces)
  160. print("Ties =", ties)
  161. print("Doubles = ", doubles)
  162. print()
  163. print("    Rounds     = " + str(rounds))
  164. print("   Total Bet   = " + str(totalBet))
  165. totalEarnings = floor(totalEarnings)
  166. print("Total Earnings = " + str(totalEarnings))
  167. gain = totalEarnings - totalBet
  168. percentage = gain / totalBet
  169. percentage100 = percentage * 100
  170. print("Gain = " + str(gain) + " = " + str(percentage100) + "%.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement