Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import floor
- from random import randrange
- # Function 1
- def sort(myList):
- for i in range(len(myList)):
- for j in range(i, len(myList)):
- if myList[i] > myList[j]:
- myList[i], myList[j] = myList[j], myList[i]
- return myList
- # Function 2
- def findMinOdd(aces, ties, doubles, index):
- array = [aces[index], ties[index], doubles[index]]
- return min(array)
- # Function 3
- def calculatePossibilities(ace, tie, double):
- SUM = ace + tie + double
- aceP = ace / SUM
- tieP = tie / SUM
- doubleP = double / SUM
- possibilities = [aceP, tieP, doubleP]
- possibilities = sort(possibilities)
- return possibilities
- # I will return the possibilities in a sorted list, so that the 3rd number
- # is matched with the highest probability and the lowest odd
- # Function 4
- def produceResult(p1, p2, p3):
- # p1, p2, p3 have 3 decimal places
- P1 = 1000 * p1
- P2 = 1000 * p2
- P3 = 1000 * p3
- spot1 = P1
- spot2 = P1 + P2
- spot3 = int(P1 + P2 + P3)
- r = randrange(1, spot3+1)
- if r <= spot1:
- return 1
- elif r <= spot2:
- return 2
- else:
- return 3
- # My function returns 1, 2 or 3.
- # 3 means that the 3rd possibility became true. The 3rd possibility is always the highest one,
- # so the 3rd possibility is combined with the result with the lowest odd
- # Function 5
- def simulate1Match(aces, ties, doubles, index):
- if len(aces) != len(ties) or len(aces) != len(doubles) or len(ties) != len(doubles):
- print("Error 1 while using function '" + simulate1Match.__name__ + "'")
- return -1000
- N = len(aces)
- if index >= N:
- print("Error 2 while using function '" + simulate1Match.__name__ + "'")
- return -1000
- ace = aces[index]
- tie = ties[index]
- double = doubles[index]
- p1, p2, p3 = calculatePossibilities(ace, tie, double)
- result = produceResult(p1, p2, p3)
- return result
- # Function 6
- def simulate1Round(aces, ties, doubles, bet):
- if len(aces) != len(ties) or len(aces) != len(doubles) or len(ties) != len(doubles):
- print("Error 1 while using function '" + simulate1Match.__name__ + "'")
- return -1000
- N = len(aces)
- betPerRound = N * bet
- moneyWon = 0
- for index in range(N):
- result = simulate1Match(aces, ties, doubles, index)
- # I will always bet in result = 3, because that means I am betting
- # in the highest possibility and minimum odd
- if result == 3:
- # I will gain money
- apodosi = findMinOdd(aces, ties, doubles, index)
- extraMoney = apodosi * bet
- moneyWon += extraMoney
- # print("index = " + str(index))
- # print("apodosi = " + str(apodosi))
- # print("extra money = " + str(extraMoney))
- # print("Money won = " + str(moneyWon))
- # print()
- print("Bet per round = " + str(N) + " * " + str(bet) + " = " + str(betPerRound))
- print("Money won = " + str(moneyWon))
- return moneyWon, betPerRound
- # Function 7
- def giveOdd(n1, n2):
- if n1 >= n2:
- print("Error while using function '" + selectData.__name__ + "'")
- print("n1 >= n2")
- return -1000
- N1 = int(100 * n1)
- N2 = int(100 * n2)
- N = randrange(N1, N2+1)
- n = N / 100
- return n
- # Function 8 - Select data vectors
- def selectData(caseNumber):
- if caseNumber == 1:
- 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]
- 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]
- 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]
- return aces, ties, doubles
- elif caseNumber == 2:
- ace1 = 1.05
- ace2 = 1.5
- tie1 = 5.5
- tie2 = 7.5
- double1 = 14.5
- double2 = 15.5
- N = 13
- aces = []
- ties = []
- doubles = []
- for i in range(N):
- aces.append(giveOdd(ace1, ace2))
- ties.append(giveOdd(tie1, tie2))
- doubles.append(giveOdd(double1, double2))
- return aces, ties, doubles
- else:
- print("Error while using function '" + selectData.__name__ + "'")
- print("CaseNumber " + str(caseNumber) + " not valid.")
- return -1000
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # MAIN FUNCTION
- # Simulation
- bet = 10
- caseNumber = 2 # IMPORTANT! 1 FOR PLAYING WITH REAL DATA, 2 FOR PLAYING UNDER CONDITIONS OF FUNCTION 8
- aces, ties, doubles = selectData(caseNumber)
- rounds = 10**4
- totalEarnings = 0
- totalBet = 0
- for round in range(1, rounds+1):
- print("Round " + str(round))
- moneyWon, betPerRound = simulate1Round(aces, ties, doubles, bet)
- totalEarnings += moneyWon
- totalBet += betPerRound
- print()
- print()
- print("**************** Total Stats ****************")
- print("Aces =", aces)
- print("Ties =", ties)
- print("Doubles = ", doubles)
- print()
- print(" Rounds = " + str(rounds))
- print(" Total Bet = " + str(totalBet))
- totalEarnings = floor(totalEarnings)
- print("Total Earnings = " + str(totalEarnings))
- gain = totalEarnings - totalBet
- percentage = gain / totalBet
- percentage100 = percentage * 100
- print("Gain = " + str(gain) + " = " + str(percentage100) + "%.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement