From f323447313ddcc3efe8bdafbe775e0914787647c Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 4 Jul 2009 14:35:20 -0400 Subject: [PATCH] Get shown and mucked cards for stud games. --- pyfpdb/Hand.py | 61 ++++++++++++++++++++++++++++---------- pyfpdb/PokerStarsToFpdb.py | 2 +- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index fa472b03..237b609a 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -410,6 +410,20 @@ Add a raise on [street] by [player] to [amountTo] self.collectees[player] += Decimal(pot) + def addShownCards(self, cards, player, holeandboard=None, shown=True, mucked=False): + """\ +For when a player shows cards for any reason (for showdown or out of choice). +Card ranks will be uppercased +""" + logging.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard)) + if cards is not None: + self.addHoleCards(cards,player,shown, mucked) + elif holeandboard is not None: + holeandboard = set([self.card(c) for c in holeandboard]) + board = set([c for s in self.board.values() for c in s]) + self.addHoleCards(holeandboard.difference(board),player,shown, mucked) + + def totalPot(self): """If all bets and blinds have been added, totals up the total pot size""" @@ -567,20 +581,6 @@ dealt whether they were seen in a 'dealt to' line else: self.holecards['PREFLOP'][player] = cardset - def addShownCards(self, cards, player, holeandboard=None, shown=True, mucked=False): - """\ -For when a player shows cards for any reason (for showdown or out of choice). -Card ranks will be uppercased -""" - logging.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard)) - if cards is not None: - self.addHoleCards(cards,player,shown, mucked) - elif holeandboard is not None: - holeandboard = set([self.card(c) for c in holeandboard]) - board = set([c for s in self.board.values() for c in s]) - self.addHoleCards(holeandboard.difference(board),player,shown, mucked) - - def writeHTMLHand(self, fh=sys.__stdout__): from nevow import tags as T from nevow import flat @@ -991,7 +991,7 @@ class StudHand(Hand): hhc.readStudPlayerCards(self, street) hhc.readAction(self, street) hhc.readCollectPot(self) - #hhc.readShownCards(self) # not done yet + hhc.readShownCards(self) # not done yet self.totalPot() # finalise it (total the pot) hhc.getRake(self) elif builtFrom == "DB": @@ -1014,6 +1014,36 @@ closed likewise, but known only to player except FpdbParseError, e: print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) + def addHoleCards(self, cards, player, shown, mucked, dealt=False): + """\ +Assigns observed holecards to a player. +cards list of card bigrams e.g. ['2h','Jc'] +player (string) name of player +shown whether they were revealed at showdown +mucked whether they were mucked at showdown +dealt whether they were seen in a 'dealt to' line +""" +# +# For stud games we just need to do the routine setting of shown/mucked/etc +# and then update the cards 'THIRD' and 'SEVENTH' + logging.debug("addHoleCards %s %s" % (cards, player)) + try: + self.checkPlayerExists(player) + except FpdbParseError, e: + print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) + return + + if dealt: + self.dealt.add(player) + if shown: + self.shown.add(player) + if mucked: + self.mucked.add(player) + if len(cards) > 2: + self.holecards['THIRD'][player] = (cards[0:3], None) + if len(cards) > 6: + self.holecards['SEVENTH'][player] = (cards[6], None) + # TODO: def addComplete(self, player, amount): def addComplete(self, street, player, amountTo): # assert street=='THIRD' @@ -1045,6 +1075,7 @@ Add a complete on [street] by [player] to [amountTo] self.actions['THIRD'].append(act) self.lastBet['THIRD'] = Decimal(bringin) self.pot.addMoney(player, Decimal(bringin)) + def writeHand(self, fh=sys.__stdout__): # PokerStars format. diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 75609001..2181b7cc 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -317,7 +317,7 @@ follow : whether to tail -f the input""" for m in self.re_ShownCards.finditer(hand.handText): if m.group('CARDS') is not None: cards = m.group('CARDS') - cards = set(cards.split(' ')) + cards = cards.split(' ') # needs to be a list, not a set--stud needs the order (shown, mucked) = (False, False) if m.group('SHOWED') == "showed": shown = True