From 5f9d4027011c381dea95b77b4124a56cabc6b99a Mon Sep 17 00:00:00 2001 From: Chaz Littlejohn Date: Mon, 4 Apr 2011 19:57:54 +0000 Subject: [PATCH] Added new showdownStrings dictionary in the Hand module as well as the appropriate regex in re_ShownCards for capturing the text discrption of showdown hands. FTP and Stars only for now. Once evaluating hand strings is added to Stove, this will be used as a back up for games Poker-eval does not fully support such as Razz and Badugi --- pyfpdb/FulltiltToFpdb.py | 7 ++++--- pyfpdb/Hand.py | 17 +++++++++++++---- pyfpdb/PokerStarsToFpdb.py | 5 +++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index 31f889b0..07ba6785 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -170,7 +170,7 @@ class Fulltilt(HandHistoryConverter): self.re_ShowdownAction = re.compile(r"^%s shows \[(?P.*)\]" % player_re, re.MULTILINE) self.re_CollectPot = re.compile(r"^Seat (?P[0-9]+): %(PLAYERS)s (\(button\) |\(small blind\) |\(big blind\) )?(collected|showed \[.*\] and won) \([%(LS)s]?(?P[%(NUM)s]+)\)(, mucked| with.*)?" % self.substitutions, re.MULTILINE) self.re_SitsOut = re.compile(r"^%s sits out" % player_re, re.MULTILINE) - self.re_ShownCards = re.compile(r"^Seat (?P[0-9]+): %s (\(button\) |\(small blind\) |\(big blind\) )?(?Pshowed|mucked) \[(?P.*)\].*" % player_re, re.MULTILINE) + self.re_ShownCards = re.compile(r"^Seat (?P[0-9]+): %s (\(button\) |\(small blind\) |\(big blind\) )?(?Pshowed|mucked) \[(?P.*)\](( and won \(.*\) with | and lost with | \- )(?P.*))?" % player_re, re.MULTILINE) def readSupportedGames(self): return [["ring", "hold", "nl"], @@ -525,10 +525,11 @@ class Fulltilt(HandHistoryConverter): def readShownCards(self,hand): for m in self.re_ShownCards.finditer(hand.handText): if m.group('CARDS') is not None: + string = m.group('STRING') if m.group('ACT'): - hand.addShownCards(cards=m.group('CARDS').split(' '), player=m.group('PNAME'), shown = False, mucked = True) + hand.addShownCards(cards=m.group('CARDS').split(' '), player=m.group('PNAME'), shown = False, mucked = True, string = string) else: - hand.addShownCards(cards=m.group('CARDS').split(' '), player=m.group('PNAME'), shown = True, mucked = False) + hand.addShownCards(cards=m.group('CARDS').split(' '), player=m.group('PNAME'), shown = True, mucked = False, string = string) def guessMaxSeats(self, hand): """Return a guess at max_seats when not specified in HH.""" diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index ae53bafa..a5723c59 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -113,6 +113,7 @@ class Hand(object): self.board = {} # dict from street names to community cards self.holecards = {} self.discards = {} + self.showdownStrings = {} for street in self.allStreets: self.streets[street] = "" # portions of the handText, filled by markStreets() self.actions[street] = [] @@ -711,7 +712,7 @@ 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): + def addShownCards(self, cards, player, holeandboard=None, shown=True, mucked=False, string=None): """\ For when a player shows cards for any reason (for showdown or out of choice). Card ranks will be uppercased @@ -719,6 +720,8 @@ Card ranks will be uppercased log.debug(_("addShownCards %s hole=%s all=%s") % (player, cards, holeandboard)) if cards is not None: self.addHoleCards(cards,player,shown, mucked) + if string is not None: + self.showdownStrings[player] = string 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]) @@ -913,7 +916,7 @@ class HoldemOmahaHand(Hand): pass - def addShownCards(self, cards, player, shown=True, mucked=False, dealt=False): + def addShownCards(self, cards, player, shown=True, mucked=False, dealt=False, string=None): if player == self.hero: # we have hero's cards just update shown/mucked if shown: self.shown.add(player) if mucked: self.mucked.add(player) @@ -926,6 +929,8 @@ class HoldemOmahaHand(Hand): diff = filter( lambda x: x not in self.board['FLOP']+self.board['TURN']+self.board['RIVER'], cards ) if len(diff) == 2 and self.gametype['category'] in ('holdem'): self.addHoleCards('PREFLOP', player, open=[], closed=diff, shown=shown, mucked=mucked, dealt=dealt) + if string is not None: + self.showdownStrings[player] = string def getStreetTotals(self): # street1Pot INT, /* pot size at flop/street4 */ @@ -1201,13 +1206,15 @@ class DrawHand(Hand): elif builtFrom == "DB": self.select("dummy") # Will need a handId - def addShownCards(self, cards, player, shown=True, mucked=False, dealt=False): + def addShownCards(self, cards, player, shown=True, mucked=False, dealt=False, string=None): if player == self.hero: # we have hero's cards just update shown/mucked if shown: self.shown.add(player) if mucked: self.mucked.add(player) else: # TODO: Probably better to find the last street with action and add the hole cards to that street self.addHoleCards('DRAWTHREE', player, open=[], closed=cards, shown=shown, mucked=mucked, dealt=dealt) + if string is not None: + self.showdownStrings[player] = string def discardDrawHoleCards(self, cards, player, street): @@ -1379,7 +1386,7 @@ class StudHand(Hand): elif builtFrom == "DB": self.select("dummy") # Will need a handId - def addShownCards(self, cards, player, shown=True, mucked=False, dealt=False): + def addShownCards(self, cards, player, shown=True, mucked=False, dealt=False, string=None): if player == self.hero: # we have hero's cards just update shown/mucked if shown: self.shown.add(player) if mucked: self.mucked.add(player) @@ -1390,6 +1397,8 @@ class StudHand(Hand): self.addHoleCards('SIXTH', player, open=[cards[5]], closed=cards[2:5], shown=shown, mucked=mucked) if len(cards) > 6: self.addHoleCards('SEVENTH', player, open=[], closed=[cards[6]], shown=shown, mucked=mucked) + if string is not None: + self.showdownStrings[player] = string def addPlayerCards(self, player, street, open=[], closed=[]): diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index aa2348fa..55ad9a37 100644 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -157,7 +157,7 @@ class PokerStars(HandHistoryConverter): % short_subst, re.MULTILINE|re.VERBOSE) re_ShowdownAction = re.compile(r"^%s: shows \[(?P.*)\]" % short_subst['PLYR'], re.MULTILINE) re_sitsOut = re.compile("^%s sits out" % short_subst['PLYR'], re.MULTILINE) - re_ShownCards = re.compile("^Seat (?P[0-9]+): %s (\(.*\) )?(?Pshowed|mucked) \[(?P.*)\].*" % short_subst['PLYR'], re.MULTILINE) + re_ShownCards = re.compile("^Seat (?P[0-9]+): %s (\(.*\) )?(?Pshowed|mucked) \[(?P.*)\]( and won \([.\d]+\) with (?P.*))?" % short_subst['PLYR'], re.MULTILINE) re_CollectPot = re.compile(r"Seat (?P[0-9]+): %(PLYR)s (\(button\) |\(small blind\) |\(big blind\) |\(button\) \(small blind\) |\(button\) \(big blind\) )?(collected|showed \[.*\] and won) \(%(CUR)s(?P[.\d]+)\)(, mucked| with.*|)" % short_subst, re.MULTILINE) def compilePlayerRegexs(self, hand): @@ -462,13 +462,14 @@ class PokerStars(HandHistoryConverter): if m.group('CARDS') is not None: cards = m.group('CARDS') cards = cards.split(' ') # needs to be a list, not a set--stud needs the order + string = m.group('STRING') (shown, mucked) = (False, False) if m.group('SHOWED') == "showed": shown = True elif m.group('SHOWED') == "mucked": mucked = True #print "DEBUG: hand.addShownCards(%s, %s, %s, %s)" %(cards, m.group('PNAME'), shown, mucked) - hand.addShownCards(cards=cards, player=m.group('PNAME'), shown=shown, mucked=mucked) + hand.addShownCards(cards=cards, player=m.group('PNAME'), shown=shown, mucked=mucked, string=string) if __name__ == "__main__": parser = OptionParser()