From 94ab295804a0de6847733fcfbf8236d009808333 Mon Sep 17 00:00:00 2001 From: Worros Date: Thu, 26 Aug 2010 11:25:21 +0800 Subject: [PATCH] PKR: Fix some regexes --- pyfpdb/PkrToFpdb.py | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/pyfpdb/PkrToFpdb.py b/pyfpdb/PkrToFpdb.py index 56697210..a94cd030 100755 --- a/pyfpdb/PkrToFpdb.py +++ b/pyfpdb/PkrToFpdb.py @@ -76,10 +76,10 @@ class Pkr(HandHistoryConverter): """ % substitutions, re.MULTILINE|re.VERBOSE) re_PlayerInfo = re.compile(u""" - ^Seat\s(?P[0-9]+):\s - (?P.*)\s - \((%(LS)s)?(?P[.0-9]+)\sin\schips\)""" % substitutions, - re.MULTILINE|re.VERBOSE) + ^Seat\s(?P[0-9]+):\s + (?P.*)\s-\s + (%(LS)s)?(?P[.0-9]+) + """ % substitutions, re.MULTILINE|re.VERBOSE) re_HandInfo = re.compile(""" ^Table\s\'(?P[-\ a-zA-Z\d]+)\'\s @@ -97,28 +97,24 @@ class Pkr(HandHistoryConverter): re_DateTime = re.compile("""(?P[0-9]{4})\/(?P[0-9]{2})\/(?P[0-9]{2})[\- ]+(?P[0-9]+):(?P[0-9]+):(?P[0-9]+)""", re.MULTILINE) def compilePlayerRegexs(self, hand): - print "DEBUG: compilePlayerRegexs" players = set([player[1] for player in hand.players]) if not players <= self.compiledPlayers: # x <= y means 'x is subset of y' # we need to recompile the player regexs. -# TODO: should probably rename re_HeroCards and corresponding method, -# since they are used to find all cards on lines starting with "Dealt to:" -# They still identify the hero. self.compiledPlayers = players player_re = "(?P" + "|".join(map(re.escape, players)) + ")" subst = {'PLYR': player_re, 'CUR': self.sym[hand.gametype['currency']]} log.debug("player_re: " + player_re) - self.re_PostSB = re.compile(r"^%(PLYR)s: posts small blind %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) - self.re_PostBB = re.compile(r"^%(PLYR)s: posts big blind %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) - self.re_Antes = re.compile(r"^%(PLYR)s: posts the ante %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) - self.re_BringIn = re.compile(r"^%(PLYR)s: brings[- ]in( low|) for %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) - self.re_PostBoth = re.compile(r"^%(PLYR)s: posts small \& big blinds %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) - self.re_HeroCards = re.compile(r"^Dealt to %(PLYR)s(?: \[(?P.+?)\])?( \[(?P.+?)\])" % subst, re.MULTILINE) - self.re_Action = re.compile(r""" - ^%(PLYR)s:(?P\sbets|\schecks|\sraises|\scalls|\sfolds|\sdiscards|\sstands\spat) - (\s(%(CUR)s)?(?P[.\d]+))?(\sto\s%(CUR)s(?P[.\d]+))? # the number discarded goes in - (\scards?(\s\[(?P.+?)\])?)?""" - % subst, re.MULTILINE|re.VERBOSE) + self.re_PostSB = re.compile(r"^%(PLYR)s posts small blind %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) + # FIXME: Sionel posts $0.04 is a second big blind in a different format. + self.re_PostBB = re.compile(r"^%(PLYR)s posts big blind %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) + self.re_Antes = re.compile(r"^%(PLYR)s: posts the ante %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) + self.re_BringIn = re.compile(r"^%(PLYR)s: brings[- ]in( low|) for %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) + self.re_PostBoth = re.compile(r"^%(PLYR)s: posts small \& big blinds %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) + self.re_HeroCards = re.compile(r"^Dealing( \[(?P.+?)\])?( \[(?P.+?)\]) to %(PLYR)s" % subst, re.MULTILINE) + self.re_Action = re.compile(r""" + ^%(PLYR)s(?P\sbets|\schecks|\sraises|\scalls|\sfolds)(\sto)? + (\s(%(CUR)s)?(?P[.\d]+))? + """ % subst, re.MULTILINE|re.VERBOSE) self.re_ShowdownAction = re.compile(r"^%s: shows \[(?P.*)\]" % player_re, re.MULTILINE) self.re_CollectPot = re.compile(r"Seat (?P[0-9]+): %(PLYR)s (\(button\) |\(small blind\) |\(big blind\) |\(button\) \(small blind\) )?(collected|showed \[.*\] and won) \(%(CUR)s(?P[.\d]+)\)(, mucked| with.*|)" % subst, re.MULTILINE) self.re_sitsOut = re.compile("^%s sits out" % player_re, re.MULTILINE) @@ -150,7 +146,7 @@ class Pkr(HandHistoryConverter): raise FpdbParseError(_("Unable to recognise gametype from: '%s'") % tmp) mg = m.groupdict() - print "DEBUG: %s" % mg + #print "DEBUG: %s" % mg if 'LIMIT' in mg: info['limitType'] = self.limits[mg['LIMIT']] @@ -341,7 +337,7 @@ class Pkr(HandHistoryConverter): for action in m: acts = action.groupdict() if action.group('ATYPE') == ' raises': - hand.addRaiseBy( street, action.group('PNAME'), action.group('BET') ) + hand.addRaiseTo( street, action.group('PNAME'), action.group('BET') ) elif action.group('ATYPE') == ' calls': hand.addCall( street, action.group('PNAME'), action.group('BET') ) elif action.group('ATYPE') == ' bets':