-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseSimulation.py
More file actions
88 lines (84 loc) · 3.73 KB
/
BaseSimulation.py
File metadata and controls
88 lines (84 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import random
import string
class SlotMachine:
def __init__(self,reelNum, winDict):
self.reels=[list(string.ascii_uppercase[:22])] *reelNum
self.wins=winDict
def spin(self):
spinResult = ''
for reel in self.reels:
spinResult += str(random.choice(reel))
return spinResult
def simulation(self, spinCount, potAmt, betAmt):
self.spinCount, self.potAmt, self.betAmt=spinCount, potAmt, betAmt
jackpot=0
startingpot=potAmt
totalPaid=0
winningSpins=0
for i in range(self.spinCount):
potAmt+= betAmt
currSpin=self.spin()
hits=[item for item in self.wins.keys() if item in currSpin]
if hits:
multiplier = self.wins[max(hits)]
payout = (betAmt*multiplier)
potAmt -= payout
totalPaid += payout
winningSpins += 1
if multiplier == self.wins[max(self.wins.keys())]:
jackpot += 1
returnToPlayer = float(f"{totalPaid / (betAmt * spinCount)}")
profit = potAmt - startingpot
if totalPaid == 0:
profit = f"${float(profit):,.2f}"
return f"{winningSpins} wins/{spinCount} spins. Simulated profit: {profit}. RTP: 0.0"
if profit > 0:
profit = f"${float(profit):,.2f}"
return f"{winningSpins} wins/{spinCount} spins. Simulated profit: {profit}. RTP: {returnToPlayer:.2f}"
elif profit < 0:
profit = f"${float(profit):,.2f}"
profit = str(profit).replace("-", "-$")
return f"{winningSpins} wins/{spinCount} spins. Simulated profit: {profit}. RTP: {returnToPlayer:.2f}"
else:
return f"{winningSpins} wins/{spinCount} spins. Simulated profit: {profit}. RTP: {returnToPlayer:.2f}"
class SlotMachine2:
def __init__(self,reelNum, winDict):
self.reels=[list(string.ascii_uppercase[:22])] *reelNum
self.wins=winDict
def spin(self):
spinResult = ''
for reel in self.reels:
spinResult += str(random.choice(reel))
return spinResult
def simulation(self, spinCount, potAmt, betAmt):
self.spinCount, self.potAmt, self.betAmt=spinCount, potAmt, betAmt
jackpot=0
startingpot=potAmt
totalPaid=0
winningSpins=0
for i in range(self.spinCount):
potAmt+= betAmt
currSpin=self.spin()
hits=[item for item in self.wins.keys() if item in currSpin]
if hits:
multiplier = self.wins[max(hits)]
payout = (betAmt*multiplier)
potAmt -= payout
totalPaid += payout
winningSpins += 1
if multiplier == self.wins[max(self.wins.keys())]:
jackpot += 1
returnToPlayer = float(f"{totalPaid / (betAmt * spinCount)}")
profit = potAmt - startingpot
if totalPaid == 0:
profit = f"${float(profit):,.2f}"
return f"{winningSpins} wins/{spinCount} spins. Simulated profit: {profit}. RTP: 0.0"
if profit > 0:
profit = f"${float(profit):,.2f}"
return f"{winningSpins} wins/{spinCount} spins. Simulated profit: {profit}. RTP: {returnToPlayer:.2f}"
elif profit < 0:
profit = f"${float(profit):,.2f}"
#profit = str(profit).replace("-", "-$")
return f"{winningSpins} wins/{spinCount} spins. Simulated profit: {profit}. RTP: {returnToPlayer:.2f}"
else:
return f"{winningSpins} wins/{spinCount} spins. Simulated profit: {profit}. RTP: {returnToPlayer:.2f}"