-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrissSimulator.py
214 lines (162 loc) · 5.97 KB
/
TrissSimulator.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import random
from Triss import Triss
from datetime import datetime, time
import multiprocessing
from threading import Thread
# Create list of triss:es
trissList = []
def createTrissList(start, end):
print("Calling: createTrissList({},{})".format(start, end))
# Create 200000 triss
for triss_number in range(start, end):
current_triss = Triss()
# Set each triss prize
if triss_number > 432419:
current_triss.setPrize(0)
trissList.append(current_triss)
continue
elif 252720 <= triss_number <= 432419:
current_triss.setPrize(30)
trissList.append(current_triss)
continue
elif 43920 <= triss_number <= 252719:
current_triss.setPrize(60)
trissList.append(current_triss)
continue
elif 14120 <= triss_number <= 43919:
current_triss.setPrize(90)
trissList.append(current_triss)
continue
elif 6920 <= triss_number <= 14119:
current_triss.setPrize(120)
trissList.append(current_triss)
continue
elif 3160 <= triss_number <= 6919:
current_triss.setPrize(150)
trissList.append(current_triss)
continue
elif 1960 <= triss_number <= 3159:
current_triss.setPrize(180)
trissList.append(current_triss)
continue
elif 1007 <= triss_number <= 1959:
current_triss.setPrize(300)
trissList.append(current_triss)
continue
elif 697 <= triss_number <= 1006:
current_triss.setPrize(500)
trissList.append(current_triss)
continue
elif 497 <= triss_number <= 696:
current_triss.setPrize(600)
trissList.append(current_triss)
continue
elif 397 <= triss_number <= 496:
current_triss.setPrize(900)
trissList.append(current_triss)
continue
elif 232 <= triss_number <= 396:
current_triss.setPrize(1000)
trissList.append(current_triss)
continue
elif 152 <= triss_number <= 231:
current_triss.setPrize(1500)
trissList.append(current_triss)
continue
elif 82 <= triss_number <= 151:
current_triss.setPrize(2000)
trissList.append(current_triss)
continue
elif 52 <= triss_number <= 81:
current_triss.setPrize(5000)
trissList.append(current_triss)
continue
elif 12 <= triss_number <= 51:
current_triss.setPrize(10000)
trissList.append(current_triss)
continue
elif 10 <= triss_number <= 11:
current_triss.setPrize(20000)
trissList.append(current_triss)
continue
elif 8 <= triss_number <= 9:
current_triss.setPrize(100000)
trissList.append(current_triss)
continue
elif triss_number == 7:
current_triss.setPrize(200000)
trissList.append(current_triss)
continue
elif 2 <= triss_number <= 6:
current_triss.setPrize(265000)
trissList.append(current_triss)
continue
elif triss_number == 1:
current_triss.setPrize(1000000)
trissList.append(current_triss)
continue
elif triss_number == 0:
current_triss.setPrize(2765000)
trissList.append(current_triss)
continue
print("Done with ({}->{})".format(start, end))
def scramblelist(list):
print("\n| Scrambeling.")
dest = list[:]
random.shuffle(dest)
return dest
def main():
start = datetime.now()
print("Creating 2.000.000 tickets")
generate_ticket_list()
scrambled_list = scramblelist(trissList)
print("| Done :{}\n".format(datetime.now() - start))
prize_sum = 0
# Looping through each triss in scrambled_list
for trissIndex in range(0, 1999999):
if not one_more_triss_check():
break
prize_sum = current_ticket(prize_sum, scrambled_list, trissIndex)
trissIndex += 1
printResult(prize_sum, trissIndex)
def generate_ticket_list():
# ------ Threading ------
start_index = 0
end_index = 2000000
number_of_threads = multiprocessing.cpu_count()
# Length of each interval
part_lengths = int(end_index / number_of_threads)
for intervalNumber in range(start_index, number_of_threads):
temp_start_interval = part_lengths * intervalNumber
temp_end_interval = part_lengths + (part_lengths * intervalNumber)
thread = Thread(target=createTrissList, args=(temp_start_interval, temp_end_interval))
thread.start()
# Wait for all threads
for intervalNumber in range(0, number_of_threads):
thread.join()
# ------ Threading ------
def one_more_triss_check():
print("Do you want to skrejp a triss?")
user_response = input("(Press [Enter] to skrejp or write something to exit)\n")
bol = user_response == ""
return bol
def current_ticket(prizeSum, scrambledList, trissIndex):
print("------- Triss #{} -------".format(trissIndex + 1))
currTriss = scrambledList[trissIndex]
prizeSum += currTriss.getPrize()
print("You won {} SEK!".format(currTriss.getPrize()))
print("------- Triss #{} -------\n\n".format(trissIndex + 1))
return prizeSum
def printResult(prizeSum, trissIndex):
print("\n---- Final skrejping stats ----")
print("Skrejped: {} Triss:es".format(trissIndex))
print("Spent: {} SEK".format(trissIndex * 30))
print("Won: {} SEK".format(prizeSum))
if prizeSum - (trissIndex * 30) > 0:
print("Profit: {} SEK".format(prizeSum - (trissIndex * 30)))
else:
print("Loss: {} SEK".format(prizeSum - (trissIndex * 30)))
print("---- Final skrejping stats ----")
print("\nThank you, come again!")
if __name__ == '__main__':
main()