-
Notifications
You must be signed in to change notification settings - Fork 1
/
roulette.py
142 lines (118 loc) · 2.88 KB
/
roulette.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
import random
import matplotlib.pyplot as plt
redNumbers = (1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36)
modes = ('red', 'black', 'even', 'odd', 'low', 'high')
bets = {'red': 'black', 'black': 'red', 'even': 'odd', 'odd': 'even', 'low': 'high', 'high': 'low'}
debug = False
def findSequence():
broke = False
if len(history) >= depth:
for mode in modes:
broke = False
for j in range(depth):
element = history[-1*(j+1)]
if mode == 'red':
if element not in redNumbers:
broke = True
break
if mode == 'black':
if element in redNumbers:
broke = True
break
if mode == 'even':
if element % 2 != 0:
broke = True
break
if mode == 'odd':
if element % 2 == 0:
broke = True
break
if mode == 'low':
if element > 18:
broke = True
break
if mode == 'high':
if element < 19:
broke = True
break
if not broke:
return mode
return None
else:
return None
def placeBet():
return bets[sequence]
def win():
if number in redNumbers and bet == 'red':
return True
if number not in redNumbers and bet == 'black':
return True
if number % 2 == 0 and bet == 'even':
return True
if number % 2 != 0 and bet == 'odd':
return True
if number < 19 and bet == 'low':
return True
if number > 18 and bet == 'high':
return True
if __name__ == "__main__":
startingCapital = 315
depth = 3
minBet = 10
maxBet = 900
numberOfPlays = 100
playingDuration = 50
mean_development = [0] * playingDuration
for j in range(numberOfPlays):
if debug: print '###### Game number %d started ######' % (j)
fund = startingCapital
fund_development = []
history = []
status = 'WAIT'
sequence = None
bet = None
amount = minBet
for i in range(playingDuration):
number = random.randint(0, 36)
history.append(number)
if bet is not None:
if win():
fund = fund + amount * 2
if debug: print 'WON %d, %d in pot' % (amount, fund)
status = 'WAIT'
sequence = None
bet = None
amount = minBet
else:
if fund == 0:
if debug: print 'No money left'
break
else:
amount = amount * 2
fund_development.append(fund)
if status == 'WAIT':
sequence = findSequence()
if sequence is not None:
if debug: print sequence
status = 'PLAY'
else:
status = 'WAIT'
if status == 'PLAY':
bet = placeBet()
if fund < amount: amount = fund
if amount > maxBet: amount = minBet
if debug: print 'Bet %d on %s' % (amount, bet)
fund = fund - amount
else:
bet = None
for f in range(playingDuration):
if f >= len(fund_development):
h = 0
else:
h = fund_development[f]
mean_development[f] = (mean_development[f] * j + h) * 1.0 / (j + 1)
plt.xlabel('number of games')
plt.ylabel('money')
plt.plot(mean_development, label='mean fund development')
plt.legend()
plt.show()