-
Notifications
You must be signed in to change notification settings - Fork 0
/
roulette_martingale.py
105 lines (92 loc) · 3.79 KB
/
roulette_martingale.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from datetime import datetime
import random
import json
import io
DOUBLE_ZERO = '00'
BLACK = 'BLACK'
RED = 'RED'
ZERO = '0'
class roulette_martingale:
def __init__(self, starting_amount, min_bet, max_bet, modified_strategy, bet_target=BLACK):
self.modified_strategy = modified_strategy
self.amount_before_losing_streak = starting_amount
self.starting_amount = starting_amount
self.current_amount = starting_amount
self.bet_target = bet_target
self.min_bet = min_bet
self.max_bet = max_bet
self.spin_count = 0
self.history = {
'spins': [],
'winnings': []
}
self.spinner = []
for _ in range(49):
self.spinner.append(BLACK)
self.spinner.append(RED)
self.spinner.append(ZERO)
self.spinner.append(DOUBLE_ZERO)
def get_spins_history(self):
return self.history['spins']
def get_winnings_history(self):
return self.history['winnings']
def spin(self):
self.spin_count += 1
random.seed(datetime.now())
random_num = random.randrange(0, 100)
spin_value = self.spinner[random_num]
if spin_value in [ZERO, DOUBLE_ZERO]:
return spin_value
return [spin_value, random_num]
def bet(self,units_bet):
self.current_amount -= units_bet
spin_outcome = self.spin()
if self.bet_target in spin_outcome:
units_won = 2 * units_bet
self.current_amount += units_won
self.amount_before_losing_streak = self.current_amount
return True # Win
return False # Lose
def get_bullets(self):
bullets = []
leftover_bankroll = self.starting_amount
next_bullet = self.min_bet
while leftover_bankroll >= next_bullet:
bullets.append(next_bullet)
leftover_bankroll -= next_bullet
if self.modified_strategy and next_bullet == 2 * self.min_bet:
next_bullet = min(self.min_bet * 3, self.max_bet)
else:
next_bullet = min(next_bullet * 2, self.max_bet)
if leftover_bankroll > 0: bullets.append(leftover_bankroll)
return bullets
def reset(self):
self.spin_count = 0
self.current_amount = self.starting_amount
self.amount_before_losing_streak = self.starting_amount
def play_to_bust(self):
bet_amount = self.min_bet
while bet_amount <= self.current_amount and bet_amount <= self.max_bet:
won_bet = self.bet(bet_amount)
if won_bet:
# Martingale strategy dictates that a bet after a win is the minimum bet value
bet_amount = self.min_bet
else:
if self.modified_strategy and bet_amount == (2 * self.min_bet):
# If we're using the modified martinagle strategy, we'll be in "recovery mode" after the second bullet
# This allows us an additional bullet to break even for most bankrolls, at the cost of making a profit after the second bullet
# This allows additional peace of mind at the cost of ROI
bet_amount = (3 * self.min_bet)
else:
# Martingale strategy dictates that a bet after a loss is double the previous bet's value
bet_amount = (2 * bet_amount)
# Now the player has gone bust due to their inability to win back their losses
self.history['spins'].append(self.spin_count)
self.history['winnings'].append(self.amount_before_losing_streak)
self.reset()
def play_x_sessions(self, x):
for _ in range(x):
self.play_to_bust()
def get_json_results(self):
dump = json.dumps(self.history)
return dump