-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz.py
256 lines (215 loc) · 9.84 KB
/
quiz.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# Quiz: Test your knowledge of equity of poker hands
from Tkinter import *
from random import randrange
from equity_calculator import holdem_postflop_equity_calculator as hpec
from equity_calculator import razz_equity_calculator as razz_calc
from equity_calculator import stud_equity_calculator as stud_calc
from math import fabs
# Global Variables
suits = ["s","h","d","c"]
lo_values = ["A","2","3","4","5","6","7","8","9","T","J","Q","K"]
deck = [value+suit for suit in suits for value in lo_values]
root = Tk()
incorrect = 0
correct = 0
user_hand = []
villain_hand = []
flop = []
def quiz():
root.wm_title("PokerTempo v1.0")
def holdem_solve():
global correct
global incorrect
answer = int(e.get())
actual = 100.0*hpec("".join(board),"".join(hero),"".join(villain))[1]
if fabs(answer - actual) <= 5:
Label(root,text="Correct: %.2f equity" % (actual)).grid(row=5,column=0)
correct += 1
else:
Label(root,text="Incorrect: %.2f equity" % (actual)).grid(row=5,column=0)
incorrect += 1
Button(root, text="Next", width=5, command=next,relief="flat").grid(row=4,column=1)
Label(root,text="Correct: %s" % (correct)).grid(row=5,column=2)
Label(root,text="Incorrect: %s" % (incorrect)).grid(row=5,column=3)
def razz_solve():
global correct
global incorrect
answer = int(e.get())
actual = 100.0*razz_calc("".join(hero) + " vs " + "".join(villain)+"xx")[1]
difference = answer - actual
if fabs(answer - actual) <= 5:
Label(root,text="Correct: %.2f equity" % (actual)).grid(row=5,column=0)
correct += 1
else:
Label(root,text="Incorrect: %.2f equity" % (actual)).grid(row=5,column=0)
incorrect += 1
Label(root,text="Correct: %s" % (correct)).grid(row=5,column=2)
Label(root,text="Incorrect: %s" % (incorrect)).grid(row=5,column=3)
def stud_solve():
global correct
global incorrect
answer = int(e.get())
actual = 100.0*stud_calc("".join(hero) + " vs " + "".join(villain)+"xx")[1]
difference = answer - actual
if fabs(answer - actual) <= 5:
Label(root,text="Correct: %.2f equity" % (actual)).grid(row=5,column=0)
correct += 1
else:
Label(root,text="Incorrect: %.2f equity" % (actual)).grid(row=5,column=0)
incorrect += 1
Label(root,text="Correct: %s" % (correct)).grid(row=5,column=2)
Label(root,text="Incorrect: %s" % (incorrect)).grid(row=5,column=3)
def next():
for child in root.winfo_children():
child.destroy()
quiz()
deck = [value+suit for suit in suits for value in lo_values]
game = randrange(1,4)
# Hold Em Post Flop Quiz
if game == 1:
print len(deck),len(user_hand),len(villain_hand),len(flop)
while len(user_hand) < 2:
x = randrange(len(deck))
user_hand.append(deck[x])
deck.remove(deck[x])
while len(villain_hand) < 2:
x = randrange(len(deck))
villain_hand.append(deck[x])
deck.remove(deck[x])
while len(flop) < 3:
x = randrange(len(deck))
flop.append(deck[x])
deck.remove(deck[x])
hero = user_hand[:]
villain = villain_hand[:]
board = flop[:]
user_card = PhotoImage(file="./img/"+user_hand[0]+".gif")
user_card2 = PhotoImage(file="./img/"+user_hand[1]+".gif")
villain_card = PhotoImage(file="./img/"+villain_hand[0]+".gif")
villain_card2 = PhotoImage(file="./img/"+villain_hand[1]+".gif")
flop1 = PhotoImage(file="./img/"+flop[0]+".gif")
flop2 = PhotoImage(file="./img/"+flop[1]+".gif")
flop3 = PhotoImage(file="./img/"+flop[2]+".gif")
Label(root,text="Hero").grid(row=1,column=0)
Label(root,image=user_card).grid(row=1,column=1)
Label(root,image=user_card2).grid(row=1,column=2)
Label(root,text="Villain").grid(row=2,column=0)
Label(root,image=villain_card).grid(row=2,column=1)
Label(root,image=villain_card2).grid(row=2,column=2)
Label(root,text="Flop").grid(row=3,column=0)
Label(root,image=flop1).grid(row=3,column=1)
Label(root,image=flop2).grid(row=3,column=2)
Label(root,image=flop3).grid(row=3,column=3)
e=Entry(root,width=8)
e.grid(row=4, column=2)
e.focus_set()
Button(root, text="Submit", width=5, command=holdem_solve,relief="flat").grid(row=4,column=1)
Label(root,text="Hold Em").grid(row=5,column=1)
Label(root,text="Correct: %s" % (correct)).grid(row=5,column=2)
Label(root,text="Incorrect: %s" % (incorrect)).grid(row=5,column=3)
print user_hand,villain_hand,flop
deck.extend(user_hand)
deck.extend(villain_hand)
deck.extend(flop)
del user_hand[:]
del villain_hand[:]
del flop[:]
print user_hand,villain_hand,flop
# Razz Fifth Street Quiz
elif game == 2:
print len(deck),len(user_hand),len(villain_hand)
while len(user_hand) < 5:
x = randrange(len(deck))
user_hand.append(deck[x])
deck.remove(deck[x])
while len(villain_hand) < 3:
x = randrange(len(deck))
villain_hand.append(deck[x])
deck.remove(deck[x])
hero = user_hand[:]
villain = villain_hand[:]
user_card = PhotoImage(file="./img/"+user_hand[0]+".gif")
user_card2 = PhotoImage(file="./img/"+user_hand[1]+".gif")
user_card3 = PhotoImage(file="./img/"+user_hand[2]+".gif")
user_card4 = PhotoImage(file="./img/"+user_hand[3]+".gif")
user_card5 = PhotoImage(file="./img/"+user_hand[4]+".gif")
down_card = PhotoImage(file="./img/BV.gif")
villain_card = PhotoImage(file="./img/"+villain_hand[0]+".gif")
villain_card2 = PhotoImage(file="./img/"+villain_hand[1]+".gif")
villain_card3 = PhotoImage(file="./img/"+villain_hand[2]+".gif")
Label(root,text="Hero").grid(row=1,column=0)
Label(root,image=user_card).grid(row=1,column=1)
Label(root,image=user_card2).grid(row=1,column=2)
Label(root,image=user_card3).grid(row=1,column=3)
Label(root,image=user_card4).grid(row=1,column=4)
Label(root,image=user_card5).grid(row=1,column=5)
Label(root,text="Villain").grid(row=2,column=0)
Label(root,image=down_card).grid(row=2,column=1)
Label(root,image=down_card).grid(row=2,column=2)
Label(root,image=villain_card).grid(row=2,column=3)
Label(root,image=villain_card2).grid(row=2,column=4)
Label(root,image=villain_card3).grid(row=2,column=5)
e=Entry(root,width=15)
e.grid(row=4, column=0)
e.focus_set()
b = Button(root, text="Submit", width=5, command=razz_solve,borderwidth=.001).grid(row=4,column=1)
n = Button(root, text="Next", width=5, command=next,borderwidth=.001).grid(row=4,column=2)
Label(root,text="Razz").grid(row=5,column=1)
Label(root,text="Correct: %s" % (correct)).grid(row=5,column=2)
Label(root,text="Incorrect: %s" % (incorrect)).grid(row=5,column=3)
print user_hand,villain_hand
deck.extend(user_hand)
deck.extend(villain_hand)
del user_hand[:]
del villain_hand[:]
print user_hand,villain_hand
# Stud Fifth Street Quiz
elif game == 3:
print len(deck),len(user_hand),len(villain_hand)
while len(user_hand) < 5:
x = randrange(len(deck))
user_hand.append(deck[x])
deck.remove(deck[x])
while len(villain_hand) < 3:
x = randrange(len(deck))
villain_hand.append(deck[x])
deck.remove(deck[x])
hero = user_hand[:]
villain = villain_hand[:]
user_card = PhotoImage(file="./img/"+user_hand[0]+".gif")
user_card2 = PhotoImage(file="./img/"+user_hand[1]+".gif")
user_card3 = PhotoImage(file="./img/"+user_hand[2]+".gif")
user_card4 = PhotoImage(file="./img/"+user_hand[3]+".gif")
user_card5 = PhotoImage(file="./img/"+user_hand[4]+".gif")
down_card = PhotoImage(file="./img/BV.gif")
villain_card = PhotoImage(file="./img/"+villain_hand[0]+".gif")
villain_card2 = PhotoImage(file="./img/"+villain_hand[1]+".gif")
villain_card3 = PhotoImage(file="./img/"+villain_hand[2]+".gif")
Label(root,text="Hero").grid(row=1,column=0)
Label(root,image=user_card).grid(row=1,column=1)
Label(root,image=user_card2).grid(row=1,column=2)
Label(root,image=user_card3).grid(row=1,column=3)
Label(root,image=user_card4).grid(row=1,column=4)
Label(root,image=user_card5).grid(row=1,column=5)
Label(root,text="Villain").grid(row=2,column=0)
Label(root,image=down_card).grid(row=2,column=1)
Label(root,image=down_card).grid(row=2,column=2)
Label(root,image=villain_card).grid(row=2,column=3)
Label(root,image=villain_card2).grid(row=2,column=4)
Label(root,image=villain_card3).grid(row=2,column=5)
e=Entry(root,width=15)
e.grid(row=4, column=0)
e.focus_set()
b = Button(root, text="Submit", width=5, command=stud_solve,borderwidth=.001).grid(row=4,column=1)
n = Button(root, text="Next", width=5, command=next,borderwidth=.001).grid(row=4,column=2)
Label(root,text="Stud Hi").grid(row=5,column=1)
Label(root,text="Correct: %s" % (correct)).grid(row=5,column=2)
Label(root,text="Incorrect: %s" % (incorrect)).grid(row=5,column=3)
print user_hand,villain_hand
deck.extend(user_hand)
deck.extend(villain_hand)
del user_hand[:]
del villain_hand[:]
print user_hand,villain_hand
root.mainloop()
quiz()