Coverage for GuiReplayer.py: 0%
1068 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-28 16:41 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-28 16:41 +0000
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
4# Copyright 2010-2011 Maxime Grandchamp
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as published by
7# the Free Software Foundation, version 3 of the License.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16# In the "official" distribution you can find the license in agpl-3.0.txt.
18# Note that this now contains the replayer only! The list of hands has been moved to GuiHandViewer by zarturo.
20from __future__ import print_function
21from __future__ import division
22from ast import Return
24from collections import defaultdict
25from unicodedata import decimal, name
26from past.utils import old_div
27# import L10n
28# _ = L10n.get_translation()
30from functools import partial
31import xml.dom.minidom
33import json
34import Hand
35import Card
36import Configuration
37import Database
38import SQL
39import Deck
40import Filters
41import Charset
43from PyQt5.QtCore import (QPoint, QRect, Qt, QTimer, QRectF)
44from PyQt5.QtGui import (QColor, QImage, QPainter, QTextDocument)
45from PyQt5.QtWidgets import (QHBoxLayout, QPushButton, QSlider, QVBoxLayout, QCheckBox,
46 QWidget)
48from math import pi, cos, sin
49from decimal_wrapper import Decimal
50import numpy as np
51from matplotlib import pyplot as plt
52import copy
53import os
55CARD_HEIGHT = 90
56CARD_WIDTH = 70
59class GuiReplayer(QWidget):
60 """A Replayer to replay hands."""
62 def __init__(self, config, querylist, mainwin, handlist):
63 QWidget.__init__(self, None)
64 self.resize(1800, 1080)
65 self.setMinimumSize(800, 600)
66 self.conf = config
67 self.main_window = mainwin
68 self.sql = querylist
69 self.newpot = Decimal()
70 self.db = Database.Database(self.conf, sql=self.sql)
71 self.states = [] # List with all table states.
72 self.handlist = handlist
73 self.handidx = 0
74 self.Heroes = ""
75 self.setWindowTitle("FPDB Hand Replayer")
77 self.replayBox = QVBoxLayout()
79 self.setLayout(self.replayBox)
81 self.replayBox.addStretch()
82 self.buttonBox2 = QHBoxLayout()
83 self.buttonBox = QHBoxLayout()
84 self.showCards = QCheckBox("Hide Cards")
85 self.showCards.setChecked(True)
86 self.buttonBox2.addWidget(self.showCards)
87 self.prevButton = QPushButton("Prev")
88 self.prevButton.clicked.connect(self.prev_clicked)
89 self.prevButton.setFocusPolicy(Qt.NoFocus)
90 self.startButton = QPushButton("Start")
91 self.startButton.clicked.connect(self.start_clicked)
92 self.startButton.setFocusPolicy(Qt.NoFocus)
93 self.endButton = QPushButton("End")
94 self.endButton.clicked.connect(self.end_clicked)
95 self.endButton.setFocusPolicy(Qt.NoFocus)
96 self.playPauseButton = QPushButton("Play")
97 self.playPauseButton.clicked.connect(self.play_clicked)
98 self.playPauseButton.setFocusPolicy(Qt.NoFocus)
99 self.nextButton = QPushButton("Next")
100 self.nextButton.clicked.connect(self.next_clicked)
101 self.nextButton.setFocusPolicy(Qt.NoFocus)
103 self.replayBox.addLayout(self.buttonBox)
104 self.replayBox.addLayout(self.buttonBox2)
106 self.stateSlider = QSlider(Qt.Horizontal)
107 self.stateSlider.valueChanged.connect(self.slider_changed)
108 self.stateSlider.setFocusPolicy(Qt.NoFocus)
110 self.replayBox.addWidget(self.stateSlider, False)
112 self.playing = False
114 self.tableImage = None
115 self.playerBackdrop = None
117 self.cardImages = None
118 self.deck_inst = Deck.Deck(self.conf, height=CARD_HEIGHT, width=CARD_WIDTH)
119 self.show()
121 def renderCards(self, painter, cards, x, y):
122 for card in cards:
123 cardIndex = Card.encodeCard(card)
124 painter.drawPixmap(QPoint(x, y), self.cardImages[cardIndex])
125 x += int(self.cardwidth / 2) - 15
127 def renderboardCards(self, painter, cards, x, y):
128 for card in cards:
129 cardIndex = Card.encodeCard(card)
130 painter.drawPixmap(QPoint(x, y), self.cardImages[cardIndex])
131 x += self.cardwidth
133 def paintEvent(self, event):
134 hand = Hand.hand_factory(self.handlist[self.handidx], self.conf, self.db)
135 if self.tableImage is None or self.playerBackdrop is None:
136 try:
137 self.playerBackdrop = QImage(os.path.join(self.conf.graphics_path, "playerbackdrop.png"))
138 self.tableImage = QImage(os.path.join(self.conf.graphics_path, "TableR.png"))
139 self.dealer = QImage(os.path.join(self.conf.graphics_path, "dealer.png"))
140 except:
141 return
142 if self.cardImages is None:
143 self.cardwidth = CARD_WIDTH
144 self.cardheight = CARD_HEIGHT
145 self.cardImages = [None] * 53
146 suits = ('s', 'h', 'd', 'c')
147 ranks = (14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2)
148 for j in range(0, 13):
149 for i in range(0, 4):
150 index = Card.cardFromValueSuit(ranks[j], suits[i])
151 self.cardImages[index] = self.deck_inst.card(suits[i], ranks[j])
152 self.cardImages[0] = self.deck_inst.back()
154 if not event.rect().intersects(QRect(0, 0, self.tableImage.width(), self.tableImage.height())):
155 return
157 painter = QPainter(self)
158 # table position
159 painter.drawImage(QPoint(200, 200), self.tableImage)
161 # initial state
162 if len(self.states) == 0:
163 return
165 state = self.states[self.stateSlider.value()]
167 # communityLeft = int(old_div(self.tableImage.width(), 2) - 2.5 * self.cardwidth)
168 # communityTop = int(old_div(self.tableImage.height(), 2) - 1.75 * self.cardheight)
170 # convertx = lambda x: int(x * self.tableImage.width() * 0.8) + old_div(self.tableImage.width(), 2)
171 # converty = lambda y: int(y * self.tableImage.height() * 0.6) + old_div(self.tableImage.height(), 2)
172 # paint hand infos
173 painter.drawText(QRect(-40, 0, 600, 80), Qt.AlignCenter, self.info)
174 #
175 nb_player = len(list(state.players.values()))
176 #find hero in site
177 path = os.path.join(Configuration.Config().config_path, "HUD_config.xml")
178 print(path)
179 doc = xml.dom.minidom.parse(path)
180 for site_node in doc.getElementsByTagName("site"):
181 if site_node.getAttribute("site_name") == str(hand.sitename):
182 print(site_node.getAttribute("screen_name"))
183 self.Heroes = site_node.getAttribute("screen_name")
185 print("list players:", (list(state.players.values())))
186 #print("list players:", self.Heroes)
187 if nb_player == 2:
188 # set 2 player
189 print('nb player :', nb_player)
190 i = 0
191 for player in list(state.players.values()):
192 #print(player.holecards)
193 print(hand.gametype["category"])
194 if player.name == list(state.players.values())[0].name:
195 print("round", i, "player", player.name)
196 # draw player bloc
197 painter.drawImage(QPoint(635, 790), self.playerBackdrop)
198 if player.action == "folds":
199 painter.setPen(QColor("red"))
200 else:
201 painter.setPen(QColor("white"))
202 # if check box hide cards and hero
204 if not self.showCards.isChecked():
205 # draw player's card
206 self.renderCards(painter, player.holecards, 660, 700)
207 elif self.showCards.isChecked():
208 if player.name == self.Heroes:
210 self.renderCards(painter, player.holecards, 660, 700)
211 else:
212 if hand.gametype["category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion" :
213 self.renderCards(painter, ['0', '0', '0', '0'], 660, 700)
214 elif hand.gametype["category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
215 self.renderCards(painter, ['0', '0', '0', '0', '0'], 660, 700)
216 elif hand.gametype["category"] == "6_omahahi":
217 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 660, 700)
218 elif hand.gametype["category"] == "holdem" or "6_holdem":
219 self.renderCards(painter, ['0', '0'], 660, 700)
220 elif hand.gametype["category"] == "2_holdem":
221 self.renderCards(painter, ['0', '0', '0'], 660, 700)
222 else:
223 self.renderCards(painter, player.holecards, 660, 700)
224 # draw player's stack
225 painter.drawText(QRect(605, 790, 200, 20),
226 Qt.AlignCenter,
227 '%s %s%.2f' % (player.name,
228 self.currency,
229 player.stack))
230 if player.justacted:
231 painter.setPen(QColor("yellow"))
232 # draw player's actions
233 painter.drawText(QRect(605, 807, 200, 20), Qt.AlignCenter, player.action)
234 # draw pot
235 painter.drawText(QRect(380, 480, 200, 40), Qt.AlignCenter,
236 'Pot: %s%.2f' % (self.currency, state.newpot))
237 else:
238 painter.setPen(QColor("white"))
239 if player.chips != 0:
240 # draw player's bet
241 painter.drawText(QRect(605, 670, 200, 20),
242 Qt.AlignCenter,
243 '%s%.2f' % (self.currency, player.chips))
244 elif player.name == list(state.players.values())[1].name:
245 print("round", i, "player", player.name)
246 # draw player bloc
247 painter.drawImage(QPoint(1090, 490), self.playerBackdrop)
248 if player.action == "folds":
249 painter.setPen(QColor("red"))
250 else:
251 painter.setPen(QColor("white"))
252 # if check box hide cards and hero
254 if not self.showCards.isChecked():
255 # draw player's card
256 self.renderCards(painter, player.holecards, 1115, 400)
257 elif self.showCards.isChecked():
258 if player.name == self.Heroes:
259 self.renderCards(painter, player.holecards, 1115, 400)
260 else:
261 if hand.gametype["category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
262 self.renderCards(painter, ['0', '0', '0', '0'], 1115, 400)
263 elif hand.gametype["category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
264 self.renderCards(painter, ['0', '0', '0', '0', '0'], 1115, 400)
265 elif hand.gametype["category"] == "6_omahahi":
266 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 1115, 400)
267 elif hand.gametype["category"] == "holdem" or "6_holdem":
268 self.renderCards(painter, ['0', '0'], 1115, 400)
269 elif hand.gametype["category"] == "2_holdem":
270 self.renderCards(painter, ['0', '0', '0'], 1115, 400)
271 else:
272 self.renderCards(painter, player.holecards, 1115, 400)
274 # draw player's info
275 painter.drawText(QRect(1070, 490, 200, 20),
276 Qt.AlignCenter,
277 '%s %s%.2f' % (player.name,
278 self.currency,
279 player.stack))
280 if player.justacted:
281 painter.setPen(QColor("yellow"))
282 # draw player's actions
283 painter.drawText(QRect(1070, 507, 200, 20), Qt.AlignCenter, player.action)
284 # draw bet pot
285 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
286 'Pot: %s%.2f' % (self.currency, state.newpot))
287 else:
288 painter.setPen(QColor("white"))
289 if player.chips != 0:
290 # draw player's bet
291 painter.drawText(QRect(930, 490, 200, 20),
292 Qt.AlignCenter,
293 '%s%.2f' % (self.currency, player.chips))
294 else:
295 pass
296 i += 1
297 elif nb_player == 3:
298 print('nb player :', nb_player)
299 i = 0
300 for player in list(state.players.values()):
301 #print(player.holecards)
302 print(hand.gametype["category"])
303 if player.name == list(state.players.values())[0].name:
304 if hand.get_player_position(player.name) == "S":
305 painter.drawImage(QPoint(530, 650), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
306 print("round", i, "player", player.name)
307 # draw player bloc
309 painter.drawImage(QPoint(635, 790), self.playerBackdrop)
310 if player.action == "folds":
311 painter.setPen(QColor("red"))
312 else:
313 painter.setPen(QColor("white"))
314 # if check box hide cards and hero
315 # show known cards or not
316 if not self.showCards.isChecked():
318 # draw player's card
319 self.renderCards(painter, player.holecards, 660, 700)
320 elif self.showCards.isChecked():
321 if player.name == self.Heroes:
324 self.renderCards(painter, player.holecards, 660, 700)
325 else:
326 if hand.gametype["category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
327 self.renderCards(painter, ['0', '0', '0', '0'], 660, 700)
328 elif hand.gametype["category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
329 self.renderCards(painter, ['0', '0', '0', '0', '0'], 660, 700)
330 elif hand.gametype["category"] == "6_omahahi":
331 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 660, 700)
332 elif hand.gametype["category"] == "holdem" or "6_holdem":
333 self.renderCards(painter, ['0', '0'], 660, 700)
334 elif hand.gametype["category"] == "2_holdem":
335 self.renderCards(painter, ['0', '0', '0'], 660, 700)
336 else:
337 self.renderCards(painter, player.holecards, 660, 700)
338 # draw player's stack
339 painter.drawText(QRect(605, 790, 200, 20),
340 Qt.AlignCenter,
341 '%s %s%.2f' % (player.name,
342 self.currency,
343 player.stack))
345 if player.justacted:
346 painter.setPen(QColor("yellow"))
347 # draw player's actions
348 painter.drawText(QRect(605, 807, 200, 20), Qt.AlignCenter, player.action)
349 # draw pot
350 painter.drawText(QRect(380, 480, 200, 40), Qt.AlignCenter,
351 'Pot: %s%.2f' % (self.currency, state.newpot))
352 else:
353 painter.setPen(QColor("white"))
354 if player.chips != 0:
355 # draw player's bet
356 painter.drawText(QRect(605, 670, 200, 20),
357 Qt.AlignCenter,
358 '%s%.2f' % (self.currency, player.chips))
359 elif player.name == list(state.players.values())[1].name:
360 if hand.get_player_position(player.name) == "S":
361 painter.drawImage(QPoint(990, 570), self.dealer.scaled(40, 40, Qt.KeepAspectRatio)) #ok
362 print("round", i, "player", player.name)
363 # draw player bloc
364 painter.drawImage(QPoint(1090, 490), self.playerBackdrop)
365 if player.action == "folds":
366 painter.setPen(QColor("red"))
367 else:
368 painter.setPen(QColor("white"))
369 # if check box hide cards and hero
371 if not self.showCards.isChecked():
372 # draw player's card
373 self.renderCards(painter, player.holecards, 1115, 400)
374 elif self.showCards.isChecked():
375 if player.name == self.Heroes:
376 self.renderCards(painter, player.holecards, 1115, 400)
377 else:
378 if hand.gametype["category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
379 self.renderCards(painter, ['0', '0', '0', '0'], 1115, 400)
380 elif hand.gametype["category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
381 self.renderCards(painter, ['0', '0', '0', '0', '0'], 1115, 400)
382 elif hand.gametype["category"] == "6_omahahi":
383 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 1115, 400)
384 elif hand.gametype["category"] == "holdem" or "6_holdem":
385 self.renderCards(painter, ['0', '0'], 1115, 400)
386 elif hand.gametype["category"] == "2_holdem":
387 self.renderCards(painter, ['0', '0', '0'], 1115, 400)
388 else:
389 self.renderCards(painter, player.holecards, 1115, 400)
391 # draw player's info
392 painter.drawText(QRect(1070, 490, 200, 20),
393 Qt.AlignCenter,
394 '%s %s%.2f' % (player.name,
395 self.currency,
396 player.stack))
397 if player.justacted:
398 painter.setPen(QColor("yellow"))
399 # draw player's actions
400 painter.drawText(QRect(1070, 507, 200, 20), Qt.AlignCenter, player.action)
401 # draw bet pot
402 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
403 'Pot: %s%.2f' % (self.currency, state.newpot))
404 else:
405 painter.setPen(QColor("white"))
406 if player.chips != 0:
407 # draw player's bet
408 painter.drawText(QRect(930, 490, 200, 20),
409 Qt.AlignCenter,
410 '%s%.2f' % (self.currency, player.chips))
411 elif player.name == list(state.players.values())[2].name:
412 if hand.get_player_position(player.name) == "S":
413 painter.drawImage(QPoint(450, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
414 print(list(state.players.values())[2])
415 # draw player bloc
416 painter.drawImage(QPoint(160, 490), self.playerBackdrop)
417 if player.action == "folds":
418 painter.setPen(QColor("red"))
419 else:
420 painter.setPen(QColor("white"))
421 # if check box hide cards and hero
423 if not self.showCards.isChecked():
424 # draw player's card
425 self.renderCards(painter, player.holecards, 185, 400)
426 elif self.showCards.isChecked():
427 if player.name == self.Heroes:
428 self.renderCards(painter, player.holecards, 185, 400)
429 else:
430 if hand.gametype["category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
431 self.renderCards(painter, ['0', '0', '0', '0'], 185, 400)
432 elif hand.gametype["category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
433 self.renderCards(painter, ['0', '0', '0', '0', '0'], 185, 400)
434 elif hand.gametype["category"] == "6_omahahi":
435 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 185, 400)
436 elif hand.gametype["category"] == "holdem" or "6_holdem":
437 self.renderCards(painter, ['0', '0'], 185, 400)
438 elif hand.gametype["category"] == "2_holdem":
439 self.renderCards(painter, ['0', '0', '0'], 185, 400)
440 else:
441 self.renderCards(painter, player.holecards, 185, 400)
444 # draw player's info
445 painter.drawText(QRect(140, 490, 200, 20),
446 Qt.AlignCenter,
447 '%s %s%.2f' % (player.name,
448 self.currency,
449 player.stack))
450 if player.justacted:
451 painter.setPen(QColor("yellow"))
452 # draw player's actions
453 painter.drawText(QRect(140, 507, 200, 20), Qt.AlignCenter, player.action)
454 # draw bet pot
455 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
456 'Pot: %s%.2f' % (self.currency, state.newpot))
457 else:
458 painter.setPen(QColor("white"))
459 if player.chips != 0:
460 # draw player's bet
461 painter.drawText(QRect(260, 490, 200, 20),
462 Qt.AlignCenter,
463 '%s%.2f' % (self.currency, player.chips))
464 else:
465 pass
466 i += 1
467 elif nb_player == 4:
468 print('nb player :', nb_player)
469 i = 0
470 for player in list(state.players.values()):
471 # print(player.holecards)
472 print(hand.gametype["category"])
473 if player.name == list(state.players.values())[0].name:
474 if hand.get_player_position(player.name) == "S":
475 painter.drawImage(QPoint(530, 650), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
476 print("round", i, "player", player.name)
477 # draw player bloc
478 painter.drawImage(QPoint(635, 790), self.playerBackdrop)
479 if player.action == "folds":
480 painter.setPen(QColor("red"))
481 else:
482 painter.setPen(QColor("white"))
483 # if check box hide cards and hero
485 if not self.showCards.isChecked():
486 # draw player's card
487 self.renderCards(painter, player.holecards, 660, 700)
488 elif self.showCards.isChecked():
489 if player.name == self.Heroes:
491 self.renderCards(painter, player.holecards, 660, 700)
492 else:
493 if hand.gametype[
494 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
495 self.renderCards(painter, ['0', '0', '0', '0'], 660, 700)
496 elif hand.gametype[
497 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
498 self.renderCards(painter, ['0', '0', '0', '0', '0'], 660, 700)
499 elif hand.gametype["category"] == "6_omahahi":
500 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 660, 700)
501 elif hand.gametype["category"] == "holdem" or "6_holdem":
502 self.renderCards(painter, ['0', '0'], 660, 700)
503 elif hand.gametype["category"] == "2_holdem":
504 self.renderCards(painter, ['0', '0', '0'], 660, 700)
505 else:
506 self.renderCards(painter, player.holecards, 660, 700)
507 # draw player's stack
508 painter.drawText(QRect(605, 790, 200, 20),
509 Qt.AlignCenter,
510 '%s %s%.2f' % (player.name,
511 self.currency,
512 player.stack))
514 if player.justacted:
515 painter.setPen(QColor("yellow"))
516 # draw player's actions
517 painter.drawText(QRect(605, 807, 200, 20), Qt.AlignCenter, player.action)
518 # draw pot
519 painter.drawText(QRect(380, 480, 200, 40), Qt.AlignCenter,
520 'Pot: %s%.2f' % (self.currency, state.newpot))
521 else:
522 painter.setPen(QColor("white"))
523 if player.chips != 0:
524 # draw player's bet
525 painter.drawText(QRect(605, 670, 200, 20),
526 Qt.AlignCenter,
527 '%s%.2f' % (self.currency, player.chips))
528 elif player.name == list(state.players.values())[1].name:
529 if hand.get_player_position(player.name) == "S":
530 painter.drawImage(QPoint(990, 570), self.dealer.scaled(40, 40, Qt.KeepAspectRatio)) # ok
531 print("round", i, "player", player.name)
532 # draw player bloc
533 painter.drawImage(QPoint(1090, 490), self.playerBackdrop)
534 if player.action == "folds":
535 painter.setPen(QColor("red"))
536 else:
537 painter.setPen(QColor("white"))
538 # if check box hide cards and hero
540 if not self.showCards.isChecked():
541 # draw player's card
542 self.renderCards(painter, player.holecards, 1115, 400)
543 elif self.showCards.isChecked():
544 if player.name == self.Heroes:
545 self.renderCards(painter, player.holecards, 1115, 400)
546 else:
547 if hand.gametype[
548 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
549 self.renderCards(painter, ['0', '0', '0', '0'], 1115, 400)
550 elif hand.gametype[
551 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
552 self.renderCards(painter, ['0', '0', '0', '0', '0'], 1115, 400)
553 elif hand.gametype["category"] == "6_omahahi":
554 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 1115, 400)
555 elif hand.gametype["category"] == "holdem" or "6_holdem":
556 self.renderCards(painter, ['0', '0'], 1115, 400)
557 elif hand.gametype["category"] == "2_holdem":
558 self.renderCards(painter, ['0', '0', '0'], 1115, 400)
559 else:
560 self.renderCards(painter, player.holecards, 1115, 400)
562 # draw player's info
563 painter.drawText(QRect(1070, 490, 200, 20),
564 Qt.AlignCenter,
565 '%s %s%.2f' % (player.name,
566 self.currency,
567 player.stack))
568 if player.justacted:
569 painter.setPen(QColor("yellow"))
570 # draw player's actions
571 painter.drawText(QRect(1070, 507, 200, 20), Qt.AlignCenter, player.action)
572 # draw bet pot
573 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
574 'Pot: %s%.2f' % (self.currency, state.newpot))
575 else:
576 painter.setPen(QColor("white"))
577 if player.chips != 0:
578 # draw player's bet
579 painter.drawText(QRect(930, 490, 200, 20),
580 Qt.AlignCenter,
581 '%s%.2f' % (self.currency, player.chips))
582 elif player.name == list(state.players.values())[2].name:
583 if hand.get_player_position(player.name) == "S":
584 painter.drawImage(QPoint(850, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
585 print(list(state.players.values())[2])
586 # draw player bloc
587 painter.drawImage(QPoint(635, 220), self.playerBackdrop) #
588 if player.action == "folds":
589 painter.setPen(QColor("red"))
590 else:
591 painter.setPen(QColor("white"))
592 # if check box hide cards and hero
594 if not self.showCards.isChecked():
595 # draw player's card
596 self.renderCards(painter, player.holecards, 655, 130) #ok
597 elif self.showCards.isChecked():
598 if player.name == self.Heroes:
599 self.renderCards(painter, player.holecards, 655, 130)
600 else:
601 if hand.gametype[
602 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
603 self.renderCards(painter, ['0', '0', '0', '0'], 655, 130)
604 elif hand.gametype[
605 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
606 self.renderCards(painter, ['0', '0', '0', '0', '0'], 655, 130)
607 elif hand.gametype["category"] == "6_omahahi":
608 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 655, 130)
609 elif hand.gametype["category"] == "holdem" or "6_holdem":
610 self.renderCards(painter, ['0', '0'], 655, 130)
611 elif hand.gametype["category"] == "2_holdem":
612 self.renderCards(painter, ['0', '0', '0'], 655, 130)
613 else:
614 self.renderCards(painter, player.holecards, 655, 130)
616 # draw player's info
617 painter.drawText(QRect(605, 220, 200, 20),
618 Qt.AlignCenter,
619 '%s %s%.2f' % (player.name,
620 self.currency,
621 player.stack))
622 if player.justacted:
623 painter.setPen(QColor("yellow"))
624 # draw player's actions
625 painter.drawText(QRect(605, 237, 200, 20), Qt.AlignCenter, player.action)
626 # draw bet pot
627 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
628 'Pot: %s%.2f' % (self.currency, state.newpot))
629 else:
630 painter.setPen(QColor("white"))
631 if player.chips != 0:
632 # draw player's bet
633 painter.drawText(QRect(605, 294, 200, 20),
634 Qt.AlignCenter,
635 '%s%.2f' % (self.currency, player.chips))
636 elif player.name == list(state.players.values())[3].name:
637 if hand.get_player_position(player.name) == "S":
638 painter.drawImage(QPoint(450, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
639 print(list(state.players.values())[2])
640 # draw player bloc
641 painter.drawImage(QPoint(160, 490), self.playerBackdrop)
642 if player.action == "folds":
643 painter.setPen(QColor("red"))
644 else:
645 painter.setPen(QColor("white"))
646 # if check box hide cards and hero
648 if not self.showCards.isChecked():
649 # draw player's card
650 self.renderCards(painter, player.holecards, 185, 400)
651 elif self.showCards.isChecked():
652 if player.name == self.Heroes:
653 self.renderCards(painter, player.holecards, 185, 400)
654 else:
655 if hand.gametype[
656 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
657 self.renderCards(painter, ['0', '0', '0', '0'], 185, 400)
658 elif hand.gametype[
659 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
660 self.renderCards(painter, ['0', '0', '0', '0', '0'], 185, 400)
661 elif hand.gametype["category"] == "6_omahahi":
662 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 185, 400)
663 elif hand.gametype["category"] == "holdem" or "6_holdem":
664 self.renderCards(painter, ['0', '0'], 185, 400)
665 elif hand.gametype["category"] == "2_holdem":
666 self.renderCards(painter, ['0', '0', '0'], 185, 400)
667 else:
668 self.renderCards(painter, player.holecards, 185, 400)
670 # draw player's info
671 painter.drawText(QRect(140, 490, 200, 20),
672 Qt.AlignCenter,
673 '%s %s%.2f' % (player.name,
674 self.currency,
675 player.stack))
676 if player.justacted:
677 painter.setPen(QColor("yellow"))
678 # draw player's actions
679 painter.drawText(QRect(140, 507, 200, 20), Qt.AlignCenter, player.action)
680 # draw bet pot
681 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
682 'Pot: %s%.2f' % (self.currency, state.newpot))
683 else:
684 painter.setPen(QColor("white"))
685 if player.chips != 0:
686 # draw player's bet
687 painter.drawText(QRect(260, 490, 200, 20),
688 Qt.AlignCenter,
689 '%s%.2f' % (self.currency, player.chips))
690 else:
691 pass
692 i += 1
693 elif nb_player == 5:
694 print('nb player :', nb_player)
695 i = 0
696 for player in list(state.players.values()):
697 # print(player.holecards)
698 print(hand.gametype["category"])
699 if player.name == list(state.players.values())[0].name:
700 if hand.get_player_position(player.name) == "S":
701 painter.drawImage(QPoint(530, 650), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
702 print("round", i, "player", player.name)
703 # draw player bloc
704 painter.drawImage(QPoint(635, 790), self.playerBackdrop)
705 if player.action == "folds":
706 painter.setPen(QColor("red"))
707 else:
708 painter.setPen(QColor("white"))
709 # if check box hide cards and hero
711 if not self.showCards.isChecked():
712 # draw player's card
713 self.renderCards(painter, player.holecards, 660, 700)
714 elif self.showCards.isChecked():
715 if player.name == self.Heroes:
717 self.renderCards(painter, player.holecards, 660, 700)
718 else:
719 if hand.gametype[
720 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
721 self.renderCards(painter, ['0', '0', '0', '0'], 660, 700)
722 elif hand.gametype[
723 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
724 self.renderCards(painter, ['0', '0', '0', '0', '0'], 660, 700)
725 elif hand.gametype["category"] == "6_omahahi":
726 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 660, 700)
727 elif hand.gametype["category"] == "holdem" or "6_holdem":
728 self.renderCards(painter, ['0', '0'], 660, 700)
729 elif hand.gametype["category"] == "2_holdem":
730 self.renderCards(painter, ['0', '0', '0'], 660, 700)
731 else:
732 self.renderCards(painter, player.holecards, 660, 700)
733 # draw player's stack
734 painter.drawText(QRect(605, 790, 200, 20),
735 Qt.AlignCenter,
736 '%s %s%.2f' % (player.name,
737 self.currency,
738 player.stack))
740 if player.justacted:
741 painter.setPen(QColor("yellow"))
742 # draw player's actions
743 painter.drawText(QRect(605, 807, 200, 20), Qt.AlignCenter, player.action)
744 # draw pot
745 painter.drawText(QRect(380, 480, 200, 40), Qt.AlignCenter,
746 'Pot: %s%.2f' % (self.currency, state.newpot))
747 else:
748 painter.setPen(QColor("white"))
749 if player.chips != 0:
750 # draw player's bet
751 painter.drawText(QRect(605, 670, 200, 20),
752 Qt.AlignCenter,
753 '%s%.2f' % (self.currency, player.chips))
754 elif player.name == list(state.players.values())[1].name:
755 if hand.get_player_position(player.name) == "S":
756 painter.drawImage(QPoint(990, 570), self.dealer.scaled(40, 40, Qt.KeepAspectRatio)) # ok
757 print("round", i, "player", player.name)
758 # draw player bloc
759 painter.drawImage(QPoint(1090, 490), self.playerBackdrop)
760 if player.action == "folds":
761 painter.setPen(QColor("red"))
762 else:
763 painter.setPen(QColor("white"))
764 # if check box hide cards and hero
766 if not self.showCards.isChecked():
767 # draw player's card
768 self.renderCards(painter, player.holecards, 1115, 400)
769 elif self.showCards.isChecked():
770 if player.name == self.Heroes:
771 self.renderCards(painter, player.holecards, 1115, 400)
772 else:
773 if hand.gametype[
774 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
775 self.renderCards(painter, ['0', '0', '0', '0'], 1115, 400)
776 elif hand.gametype[
777 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
778 self.renderCards(painter, ['0', '0', '0', '0', '0'], 1115, 400)
779 elif hand.gametype["category"] == "6_omahahi":
780 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 1115, 400)
781 elif hand.gametype["category"] == "holdem" or "6_holdem":
782 self.renderCards(painter, ['0', '0'], 1115, 400)
783 elif hand.gametype["category"] == "2_holdem":
784 self.renderCards(painter, ['0', '0', '0'], 1115, 400)
785 else:
786 self.renderCards(painter, player.holecards, 1115, 400)
788 # draw player's info
789 painter.drawText(QRect(1070, 490, 200, 20),
790 Qt.AlignCenter,
791 '%s %s%.2f' % (player.name,
792 self.currency,
793 player.stack))
794 if player.justacted:
795 painter.setPen(QColor("yellow"))
796 # draw player's actions
797 painter.drawText(QRect(1070, 507, 200, 20), Qt.AlignCenter, player.action)
798 # draw bet pot
799 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
800 'Pot: %s%.2f' % (self.currency, state.newpot))
801 else:
802 painter.setPen(QColor("white"))
803 if player.chips != 0:
804 # draw player's bet
805 painter.drawText(QRect(930, 490, 200, 20),
806 Qt.AlignCenter,
807 '%s%.2f' % (self.currency, player.chips))
808 elif player.name == list(state.players.values())[3].name:
809 if hand.get_player_position(player.name) == "S":
810 painter.drawImage(QPoint(660, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
811 print(list(state.players.values())[2])
812 # draw player bloc
813 painter.drawImage(QPoint(500, 220), self.playerBackdrop) #ok
814 if player.action == "folds":
815 painter.setPen(QColor("red"))
816 else:
817 painter.setPen(QColor("white"))
818 # if check box hide cards and hero
820 if not self.showCards.isChecked():
821 # draw player's card
822 self.renderCards(painter, player.holecards, 520, 130) #ok
823 elif self.showCards.isChecked():
824 if player.name == self.Heroes:
825 self.renderCards(painter, player.holecards, 520, 130)
826 else:
827 if hand.gametype[
828 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
829 self.renderCards(painter, ['0', '0', '0', '0'], 520, 130)
830 elif hand.gametype[
831 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
832 self.renderCards(painter, ['0', '0', '0', '0', '0'], 520, 130)
833 elif hand.gametype["category"] == "6_omahahi":
834 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 520, 130)
835 elif hand.gametype["category"] == "holdem" or "6_holdem":
836 self.renderCards(painter, ['0', '0'], 520, 130)
837 elif hand.gametype["category"] == "2_holdem":
838 self.renderCards(painter, ['0', '0', '0'], 520, 130)
839 else:
840 self.renderCards(painter, player.holecards, 520, 130)
842 # draw player's info
843 painter.drawText(QRect(480, 220, 200, 20),
844 Qt.AlignCenter,
845 '%s %s%.2f' % (player.name,
846 self.currency,
847 player.stack))
848 if player.justacted:
849 painter.setPen(QColor("yellow"))
850 # draw player's actions
851 painter.drawText(QRect(480, 237, 200, 20), Qt.AlignCenter, player.action)
852 # draw bet pot
853 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
854 'Pot: %s%.2f' % (self.currency, state.newpot))
855 else:
856 painter.setPen(QColor("white"))
857 if player.chips != 0:
858 # draw player's bet
859 painter.drawText(QRect(500, 294, 200, 20),
860 Qt.AlignCenter,
861 '%s%.2f' % (self.currency, player.chips))
862 elif player.name == list(state.players.values())[2].name:
863 if hand.get_player_position(player.name) == "S":
864 painter.drawImage(QPoint(950, 350), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
865 print(list(state.players.values())[2])
866 # draw player bloc
867 painter.drawImage(QPoint(750, 220), self.playerBackdrop) #ok
868 if player.action == "folds":
869 painter.setPen(QColor("red"))
870 else:
871 painter.setPen(QColor("white"))
872 # if check box hide cards and hero
874 if not self.showCards.isChecked():
875 # draw player's card
876 self.renderCards(painter, player.holecards, 770, 130) #ok
877 elif self.showCards.isChecked():
878 if player.name == self.Heroes:
879 self.renderCards(painter, player.holecards, 770, 130)
880 else:
881 if hand.gametype[
882 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
883 self.renderCards(painter, ['0', '0', '0', '0'], 770, 130)
884 elif hand.gametype[
885 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
886 self.renderCards(painter, ['0', '0', '0', '0', '0'], 770, 130)
887 elif hand.gametype["category"] == "6_omahahi":
888 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 770, 130)
889 elif hand.gametype["category"] == "holdem" or "6_holdem":
890 self.renderCards(painter, ['0', '0'], 770, 130)
891 elif hand.gametype["category"] == "2_holdem":
892 self.renderCards(painter, ['0', '0', '0'], 770, 130)
893 else:
894 self.renderCards(painter, player.holecards, 770, 130)
896 # draw player's info
897 painter.drawText(QRect(730, 220, 200, 20),
898 Qt.AlignCenter,
899 '%s %s%.2f' % (player.name,
900 self.currency,
901 player.stack))
902 if player.justacted:
903 painter.setPen(QColor("yellow"))
904 # draw player's actions
905 painter.drawText(QRect(730, 237, 200, 20), Qt.AlignCenter, player.action)
906 # draw bet pot
907 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
908 'Pot: %s%.2f' % (self.currency, state.newpot))
909 else:
910 painter.setPen(QColor("white"))
911 if player.chips != 0:
912 # draw player's bet
913 painter.drawText(QRect(730, 294, 200, 20),
914 Qt.AlignCenter,
915 '%s%.2f' % (self.currency, player.chips))
916 elif player.name == list(state.players.values())[4].name:
917 if hand.get_player_position(player.name) == "S":
918 painter.drawImage(QPoint(450, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
919 print(list(state.players.values())[2])
920 # draw player bloc
921 painter.drawImage(QPoint(160, 490), self.playerBackdrop)
922 if player.action == "folds":
923 painter.setPen(QColor("red"))
924 else:
925 painter.setPen(QColor("white"))
926 # if check box hide cards and hero
928 if not self.showCards.isChecked():
929 # draw player's card
930 self.renderCards(painter, player.holecards, 185, 400)
931 elif self.showCards.isChecked():
932 if player.name == self.Heroes:
933 self.renderCards(painter, player.holecards, 185, 400)
934 else:
935 if hand.gametype[
936 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
937 self.renderCards(painter, ['0', '0', '0', '0'], 185, 400)
938 elif hand.gametype[
939 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
940 self.renderCards(painter, ['0', '0', '0', '0', '0'], 185, 400)
941 elif hand.gametype["category"] == "6_omahahi":
942 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 185, 400)
943 elif hand.gametype["category"] == "holdem" or "6_holdem":
944 self.renderCards(painter, ['0', '0'], 185, 400)
945 elif hand.gametype["category"] == "2_holdem":
946 self.renderCards(painter, ['0', '0', '0'], 185, 400)
947 else:
948 self.renderCards(painter, player.holecards, 185, 400)
950 # draw player's info
951 painter.drawText(QRect(140, 490, 200, 20),
952 Qt.AlignCenter,
953 '%s %s%.2f' % (player.name,
954 self.currency,
955 player.stack))
956 if player.justacted:
957 painter.setPen(QColor("yellow"))
958 # draw player's actions
959 painter.drawText(QRect(140, 507, 200, 20), Qt.AlignCenter, player.action)
960 # draw bet pot
961 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
962 'Pot: %s%.2f' % (self.currency, state.newpot))
963 else:
964 painter.setPen(QColor("white"))
965 if player.chips != 0:
966 # draw player's bet
967 painter.drawText(QRect(260, 490, 200, 20),
968 Qt.AlignCenter,
969 '%s%.2f' % (self.currency, player.chips))
970 else:
971 pass
972 i += 1
973 elif nb_player == 6:
974 print('nb player :', nb_player)
975 i = 0
976 for player in list(state.players.values()):
977 # print(player.holecards)
978 print(hand.gametype["category"])
979 if player.name == list(state.players.values())[0].name:
980 if hand.get_player_position(player.name) == "S":
981 painter.drawImage(QPoint(650, 650), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
982 print("round", i, "player", player.name)
983 # draw player bloc
984 painter.drawImage(QPoint(750, 790), self.playerBackdrop)
985 if player.action == "folds":
986 painter.setPen(QColor("red"))
987 else:
988 painter.setPen(QColor("white"))
989 # if check box hide cards and hero
991 if not self.showCards.isChecked():
992 # draw player's card
993 self.renderCards(painter, player.holecards, 770, 700)
994 elif self.showCards.isChecked():
995 if player.name == self.Heroes:
997 self.renderCards(painter, player.holecards, 770, 700)
998 else:
999 if hand.gametype[
1000 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
1001 self.renderCards(painter, ['0', '0', '0', '0'], 770, 700)
1002 elif hand.gametype[
1003 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
1004 self.renderCards(painter, ['0', '0', '0', '0', '0'], 770, 700)
1005 elif hand.gametype["category"] == "6_omahahi":
1006 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 770, 700)
1007 elif hand.gametype["category"] == "holdem" or "6_holdem":
1008 self.renderCards(painter, ['0', '0'], 770, 700)
1009 elif hand.gametype["category"] == "2_holdem":
1010 self.renderCards(painter, ['0', '0', '0'], 770, 700)
1011 else:
1012 self.renderCards(painter, player.holecards, 770, 700)
1013 # draw player's stack
1014 painter.drawText(QRect(730, 790, 200, 20),
1015 Qt.AlignCenter,
1016 '%s %s%.2f' % (player.name,
1017 self.currency,
1018 player.stack))
1020 if player.justacted:
1021 painter.setPen(QColor("yellow"))
1022 # draw player's actions
1023 painter.drawText(QRect(730, 807, 200, 20), Qt.AlignCenter, player.action)
1024 # draw pot
1026 painter.drawText(QRect(380, 480, 200, 40), Qt.AlignCenter,
1027 'Pot: %s%.2f' % (self.currency, state.newpot))
1028 else:
1029 painter.setPen(QColor("white"))
1030 if player.chips != 0:
1031 # draw player's bet
1032 painter.drawText(QRect(730, 670, 200, 20),
1033 Qt.AlignCenter,
1034 '%s%.2f' % (self.currency, player.chips))
1035 elif player.name == list(state.players.values())[1].name:
1036 if hand.get_player_position(player.name) == "S":
1037 painter.drawImage(QPoint(990, 570), self.dealer.scaled(40, 40, Qt.KeepAspectRatio)) # ok
1038 print("round", i, "player", player.name)
1039 # draw player bloc
1040 painter.drawImage(QPoint(1090, 490), self.playerBackdrop)
1041 if player.action == "folds":
1042 painter.setPen(QColor("red"))
1043 else:
1044 painter.setPen(QColor("white"))
1045 # if check box hide cards and hero
1047 if not self.showCards.isChecked():
1048 # draw player's card
1049 self.renderCards(painter, player.holecards, 1115, 400)
1050 elif self.showCards.isChecked():
1051 if player.name == self.Heroes:
1052 self.renderCards(painter, player.holecards, 1115, 400)
1053 else:
1054 if hand.gametype[
1055 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
1056 self.renderCards(painter, ['0', '0', '0', '0'], 1115, 400)
1057 elif hand.gametype[
1058 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
1059 self.renderCards(painter, ['0', '0', '0', '0', '0'], 1115, 400)
1060 elif hand.gametype["category"] == "6_omahahi":
1061 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 1115, 400)
1062 elif hand.gametype["category"] == "holdem" or "6_holdem":
1063 self.renderCards(painter, ['0', '0'], 1115, 400)
1064 elif hand.gametype["category"] == "2_holdem":
1065 self.renderCards(painter, ['0', '0', '0'], 1115, 400)
1066 else:
1067 self.renderCards(painter, player.holecards, 1115, 400)
1069 # draw player's info
1070 painter.drawText(QRect(1070, 490, 200, 20),
1071 Qt.AlignCenter,
1072 '%s %s%.2f' % (player.name,
1073 self.currency,
1074 player.stack))
1075 if player.justacted:
1076 painter.setPen(QColor("yellow"))
1077 # draw player's actions
1078 painter.drawText(QRect(1070, 507, 200, 20), Qt.AlignCenter, player.action)
1079 # draw bet pot
1081 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
1082 'Pot: %s%.2f' % (self.currency, state.newpot))
1083 else:
1084 painter.setPen(QColor("white"))
1085 if player.chips != 0:
1086 # draw player's bet
1087 painter.drawText(QRect(930, 490, 200, 20),
1088 Qt.AlignCenter,
1089 '%s%.2f' % (self.currency, player.chips))
1090 elif player.name == list(state.players.values())[3].name:
1091 if hand.get_player_position(player.name) == "S":
1092 painter.drawImage(QPoint(660, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1093 print("round", i, "player", player.name)
1094 print(list(state.players.values())[2])
1095 # draw player bloc
1096 painter.drawImage(QPoint(500, 220), self.playerBackdrop) #ok
1097 if player.action == "folds":
1098 painter.setPen(QColor("red"))
1099 else:
1100 painter.setPen(QColor("white"))
1101 # if check box hide cards and hero
1103 if not self.showCards.isChecked():
1104 # draw player's card
1105 self.renderCards(painter, player.holecards, 520, 130) #ok
1106 elif self.showCards.isChecked():
1107 if player.name == self.Heroes:
1108 self.renderCards(painter, player.holecards, 520, 130)
1109 else:
1110 if hand.gametype[
1111 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
1112 self.renderCards(painter, ['0', '0', '0', '0'], 520, 130)
1113 elif hand.gametype[
1114 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
1115 self.renderCards(painter, ['0', '0', '0', '0', '0'], 520, 130)
1116 elif hand.gametype["category"] == "6_omahahi":
1117 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 520, 130)
1118 elif hand.gametype["category"] == "holdem" or "6_holdem":
1119 self.renderCards(painter, ['0', '0'], 520, 130)
1120 elif hand.gametype["category"] == "2_holdem":
1121 self.renderCards(painter, ['0', '0', '0'], 520, 130)
1122 else:
1123 self.renderCards(painter, player.holecards, 520, 130)
1125 # draw player's info
1126 painter.drawText(QRect(480, 220, 200, 20),
1127 Qt.AlignCenter,
1128 '%s %s%.2f' % (player.name,
1129 self.currency,
1130 player.stack))
1131 if player.justacted:
1132 painter.setPen(QColor("yellow"))
1133 # draw player's actions
1134 painter.drawText(QRect(480, 237, 200, 20), Qt.AlignCenter, player.action)
1135 # draw bet pot
1136 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
1137 'Pot: %s%.2f' % (self.currency, state.newpot))
1138 else:
1139 painter.setPen(QColor("white"))
1140 if player.chips != 0:
1141 # draw player's bet
1142 painter.drawText(QRect(500, 294, 200, 20),
1143 Qt.AlignCenter,
1144 '%s%.2f' % (self.currency, player.chips))
1145 elif player.name == list(state.players.values())[2].name:
1146 if hand.get_player_position(player.name) == "S":
1147 painter.drawImage(QPoint(950, 350), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1148 print("round", i, "player", player.name)
1149 print(list(state.players.values())[2])
1150 # draw player bloc
1151 painter.drawImage(QPoint(750, 220), self.playerBackdrop) #ok
1152 if player.action == "folds":
1153 painter.setPen(QColor("red"))
1154 else:
1155 painter.setPen(QColor("white"))
1156 # if check box hide cards and hero
1158 if not self.showCards.isChecked():
1159 # draw player's card
1160 self.renderCards(painter, player.holecards, 770, 130) #ok
1161 elif self.showCards.isChecked():
1162 if player.name == self.Heroes:
1163 self.renderCards(painter, player.holecards, 770, 130)
1164 else:
1165 if hand.gametype[
1166 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
1167 self.renderCards(painter, ['0', '0', '0', '0'], 770, 130)
1168 elif hand.gametype[
1169 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
1170 self.renderCards(painter, ['0', '0', '0', '0', '0'], 770, 130)
1171 elif hand.gametype["category"] == "6_omahahi":
1172 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 770, 130)
1173 elif hand.gametype["category"] == "holdem" or "6_holdem":
1174 self.renderCards(painter, ['0', '0'], 770, 130)
1175 elif hand.gametype["category"] == "2_holdem":
1176 self.renderCards(painter, ['0', '0', '0'], 770, 130)
1177 else:
1178 self.renderCards(painter, player.holecards, 770, 130)
1180 # draw player's info
1181 painter.drawText(QRect(730, 220, 200, 20),
1182 Qt.AlignCenter,
1183 '%s %s%.2f' % (player.name,
1184 self.currency,
1185 player.stack))
1186 if player.justacted:
1187 painter.setPen(QColor("yellow"))
1188 # draw player's actions
1189 painter.drawText(QRect(730, 237, 200, 20), Qt.AlignCenter, player.action)
1190 # draw bet pot
1191 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
1192 'Pot: %s%.2f' % (self.currency, state.newpot))
1193 else:
1194 painter.setPen(QColor("white"))
1195 if player.chips != 0:
1196 # draw player's bet
1197 painter.drawText(QRect(730, 294, 200, 20),
1198 Qt.AlignCenter,
1199 '%s%.2f' % (self.currency, player.chips))
1200 elif player.name == list(state.players.values())[4].name:
1201 if hand.get_player_position(player.name) == "S":
1202 painter.drawImage(QPoint(450, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1203 print("round", i, "player", player.name)
1204 print(list(state.players.values())[2])
1205 # draw player bloc
1206 painter.drawImage(QPoint(160, 490), self.playerBackdrop)
1207 if player.action == "folds":
1208 painter.setPen(QColor("red"))
1209 else:
1210 painter.setPen(QColor("white"))
1211 # if check box hide cards and hero
1213 if not self.showCards.isChecked():
1214 # draw player's card
1215 self.renderCards(painter, player.holecards, 185, 400)
1216 elif self.showCards.isChecked():
1217 if player.name == self.Heroes:
1218 self.renderCards(painter, player.holecards, 185, 400)
1219 else:
1220 if hand.gametype[
1221 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
1222 self.renderCards(painter, ['0', '0', '0', '0'], 185, 400)
1223 elif hand.gametype[
1224 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
1225 self.renderCards(painter, ['0', '0', '0', '0', '0'], 185, 400)
1226 elif hand.gametype["category"] == "6_omahahi":
1227 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 185, 400)
1228 elif hand.gametype["category"] == "holdem" or "6_holdem":
1229 self.renderCards(painter, ['0', '0'], 185, 400)
1230 elif hand.gametype["category"] == "2_holdem":
1231 self.renderCards(painter, ['0', '0', '0'], 185, 400)
1232 else:
1233 self.renderCards(painter, player.holecards, 185, 400)
1235 # draw player's info
1236 painter.drawText(QRect(140, 490, 200, 20),
1237 Qt.AlignCenter,
1238 '%s %s%.2f' % (player.name,
1239 self.currency,
1240 player.stack))
1241 if player.justacted:
1242 painter.setPen(QColor("yellow"))
1243 # draw player's actions
1244 painter.drawText(QRect(140, 507, 200, 20), Qt.AlignCenter, player.action)
1245 # draw bet pot
1246 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
1247 'Pot: %s%.2f' % (self.currency, state.newpot))
1248 else:
1249 painter.setPen(QColor("white"))
1250 if player.chips != 0:
1251 # draw player's bet
1252 painter.drawText(QRect(260, 490, 200, 20),
1253 Qt.AlignCenter,
1254 '%s%.2f' % (self.currency, player.chips))
1255 elif player.name == list(state.players.values())[5].name:
1256 if hand.get_player_position(player.name) == "S":
1257 painter.drawImage(QPoint(450, 620), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1258 print("round", i, "player", player.name)
1259 print(list(state.players.values())[2])
1260 # draw player bloc
1261 painter.drawImage(QPoint(500, 790), self.playerBackdrop)
1262 if player.action == "folds":
1263 painter.setPen(QColor("red"))
1264 else:
1265 painter.setPen(QColor("white"))
1266 # if check box hide cards and hero
1268 if not self.showCards.isChecked():
1269 # draw player's card
1270 self.renderCards(painter, player.holecards, 520, 700)
1271 elif self.showCards.isChecked():
1272 if player.name == self.Heroes:
1273 self.renderCards(painter, player.holecards, 520, 700)
1274 else:
1275 if hand.gametype[
1276 "category"] == "omahahi" or "omahahilo" or "badugi" or "badacey" or "badeucey" or "irish" or "fusion":
1277 self.renderCards(painter, ['0', '0', '0', '0'], 520, 700)
1278 elif hand.gametype[
1279 "category"] == "5_omahahi" or "5_omaha8" or "cour_hi" or "cour_hilo" or "27_1draw" or "27_3draw" or "a5_3draw" or "a5_1draw" or "drawmaha":
1280 self.renderCards(painter, ['0', '0', '0', '0', '0'], 520, 700)
1281 elif hand.gametype["category"] == "6_omahahi":
1282 self.renderCards(painter, ['0', '0', '0', '0', '0', '0'], 520, 700)
1283 elif hand.gametype["category"] == "holdem" or "6_holdem":
1284 self.renderCards(painter, ['0', '0'], 520, 700)
1285 elif hand.gametype["category"] == "2_holdem":
1286 self.renderCards(painter, ['0', '0', '0'], 520, 700)
1287 else:
1288 self.renderCards(painter, player.holecards, 520, 700)
1290 # draw player's info
1291 painter.drawText(QRect(480, 790, 200, 20),
1292 Qt.AlignCenter,
1293 '%s %s%.2f' % (player.name,
1294 self.currency,
1295 player.stack))
1296 if player.justacted:
1297 painter.setPen(QColor("yellow"))
1298 # draw player's actions
1299 painter.drawText(QRect(480, 807, 200, 20), Qt.AlignCenter, player.action)
1300 # draw bet pot
1301 painter.drawText(QRect(380, 480, 200, 40),Qt.AlignCenter,
1302 'Pot: %s%.2f' % (self.currency, state.newpot))
1303 else:
1304 painter.setPen(QColor("white"))
1305 if player.chips != 0:
1306 # draw player's bet
1307 painter.drawText(QRect(480, 670, 200, 20),
1308 Qt.AlignCenter,
1309 '%s%.2f' % (self.currency, player.chips))
1311 else:
1312 pass
1313 i += 1
1314 elif nb_player == 7:
1315 print('nb player :', nb_player)
1316 elif nb_player == 8:
1317 print('nb player :', nb_player)
1318 elif nb_player == 9:
1319 print('nb player :', nb_player)
1320 elif nb_player == 10:
1321 print('nb player :', nb_player)
1323 painter.setPen(QColor("white"))
1325 for street in state.renderBoard:
1326 x = 520
1327 y = 400
1328 print("street", street, "value street", state.board[street])
1329 if street == "FLOP" and state.board[street] != []:
1330 self.renderboardCards(painter, state.board[street], x, y)
1331 elif street == "FLOP1" and state.board[street] != []:
1332 y -= int(self.cardheight / 2)
1333 self.renderboardCards(painter, state.board[street], x, y)
1334 elif street == "FLOP2" and state.board[street] != []:
1335 y += int(self.cardheight / 2)
1336 self.renderboardCards(painter, state.board[street], x, y)
1337 elif street == "FLOP3" and state.board[street] != []:
1338 y += self.cardheight + int(self.cardheight / 2)
1339 self.renderboardCards(painter, state.board[street], x, y)
1340 elif street == "TURN" and state.board[street] != []:
1341 x += 3 * self.cardwidth
1342 self.renderboardCards(painter, state.board[street], x, y)
1343 elif street == "TURN1" and state.board[street] != []:
1344 x += 3 * self.cardwidth
1345 y -= int(self.cardheight / 2)
1346 self.renderboardCards(painter, state.board[street], x, y)
1347 elif street == "TURN2" and state.board[street] != []:
1348 x += 3 * self.cardwidth
1349 y += int(self.cardheight / 2)
1350 self.renderboardCards(painter, state.board[street], x, y)
1351 elif street == "TURN3" and state.board[street] != []:
1352 x += 3 * self.cardwidth
1353 y += self.cardheight + int(self.cardheight / 2)
1354 self.renderboardCards(painter, state.board[street], x, y)
1355 elif street == "RIVER" and state.board[street] != []:
1356 x += 4 * self.cardwidth
1357 self.renderboardCards(painter, state.board[street], x, y)
1358 elif street == "RIVER1" and state.board[street] != []:
1359 x += 4 * self.cardwidth
1360 y -= int(self.cardheight / 2)
1361 self.renderboardCards(painter, state.board[street], x, y)
1362 elif street == "RIVER2" and state.board[street] != []:
1363 x += 4 * self.cardwidth
1364 y += int(self.cardheight / 2)
1365 self.renderboardCards(painter, state.board[street], x, y)
1366 elif street == "RIVER3" and state.board[street] != []:
1367 x += 4 * self.cardwidth
1368 y += self.cardheight + int(self.cardheight / 2)
1369 self.renderboardCards(painter, state.board[street], x, y)
1370 else:
1371 pass
1374 if self.stateSlider.value() == self.stateSlider.maximum():
1375 if nb_player == 2:
1376 # set 2 player
1377 print('nb player :', nb_player)
1378 i = 0
1379 for player in list(state.players.values()):
1380 #print(player.holecards)
1381 print(hand.gametype["category"])
1382 if player.name == list(state.players.values())[0].name:
1383 self.renderCards(painter, player.holecards, 660, 700)
1384 elif player.name == list(state.players.values())[1].name:
1385 self.renderCards(painter, player.holecards, 1115, 400)
1386 else:
1387 pass
1388 i += 1
1389 elif nb_player == 3:
1390 print('nb player :', nb_player)
1391 i = 0
1392 for player in list(state.players.values()):
1393 #print(player.holecards)
1394 print(hand.gametype["category"])
1395 if player.name == list(state.players.values())[0].name:
1396 self.renderCards(painter, player.holecards, 660, 700)
1397 elif player.name == list(state.players.values())[1].name:
1398 self.renderCards(painter, player.holecards, 1115, 400)
1399 elif player.name == list(state.players.values())[2].name:
1400 self.renderCards(painter, player.holecards, 185, 400)
1401 else:
1402 pass
1403 i += 1
1404 elif nb_player == 4:
1405 print('nb player :', nb_player)
1406 i = 0
1407 for player in list(state.players.values()):
1408 #print(player.holecards)
1409 print(hand.gametype["category"])
1410 if player.name == list(state.players.values())[0].name:
1411 self.renderCards(painter, player.holecards, 660, 700)
1412 elif player.name == list(state.players.values())[1].name:
1413 self.renderCards(painter, player.holecards, 1115, 400)
1414 elif player.name == list(state.players.values())[2].name:
1415 self.renderCards(painter, player.holecards, 655, 130)
1416 elif player.name == list(state.players.values())[3].name:
1417 self.renderCards(painter, player.holecards, 185, 400)
1418 else:
1419 pass
1420 i += 1
1421 elif nb_player == 5:
1422 print('nb player :', nb_player)
1423 i = 0
1424 for player in list(state.players.values()):
1425 #print(player.holecards)
1426 print(hand.gametype["category"])
1427 if player.name == list(state.players.values())[0].name:
1428 self.renderCards(painter, player.holecards, 660, 700)
1429 elif player.name == list(state.players.values())[1].name:
1430 self.renderCards(painter, player.holecards, 1115, 400)
1431 elif player.name == list(state.players.values())[2].name:
1432 self.renderCards(painter, player.holecards, 770, 130)
1433 elif player.name == list(state.players.values())[3].name:
1434 self.renderCards(painter, player.holecards, 520, 130)
1435 elif player.name == list(state.players.values())[4].name:
1436 self.renderCards(painter, player.holecards, 185, 400)
1437 else:
1438 pass
1439 i += 1
1440 elif nb_player == 6:
1441 print('nb player :', nb_player)
1442 i = 0
1443 for player in list(state.players.values()):
1444 # print(player.holecards)
1445 print(hand.gametype["category"])
1446 if player.name == list(state.players.values())[0].name:
1447 self.renderCards(painter, player.holecards, 770, 700)
1448 elif player.name == list(state.players.values())[1].name:
1449 self.renderCards(painter, player.holecards, 1115, 400)
1450 elif player.name == list(state.players.values())[2].name:
1451 self.renderCards(painter, player.holecards, 770, 130)
1452 elif player.name == list(state.players.values())[3].name:
1453 self.renderCards(painter, player.holecards, 520, 130)
1454 elif player.name == list(state.players.values())[4].name:
1455 self.renderCards(painter, player.holecards, 185, 400)
1456 elif player.name == list(state.players.values())[5].name:
1457 self.renderCards(painter, player.holecards, 520, 700)
1458 else:
1459 pass
1460 i += 1
1461 elif nb_player == 7:
1462 print('nb player :', nb_player)
1463 elif nb_player == 8:
1464 print('nb player :', nb_player)
1465 elif nb_player == 9:
1466 print('nb player :', nb_player)
1467 elif nb_player == 10:
1468 print('nb player :', nb_player)
1470 def keyPressEvent(self, event):
1471 if event.key() == Qt.Key_Left:
1472 self.stateSlider.setValue(max(0, self.stateSlider.value() - 1))
1473 elif event.key() == Qt.Key_Right:
1474 self.stateSlider.setValue(min(self.stateSlider.maximum(), self.stateSlider.value() + 1))
1475 elif event.key() == Qt.Key_Up:
1476 if self.handidx < len(self.handlist) - 1:
1477 self.play_hand(self.handidx + 1)
1478 elif event.key() == Qt.Key_Down:
1479 if self.handidx > 0:
1480 self.play_hand(self.handidx - 1)
1481 else:
1482 QWidget.keyPressEvent(self, event)
1484 def play_hand(self, handidx):
1485 self.handidx = handidx
1486 hand = Hand.hand_factory(self.handlist[handidx], self.conf, self.db)
1487 # hand.writeHand() # Print handhistory to stdout -> should be an option in the GUI
1488 self.currency = hand.sym
1490 self.states = []
1492 # info for drawing (game, limite, site ...)
1493 print(hand)
1494 print(hand.gametype)
1495 info_gen = hand.gametype['category']
1496 if info_gen == "omahahilo":
1497 info_gen = "Omaha Hi/Lo"
1498 elif info_gen == "fusion":
1499 info_gen = "Fusion"
1500 elif info_gen == "27_1draw":
1501 info_gen = "Single Draw 2-7 Lowball"
1502 elif info_gen == "27_3draw":
1503 info_gen = "Triple Draw 2-7 Lowball"
1504 elif info_gen == "a5_3draw":
1505 info_gen = "Triple Draw A-5 Lowball"
1506 elif info_gen == "5_studhi":
1507 info_gen = "5 Card Stud"
1508 elif info_gen == "badugi":
1509 info_gen = "Badugi"
1510 elif info_gen == "badacey":
1511 info_gen = "Badacey"
1512 elif info_gen == "badeucey":
1513 info_gen = "Badeucey"
1514 elif info_gen == "drawmaha":
1515 info_gen = "2-7 Drawmaha"
1516 elif info_gen == "a5_1draw":
1517 info_gen = "A-5 Single Draw"
1518 elif info_gen == "27_razz":
1519 info_gen = "2-7 Razz"
1520 elif info_gen == "fivedraw":
1521 info_gen = "5 Card Draw"
1522 elif info_gen == "holdem":
1523 info_gen = "Hold'em"
1524 elif info_gen == "6_holdem":
1525 info_gen = "Hold'em"
1526 elif info_gen == "omahahi":
1527 info_gen = "Omaha"
1528 elif info_gen == "razz":
1529 info_gen = "Razz"
1530 elif info_gen == "studhi":
1531 info_gen = "7 Card Stud"
1532 elif info_gen == "studhilo":
1533 info_gen = "7 Card Stud Hi/Lo"
1534 elif info_gen == "5_omahahi":
1535 info_gen = "5 Card Omaha"
1536 elif info_gen == "5_omaha8":
1537 info_gen = "5 Card Omaha Hi/Lo"
1538 elif info_gen == "cour_hi":
1539 info_gen = "Courchevel"
1540 elif info_gen == "cour_hilo":
1541 info_gen = "Courchevel Hi/Lo"
1542 elif info_gen == "2_holdem":
1543 info_gen = "Double hold'em"
1544 elif info_gen == "irish":
1545 info_gen = "Irish"
1546 elif info_gen == "6_omahahi":
1547 info_gen = "6 Card Omaha"
1548 else:
1549 info_gen = "unknown"
1550 limit_info = hand.gametype['limitType']
1551 if limit_info == "fl":
1552 limit_info = "Fixed Limit"
1553 elif limit_info == "nl":
1554 limit_info = "No Limit"
1555 elif limit_info == "pl":
1556 limit_info = "Pot Limit"
1557 elif limit_info == "cn":
1558 limit_info = "Cap No Limit"
1559 elif limit_info == "cp":
1560 limit_info = "Cap Pot Limit"
1561 else:
1562 limit_info = "unknown"
1563 print(limit_info)
1564 self.info = str(limit_info) + " " + str(info_gen) + " " + str(hand.gametype['bb']) + str(
1565 hand.gametype['currency']) + " hand n° " + str(hand.handid) + " played on " + str(hand.sitename)
1567 state = TableState(hand)
1569 # print (state)
1570 seenStreets = []
1571 for street in hand.allStreets:
1572 if state.called > 0:
1573 for player in list(state.players.values()):
1574 if player.stack == 0:
1575 state.allin = True
1576 break
1577 if not hand.actions[street] and not state.allin:
1578 break
1579 seenStreets.append(street)
1580 state = copy.deepcopy(state)
1581 state.startPhase(street)
1582 self.states.append(state)
1583 for action in hand.actions[street]:
1584 state = copy.deepcopy(state)
1585 state.updateForAction(action)
1586 self.states.append(state)
1588 state = copy.deepcopy(state)
1589 state.endHand(hand.collectees, hand.pot.returned)
1590 self.states.append(state)
1592 # Clear and repopulate the row of buttons
1593 for idx in reversed(list(range(self.buttonBox.count()))):
1594 self.buttonBox.takeAt(idx).widget().setParent(None)
1595 self.buttonBox.addWidget(self.prevButton)
1596 self.prevButton.setEnabled(self.handidx > 0)
1597 self.buttonBox.addWidget(self.startButton)
1598 for street in hand.allStreets[1:]:
1599 btn = QPushButton(street.capitalize())
1600 self.buttonBox.addWidget(btn)
1601 btn.clicked.connect(partial(self.street_clicked, street=street))
1602 btn.setEnabled(street in seenStreets)
1603 btn.setFocusPolicy(Qt.NoFocus)
1604 self.buttonBox.addWidget(self.endButton)
1605 self.buttonBox.addWidget(self.playPauseButton)
1606 self.buttonBox.addWidget(self.nextButton)
1607 self.nextButton.setEnabled(self.handidx < len(self.handlist) - 1)
1609 self.stateSlider.setMaximum(len(self.states) - 1)
1610 self.stateSlider.setValue(0)
1611 self.update()
1613 def increment_state(self):
1614 if self.stateSlider.value() == self.stateSlider.maximum():
1615 self.playing = False
1616 self.playPauseButton.setText("Play")
1618 if self.playing:
1619 self.stateSlider.setValue(self.stateSlider.value() + 1)
1621 def slider_changed(self, value):
1622 self.update()
1624 def importhand(self, handid=1):
1626 h = Hand.hand_factory(handid, self.conf, self.db)
1628 return h
1630 def play_clicked(self, checkState):
1631 self.playing = not self.playing
1632 if self.playing:
1633 self.playPauseButton.setText("Pause")
1634 self.playTimer = QTimer()
1635 self.playTimer.timeout.connect(self.increment_state)
1636 self.playTimer.start(1000)
1637 else:
1638 self.playPauseButton.setText("Play")
1639 self.playTimer = None
1641 def start_clicked(self, checkState):
1642 self.stateSlider.setValue(0)
1644 def end_clicked(self, checkState):
1645 self.stateSlider.setValue(self.stateSlider.maximum())
1647 def prev_clicked(self, checkState):
1648 self.play_hand(self.handidx - 1)
1650 def next_clicked(self, checkState):
1651 self.play_hand(self.handidx + 1)
1653 def street_clicked(self, checkState, street):
1654 for i, state in enumerate(self.states):
1655 if state.street == street:
1656 self.stateSlider.setValue(i)
1657 break
1660# ICM code originally grabbed from http://svn.gna.org/svn/pokersource/trunk/icm-calculator/icm-webservice.py
1661# Copyright (c) 2008 Thomas Johnson <tomfmason@gmail.com>
1663class ICM(object):
1664 def __init__(self, stacks, payouts):
1665 self.stacks = stacks
1666 self.payouts = payouts
1667 self.equities = []
1668 self.prepare()
1670 def prepare(self):
1671 total = sum(self.stacks)
1672 for k in self.stacks:
1673 self.equities.append(round(Decimal(str(self.getEquities(total, k, 0))), 4))
1675 def getEquities(self, total, player, depth):
1676 D = Decimal
1677 eq = D(self.stacks[player]) / total * D(str(self.payouts[depth]))
1678 if (depth + 1 < len(self.payouts)):
1679 i = 0
1680 for stack in self.stacks:
1681 if i != player and stack > 0.0:
1682 self.stacks[i] = 0.0
1683 eq += self.getEquities((total - stack), player, (depth + 1)) * (old_div(stack, D(total)))
1684 self.stacks[i] = stack
1685 i += 1
1686 return eq
1689class TableState(object):
1690 def __init__(self, hand):
1691 self.pot = Decimal(0)
1692 self.street = None
1693 self.board = hand.board
1694 self.renderBoard = set()
1695 self.bet = Decimal(0)
1696 self.called = Decimal(0)
1697 self.gametype = hand.gametype['category']
1698 self.gamebase = hand.gametype['base']
1699 self.allin = False
1700 self.allinThisStreet = False
1701 self.newpot = Decimal()
1702 # NOTE: Need a useful way to grab payouts
1703 # self.icm = ICM(stacks,payouts)
1704 # print icm.equities
1706 self.players = {}
1707 # print ('hand.players', hand.players)
1708 # print (type(hand.players))
1709 # print (type(self.players))
1710 # for name, chips, seat in hand.players[-1]:
1711 # self.players.append(Player(name, chips, seat))
1712 # # self.players[name] = Player(hand, name, chips, seat)
1713 for items in hand.players:
1714 # print (items)
1715 # print ('type', (type(items)))
1716 # print (items[0])
1717 # print (items[1])
1718 # print (items[2])
1719 # print (items[3])
1721 self.players[items[1]] = Player(hand, items[1], items[2], int(items[0]))
1722 print(self.players[items[1]])
1724 def startPhase(self, phase):
1725 self.street = phase
1726 self.newpot = self.newpot
1727 if phase in ("BLINDSANTES", "PREFLOP", "DEAL"):
1728 return
1730 self.renderBoard.add(phase)
1732 for player in list(self.players.values()):
1733 player.justacted = False
1734 if player.chips > self.called:
1735 player.stack += player.chips - self.called
1736 player.chips = self.called
1737 self.pot += player.chips
1739 player.chips = Decimal(0)
1740 if phase in ("THIRD", "FOURTH", "FIFTH", "SIXTH", "SEVENTH"):
1741 player.holecards = player.streetcards[self.street]
1742 self.bet = Decimal(0)
1743 self.called = Decimal(0)
1744 self.allinThisStreet = False
1746 def updateForAction(self, action):
1747 for player in list(self.players.values()):
1748 player.justacted = False
1750 player = self.players[action[0]]
1751 player.action = action[1]
1752 player.justacted = True
1753 if action[1] == "folds" or action[1] == "checks":
1754 pass
1755 elif action[1] == "raises" or action[1] == "bets":
1756 if self.allinThisStreet:
1757 self.called = Decimal(self.bet)
1758 else:
1759 self.called = Decimal(0)
1760 diff = self.bet - player.chips
1761 self.bet += action[2]
1762 player.chips += action[2] + diff
1763 player.stack -= action[2] + diff
1764 self.newpot += action[2] + diff
1765 elif action[1] == "big blind":
1766 self.bet = action[2]
1767 player.chips += action[2]
1768 player.stack -= action[2]
1769 self.newpot += action[2]
1770 elif action[1] == "calls" or action[1] == "small blind" or action[1] == "secondsb":
1771 player.chips += action[2]
1772 player.stack -= action[2]
1773 self.called = max(self.called, player.chips)
1774 self.newpot += action[2]
1775 elif action[1] == "both":
1776 player.chips += action[2]
1777 player.stack -= action[2]
1778 self.newpot += action[2]
1779 elif action[1] == "ante":
1780 self.pot += action[2]
1781 player.stack -= action[2]
1782 self.newpot += action[2]
1783 elif action[1] == "discards":
1784 player.action += " " + str(action[2])
1785 if len(action) > 3:
1786 # Must be hero as we have discard information. Update holecards now.
1787 player.holecards = player.streetcards[self.street]
1788 elif action[1] == "stands pat":
1789 pass
1790 elif action[1] == "bringin":
1791 player.chips += action[2]
1792 player.stack -= action[2]
1793 self.newpot += action[2]
1794 else:
1795 print("unhandled action: " + str(action))
1797 if player.stack == 0:
1798 self.allinThisStreet = True
1800 def endHand(self, collectees, returned):
1801 self.pot = Decimal(0)
1802 for player in list(self.players.values()):
1803 player.justacted = False
1804 player.chips = Decimal(0)
1805 if self.gamebase == 'draw':
1806 player.holecards = player.streetcards[self.street]
1807 for name, amount in list(collectees.items()):
1808 player = self.players[name]
1809 player.chips += amount
1810 player.action = "collected"
1811 player.justacted = True
1812 for name, amount in list(returned.items()):
1813 self.players[name].stack += amount
1816class Player(object):
1817 def __init__(self, hand, name, stack, seat):
1818 self.stack = Decimal(stack)
1819 self.chips = Decimal(0)
1820 self.seat = seat
1821 self.name = name
1822 self.action = None
1823 self.justacted = False
1824 self.holecards = hand.join_holecards(name, asList=True)
1825 self.streetcards = {}
1826 if hand.gametype['base'] == 'draw':
1827 for street in hand.actionStreets[1:]:
1828 self.streetcards[street] = hand.join_holecards(name, asList=True, street=street)
1829 self.holecards = self.streetcards[hand.actionStreets[1]]
1830 elif hand.gametype['base'] == 'stud':
1831 for i, street in enumerate(hand.actionStreets[1:]):
1832 self.streetcards[street] = self.holecards[:i + 3]
1833 self.holecards = self.streetcards[hand.actionStreets[1]]
1834 print('seat', seat)
1835 self.x = 0.5 * cos(2 * self.seat * pi / hand.maxseats)
1836 self.y = 0.8 * sin(2 * self.seat * pi / hand.maxseats)
1839if __name__ == '__main__':
1840 config = Configuration.Config()
1841 db = Database.Database(config)
1842 sql = SQL.Sql(db_server=config.get_db_parameters()['db-server'])
1844 from PyQt5.QtWidgets import QApplication
1846 app = QApplication([])
1847 handlist = [10, 39, 40]
1848 replayer = GuiReplayer(config, sql, None, handlist)
1849 replayer.play_hand(0)
1851 app.exec_()