Coverage for GuiReplayer.py: 0%
1063 statements
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-15 19:33 +0000
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-15 19:33 +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
23from past.utils import old_div
24# import L10n
25# _ = L10n.get_translation()
27from functools import partial
28import xml.dom.minidom
30import Hand
31import Card
32import Configuration
33import Database
34import SQL
35import Deck
37from PyQt5.QtCore import QPoint, QRect, Qt, QTimer
38from PyQt5.QtGui import QColor, QImage, QPainter
39from PyQt5.QtWidgets import QHBoxLayout, QPushButton, QSlider, QVBoxLayout, QCheckBox, QWidget
41from math import pi, cos, sin
42from decimal import Decimal
43import copy
44import os
45import logging
47log = logging.getLogger("replayer")
49CARD_HEIGHT = 90
50CARD_WIDTH = 70
53class GuiReplayer(QWidget):
54 """A Replayer to replay hands."""
56 def __init__(self, config, querylist, mainwin, handlist):
57 QWidget.__init__(self, None)
58 self.resize(1800, 1080)
59 self.setMinimumSize(800, 600)
60 self.conf = config
61 self.main_window = mainwin
62 self.sql = querylist
63 self.newpot = Decimal()
64 self.db = Database.Database(self.conf, sql=self.sql)
65 self.states = [] # List with all table states.
66 self.handlist = handlist
67 self.handidx = 0
68 self.Heroes = ""
69 self.setWindowTitle("FPDB Hand Replayer")
71 self.replayBox = QVBoxLayout()
73 self.setLayout(self.replayBox)
75 self.replayBox.addStretch()
76 self.buttonBox2 = QHBoxLayout()
77 self.buttonBox = QHBoxLayout()
78 self.showCards = QCheckBox("Hide Cards")
79 self.showCards.setChecked(True)
80 self.buttonBox2.addWidget(self.showCards)
81 self.prevButton = QPushButton("Prev")
82 self.prevButton.clicked.connect(self.prev_clicked)
83 self.prevButton.setFocusPolicy(Qt.NoFocus)
84 self.startButton = QPushButton("Start")
85 self.startButton.clicked.connect(self.start_clicked)
86 self.startButton.setFocusPolicy(Qt.NoFocus)
87 self.endButton = QPushButton("End")
88 self.endButton.clicked.connect(self.end_clicked)
89 self.endButton.setFocusPolicy(Qt.NoFocus)
90 self.playPauseButton = QPushButton("Play")
91 self.playPauseButton.clicked.connect(self.play_clicked)
92 self.playPauseButton.setFocusPolicy(Qt.NoFocus)
93 self.nextButton = QPushButton("Next")
94 self.nextButton.clicked.connect(self.next_clicked)
95 self.nextButton.setFocusPolicy(Qt.NoFocus)
97 self.replayBox.addLayout(self.buttonBox)
98 self.replayBox.addLayout(self.buttonBox2)
100 self.stateSlider = QSlider(Qt.Horizontal)
101 self.stateSlider.valueChanged.connect(self.slider_changed)
102 self.stateSlider.setFocusPolicy(Qt.NoFocus)
104 self.replayBox.addWidget(self.stateSlider, False)
106 self.playing = False
108 self.tableImage = None
109 self.playerBackdrop = None
111 self.cardImages = None
112 self.deck_inst = Deck.Deck(self.conf, height=CARD_HEIGHT, width=CARD_WIDTH)
113 self.show()
115 def renderCards(self, painter, cards, x, y):
116 for card in cards:
117 cardIndex = Card.encodeCard(card)
118 painter.drawPixmap(QPoint(x, y), self.cardImages[cardIndex])
119 x += int(self.cardwidth / 2) - 15
121 def renderboardCards(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 += self.cardwidth
127 def paintEvent(self, event):
128 hand = Hand.hand_factory(self.handlist[self.handidx], self.conf, self.db)
129 if self.tableImage is None or self.playerBackdrop is None:
130 try:
131 self.playerBackdrop = QImage(os.path.join(self.conf.graphics_path, "playerbackdrop.png"))
132 self.tableImage = QImage(os.path.join(self.conf.graphics_path, "TableR.png"))
133 self.dealer = QImage(os.path.join(self.conf.graphics_path, "dealer.png"))
134 except (FileNotFoundError, OSError) as e:
135 log.error(f"Error loading images: {e}")
136 return
137 if self.cardImages is None:
138 self.cardwidth = CARD_WIDTH
139 self.cardheight = CARD_HEIGHT
140 self.cardImages = [None] * 53
141 suits = ("s", "h", "d", "c")
142 ranks = (14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2)
143 for j in range(0, 13):
144 for i in range(0, 4):
145 index = Card.cardFromValueSuit(ranks[j], suits[i])
146 self.cardImages[index] = self.deck_inst.card(suits[i], ranks[j])
147 self.cardImages[0] = self.deck_inst.back()
149 if not event.rect().intersects(QRect(0, 0, self.tableImage.width(), self.tableImage.height())):
150 return
152 painter = QPainter(self)
153 # table position
154 painter.drawImage(QPoint(200, 200), self.tableImage)
156 # initial state
157 if len(self.states) == 0:
158 return
160 state = self.states[self.stateSlider.value()]
162 # communityLeft = int(old_div(self.tableImage.width(), 2) - 2.5 * self.cardwidth)
163 # communityTop = int(old_div(self.tableImage.height(), 2) - 1.75 * self.cardheight)
165 # convertx = lambda x: int(x * self.tableImage.width() * 0.8) + old_div(self.tableImage.width(), 2)
166 # converty = lambda y: int(y * self.tableImage.height() * 0.6) + old_div(self.tableImage.height(), 2)
167 # paint hand infos
168 painter.drawText(QRect(-40, 0, 600, 80), Qt.AlignCenter, self.info)
169 #
170 nb_player = len(list(state.players.values()))
171 # find hero in site
172 path = os.path.join(Configuration.Config().config_path, "HUD_config.xml")
173 print(path)
174 doc = xml.dom.minidom.parse(path)
175 for site_node in doc.getElementsByTagName("site"):
176 if site_node.getAttribute("site_name") == str(hand.sitename):
177 print(site_node.getAttribute("screen_name"))
178 self.Heroes = site_node.getAttribute("screen_name")
180 print("list players:", (list(state.players.values())))
181 # print("list players:", self.Heroes)
182 if nb_player == 2:
183 # set 2 player
184 print("nb player :", nb_player)
185 i = 0
186 for player in list(state.players.values()):
187 # print(player.holecards)
188 print(hand.gametype["category"])
189 if player.name == list(state.players.values())[0].name:
190 print("round", i, "player", player.name)
191 # draw player bloc
192 painter.drawImage(QPoint(635, 790), self.playerBackdrop)
193 if player.action == "folds":
194 painter.setPen(QColor("red"))
195 else:
196 painter.setPen(QColor("white"))
197 # if check box hide cards and hero
199 if not self.showCards.isChecked():
200 # draw player's card
201 self.renderCards(painter, player.holecards, 660, 700)
202 elif self.showCards.isChecked():
203 if player.name == self.Heroes:
204 self.renderCards(painter, player.holecards, 660, 700)
205 else:
206 if (
207 hand.gametype["category"] == "omahahi"
208 or "omahahilo"
209 or "badugi"
210 or "badacey"
211 or "badeucey"
212 or "irish"
213 or "fusion"
214 ):
215 self.renderCards(painter, ["0", "0", "0", "0"], 660, 700)
216 elif (
217 hand.gametype["category"] == "5_omahahi"
218 or "5_omaha8"
219 or "cour_hi"
220 or "cour_hilo"
221 or "27_1draw"
222 or "27_3draw"
223 or "a5_3draw"
224 or "a5_1draw"
225 or "drawmaha"
226 ):
227 self.renderCards(painter, ["0", "0", "0", "0", "0"], 660, 700)
228 elif hand.gametype["category"] == "6_omahahi":
229 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 660, 700)
230 elif hand.gametype["category"] == "holdem" or "6_holdem":
231 self.renderCards(painter, ["0", "0"], 660, 700)
232 elif hand.gametype["category"] == "2_holdem":
233 self.renderCards(painter, ["0", "0", "0"], 660, 700)
234 else:
235 self.renderCards(painter, player.holecards, 660, 700)
236 # draw player's stack
237 painter.drawText(
238 QRect(605, 790, 200, 20),
239 Qt.AlignCenter,
240 "%s %s%.2f" % (player.name, self.currency, player.stack),
241 )
242 if player.justacted:
243 painter.setPen(QColor("yellow"))
244 # draw player's actions
245 painter.drawText(QRect(605, 807, 200, 20), Qt.AlignCenter, player.action)
246 # draw pot
247 painter.drawText(
248 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
249 )
250 else:
251 painter.setPen(QColor("white"))
252 if player.chips != 0:
253 # draw player's bet
254 painter.drawText(
255 QRect(605, 670, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
256 )
257 elif player.name == list(state.players.values())[1].name:
258 print("round", i, "player", player.name)
259 # draw player bloc
260 painter.drawImage(QPoint(1090, 490), self.playerBackdrop)
261 if player.action == "folds":
262 painter.setPen(QColor("red"))
263 else:
264 painter.setPen(QColor("white"))
265 # if check box hide cards and hero
267 if not self.showCards.isChecked():
268 # draw player's card
269 self.renderCards(painter, player.holecards, 1115, 400)
270 elif self.showCards.isChecked():
271 if player.name == self.Heroes:
272 self.renderCards(painter, player.holecards, 1115, 400)
273 else:
274 if (
275 hand.gametype["category"] == "omahahi"
276 or "omahahilo"
277 or "badugi"
278 or "badacey"
279 or "badeucey"
280 or "irish"
281 or "fusion"
282 ):
283 self.renderCards(painter, ["0", "0", "0", "0"], 1115, 400)
284 elif (
285 hand.gametype["category"] == "5_omahahi"
286 or "5_omaha8"
287 or "cour_hi"
288 or "cour_hilo"
289 or "27_1draw"
290 or "27_3draw"
291 or "a5_3draw"
292 or "a5_1draw"
293 or "drawmaha"
294 ):
295 self.renderCards(painter, ["0", "0", "0", "0", "0"], 1115, 400)
296 elif hand.gametype["category"] == "6_omahahi":
297 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 1115, 400)
298 elif hand.gametype["category"] == "holdem" or "6_holdem":
299 self.renderCards(painter, ["0", "0"], 1115, 400)
300 elif hand.gametype["category"] == "2_holdem":
301 self.renderCards(painter, ["0", "0", "0"], 1115, 400)
302 else:
303 self.renderCards(painter, player.holecards, 1115, 400)
305 # draw player's info
306 painter.drawText(
307 QRect(1070, 490, 200, 20),
308 Qt.AlignCenter,
309 "%s %s%.2f" % (player.name, self.currency, player.stack),
310 )
311 if player.justacted:
312 painter.setPen(QColor("yellow"))
313 # draw player's actions
314 painter.drawText(QRect(1070, 507, 200, 20), Qt.AlignCenter, player.action)
315 # draw bet pot
316 painter.drawText(
317 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
318 )
319 else:
320 painter.setPen(QColor("white"))
321 if player.chips != 0:
322 # draw player's bet
323 painter.drawText(
324 QRect(930, 490, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
325 )
326 else:
327 pass
328 i += 1
329 elif nb_player == 3:
330 print("nb player :", nb_player)
331 i = 0
332 for player in list(state.players.values()):
333 # print(player.holecards)
334 print(hand.gametype["category"])
335 if player.name == list(state.players.values())[0].name:
336 if hand.get_player_position(player.name) == "S":
337 painter.drawImage(QPoint(530, 650), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
338 print("round", i, "player", player.name)
339 # draw player bloc
341 painter.drawImage(QPoint(635, 790), self.playerBackdrop)
342 if player.action == "folds":
343 painter.setPen(QColor("red"))
344 else:
345 painter.setPen(QColor("white"))
346 # if check box hide cards and hero
347 # show known cards or not
348 if not self.showCards.isChecked():
349 # draw player's card
350 self.renderCards(painter, player.holecards, 660, 700)
351 elif self.showCards.isChecked():
352 if player.name == self.Heroes:
353 self.renderCards(painter, player.holecards, 660, 700)
354 else:
355 if (
356 hand.gametype["category"] == "omahahi"
357 or "omahahilo"
358 or "badugi"
359 or "badacey"
360 or "badeucey"
361 or "irish"
362 or "fusion"
363 ):
364 self.renderCards(painter, ["0", "0", "0", "0"], 660, 700)
365 elif (
366 hand.gametype["category"] == "5_omahahi"
367 or "5_omaha8"
368 or "cour_hi"
369 or "cour_hilo"
370 or "27_1draw"
371 or "27_3draw"
372 or "a5_3draw"
373 or "a5_1draw"
374 or "drawmaha"
375 ):
376 self.renderCards(painter, ["0", "0", "0", "0", "0"], 660, 700)
377 elif hand.gametype["category"] == "6_omahahi":
378 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 660, 700)
379 elif hand.gametype["category"] == "holdem" or "6_holdem":
380 self.renderCards(painter, ["0", "0"], 660, 700)
381 elif hand.gametype["category"] == "2_holdem":
382 self.renderCards(painter, ["0", "0", "0"], 660, 700)
383 else:
384 self.renderCards(painter, player.holecards, 660, 700)
385 # draw player's stack
386 painter.drawText(
387 QRect(605, 790, 200, 20),
388 Qt.AlignCenter,
389 "%s %s%.2f" % (player.name, self.currency, player.stack),
390 )
392 if player.justacted:
393 painter.setPen(QColor("yellow"))
394 # draw player's actions
395 painter.drawText(QRect(605, 807, 200, 20), Qt.AlignCenter, player.action)
396 # draw pot
397 painter.drawText(
398 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
399 )
400 else:
401 painter.setPen(QColor("white"))
402 if player.chips != 0:
403 # draw player's bet
404 painter.drawText(
405 QRect(605, 670, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
406 )
407 elif player.name == list(state.players.values())[1].name:
408 if hand.get_player_position(player.name) == "S":
409 painter.drawImage(QPoint(990, 570), self.dealer.scaled(40, 40, Qt.KeepAspectRatio)) # ok
410 print("round", i, "player", player.name)
411 # draw player bloc
412 painter.drawImage(QPoint(1090, 490), self.playerBackdrop)
413 if player.action == "folds":
414 painter.setPen(QColor("red"))
415 else:
416 painter.setPen(QColor("white"))
417 # if check box hide cards and hero
419 if not self.showCards.isChecked():
420 # draw player's card
421 self.renderCards(painter, player.holecards, 1115, 400)
422 elif self.showCards.isChecked():
423 if player.name == self.Heroes:
424 self.renderCards(painter, player.holecards, 1115, 400)
425 else:
426 if (
427 hand.gametype["category"] == "omahahi"
428 or "omahahilo"
429 or "badugi"
430 or "badacey"
431 or "badeucey"
432 or "irish"
433 or "fusion"
434 ):
435 self.renderCards(painter, ["0", "0", "0", "0"], 1115, 400)
436 elif (
437 hand.gametype["category"] == "5_omahahi"
438 or "5_omaha8"
439 or "cour_hi"
440 or "cour_hilo"
441 or "27_1draw"
442 or "27_3draw"
443 or "a5_3draw"
444 or "a5_1draw"
445 or "drawmaha"
446 ):
447 self.renderCards(painter, ["0", "0", "0", "0", "0"], 1115, 400)
448 elif hand.gametype["category"] == "6_omahahi":
449 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 1115, 400)
450 elif hand.gametype["category"] == "holdem" or "6_holdem":
451 self.renderCards(painter, ["0", "0"], 1115, 400)
452 elif hand.gametype["category"] == "2_holdem":
453 self.renderCards(painter, ["0", "0", "0"], 1115, 400)
454 else:
455 self.renderCards(painter, player.holecards, 1115, 400)
457 # draw player's info
458 painter.drawText(
459 QRect(1070, 490, 200, 20),
460 Qt.AlignCenter,
461 "%s %s%.2f" % (player.name, self.currency, player.stack),
462 )
463 if player.justacted:
464 painter.setPen(QColor("yellow"))
465 # draw player's actions
466 painter.drawText(QRect(1070, 507, 200, 20), Qt.AlignCenter, player.action)
467 # draw bet pot
468 painter.drawText(
469 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
470 )
471 else:
472 painter.setPen(QColor("white"))
473 if player.chips != 0:
474 # draw player's bet
475 painter.drawText(
476 QRect(930, 490, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
477 )
478 elif player.name == list(state.players.values())[2].name:
479 if hand.get_player_position(player.name) == "S":
480 painter.drawImage(QPoint(450, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
481 print(list(state.players.values())[2])
482 # draw player bloc
483 painter.drawImage(QPoint(160, 490), self.playerBackdrop)
484 if player.action == "folds":
485 painter.setPen(QColor("red"))
486 else:
487 painter.setPen(QColor("white"))
488 # if check box hide cards and hero
490 if not self.showCards.isChecked():
491 # draw player's card
492 self.renderCards(painter, player.holecards, 185, 400)
493 elif self.showCards.isChecked():
494 if player.name == self.Heroes:
495 self.renderCards(painter, player.holecards, 185, 400)
496 else:
497 if (
498 hand.gametype["category"] == "omahahi"
499 or "omahahilo"
500 or "badugi"
501 or "badacey"
502 or "badeucey"
503 or "irish"
504 or "fusion"
505 ):
506 self.renderCards(painter, ["0", "0", "0", "0"], 185, 400)
507 elif (
508 hand.gametype["category"] == "5_omahahi"
509 or "5_omaha8"
510 or "cour_hi"
511 or "cour_hilo"
512 or "27_1draw"
513 or "27_3draw"
514 or "a5_3draw"
515 or "a5_1draw"
516 or "drawmaha"
517 ):
518 self.renderCards(painter, ["0", "0", "0", "0", "0"], 185, 400)
519 elif hand.gametype["category"] == "6_omahahi":
520 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 185, 400)
521 elif hand.gametype["category"] == "holdem" or "6_holdem":
522 self.renderCards(painter, ["0", "0"], 185, 400)
523 elif hand.gametype["category"] == "2_holdem":
524 self.renderCards(painter, ["0", "0", "0"], 185, 400)
525 else:
526 self.renderCards(painter, player.holecards, 185, 400)
528 # draw player's info
529 painter.drawText(
530 QRect(140, 490, 200, 20),
531 Qt.AlignCenter,
532 "%s %s%.2f" % (player.name, self.currency, player.stack),
533 )
534 if player.justacted:
535 painter.setPen(QColor("yellow"))
536 # draw player's actions
537 painter.drawText(QRect(140, 507, 200, 20), Qt.AlignCenter, player.action)
538 # draw bet pot
539 painter.drawText(
540 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
541 )
542 else:
543 painter.setPen(QColor("white"))
544 if player.chips != 0:
545 # draw player's bet
546 painter.drawText(
547 QRect(260, 490, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
548 )
549 else:
550 pass
551 i += 1
552 elif nb_player == 4:
553 print("nb player :", nb_player)
554 i = 0
555 for player in list(state.players.values()):
556 # print(player.holecards)
557 print(hand.gametype["category"])
558 if player.name == list(state.players.values())[0].name:
559 if hand.get_player_position(player.name) == "S":
560 painter.drawImage(QPoint(530, 650), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
561 print("round", i, "player", player.name)
562 # draw player bloc
563 painter.drawImage(QPoint(635, 790), self.playerBackdrop)
564 if player.action == "folds":
565 painter.setPen(QColor("red"))
566 else:
567 painter.setPen(QColor("white"))
568 # if check box hide cards and hero
570 if not self.showCards.isChecked():
571 # draw player's card
572 self.renderCards(painter, player.holecards, 660, 700)
573 elif self.showCards.isChecked():
574 if player.name == self.Heroes:
575 self.renderCards(painter, player.holecards, 660, 700)
576 else:
577 if (
578 hand.gametype["category"] == "omahahi"
579 or "omahahilo"
580 or "badugi"
581 or "badacey"
582 or "badeucey"
583 or "irish"
584 or "fusion"
585 ):
586 self.renderCards(painter, ["0", "0", "0", "0"], 660, 700)
587 elif (
588 hand.gametype["category"] == "5_omahahi"
589 or "5_omaha8"
590 or "cour_hi"
591 or "cour_hilo"
592 or "27_1draw"
593 or "27_3draw"
594 or "a5_3draw"
595 or "a5_1draw"
596 or "drawmaha"
597 ):
598 self.renderCards(painter, ["0", "0", "0", "0", "0"], 660, 700)
599 elif hand.gametype["category"] == "6_omahahi":
600 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 660, 700)
601 elif hand.gametype["category"] == "holdem" or "6_holdem":
602 self.renderCards(painter, ["0", "0"], 660, 700)
603 elif hand.gametype["category"] == "2_holdem":
604 self.renderCards(painter, ["0", "0", "0"], 660, 700)
605 else:
606 self.renderCards(painter, player.holecards, 660, 700)
607 # draw player's stack
608 painter.drawText(
609 QRect(605, 790, 200, 20),
610 Qt.AlignCenter,
611 "%s %s%.2f" % (player.name, self.currency, player.stack),
612 )
614 if player.justacted:
615 painter.setPen(QColor("yellow"))
616 # draw player's actions
617 painter.drawText(QRect(605, 807, 200, 20), Qt.AlignCenter, player.action)
618 # draw pot
619 painter.drawText(
620 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
621 )
622 else:
623 painter.setPen(QColor("white"))
624 if player.chips != 0:
625 # draw player's bet
626 painter.drawText(
627 QRect(605, 670, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
628 )
629 elif player.name == list(state.players.values())[1].name:
630 if hand.get_player_position(player.name) == "S":
631 painter.drawImage(QPoint(990, 570), self.dealer.scaled(40, 40, Qt.KeepAspectRatio)) # ok
632 print("round", i, "player", player.name)
633 # draw player bloc
634 painter.drawImage(QPoint(1090, 490), self.playerBackdrop)
635 if player.action == "folds":
636 painter.setPen(QColor("red"))
637 else:
638 painter.setPen(QColor("white"))
639 # if check box hide cards and hero
641 if not self.showCards.isChecked():
642 # draw player's card
643 self.renderCards(painter, player.holecards, 1115, 400)
644 elif self.showCards.isChecked():
645 if player.name == self.Heroes:
646 self.renderCards(painter, player.holecards, 1115, 400)
647 else:
648 if (
649 hand.gametype["category"] == "omahahi"
650 or "omahahilo"
651 or "badugi"
652 or "badacey"
653 or "badeucey"
654 or "irish"
655 or "fusion"
656 ):
657 self.renderCards(painter, ["0", "0", "0", "0"], 1115, 400)
658 elif (
659 hand.gametype["category"] == "5_omahahi"
660 or "5_omaha8"
661 or "cour_hi"
662 or "cour_hilo"
663 or "27_1draw"
664 or "27_3draw"
665 or "a5_3draw"
666 or "a5_1draw"
667 or "drawmaha"
668 ):
669 self.renderCards(painter, ["0", "0", "0", "0", "0"], 1115, 400)
670 elif hand.gametype["category"] == "6_omahahi":
671 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 1115, 400)
672 elif hand.gametype["category"] == "holdem" or "6_holdem":
673 self.renderCards(painter, ["0", "0"], 1115, 400)
674 elif hand.gametype["category"] == "2_holdem":
675 self.renderCards(painter, ["0", "0", "0"], 1115, 400)
676 else:
677 self.renderCards(painter, player.holecards, 1115, 400)
679 # draw player's info
680 painter.drawText(
681 QRect(1070, 490, 200, 20),
682 Qt.AlignCenter,
683 "%s %s%.2f" % (player.name, self.currency, player.stack),
684 )
685 if player.justacted:
686 painter.setPen(QColor("yellow"))
687 # draw player's actions
688 painter.drawText(QRect(1070, 507, 200, 20), Qt.AlignCenter, player.action)
689 # draw bet pot
690 painter.drawText(
691 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
692 )
693 else:
694 painter.setPen(QColor("white"))
695 if player.chips != 0:
696 # draw player's bet
697 painter.drawText(
698 QRect(930, 490, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
699 )
700 elif player.name == list(state.players.values())[2].name:
701 if hand.get_player_position(player.name) == "S":
702 painter.drawImage(QPoint(850, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
703 print(list(state.players.values())[2])
704 # draw player bloc
705 painter.drawImage(QPoint(635, 220), self.playerBackdrop) #
706 if player.action == "folds":
707 painter.setPen(QColor("red"))
708 else:
709 painter.setPen(QColor("white"))
710 # if check box hide cards and hero
712 if not self.showCards.isChecked():
713 # draw player's card
714 self.renderCards(painter, player.holecards, 655, 130) # ok
715 elif self.showCards.isChecked():
716 if player.name == self.Heroes:
717 self.renderCards(painter, player.holecards, 655, 130)
718 else:
719 if (
720 hand.gametype["category"] == "omahahi"
721 or "omahahilo"
722 or "badugi"
723 or "badacey"
724 or "badeucey"
725 or "irish"
726 or "fusion"
727 ):
728 self.renderCards(painter, ["0", "0", "0", "0"], 655, 130)
729 elif (
730 hand.gametype["category"] == "5_omahahi"
731 or "5_omaha8"
732 or "cour_hi"
733 or "cour_hilo"
734 or "27_1draw"
735 or "27_3draw"
736 or "a5_3draw"
737 or "a5_1draw"
738 or "drawmaha"
739 ):
740 self.renderCards(painter, ["0", "0", "0", "0", "0"], 655, 130)
741 elif hand.gametype["category"] == "6_omahahi":
742 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 655, 130)
743 elif hand.gametype["category"] == "holdem" or "6_holdem":
744 self.renderCards(painter, ["0", "0"], 655, 130)
745 elif hand.gametype["category"] == "2_holdem":
746 self.renderCards(painter, ["0", "0", "0"], 655, 130)
747 else:
748 self.renderCards(painter, player.holecards, 655, 130)
750 # draw player's info
751 painter.drawText(
752 QRect(605, 220, 200, 20),
753 Qt.AlignCenter,
754 "%s %s%.2f" % (player.name, self.currency, player.stack),
755 )
756 if player.justacted:
757 painter.setPen(QColor("yellow"))
758 # draw player's actions
759 painter.drawText(QRect(605, 237, 200, 20), Qt.AlignCenter, player.action)
760 # draw bet pot
761 painter.drawText(
762 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
763 )
764 else:
765 painter.setPen(QColor("white"))
766 if player.chips != 0:
767 # draw player's bet
768 painter.drawText(
769 QRect(605, 294, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
770 )
771 elif player.name == list(state.players.values())[3].name:
772 if hand.get_player_position(player.name) == "S":
773 painter.drawImage(QPoint(450, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
774 print(list(state.players.values())[2])
775 # draw player bloc
776 painter.drawImage(QPoint(160, 490), self.playerBackdrop)
777 if player.action == "folds":
778 painter.setPen(QColor("red"))
779 else:
780 painter.setPen(QColor("white"))
781 # if check box hide cards and hero
783 if not self.showCards.isChecked():
784 # draw player's card
785 self.renderCards(painter, player.holecards, 185, 400)
786 elif self.showCards.isChecked():
787 if player.name == self.Heroes:
788 self.renderCards(painter, player.holecards, 185, 400)
789 else:
790 if (
791 hand.gametype["category"] == "omahahi"
792 or "omahahilo"
793 or "badugi"
794 or "badacey"
795 or "badeucey"
796 or "irish"
797 or "fusion"
798 ):
799 self.renderCards(painter, ["0", "0", "0", "0"], 185, 400)
800 elif (
801 hand.gametype["category"] == "5_omahahi"
802 or "5_omaha8"
803 or "cour_hi"
804 or "cour_hilo"
805 or "27_1draw"
806 or "27_3draw"
807 or "a5_3draw"
808 or "a5_1draw"
809 or "drawmaha"
810 ):
811 self.renderCards(painter, ["0", "0", "0", "0", "0"], 185, 400)
812 elif hand.gametype["category"] == "6_omahahi":
813 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 185, 400)
814 elif hand.gametype["category"] == "holdem" or "6_holdem":
815 self.renderCards(painter, ["0", "0"], 185, 400)
816 elif hand.gametype["category"] == "2_holdem":
817 self.renderCards(painter, ["0", "0", "0"], 185, 400)
818 else:
819 self.renderCards(painter, player.holecards, 185, 400)
821 # draw player's info
822 painter.drawText(
823 QRect(140, 490, 200, 20),
824 Qt.AlignCenter,
825 "%s %s%.2f" % (player.name, self.currency, player.stack),
826 )
827 if player.justacted:
828 painter.setPen(QColor("yellow"))
829 # draw player's actions
830 painter.drawText(QRect(140, 507, 200, 20), Qt.AlignCenter, player.action)
831 # draw bet pot
832 painter.drawText(
833 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
834 )
835 else:
836 painter.setPen(QColor("white"))
837 if player.chips != 0:
838 # draw player's bet
839 painter.drawText(
840 QRect(260, 490, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
841 )
842 else:
843 pass
844 i += 1
845 elif nb_player == 5:
846 print("nb player :", nb_player)
847 i = 0
848 for player in list(state.players.values()):
849 # print(player.holecards)
850 print(hand.gametype["category"])
851 if player.name == list(state.players.values())[0].name:
852 if hand.get_player_position(player.name) == "S":
853 painter.drawImage(QPoint(530, 650), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
854 print("round", i, "player", player.name)
855 # draw player bloc
856 painter.drawImage(QPoint(635, 790), self.playerBackdrop)
857 if player.action == "folds":
858 painter.setPen(QColor("red"))
859 else:
860 painter.setPen(QColor("white"))
861 # if check box hide cards and hero
863 if not self.showCards.isChecked():
864 # draw player's card
865 self.renderCards(painter, player.holecards, 660, 700)
866 elif self.showCards.isChecked():
867 if player.name == self.Heroes:
868 self.renderCards(painter, player.holecards, 660, 700)
869 else:
870 if (
871 hand.gametype["category"] == "omahahi"
872 or "omahahilo"
873 or "badugi"
874 or "badacey"
875 or "badeucey"
876 or "irish"
877 or "fusion"
878 ):
879 self.renderCards(painter, ["0", "0", "0", "0"], 660, 700)
880 elif (
881 hand.gametype["category"] == "5_omahahi"
882 or "5_omaha8"
883 or "cour_hi"
884 or "cour_hilo"
885 or "27_1draw"
886 or "27_3draw"
887 or "a5_3draw"
888 or "a5_1draw"
889 or "drawmaha"
890 ):
891 self.renderCards(painter, ["0", "0", "0", "0", "0"], 660, 700)
892 elif hand.gametype["category"] == "6_omahahi":
893 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 660, 700)
894 elif hand.gametype["category"] == "holdem" or "6_holdem":
895 self.renderCards(painter, ["0", "0"], 660, 700)
896 elif hand.gametype["category"] == "2_holdem":
897 self.renderCards(painter, ["0", "0", "0"], 660, 700)
898 else:
899 self.renderCards(painter, player.holecards, 660, 700)
900 # draw player's stack
901 painter.drawText(
902 QRect(605, 790, 200, 20),
903 Qt.AlignCenter,
904 "%s %s%.2f" % (player.name, self.currency, player.stack),
905 )
907 if player.justacted:
908 painter.setPen(QColor("yellow"))
909 # draw player's actions
910 painter.drawText(QRect(605, 807, 200, 20), Qt.AlignCenter, player.action)
911 # draw pot
912 painter.drawText(
913 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
914 )
915 else:
916 painter.setPen(QColor("white"))
917 if player.chips != 0:
918 # draw player's bet
919 painter.drawText(
920 QRect(605, 670, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
921 )
922 elif player.name == list(state.players.values())[1].name:
923 if hand.get_player_position(player.name) == "S":
924 painter.drawImage(QPoint(990, 570), self.dealer.scaled(40, 40, Qt.KeepAspectRatio)) # ok
925 print("round", i, "player", player.name)
926 # draw player bloc
927 painter.drawImage(QPoint(1090, 490), self.playerBackdrop)
928 if player.action == "folds":
929 painter.setPen(QColor("red"))
930 else:
931 painter.setPen(QColor("white"))
932 # if check box hide cards and hero
934 if not self.showCards.isChecked():
935 # draw player's card
936 self.renderCards(painter, player.holecards, 1115, 400)
937 elif self.showCards.isChecked():
938 if player.name == self.Heroes:
939 self.renderCards(painter, player.holecards, 1115, 400)
940 else:
941 if (
942 hand.gametype["category"] == "omahahi"
943 or "omahahilo"
944 or "badugi"
945 or "badacey"
946 or "badeucey"
947 or "irish"
948 or "fusion"
949 ):
950 self.renderCards(painter, ["0", "0", "0", "0"], 1115, 400)
951 elif (
952 hand.gametype["category"] == "5_omahahi"
953 or "5_omaha8"
954 or "cour_hi"
955 or "cour_hilo"
956 or "27_1draw"
957 or "27_3draw"
958 or "a5_3draw"
959 or "a5_1draw"
960 or "drawmaha"
961 ):
962 self.renderCards(painter, ["0", "0", "0", "0", "0"], 1115, 400)
963 elif hand.gametype["category"] == "6_omahahi":
964 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 1115, 400)
965 elif hand.gametype["category"] == "holdem" or "6_holdem":
966 self.renderCards(painter, ["0", "0"], 1115, 400)
967 elif hand.gametype["category"] == "2_holdem":
968 self.renderCards(painter, ["0", "0", "0"], 1115, 400)
969 else:
970 self.renderCards(painter, player.holecards, 1115, 400)
972 # draw player's info
973 painter.drawText(
974 QRect(1070, 490, 200, 20),
975 Qt.AlignCenter,
976 "%s %s%.2f" % (player.name, self.currency, player.stack),
977 )
978 if player.justacted:
979 painter.setPen(QColor("yellow"))
980 # draw player's actions
981 painter.drawText(QRect(1070, 507, 200, 20), Qt.AlignCenter, player.action)
982 # draw bet pot
983 painter.drawText(
984 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
985 )
986 else:
987 painter.setPen(QColor("white"))
988 if player.chips != 0:
989 # draw player's bet
990 painter.drawText(
991 QRect(930, 490, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
992 )
993 elif player.name == list(state.players.values())[3].name:
994 if hand.get_player_position(player.name) == "S":
995 painter.drawImage(QPoint(660, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
996 print(list(state.players.values())[2])
997 # draw player bloc
998 painter.drawImage(QPoint(500, 220), self.playerBackdrop) # ok
999 if player.action == "folds":
1000 painter.setPen(QColor("red"))
1001 else:
1002 painter.setPen(QColor("white"))
1003 # if check box hide cards and hero
1005 if not self.showCards.isChecked():
1006 # draw player's card
1007 self.renderCards(painter, player.holecards, 520, 130) # ok
1008 elif self.showCards.isChecked():
1009 if player.name == self.Heroes:
1010 self.renderCards(painter, player.holecards, 520, 130)
1011 else:
1012 if (
1013 hand.gametype["category"] == "omahahi"
1014 or "omahahilo"
1015 or "badugi"
1016 or "badacey"
1017 or "badeucey"
1018 or "irish"
1019 or "fusion"
1020 ):
1021 self.renderCards(painter, ["0", "0", "0", "0"], 520, 130)
1022 elif (
1023 hand.gametype["category"] == "5_omahahi"
1024 or "5_omaha8"
1025 or "cour_hi"
1026 or "cour_hilo"
1027 or "27_1draw"
1028 or "27_3draw"
1029 or "a5_3draw"
1030 or "a5_1draw"
1031 or "drawmaha"
1032 ):
1033 self.renderCards(painter, ["0", "0", "0", "0", "0"], 520, 130)
1034 elif hand.gametype["category"] == "6_omahahi":
1035 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 520, 130)
1036 elif hand.gametype["category"] == "holdem" or "6_holdem":
1037 self.renderCards(painter, ["0", "0"], 520, 130)
1038 elif hand.gametype["category"] == "2_holdem":
1039 self.renderCards(painter, ["0", "0", "0"], 520, 130)
1040 else:
1041 self.renderCards(painter, player.holecards, 520, 130)
1043 # draw player's info
1044 painter.drawText(
1045 QRect(480, 220, 200, 20),
1046 Qt.AlignCenter,
1047 "%s %s%.2f" % (player.name, self.currency, player.stack),
1048 )
1049 if player.justacted:
1050 painter.setPen(QColor("yellow"))
1051 # draw player's actions
1052 painter.drawText(QRect(480, 237, 200, 20), Qt.AlignCenter, player.action)
1053 # draw bet pot
1054 painter.drawText(
1055 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
1056 )
1057 else:
1058 painter.setPen(QColor("white"))
1059 if player.chips != 0:
1060 # draw player's bet
1061 painter.drawText(
1062 QRect(500, 294, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
1063 )
1064 elif player.name == list(state.players.values())[2].name:
1065 if hand.get_player_position(player.name) == "S":
1066 painter.drawImage(QPoint(950, 350), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1067 print(list(state.players.values())[2])
1068 # draw player bloc
1069 painter.drawImage(QPoint(750, 220), self.playerBackdrop) # ok
1070 if player.action == "folds":
1071 painter.setPen(QColor("red"))
1072 else:
1073 painter.setPen(QColor("white"))
1074 # if check box hide cards and hero
1076 if not self.showCards.isChecked():
1077 # draw player's card
1078 self.renderCards(painter, player.holecards, 770, 130) # ok
1079 elif self.showCards.isChecked():
1080 if player.name == self.Heroes:
1081 self.renderCards(painter, player.holecards, 770, 130)
1082 else:
1083 if (
1084 hand.gametype["category"] == "omahahi"
1085 or "omahahilo"
1086 or "badugi"
1087 or "badacey"
1088 or "badeucey"
1089 or "irish"
1090 or "fusion"
1091 ):
1092 self.renderCards(painter, ["0", "0", "0", "0"], 770, 130)
1093 elif (
1094 hand.gametype["category"] == "5_omahahi"
1095 or "5_omaha8"
1096 or "cour_hi"
1097 or "cour_hilo"
1098 or "27_1draw"
1099 or "27_3draw"
1100 or "a5_3draw"
1101 or "a5_1draw"
1102 or "drawmaha"
1103 ):
1104 self.renderCards(painter, ["0", "0", "0", "0", "0"], 770, 130)
1105 elif hand.gametype["category"] == "6_omahahi":
1106 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 770, 130)
1107 elif hand.gametype["category"] == "holdem" or "6_holdem":
1108 self.renderCards(painter, ["0", "0"], 770, 130)
1109 elif hand.gametype["category"] == "2_holdem":
1110 self.renderCards(painter, ["0", "0", "0"], 770, 130)
1111 else:
1112 self.renderCards(painter, player.holecards, 770, 130)
1114 # draw player's info
1115 painter.drawText(
1116 QRect(730, 220, 200, 20),
1117 Qt.AlignCenter,
1118 "%s %s%.2f" % (player.name, self.currency, player.stack),
1119 )
1120 if player.justacted:
1121 painter.setPen(QColor("yellow"))
1122 # draw player's actions
1123 painter.drawText(QRect(730, 237, 200, 20), Qt.AlignCenter, player.action)
1124 # draw bet pot
1125 painter.drawText(
1126 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
1127 )
1128 else:
1129 painter.setPen(QColor("white"))
1130 if player.chips != 0:
1131 # draw player's bet
1132 painter.drawText(
1133 QRect(730, 294, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
1134 )
1135 elif player.name == list(state.players.values())[4].name:
1136 if hand.get_player_position(player.name) == "S":
1137 painter.drawImage(QPoint(450, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1138 print(list(state.players.values())[2])
1139 # draw player bloc
1140 painter.drawImage(QPoint(160, 490), self.playerBackdrop)
1141 if player.action == "folds":
1142 painter.setPen(QColor("red"))
1143 else:
1144 painter.setPen(QColor("white"))
1145 # if check box hide cards and hero
1147 if not self.showCards.isChecked():
1148 # draw player's card
1149 self.renderCards(painter, player.holecards, 185, 400)
1150 elif self.showCards.isChecked():
1151 if player.name == self.Heroes:
1152 self.renderCards(painter, player.holecards, 185, 400)
1153 else:
1154 if (
1155 hand.gametype["category"] == "omahahi"
1156 or "omahahilo"
1157 or "badugi"
1158 or "badacey"
1159 or "badeucey"
1160 or "irish"
1161 or "fusion"
1162 ):
1163 self.renderCards(painter, ["0", "0", "0", "0"], 185, 400)
1164 elif (
1165 hand.gametype["category"] == "5_omahahi"
1166 or "5_omaha8"
1167 or "cour_hi"
1168 or "cour_hilo"
1169 or "27_1draw"
1170 or "27_3draw"
1171 or "a5_3draw"
1172 or "a5_1draw"
1173 or "drawmaha"
1174 ):
1175 self.renderCards(painter, ["0", "0", "0", "0", "0"], 185, 400)
1176 elif hand.gametype["category"] == "6_omahahi":
1177 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 185, 400)
1178 elif hand.gametype["category"] == "holdem" or "6_holdem":
1179 self.renderCards(painter, ["0", "0"], 185, 400)
1180 elif hand.gametype["category"] == "2_holdem":
1181 self.renderCards(painter, ["0", "0", "0"], 185, 400)
1182 else:
1183 self.renderCards(painter, player.holecards, 185, 400)
1185 # draw player's info
1186 painter.drawText(
1187 QRect(140, 490, 200, 20),
1188 Qt.AlignCenter,
1189 "%s %s%.2f" % (player.name, self.currency, player.stack),
1190 )
1191 if player.justacted:
1192 painter.setPen(QColor("yellow"))
1193 # draw player's actions
1194 painter.drawText(QRect(140, 507, 200, 20), Qt.AlignCenter, player.action)
1195 # draw bet pot
1196 painter.drawText(
1197 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
1198 )
1199 else:
1200 painter.setPen(QColor("white"))
1201 if player.chips != 0:
1202 # draw player's bet
1203 painter.drawText(
1204 QRect(260, 490, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
1205 )
1206 else:
1207 pass
1208 i += 1
1209 elif nb_player == 6:
1210 print("nb player :", nb_player)
1211 i = 0
1212 for player in list(state.players.values()):
1213 # print(player.holecards)
1214 print(hand.gametype["category"])
1215 if player.name == list(state.players.values())[0].name:
1216 if hand.get_player_position(player.name) == "S":
1217 painter.drawImage(QPoint(650, 650), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1218 print("round", i, "player", player.name)
1219 # draw player bloc
1220 painter.drawImage(QPoint(750, 790), self.playerBackdrop)
1221 if player.action == "folds":
1222 painter.setPen(QColor("red"))
1223 else:
1224 painter.setPen(QColor("white"))
1225 # if check box hide cards and hero
1227 if not self.showCards.isChecked():
1228 # draw player's card
1229 self.renderCards(painter, player.holecards, 770, 700)
1230 elif self.showCards.isChecked():
1231 if player.name == self.Heroes:
1232 self.renderCards(painter, player.holecards, 770, 700)
1233 else:
1234 if (
1235 hand.gametype["category"] == "omahahi"
1236 or "omahahilo"
1237 or "badugi"
1238 or "badacey"
1239 or "badeucey"
1240 or "irish"
1241 or "fusion"
1242 ):
1243 self.renderCards(painter, ["0", "0", "0", "0"], 770, 700)
1244 elif (
1245 hand.gametype["category"] == "5_omahahi"
1246 or "5_omaha8"
1247 or "cour_hi"
1248 or "cour_hilo"
1249 or "27_1draw"
1250 or "27_3draw"
1251 or "a5_3draw"
1252 or "a5_1draw"
1253 or "drawmaha"
1254 ):
1255 self.renderCards(painter, ["0", "0", "0", "0", "0"], 770, 700)
1256 elif hand.gametype["category"] == "6_omahahi":
1257 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 770, 700)
1258 elif hand.gametype["category"] == "holdem" or "6_holdem":
1259 self.renderCards(painter, ["0", "0"], 770, 700)
1260 elif hand.gametype["category"] == "2_holdem":
1261 self.renderCards(painter, ["0", "0", "0"], 770, 700)
1262 else:
1263 self.renderCards(painter, player.holecards, 770, 700)
1264 # draw player's stack
1265 painter.drawText(
1266 QRect(730, 790, 200, 20),
1267 Qt.AlignCenter,
1268 "%s %s%.2f" % (player.name, self.currency, player.stack),
1269 )
1271 if player.justacted:
1272 painter.setPen(QColor("yellow"))
1273 # draw player's actions
1274 painter.drawText(QRect(730, 807, 200, 20), Qt.AlignCenter, player.action)
1275 # draw pot
1277 painter.drawText(
1278 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
1279 )
1280 else:
1281 painter.setPen(QColor("white"))
1282 if player.chips != 0:
1283 # draw player's bet
1284 painter.drawText(
1285 QRect(730, 670, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
1286 )
1287 elif player.name == list(state.players.values())[1].name:
1288 if hand.get_player_position(player.name) == "S":
1289 painter.drawImage(QPoint(990, 570), self.dealer.scaled(40, 40, Qt.KeepAspectRatio)) # ok
1290 print("round", i, "player", player.name)
1291 # draw player bloc
1292 painter.drawImage(QPoint(1090, 490), self.playerBackdrop)
1293 if player.action == "folds":
1294 painter.setPen(QColor("red"))
1295 else:
1296 painter.setPen(QColor("white"))
1297 # if check box hide cards and hero
1299 if not self.showCards.isChecked():
1300 # draw player's card
1301 self.renderCards(painter, player.holecards, 1115, 400)
1302 elif self.showCards.isChecked():
1303 if player.name == self.Heroes:
1304 self.renderCards(painter, player.holecards, 1115, 400)
1305 else:
1306 if (
1307 hand.gametype["category"] == "omahahi"
1308 or "omahahilo"
1309 or "badugi"
1310 or "badacey"
1311 or "badeucey"
1312 or "irish"
1313 or "fusion"
1314 ):
1315 self.renderCards(painter, ["0", "0", "0", "0"], 1115, 400)
1316 elif (
1317 hand.gametype["category"] == "5_omahahi"
1318 or "5_omaha8"
1319 or "cour_hi"
1320 or "cour_hilo"
1321 or "27_1draw"
1322 or "27_3draw"
1323 or "a5_3draw"
1324 or "a5_1draw"
1325 or "drawmaha"
1326 ):
1327 self.renderCards(painter, ["0", "0", "0", "0", "0"], 1115, 400)
1328 elif hand.gametype["category"] == "6_omahahi":
1329 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 1115, 400)
1330 elif hand.gametype["category"] == "holdem" or "6_holdem":
1331 self.renderCards(painter, ["0", "0"], 1115, 400)
1332 elif hand.gametype["category"] == "2_holdem":
1333 self.renderCards(painter, ["0", "0", "0"], 1115, 400)
1334 else:
1335 self.renderCards(painter, player.holecards, 1115, 400)
1337 # draw player's info
1338 painter.drawText(
1339 QRect(1070, 490, 200, 20),
1340 Qt.AlignCenter,
1341 "%s %s%.2f" % (player.name, self.currency, player.stack),
1342 )
1343 if player.justacted:
1344 painter.setPen(QColor("yellow"))
1345 # draw player's actions
1346 painter.drawText(QRect(1070, 507, 200, 20), Qt.AlignCenter, player.action)
1347 # draw bet pot
1349 painter.drawText(
1350 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
1351 )
1352 else:
1353 painter.setPen(QColor("white"))
1354 if player.chips != 0:
1355 # draw player's bet
1356 painter.drawText(
1357 QRect(930, 490, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
1358 )
1359 elif player.name == list(state.players.values())[3].name:
1360 if hand.get_player_position(player.name) == "S":
1361 painter.drawImage(QPoint(660, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1362 print("round", i, "player", player.name)
1363 print(list(state.players.values())[2])
1364 # draw player bloc
1365 painter.drawImage(QPoint(500, 220), self.playerBackdrop) # ok
1366 if player.action == "folds":
1367 painter.setPen(QColor("red"))
1368 else:
1369 painter.setPen(QColor("white"))
1370 # if check box hide cards and hero
1372 if not self.showCards.isChecked():
1373 # draw player's card
1374 self.renderCards(painter, player.holecards, 520, 130) # ok
1375 elif self.showCards.isChecked():
1376 if player.name == self.Heroes:
1377 self.renderCards(painter, player.holecards, 520, 130)
1378 else:
1379 if (
1380 hand.gametype["category"] == "omahahi"
1381 or "omahahilo"
1382 or "badugi"
1383 or "badacey"
1384 or "badeucey"
1385 or "irish"
1386 or "fusion"
1387 ):
1388 self.renderCards(painter, ["0", "0", "0", "0"], 520, 130)
1389 elif (
1390 hand.gametype["category"] == "5_omahahi"
1391 or "5_omaha8"
1392 or "cour_hi"
1393 or "cour_hilo"
1394 or "27_1draw"
1395 or "27_3draw"
1396 or "a5_3draw"
1397 or "a5_1draw"
1398 or "drawmaha"
1399 ):
1400 self.renderCards(painter, ["0", "0", "0", "0", "0"], 520, 130)
1401 elif hand.gametype["category"] == "6_omahahi":
1402 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 520, 130)
1403 elif hand.gametype["category"] == "holdem" or "6_holdem":
1404 self.renderCards(painter, ["0", "0"], 520, 130)
1405 elif hand.gametype["category"] == "2_holdem":
1406 self.renderCards(painter, ["0", "0", "0"], 520, 130)
1407 else:
1408 self.renderCards(painter, player.holecards, 520, 130)
1410 # draw player's info
1411 painter.drawText(
1412 QRect(480, 220, 200, 20),
1413 Qt.AlignCenter,
1414 "%s %s%.2f" % (player.name, self.currency, player.stack),
1415 )
1416 if player.justacted:
1417 painter.setPen(QColor("yellow"))
1418 # draw player's actions
1419 painter.drawText(QRect(480, 237, 200, 20), Qt.AlignCenter, player.action)
1420 # draw bet pot
1421 painter.drawText(
1422 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
1423 )
1424 else:
1425 painter.setPen(QColor("white"))
1426 if player.chips != 0:
1427 # draw player's bet
1428 painter.drawText(
1429 QRect(500, 294, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
1430 )
1431 elif player.name == list(state.players.values())[2].name:
1432 if hand.get_player_position(player.name) == "S":
1433 painter.drawImage(QPoint(950, 350), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1434 print("round", i, "player", player.name)
1435 print(list(state.players.values())[2])
1436 # draw player bloc
1437 painter.drawImage(QPoint(750, 220), self.playerBackdrop) # ok
1438 if player.action == "folds":
1439 painter.setPen(QColor("red"))
1440 else:
1441 painter.setPen(QColor("white"))
1442 # if check box hide cards and hero
1444 if not self.showCards.isChecked():
1445 # draw player's card
1446 self.renderCards(painter, player.holecards, 770, 130) # ok
1447 elif self.showCards.isChecked():
1448 if player.name == self.Heroes:
1449 self.renderCards(painter, player.holecards, 770, 130)
1450 else:
1451 if (
1452 hand.gametype["category"] == "omahahi"
1453 or "omahahilo"
1454 or "badugi"
1455 or "badacey"
1456 or "badeucey"
1457 or "irish"
1458 or "fusion"
1459 ):
1460 self.renderCards(painter, ["0", "0", "0", "0"], 770, 130)
1461 elif (
1462 hand.gametype["category"] == "5_omahahi"
1463 or "5_omaha8"
1464 or "cour_hi"
1465 or "cour_hilo"
1466 or "27_1draw"
1467 or "27_3draw"
1468 or "a5_3draw"
1469 or "a5_1draw"
1470 or "drawmaha"
1471 ):
1472 self.renderCards(painter, ["0", "0", "0", "0", "0"], 770, 130)
1473 elif hand.gametype["category"] == "6_omahahi":
1474 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 770, 130)
1475 elif hand.gametype["category"] == "holdem" or "6_holdem":
1476 self.renderCards(painter, ["0", "0"], 770, 130)
1477 elif hand.gametype["category"] == "2_holdem":
1478 self.renderCards(painter, ["0", "0", "0"], 770, 130)
1479 else:
1480 self.renderCards(painter, player.holecards, 770, 130)
1482 # draw player's info
1483 painter.drawText(
1484 QRect(730, 220, 200, 20),
1485 Qt.AlignCenter,
1486 "%s %s%.2f" % (player.name, self.currency, player.stack),
1487 )
1488 if player.justacted:
1489 painter.setPen(QColor("yellow"))
1490 # draw player's actions
1491 painter.drawText(QRect(730, 237, 200, 20), Qt.AlignCenter, player.action)
1492 # draw bet pot
1493 painter.drawText(
1494 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
1495 )
1496 else:
1497 painter.setPen(QColor("white"))
1498 if player.chips != 0:
1499 # draw player's bet
1500 painter.drawText(
1501 QRect(730, 294, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
1502 )
1503 elif player.name == list(state.players.values())[4].name:
1504 if hand.get_player_position(player.name) == "S":
1505 painter.drawImage(QPoint(450, 320), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1506 print("round", i, "player", player.name)
1507 print(list(state.players.values())[2])
1508 # draw player bloc
1509 painter.drawImage(QPoint(160, 490), self.playerBackdrop)
1510 if player.action == "folds":
1511 painter.setPen(QColor("red"))
1512 else:
1513 painter.setPen(QColor("white"))
1514 # if check box hide cards and hero
1516 if not self.showCards.isChecked():
1517 # draw player's card
1518 self.renderCards(painter, player.holecards, 185, 400)
1519 elif self.showCards.isChecked():
1520 if player.name == self.Heroes:
1521 self.renderCards(painter, player.holecards, 185, 400)
1522 else:
1523 if (
1524 hand.gametype["category"] == "omahahi"
1525 or "omahahilo"
1526 or "badugi"
1527 or "badacey"
1528 or "badeucey"
1529 or "irish"
1530 or "fusion"
1531 ):
1532 self.renderCards(painter, ["0", "0", "0", "0"], 185, 400)
1533 elif (
1534 hand.gametype["category"] == "5_omahahi"
1535 or "5_omaha8"
1536 or "cour_hi"
1537 or "cour_hilo"
1538 or "27_1draw"
1539 or "27_3draw"
1540 or "a5_3draw"
1541 or "a5_1draw"
1542 or "drawmaha"
1543 ):
1544 self.renderCards(painter, ["0", "0", "0", "0", "0"], 185, 400)
1545 elif hand.gametype["category"] == "6_omahahi":
1546 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 185, 400)
1547 elif hand.gametype["category"] == "holdem" or "6_holdem":
1548 self.renderCards(painter, ["0", "0"], 185, 400)
1549 elif hand.gametype["category"] == "2_holdem":
1550 self.renderCards(painter, ["0", "0", "0"], 185, 400)
1551 else:
1552 self.renderCards(painter, player.holecards, 185, 400)
1554 # draw player's info
1555 painter.drawText(
1556 QRect(140, 490, 200, 20),
1557 Qt.AlignCenter,
1558 "%s %s%.2f" % (player.name, self.currency, player.stack),
1559 )
1560 if player.justacted:
1561 painter.setPen(QColor("yellow"))
1562 # draw player's actions
1563 painter.drawText(QRect(140, 507, 200, 20), Qt.AlignCenter, player.action)
1564 # draw bet pot
1565 painter.drawText(
1566 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
1567 )
1568 else:
1569 painter.setPen(QColor("white"))
1570 if player.chips != 0:
1571 # draw player's bet
1572 painter.drawText(
1573 QRect(260, 490, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
1574 )
1575 elif player.name == list(state.players.values())[5].name:
1576 if hand.get_player_position(player.name) == "S":
1577 painter.drawImage(QPoint(450, 620), self.dealer.scaled(40, 40, Qt.KeepAspectRatio))
1578 print("round", i, "player", player.name)
1579 print(list(state.players.values())[2])
1580 # draw player bloc
1581 painter.drawImage(QPoint(500, 790), self.playerBackdrop)
1582 if player.action == "folds":
1583 painter.setPen(QColor("red"))
1584 else:
1585 painter.setPen(QColor("white"))
1586 # if check box hide cards and hero
1588 if not self.showCards.isChecked():
1589 # draw player's card
1590 self.renderCards(painter, player.holecards, 520, 700)
1591 elif self.showCards.isChecked():
1592 if player.name == self.Heroes:
1593 self.renderCards(painter, player.holecards, 520, 700)
1594 else:
1595 if (
1596 hand.gametype["category"] == "omahahi"
1597 or "omahahilo"
1598 or "badugi"
1599 or "badacey"
1600 or "badeucey"
1601 or "irish"
1602 or "fusion"
1603 ):
1604 self.renderCards(painter, ["0", "0", "0", "0"], 520, 700)
1605 elif (
1606 hand.gametype["category"] == "5_omahahi"
1607 or "5_omaha8"
1608 or "cour_hi"
1609 or "cour_hilo"
1610 or "27_1draw"
1611 or "27_3draw"
1612 or "a5_3draw"
1613 or "a5_1draw"
1614 or "drawmaha"
1615 ):
1616 self.renderCards(painter, ["0", "0", "0", "0", "0"], 520, 700)
1617 elif hand.gametype["category"] == "6_omahahi":
1618 self.renderCards(painter, ["0", "0", "0", "0", "0", "0"], 520, 700)
1619 elif hand.gametype["category"] == "holdem" or "6_holdem":
1620 self.renderCards(painter, ["0", "0"], 520, 700)
1621 elif hand.gametype["category"] == "2_holdem":
1622 self.renderCards(painter, ["0", "0", "0"], 520, 700)
1623 else:
1624 self.renderCards(painter, player.holecards, 520, 700)
1626 # draw player's info
1627 painter.drawText(
1628 QRect(480, 790, 200, 20),
1629 Qt.AlignCenter,
1630 "%s %s%.2f" % (player.name, self.currency, player.stack),
1631 )
1632 if player.justacted:
1633 painter.setPen(QColor("yellow"))
1634 # draw player's actions
1635 painter.drawText(QRect(480, 807, 200, 20), Qt.AlignCenter, player.action)
1636 # draw bet pot
1637 painter.drawText(
1638 QRect(380, 480, 200, 40), Qt.AlignCenter, "Pot: %s%.2f" % (self.currency, state.newpot)
1639 )
1640 else:
1641 painter.setPen(QColor("white"))
1642 if player.chips != 0:
1643 # draw player's bet
1644 painter.drawText(
1645 QRect(480, 670, 200, 20), Qt.AlignCenter, "%s%.2f" % (self.currency, player.chips)
1646 )
1648 else:
1649 pass
1650 i += 1
1651 elif nb_player == 7:
1652 print("nb player :", nb_player)
1653 elif nb_player == 8:
1654 print("nb player :", nb_player)
1655 elif nb_player == 9:
1656 print("nb player :", nb_player)
1657 elif nb_player == 10:
1658 print("nb player :", nb_player)
1660 painter.setPen(QColor("white"))
1662 for street in state.renderBoard:
1663 x = 520
1664 y = 400
1665 print("street", street, "value street", state.board[street])
1666 if street == "FLOP" and state.board[street] != []:
1667 self.renderboardCards(painter, state.board[street], x, y)
1668 elif street == "FLOP1" and state.board[street] != []:
1669 y -= int(self.cardheight / 2)
1670 self.renderboardCards(painter, state.board[street], x, y)
1671 elif street == "FLOP2" and state.board[street] != []:
1672 y += int(self.cardheight / 2)
1673 self.renderboardCards(painter, state.board[street], x, y)
1674 elif street == "FLOP3" and state.board[street] != []:
1675 y += self.cardheight + int(self.cardheight / 2)
1676 self.renderboardCards(painter, state.board[street], x, y)
1677 elif street == "TURN" and state.board[street] != []:
1678 x += 3 * self.cardwidth
1679 self.renderboardCards(painter, state.board[street], x, y)
1680 elif street == "TURN1" and state.board[street] != []:
1681 x += 3 * self.cardwidth
1682 y -= int(self.cardheight / 2)
1683 self.renderboardCards(painter, state.board[street], x, y)
1684 elif street == "TURN2" and state.board[street] != []:
1685 x += 3 * self.cardwidth
1686 y += int(self.cardheight / 2)
1687 self.renderboardCards(painter, state.board[street], x, y)
1688 elif street == "TURN3" and state.board[street] != []:
1689 x += 3 * self.cardwidth
1690 y += self.cardheight + int(self.cardheight / 2)
1691 self.renderboardCards(painter, state.board[street], x, y)
1692 elif street == "RIVER" and state.board[street] != []:
1693 x += 4 * self.cardwidth
1694 self.renderboardCards(painter, state.board[street], x, y)
1695 elif street == "RIVER1" and state.board[street] != []:
1696 x += 4 * self.cardwidth
1697 y -= int(self.cardheight / 2)
1698 self.renderboardCards(painter, state.board[street], x, y)
1699 elif street == "RIVER2" and state.board[street] != []:
1700 x += 4 * self.cardwidth
1701 y += int(self.cardheight / 2)
1702 self.renderboardCards(painter, state.board[street], x, y)
1703 elif street == "RIVER3" and state.board[street] != []:
1704 x += 4 * self.cardwidth
1705 y += self.cardheight + int(self.cardheight / 2)
1706 self.renderboardCards(painter, state.board[street], x, y)
1707 else:
1708 pass
1710 if self.stateSlider.value() == self.stateSlider.maximum():
1711 if nb_player == 2:
1712 # set 2 player
1713 print("nb player :", nb_player)
1714 i = 0
1715 for player in list(state.players.values()):
1716 # print(player.holecards)
1717 print(hand.gametype["category"])
1718 if player.name == list(state.players.values())[0].name:
1719 self.renderCards(painter, player.holecards, 660, 700)
1720 elif player.name == list(state.players.values())[1].name:
1721 self.renderCards(painter, player.holecards, 1115, 400)
1722 else:
1723 pass
1724 i += 1
1725 elif nb_player == 3:
1726 print("nb player :", nb_player)
1727 i = 0
1728 for player in list(state.players.values()):
1729 # print(player.holecards)
1730 print(hand.gametype["category"])
1731 if player.name == list(state.players.values())[0].name:
1732 self.renderCards(painter, player.holecards, 660, 700)
1733 elif player.name == list(state.players.values())[1].name:
1734 self.renderCards(painter, player.holecards, 1115, 400)
1735 elif player.name == list(state.players.values())[2].name:
1736 self.renderCards(painter, player.holecards, 185, 400)
1737 else:
1738 pass
1739 i += 1
1740 elif nb_player == 4:
1741 print("nb player :", nb_player)
1742 i = 0
1743 for player in list(state.players.values()):
1744 # print(player.holecards)
1745 print(hand.gametype["category"])
1746 if player.name == list(state.players.values())[0].name:
1747 self.renderCards(painter, player.holecards, 660, 700)
1748 elif player.name == list(state.players.values())[1].name:
1749 self.renderCards(painter, player.holecards, 1115, 400)
1750 elif player.name == list(state.players.values())[2].name:
1751 self.renderCards(painter, player.holecards, 655, 130)
1752 elif player.name == list(state.players.values())[3].name:
1753 self.renderCards(painter, player.holecards, 185, 400)
1754 else:
1755 pass
1756 i += 1
1757 elif nb_player == 5:
1758 print("nb player :", nb_player)
1759 i = 0
1760 for player in list(state.players.values()):
1761 # print(player.holecards)
1762 print(hand.gametype["category"])
1763 if player.name == list(state.players.values())[0].name:
1764 self.renderCards(painter, player.holecards, 660, 700)
1765 elif player.name == list(state.players.values())[1].name:
1766 self.renderCards(painter, player.holecards, 1115, 400)
1767 elif player.name == list(state.players.values())[2].name:
1768 self.renderCards(painter, player.holecards, 770, 130)
1769 elif player.name == list(state.players.values())[3].name:
1770 self.renderCards(painter, player.holecards, 520, 130)
1771 elif player.name == list(state.players.values())[4].name:
1772 self.renderCards(painter, player.holecards, 185, 400)
1773 else:
1774 pass
1775 i += 1
1776 elif nb_player == 6:
1777 print("nb player :", nb_player)
1778 i = 0
1779 for player in list(state.players.values()):
1780 # print(player.holecards)
1781 print(hand.gametype["category"])
1782 if player.name == list(state.players.values())[0].name:
1783 self.renderCards(painter, player.holecards, 770, 700)
1784 elif player.name == list(state.players.values())[1].name:
1785 self.renderCards(painter, player.holecards, 1115, 400)
1786 elif player.name == list(state.players.values())[2].name:
1787 self.renderCards(painter, player.holecards, 770, 130)
1788 elif player.name == list(state.players.values())[3].name:
1789 self.renderCards(painter, player.holecards, 520, 130)
1790 elif player.name == list(state.players.values())[4].name:
1791 self.renderCards(painter, player.holecards, 185, 400)
1792 elif player.name == list(state.players.values())[5].name:
1793 self.renderCards(painter, player.holecards, 520, 700)
1794 else:
1795 pass
1796 i += 1
1797 elif nb_player == 7:
1798 print("nb player :", nb_player)
1799 elif nb_player == 8:
1800 print("nb player :", nb_player)
1801 elif nb_player == 9:
1802 print("nb player :", nb_player)
1803 elif nb_player == 10:
1804 print("nb player :", nb_player)
1806 def keyPressEvent(self, event):
1807 if event.key() == Qt.Key_Left:
1808 self.stateSlider.setValue(max(0, self.stateSlider.value() - 1))
1809 elif event.key() == Qt.Key_Right:
1810 self.stateSlider.setValue(min(self.stateSlider.maximum(), self.stateSlider.value() + 1))
1811 elif event.key() == Qt.Key_Up:
1812 if self.handidx < len(self.handlist) - 1:
1813 self.play_hand(self.handidx + 1)
1814 elif event.key() == Qt.Key_Down:
1815 if self.handidx > 0:
1816 self.play_hand(self.handidx - 1)
1817 else:
1818 QWidget.keyPressEvent(self, event)
1820 def play_hand(self, handidx):
1821 self.handidx = handidx
1822 hand = Hand.hand_factory(self.handlist[handidx], self.conf, self.db)
1823 # hand.writeHand() # Print handhistory to stdout -> should be an option in the GUI
1824 self.currency = hand.sym
1826 self.states = []
1828 # info for drawing (game, limite, site ...)
1829 print(hand)
1830 print(hand.gametype)
1831 info_gen = hand.gametype["category"]
1832 if info_gen == "omahahilo":
1833 info_gen = "Omaha Hi/Lo"
1834 elif info_gen == "fusion":
1835 info_gen = "Fusion"
1836 elif info_gen == "27_1draw":
1837 info_gen = "Single Draw 2-7 Lowball"
1838 elif info_gen == "27_3draw":
1839 info_gen = "Triple Draw 2-7 Lowball"
1840 elif info_gen == "a5_3draw":
1841 info_gen = "Triple Draw A-5 Lowball"
1842 elif info_gen == "5_studhi":
1843 info_gen = "5 Card Stud"
1844 elif info_gen == "badugi":
1845 info_gen = "Badugi"
1846 elif info_gen == "badacey":
1847 info_gen = "Badacey"
1848 elif info_gen == "badeucey":
1849 info_gen = "Badeucey"
1850 elif info_gen == "drawmaha":
1851 info_gen = "2-7 Drawmaha"
1852 elif info_gen == "a5_1draw":
1853 info_gen = "A-5 Single Draw"
1854 elif info_gen == "27_razz":
1855 info_gen = "2-7 Razz"
1856 elif info_gen == "fivedraw":
1857 info_gen = "5 Card Draw"
1858 elif info_gen == "holdem":
1859 info_gen = "Hold'em"
1860 elif info_gen == "6_holdem":
1861 info_gen = "Hold'em"
1862 elif info_gen == "omahahi":
1863 info_gen = "Omaha"
1864 elif info_gen == "razz":
1865 info_gen = "Razz"
1866 elif info_gen == "studhi":
1867 info_gen = "7 Card Stud"
1868 elif info_gen == "studhilo":
1869 info_gen = "7 Card Stud Hi/Lo"
1870 elif info_gen == "5_omahahi":
1871 info_gen = "5 Card Omaha"
1872 elif info_gen == "5_omaha8":
1873 info_gen = "5 Card Omaha Hi/Lo"
1874 elif info_gen == "cour_hi":
1875 info_gen = "Courchevel"
1876 elif info_gen == "cour_hilo":
1877 info_gen = "Courchevel Hi/Lo"
1878 elif info_gen == "2_holdem":
1879 info_gen = "Double hold'em"
1880 elif info_gen == "irish":
1881 info_gen = "Irish"
1882 elif info_gen == "6_omahahi":
1883 info_gen = "6 Card Omaha"
1884 else:
1885 info_gen = "unknown"
1886 limit_info = hand.gametype["limitType"]
1887 if limit_info == "fl":
1888 limit_info = "Fixed Limit"
1889 elif limit_info == "nl":
1890 limit_info = "No Limit"
1891 elif limit_info == "pl":
1892 limit_info = "Pot Limit"
1893 elif limit_info == "cn":
1894 limit_info = "Cap No Limit"
1895 elif limit_info == "cp":
1896 limit_info = "Cap Pot Limit"
1897 else:
1898 limit_info = "unknown"
1899 print(limit_info)
1900 self.info = (
1901 str(limit_info)
1902 + " "
1903 + str(info_gen)
1904 + " "
1905 + str(hand.gametype["bb"])
1906 + str(hand.gametype["currency"])
1907 + " hand n° "
1908 + str(hand.handid)
1909 + " played on "
1910 + str(hand.sitename)
1911 )
1913 state = TableState(hand)
1915 # print (state)
1916 seenStreets = []
1917 for street in hand.allStreets:
1918 if state.called > 0:
1919 for player in list(state.players.values()):
1920 if player.stack == 0:
1921 state.allin = True
1922 break
1923 if not hand.actions[street] and not state.allin:
1924 break
1925 seenStreets.append(street)
1926 state = copy.deepcopy(state)
1927 state.startPhase(street)
1928 self.states.append(state)
1929 for action in hand.actions[street]:
1930 state = copy.deepcopy(state)
1931 state.updateForAction(action)
1932 self.states.append(state)
1934 state = copy.deepcopy(state)
1935 state.endHand(hand.collectees, hand.pot.returned)
1936 self.states.append(state)
1938 # Clear and repopulate the row of buttons
1939 for idx in reversed(list(range(self.buttonBox.count()))):
1940 self.buttonBox.takeAt(idx).widget().setParent(None)
1941 self.buttonBox.addWidget(self.prevButton)
1942 self.prevButton.setEnabled(self.handidx > 0)
1943 self.buttonBox.addWidget(self.startButton)
1944 for street in hand.allStreets[1:]:
1945 btn = QPushButton(street.capitalize())
1946 self.buttonBox.addWidget(btn)
1947 btn.clicked.connect(partial(self.street_clicked, street=street))
1948 btn.setEnabled(street in seenStreets)
1949 btn.setFocusPolicy(Qt.NoFocus)
1950 self.buttonBox.addWidget(self.endButton)
1951 self.buttonBox.addWidget(self.playPauseButton)
1952 self.buttonBox.addWidget(self.nextButton)
1953 self.nextButton.setEnabled(self.handidx < len(self.handlist) - 1)
1955 self.stateSlider.setMaximum(len(self.states) - 1)
1956 self.stateSlider.setValue(0)
1957 self.update()
1959 def increment_state(self):
1960 if self.stateSlider.value() == self.stateSlider.maximum():
1961 self.playing = False
1962 self.playPauseButton.setText("Play")
1964 if self.playing:
1965 self.stateSlider.setValue(self.stateSlider.value() + 1)
1967 def slider_changed(self, value):
1968 self.update()
1970 def importhand(self, handid=1):
1971 h = Hand.hand_factory(handid, self.conf, self.db)
1973 return h
1975 def play_clicked(self, checkState):
1976 self.playing = not self.playing
1977 if self.playing:
1978 self.playPauseButton.setText("Pause")
1979 self.playTimer = QTimer()
1980 self.playTimer.timeout.connect(self.increment_state)
1981 self.playTimer.start(1000)
1982 else:
1983 self.playPauseButton.setText("Play")
1984 self.playTimer = None
1986 def start_clicked(self, checkState):
1987 self.stateSlider.setValue(0)
1989 def end_clicked(self, checkState):
1990 self.stateSlider.setValue(self.stateSlider.maximum())
1992 def prev_clicked(self, checkState):
1993 self.play_hand(self.handidx - 1)
1995 def next_clicked(self, checkState):
1996 self.play_hand(self.handidx + 1)
1998 def street_clicked(self, checkState, street):
1999 for i, state in enumerate(self.states):
2000 if state.street == street:
2001 self.stateSlider.setValue(i)
2002 break
2005# ICM code originally grabbed from http://svn.gna.org/svn/pokersource/trunk/icm-calculator/icm-webservice.py
2006# Copyright (c) 2008 Thomas Johnson <tomfmason@gmail.com>
2009class ICM(object):
2010 def __init__(self, stacks, payouts):
2011 self.stacks = stacks
2012 self.payouts = payouts
2013 self.equities = []
2014 self.prepare()
2016 def prepare(self):
2017 total = sum(self.stacks)
2018 for k in self.stacks:
2019 self.equities.append(round(Decimal(str(self.getEquities(total, k, 0))), 4))
2021 def getEquities(self, total, player, depth):
2022 D = Decimal
2023 eq = D(self.stacks[player]) / total * D(str(self.payouts[depth]))
2024 if depth + 1 < len(self.payouts):
2025 i = 0
2026 for stack in self.stacks:
2027 if i != player and stack > 0.0:
2028 self.stacks[i] = 0.0
2029 eq += self.getEquities((total - stack), player, (depth + 1)) * (old_div(stack, D(total)))
2030 self.stacks[i] = stack
2031 i += 1
2032 return eq
2035class TableState(object):
2036 def __init__(self, hand):
2037 self.pot = Decimal(0)
2038 self.street = None
2039 self.board = hand.board
2040 self.renderBoard = set()
2041 self.bet = Decimal(0)
2042 self.called = Decimal(0)
2043 self.gametype = hand.gametype["category"]
2044 self.gamebase = hand.gametype["base"]
2045 self.allin = False
2046 self.allinThisStreet = False
2047 self.newpot = Decimal()
2048 # NOTE: Need a useful way to grab payouts
2049 # self.icm = ICM(stacks,payouts)
2050 # print icm.equities
2052 self.players = {}
2053 # print ('hand.players', hand.players)
2054 # print (type(hand.players))
2055 # print (type(self.players))
2056 # for name, chips, seat in hand.players[-1]:
2057 # self.players.append(Player(name, chips, seat))
2058 # # self.players[name] = Player(hand, name, chips, seat)
2059 for items in hand.players:
2060 # print (items)
2061 # print ('type', (type(items)))
2062 # print (items[0])
2063 # print (items[1])
2064 # print (items[2])
2065 # print (items[3])
2067 self.players[items[1]] = Player(hand, items[1], items[2], int(items[0]))
2068 print(self.players[items[1]])
2070 def startPhase(self, phase):
2071 self.street = phase
2072 self.newpot = self.newpot
2073 if phase in ("BLINDSANTES", "PREFLOP", "DEAL"):
2074 return
2076 self.renderBoard.add(phase)
2078 for player in list(self.players.values()):
2079 player.justacted = False
2080 if player.chips > self.called:
2081 player.stack += player.chips - self.called
2082 player.chips = self.called
2083 self.pot += player.chips
2085 player.chips = Decimal(0)
2086 if phase in ("THIRD", "FOURTH", "FIFTH", "SIXTH", "SEVENTH"):
2087 player.holecards = player.streetcards[self.street]
2088 self.bet = Decimal(0)
2089 self.called = Decimal(0)
2090 self.allinThisStreet = False
2092 def updateForAction(self, action):
2093 for player in list(self.players.values()):
2094 player.justacted = False
2096 player = self.players[action[0]]
2097 player.action = action[1]
2098 player.justacted = True
2099 if action[1] == "folds" or action[1] == "checks":
2100 pass
2101 elif action[1] == "raises" or action[1] == "bets":
2102 if self.allinThisStreet:
2103 self.called = Decimal(self.bet)
2104 else:
2105 self.called = Decimal(0)
2106 diff = self.bet - player.chips
2107 self.bet += action[2]
2108 player.chips += action[2] + diff
2109 player.stack -= action[2] + diff
2110 self.newpot += action[2] + diff
2111 elif action[1] == "big blind":
2112 self.bet = action[2]
2113 player.chips += action[2]
2114 player.stack -= action[2]
2115 self.newpot += action[2]
2116 elif action[1] == "calls" or action[1] == "small blind" or action[1] == "secondsb":
2117 player.chips += action[2]
2118 player.stack -= action[2]
2119 self.called = max(self.called, player.chips)
2120 self.newpot += action[2]
2121 elif action[1] == "both":
2122 player.chips += action[2]
2123 player.stack -= action[2]
2124 self.newpot += action[2]
2125 elif action[1] == "ante":
2126 self.pot += action[2]
2127 player.stack -= action[2]
2128 self.newpot += action[2]
2129 elif action[1] == "discards":
2130 player.action += " " + str(action[2])
2131 if len(action) > 3:
2132 # Must be hero as we have discard information. Update holecards now.
2133 player.holecards = player.streetcards[self.street]
2134 elif action[1] == "stands pat":
2135 pass
2136 elif action[1] == "bringin":
2137 player.chips += action[2]
2138 player.stack -= action[2]
2139 self.newpot += action[2]
2140 else:
2141 print("unhandled action: " + str(action))
2143 if player.stack == 0:
2144 self.allinThisStreet = True
2146 def endHand(self, collectees, returned):
2147 self.pot = Decimal(0)
2148 for player in list(self.players.values()):
2149 player.justacted = False
2150 player.chips = Decimal(0)
2151 if self.gamebase == "draw":
2152 player.holecards = player.streetcards[self.street]
2153 for name, amount in list(collectees.items()):
2154 player = self.players[name]
2155 player.chips += amount
2156 player.action = "collected"
2157 player.justacted = True
2158 for name, amount in list(returned.items()):
2159 self.players[name].stack += amount
2162class Player(object):
2163 def __init__(self, hand, name, stack, seat):
2164 self.stack = Decimal(stack)
2165 self.chips = Decimal(0)
2166 self.seat = seat
2167 self.name = name
2168 self.action = None
2169 self.justacted = False
2170 self.holecards = hand.join_holecards(name, asList=True)
2171 self.streetcards = {}
2172 if hand.gametype["base"] == "draw":
2173 for street in hand.actionStreets[1:]:
2174 self.streetcards[street] = hand.join_holecards(name, asList=True, street=street)
2175 self.holecards = self.streetcards[hand.actionStreets[1]]
2176 elif hand.gametype["base"] == "stud":
2177 for i, street in enumerate(hand.actionStreets[1:]):
2178 self.streetcards[street] = self.holecards[: i + 3]
2179 self.holecards = self.streetcards[hand.actionStreets[1]]
2180 print("seat", seat)
2181 self.x = 0.5 * cos(2 * self.seat * pi / hand.maxseats)
2182 self.y = 0.8 * sin(2 * self.seat * pi / hand.maxseats)
2185if __name__ == "__main__":
2186 config = Configuration.Config()
2187 db = Database.Database(config)
2188 sql = SQL.Sql(db_server=config.get_db_parameters()["db-server"])
2190 from PyQt5.QtWidgets import QApplication
2192 app = QApplication([])
2193 handlist = [10, 39, 40]
2194 replayer = GuiReplayer(config, sql, None, handlist)
2195 replayer.play_hand(0)
2197 app.exec_()