Advertisement
makispaiktis

Betting Odds

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