-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
177 lines (158 loc) · 5.96 KB
/
game.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import random
from player import decide
import os
import csv
import statistics
import matplotlib.pyplot as plt
from numba import jit
@jit(nopython = True)
def roll_wheel():
'''Get random int from 0 to 36
Returns:
int: The number it will generate
'''
return random.randint(0, 36)
def run_roulette(sessions, starter_money, rounds, bet_size, tendency, verbose):
# create csv folder if doesn't exist
if not os.path.exists('csv'):
os.makedirs('csv')
avg_profit = []
avg_loss = []
for i in range(sessions):
win = 0
lost = 0
lasted_rounds = 0
player_money = starter_money
house_money = 0 # assume house don't have any money
results_list = []
player_money_list = []
house_money_list = []
lasted_rounds_list = []
for _ in range(rounds):
roll = roll_wheel()
bet_type, decision = decide(tendency)
if verbose == True:
print(decision,',', bet_type)
# check if win or lost the best
if bet_type == 'single': # payout 35 to 1
if roll == decision:
payout = 35
win += 1
player_money += bet_size*payout
house_money -= bet_size*payout
if verbose == True:
print('win')
else:
lost += 1
player_money -= bet_size
house_money += bet_size
if verbose == True:
print('lost')
elif bet_type == 'split': # payout 17 to 1
if roll in decision:
payout = 17
win += 1
player_money += bet_size*payout
house_money -= bet_size*payout
if verbose == True:
print('win')
else:
lost += 1
player_money -= bet_size
house_money += bet_size
if verbose == True:
print('lost')
elif bet_type == 'street': # payout 11 to 1
if roll in decision:
payout = 11
win += 1
player_money += bet_size*payout
house_money -= bet_size*payout
if verbose == True:
print('win')
else:
lost += 1
player_money -= bet_size
house_money += bet_size
if verbose == True:
print('lost')
elif bet_type in ['corner', 'basket']: # payout 8 to 1
if roll in decision:
payout = 8
win += 1
player_money += bet_size*payout
house_money -= bet_size*payout
if verbose == True:
print('win')
else:
lost += 1
player_money -= bet_size
house_money += bet_size
if verbose == True:
print('lost')
elif bet_type == 'double_street': # payout 5 to 1
if roll in decision:
payout = 5
win += 1
player_money += bet_size*payout
house_money -= bet_size*payout
if verbose == True:
print('win')
else:
lost += 1
player_money -= bet_size
house_money += bet_size
if verbose == True:
print('lost')
elif bet_type in ['column', 'dozen']: # payout 2 to 1
if roll in decision:
payout = 2
win += 1
player_money += bet_size*payout
house_money -= bet_size*payout
if verbose == True:
print('win')
else:
lost += 1
player_money -= bet_size
house_money += bet_size
if verbose == True:
print('lost')
elif bet_type in ['odd_or_even', 'red_or_black', 'half']: # payout 1 to 1
if roll in decision:
payout = 1
win += 1
player_money += bet_size*payout
house_money -= bet_size*payout
if verbose == True:
print('win')
else:
lost += 1
player_money -= bet_size
house_money += bet_size
if verbose == True:
print('lost')
lasted_rounds += 1
result = [lasted_rounds, player_money, house_money]
results_list.append(result)
lasted_rounds_list.append(lasted_rounds)
player_money_list.append(player_money)
house_money_list.append(house_money)
# report results
print(f'session {i + 1}')
print('win:', win, '| lost:', lost)
print("player's money:", player_money)
print("house's money:", house_money)
print('\n')
avg_profit.append(player_money)
avg_loss.append(house_money)
# plot it
plt.plot(lasted_rounds_list, player_money_list)
plt.plot(lasted_rounds_list, house_money_list)
with open(f'csv/results_{i + 1}.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Round", "Player's Money", "House's Money"])
writer.writerows(results_list)
avg_profit = statistics.mean(avg_profit)
avg_loss = statistics.mean(avg_loss)
return lasted_rounds, win, lost, player_money, house_money, avg_profit, avg_loss