-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoscar_grind.py
158 lines (131 loc) · 5.23 KB
/
oscar_grind.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import random
from datetime import datetime
import utils
class DiceClient(object):
DEBUG = False
MIN_BET = 1
SAFE_MODE = False
LONGEST_ALLOWED_STREAK = 15
DANGER_STREAK = 10000000
THRESHOLD_JUMP = 8
ALL_IN = False
def __init__(self, server):
self.server = server
self.roll_mode = False
def start(self, minimum_balance, maximum_balance):
self.minimum_balance = minimum_balance
self.maximum_balance = maximum_balance
self.balance = self.current_balance
self.initial_balance = self.peak_balance = self.balance
self.will_stop = False
self.start_time = datetime.now()
self.last_streak = self.streak = self.longest_streak = 0
self.last_bet = 0
self.round_no = -1
self.switch_countdown = 0
self.win_round = -1
self.peak_ratio = 0
processor = self._process
self.result = {}
self.new_session()
while not self.will_stop:
processor()
return self.result
def new_session(self):
# print '-' * 80
self.session_bet = self.MIN_BET
self.session_profit = 0
self.session_target = self.MIN_BET
def _process(self):
new_balance = self.current_balance
is_win = new_balance >= self.balance
new_streak = 0 if is_win else self.streak + 1
self.round_no += 1
self.win_round += 1 if is_win else 0
self.last_streak = self.streak if is_win else self.last_streak
if self.round_no:
if is_win:
self.session_profit += self.session_bet
if self.session_profit < self.session_target:
if self.session_profit + self.session_bet + self.MIN_BET > self.session_target:
self.session_bet = self.session_target - self.session_profit
else:
self.session_bet += self.MIN_BET
else:
self.session_profit -= self.session_bet
if self.session_profit >= self.session_target:
self.new_session()
bet_amount = utils.to_2(self.session_bet)
if (new_balance >= self.maximum_balance) or (
new_balance - bet_amount <= self.minimum_balance) or (
new_balance == 0): # To handle all in strategy
self.will_stop = True
elif is_win:
if self.switch_countdown:
self.switch_countdown -= 1
else:
self.switch_countdown = random.randint(0, 9) + 1
self.roll_mode = not self.roll_mode
if self.DEBUG:
print 'Round %s | %s ::: Balance = %s | Bet = %s | Ratio = %.2f%% | Last = %s' % ( # NOQA
str(self.round_no).rjust(6),
('WIN' if is_win else 'LOST').ljust(4),
new_balance, bet_amount, self.win_ratio * 100,
self.last_streak)
if self.round_no > 100:
self.peak_ratio = max(self.peak_ratio, self.win_ratio)
self.streak = new_streak
self.longest_streak = max(self.streak, self.longest_streak)
self.last_bet = bet_amount
self.balance = new_balance
self.peak_balance = max(self.peak_balance, self.balance)
if self.will_stop:
self.stop()
else:
self.submit_bet(self.roll_mode, bet_amount)
@property
def win_ratio(self):
if self.round_no:
return float(self.win_round) / (self.round_no)
return 0
def stop(self):
# self.print_statistics()
self.result['rounds'] = self.round_no
self.result['longest_streak'] = self.longest_streak
self.result['peak_balance'] = self.peak_balance
self.result['reach_max'] = 1 if (
self.current_balance >= self.maximum_balance) else 0
self.result['balance'] = self.balance
def print_statistics(self):
profit = self.balance - self.initial_balance
time_delta = datetime.now() - self.start_time
running_time = time_delta.total_seconds()
print '-' * 80
print 'Rounds = %s' % self.round_no
# print 'Time = %.2f seconds' % running_time
print 'Streak = %s' % self.longest_streak
print 'Ratio^ = %.2f%%' % (self.peak_ratio * 100)
print
print 'Peak = %.2f' % self.peak_balance
print 'Begin = %.2f' % self.initial_balance
print 'End = %.2f' % self.balance
print 'Profit = %s (%.4f%%)' % (
profit, profit / self.initial_balance * 100)
print ' per round = %s (%.8f%%)' % (
profit / self.round_no,
profit / self.round_no / self.initial_balance * 100)
# print ' per second = %s' % (profit / running_time)
print '-' * 80
def submit_bet(self, mode, bet_amount):
self.server.roll(mode, bet_amount)
@property
def current_balance(self):
return self.server.balance
def get_initial_bet(self, balance):
accm = 2 ** self.LONGEST_ALLOWED_STREAK - 1
bet = max(balance / accm, self.MIN_BET)
if not self.SAFE_MODE:
bet = min(balance, bet * (self.last_streak + 1))
if (self.ALL_IN):
bet = self.current_balance
return utils.to_2(bet)