-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic.py
More file actions
129 lines (113 loc) · 4.56 KB
/
Copy pathlogic.py
File metadata and controls
129 lines (113 loc) · 4.56 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import random
import pandas as pd
class RouletteSession:
def __init__(self, start_bankroll=1000, trigger_losses=5, win_steps=999, loss_steps=1, take_profit=0, stop_loss=0):
self.start_bankroll = start_bankroll
self.bankroll = start_bankroll
self.history = []
self.current_mode = "MONITORING" # or "ATTACKING"
self.consecutive_losses = 0
# Strategy Config
self.fib_sequence = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
self.fib_index = 0
self.trigger_losses = trigger_losses
self.win_steps = win_steps # 999 = Reset, otherwise steps to move back
self.loss_steps = loss_steps
self.take_profit = take_profit
self.stop_loss = stop_loss
# Column 1 numbers: 1, 4, 7, ..., 34
self.column1_numbers = {i for i in range(1, 37) if i % 3 == 1}
def spin(self):
# 1. Determine Bet
bet_amount = 0
if self.current_mode == "ATTACKING":
if self.fib_index < len(self.fib_sequence):
bet_amount = self.fib_sequence[self.fib_index]
else:
# Sequence exhausted - accept loss and reset
self.current_mode = "MONITORING"
self.fib_index = 0
self.consecutive_losses = 0
bet_amount = 0 # Next spin is monitoring
# 2. Spin Wheel (0-36)
# Using standard random.randint is sufficient for simulation
number = random.randint(0, 36)
# 3. Resolve Outcome
won = False
profit = 0
if bet_amount > 0:
if number in self.column1_numbers:
won = True
# Payout 2:1
profit = bet_amount * 2
self.bankroll += profit
else:
# Loss
profit = -bet_amount
self.bankroll += profit
# 4. Update Strategy State
if bet_amount > 0:
# We were betting
if won:
# Win
if self.win_steps >= 100:
# Reset Mode
self.current_mode = "MONITORING"
self.fib_index = 0
self.consecutive_losses = 0
else:
# Step Back Mode
self.fib_index -= self.win_steps
if self.fib_index < 0:
# Recovered fully
self.current_mode = "MONITORING"
self.fib_index = 0
self.consecutive_losses = 0
else:
# Loss logic
self.fib_index += self.loss_steps
# Check bounds
if self.fib_index >= len(self.fib_sequence):
# System Failed
self.current_mode = "MONITORING"
self.fib_index = 0
self.consecutive_losses = 0
else:
# Monitoring Mode - looking for validation to start attacking
if number in self.column1_numbers:
# We "won" virtually (would have won), so streak is broken
self.consecutive_losses = 0
elif number == 0:
# 0 counts as a loss for columns
self.consecutive_losses += 1
else:
# Not col 1, not 0 (so col 2 or 3) -> Loss for col 1
self.consecutive_losses += 1
if self.consecutive_losses >= self.trigger_losses:
self.current_mode = "ATTACKING"
# Start betting next spin
# 5. Log Step
step_data = {
"bankroll": self.bankroll,
"number": number,
"bet_amount": bet_amount,
"won": won,
"mode": self.current_mode,
"fib_idx": self.fib_index,
"streak": self.consecutive_losses
}
self.history.append(step_data)
return step_data
def run_simulation(self, total_spins):
for _ in range(total_spins):
self.spin()
# Check Ruin/Stop Conditions
if self.bankroll <= 0:
break
# Stop Loss (if set)
if self.stop_loss > 0 and self.bankroll <= (self.start_bankroll - self.stop_loss):
break
# Take Profit (if set)
if self.take_profit > 0 and self.bankroll >= (self.start_bankroll + self.take_profit):
break
return pd.DataFrame(self.history)