From 92656ae6a0317ccf84527cf15d1d85436dbcd23c Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Wed, 3 Dec 2008 23:57:20 +0000 Subject: [PATCH] hole cards / community cards extracted and added to printout --- pyfpdb/EverleafToFpdb.py | 25 +++----- pyfpdb/HandHistoryConverter.py | 102 +++++++++++++++++++-------------- 2 files changed, 67 insertions(+), 60 deletions(-) mode change 100644 => 100755 pyfpdb/EverleafToFpdb.py diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py old mode 100644 new mode 100755 index b9df28e2..6d050065 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -73,14 +73,14 @@ class Everleaf(HandHistoryConverter): self.rexx.setPlayerInfoRegex('Seat (?P[0-9]+): (?P.*) \( \$ (?P[.0-9]+) USD \)') self.rexx.setPostSbRegex('.*\n(?P.*): posts small blind \[') self.rexx.setPostBbRegex('.*\n(?P.*): posts big blind \[') - self.rexx.setHeroCardsRegex('.*\nDealt\sto\s(?P.*)\s\[ (?P.*) \]') + self.rexx.setHeroCardsRegex('.*\nDealt\sto\s(?P.*)\s\[ (?P\S\S), (?P\S\S) \]') self.rexx.setActionStepRegex('.*\n(?P.*) (?Pbets|checks|raises|calls|folds)(\s\[\$ (?P[.\d]+) USD\])?') self.rexx.compileRegexes() - def readSupportedGames(self): + def readSupportedGames(self): pass - def determineGameType(self): + def determineGameType(self): # Cheating with this regex, only support nlhe at the moment gametype = ["ring", "hold", "nl"] @@ -110,7 +110,7 @@ class Everleaf(HandHistoryConverter): int(m.group('HR')), int(m.group('MIN')), int(m.group('SEC'))) hand.buttonpos = int(m.group('BUTTON')) - def readPlayerStacks(self, hand): + def readPlayerStacks(self, hand): m = self.rexx.player_info_re.finditer(hand.string) players = [] @@ -121,12 +121,12 @@ class Everleaf(HandHistoryConverter): def markStreets(self, hand): # PREFLOP = ** Dealing down cards ** - m = re.search('(\*\* Dealing down cards \*\*\n)(?P.*?\n\*\*)?( Dealing Flop \*\*)?(?P.*?\*\*)?( Dealing Turn \*\*)?(?P.*?\*\*)?( Dealing River \*\*)?(?P.*)', hand.string,re.DOTALL) + m = re.search('(\*\* Dealing down cards \*\*\n)(?P.*?\n\*\*)?( Dealing Flop \*\* \[ (?P\S\S), (?P\S\S), (?P\S\S) \])?(?P.*?\*\*)?( Dealing Turn \*\* \[ (?P\S\S) \])?(?P.*?\*\*)?( Dealing River \*\* \[ (?P\S\S) \])?(?P.*)', hand.string,re.DOTALL) # for street in m.groupdict(): # print "DEBUG: Street: %s\tspan: %s" %(street, str(m.span(street))) hand.streets = m - def readBlinds(self, hand): + def readBlinds(self, hand): try: m = self.rexx.small_blind_re.search(hand.string) hand.posted = [m.group('PNAME')] @@ -143,16 +143,9 @@ class Everleaf(HandHistoryConverter): hand.involved = False else: hand.hero = m.group('PNAME') - hand.holecards = m.group('HOLECARDS') - hand.holecards = hand.holecards.replace(',','') - #Must be a better way to do the following tr akqjt AKQJT - hand.holecards = hand.holecards.replace('a','A') - hand.holecards = hand.holecards.replace('k','K') - hand.holecards = hand.holecards.replace('q','Q') - hand.holecards = hand.holecards.replace('j','J') - hand.holecards = hand.holecards.replace('t','T') + hand.addHoleCards(m.group('HOLE1'), m.group('HOLE2')) - def readAction(self, hand, street): + def readAction(self, hand, street): m = self.rexx.action_re.finditer(hand.streets.group(street)) hand.actions[street] = [] for action in m: @@ -165,7 +158,7 @@ class Everleaf(HandHistoryConverter): if __name__ == "__main__": c = Configuration.Config() - e = Everleaf(c, "regression-test-files/everleaf/Speed_Kuala.txt") + e = Everleaf(c, "Speed_Kuala.txt") e.processFile() print str(e) diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 3050b39e..85b28a94 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -104,7 +104,7 @@ class HandHistoryConverter: def readAction(self, hand, street): abstract def sanityCheck(self): - sane = False + sane = True base_w = False #Check if hhbase exists and is writable #Note: Will not try to create the base HH directory @@ -175,7 +175,7 @@ class HandHistoryConverter: print "XXXXXXXXX FIXME XXXXXXXX" print "*** HOLE CARDS ***" - print "Dealt to %s [%s]" %(hand.hero ,hand.holecards) + print "Dealt to %s [%s %s]" %(hand.hero , hand.holecards[0], hand.holecards[1]) # ## ACTION STUFF # This is no limit only at the moment @@ -184,17 +184,17 @@ class HandHistoryConverter: self.printActionLine(act, 0) if 'FLOP' in hand.actions: - print "*** FLOP *** [%s]" %("XXXXX Flop cards XXXXXX") + print "*** FLOP *** [%s %s %s]" %(hand.streets.group("FLOP1"), hand.streets.group("FLOP2"), hand.streets.group("FLOP3")) for act in hand.actions['FLOP']: self.printActionLine(act, 0) if 'TURN' in hand.actions: - print "*** TURN *** [%s] [%s]" %("XXXXX Flop cards XXXXXX", "XXXXX Turn Card XXXXX") + print "*** TURN *** [%s %s %s] [%s]" %(hand.streets.group("FLOP1"), hand.streets.group("FLOP2"), hand.streets.group("FLOP3"), hand.streets.group("TURN1")) for act in hand.actions['TURN']: self.printActionLine(act, 0) if 'RIVER' in hand.actions: - print "*** RIVER *** [%s %s] [%s]" %("XXXXX Flop cards XXXXXX", "XXXXX Turn Card XXXXX", "XXXXX River Card XXXXX") + print "*** RIVER *** [%s %s %s %s] [%s]" %(hand.streets.group("FLOP1"), hand.streets.group("FLOP2"), hand.streets.group("FLOP3"), hand.streets.group("TURN1"), hand.streets.group("RIVER1")) for act in hand.actions['RIVER']: self.printActionLine(act, 0) @@ -232,45 +232,59 @@ class HandHistoryConverter: class Hand: # def __init__(self, sitename, gametype, sb, bb, string): - def __init__(self, sitename, gametype, string): - self.sitename = sitename - self.gametype = gametype - self.string = string - self.streets = None # A MatchObject using a groupnames to identify streets. - self.actions = {} + ups = {'a':'A', 't':'T', 'j':'J', 'q':'Q', 'k':'K'} - self.handid = 0 - self.sb = gametype[3] - self.bb = gametype[4] - self.tablename = "Slartibartfast" - self.maxseats = 10 - self.counted_seats = 0 - self.buttonpos = 0 - self.seating = [] - self.players = [] - self.posted = [] - self.involved = True - self.hero = "Hiro" - self.holecards = "Xx Xx" - self.action = [] - self.totalpot = 0 - self.rake = 0 + def __init__(self, sitename, gametype, string): + self.sitename = sitename + self.gametype = gametype + self.string = string + + self.streets = None # A MatchObject using a groupnames to identify streets. + self.actions = {} + + self.handid = 0 + self.sb = gametype[3] + self.bb = gametype[4] + self.tablename = "Slartibartfast" + self.maxseats = 10 + self.counted_seats = 0 + self.buttonpos = 0 + self.seating = [] + self.players = [] + self.posted = [] + self.involved = True + self.hero = "Hiro" + self.holecards = "Xx Xx" + self.action = [] + self.totalpot = 0 + self.rake = 0 - def printHand(self): - print self.sitename - print self.gametype - print self.string - print self.handid - print self.sb - print self.bb - print self.tablename - print self.maxseats - print self.counted_seats - print self.buttonpos - print self.seating - print self.players - print self.posted - print self.action - print self.involved - print self.hero + def addHoleCards(self,h1,h2,seat=None): # generalise to add hole cards for a specific seat or player + self.holecards = [self.card(h1), self.card(h2)] + + + def card(self,c): + """upper case the ranks but not suits, 'atjqk' => 'ATJQK'""" + # don't know how to make this 'static' + for k,v in self.ups.items(): + c = c.replace(k,v) + return c + + def printHand(self): + print self.sitename + print self.gametype + print self.string + print self.handid + print self.sb + print self.bb + print self.tablename + print self.maxseats + print self.counted_seats + print self.buttonpos + print self.seating + print self.players + print self.posted + print self.action + print self.involved + print self.hero