From f250fec935183d7dd6dce3e412a956ea2b0b24d1 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Fri, 20 Aug 2010 22:32:14 +0100 Subject: [PATCH] getting closer - still breaks --- pyfpdb/OnGameToFpdb.py | 86 ++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/pyfpdb/OnGameToFpdb.py b/pyfpdb/OnGameToFpdb.py index 39ddb906..d7117e9c 100755 --- a/pyfpdb/OnGameToFpdb.py +++ b/pyfpdb/OnGameToFpdb.py @@ -96,28 +96,37 @@ class OnGame(HandHistoryConverter): #Seat 1: .Lucchess ($4.17 in chips) re_PlayerInfo = re.compile(u'Seat (?P[0-9]+): (?P.*) \((?P[.0-9]+) \)') - - #ANTES/BLINDS - #helander2222 posts blind ($0.25), lopllopl posts blind ($0.50). - re_PostSB = re.compile('(?P.*) posts blind \(\$?(?P[.0-9]+)\), ') - re_PostBB = re.compile('\), (?P.*) posts blind \(\$?(?P[.0-9]+)\).') - re_PostBoth = re.compile('.*\n(?P.*): posts small \& big blinds \[\$? (?P[.0-9]+)') - re_HeroCards = re.compile('.*\nDealt\sto\s(?P.*)\s\[ (?P.*) \]') - - #lopllopl checks, Eurolll checks, .Lucchess checks. - re_Action = re.compile('(, )?(?P.*?)(?P bets| checks| raises| calls| folds)( \$(?P\d*\.?\d*))?( and is all-in)?') - re_Board = re.compile(r"\[board cards (?P.+) \]") - - #Uchilka shows [ KC,JD ] - re_ShowdownAction = re.compile('(?P.*) shows \[ (?P.+) \]') - - # TODO: read SUMMARY correctly for collected pot stuff. - #Uchilka, bets $11.75, collects $23.04, net $11.29 - re_CollectPot = re.compile('(?P.*), bets.+, collects \$(?P\d*\.?\d*), net.* ') - re_sitsOut = re.compile('(?P.*) sits out') def compilePlayerRegexs(self, hand): - pass + 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. + + #ANTES/BLINDS + #helander2222 posts blind ($0.25), lopllopl posts blind ($0.50). + player_re = "(?P" + "|".join(map(re.escape, players)) + ")" + subst = {'PLYR': player_re, 'CUR': self.sym[hand.gametype['currency']]} + re_PostSB = re.compile('(?P.*) posts blind \(\$?(?P[.0-9]+)\), ') + re_PostBB = re.compile('\), (?P.*) posts blind \(\$?(?P[.0-9]+)\).') + re_Antes = re.compile(r"^%(PLYR)s: posts the ante %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) + re_BringIn = re.compile(r"^%(PLYR)s: brings[- ]in( low|) for %(CUR)s(?P[.0-9]+)" % subst, re.MULTILINE) + re_PostBoth = re.compile('.*\n(?P.*): posts small \& big blinds \[\$? (?P[.0-9]+)') + re_HeroCards = re.compile('.*\nDealt\sto\s(?P.*)\s\[ (?P.*) \]') + + #lopllopl checks, Eurolll checks, .Lucchess checks. + re_Action = re.compile('(, )?(?P.*?)(?P bets| checks| raises| calls| folds)( \$(?P\d*\.?\d*))?( and is all-in)?') + re_Board = re.compile(r"\[board cards (?P.+) \]") + + #Uchilka shows [ KC,JD ] + re_ShowdownAction = re.compile('(?P.*) shows \[ (?P.+) \]') + + # TODO: read SUMMARY correctly for collected pot stuff. + #Uchilka, bets $11.75, collects $23.04, net $11.29 + re_CollectPot = re.compile('(?P.*), bets.+, collects \$(?P\d*\.?\d*), net.* ') + re_sitsOut = re.compile('(?P.*) sits out') def readSupportedGames(self): return [ @@ -193,13 +202,27 @@ class OnGame(HandHistoryConverter): # This re fails if, say, river is missing; then we don't get the ** that starts the river. #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) - m = re.search(r"PRE-FLOP(?P.+(?=FLOP)|.+(?=SHOWDOWN))" - r"(FLOP (?P\[board cards .+ \].+(?=TURN)|.+(?=SHOWDOWN)))?" - r"(TURN (?P\[board cards .+ \].+(?=RIVER)|.+(?=SHOWDOWN)))?" - r"(RIVER (?P\[board cards .+ \].+(?=SHOWDOWN)))?", hand.handText, re.DOTALL) + #if hand.gametype['base'] in ("hold"): + #elif hand.gametype['base'] in ("stud"): + #elif hand.gametype['base'] in ("draw"): + # only holdem so far: + m = re.search(r"pocket cards(?P.+(?=flop)|.+(?=Summary))" + r"(flop (?P\[\S\S, \S\S, \S\S\].+(?=turn)|.+(?=Summary)))?" + r"(turn (?P\[\S\S, \S\S, \S\S\, \S\S\].+(?=river)|.+(?=Summary)))?" + r"(river (?P\[\S\S, \S\S, \S\S\, \S\S, \S\S\].+(?=Summary)))?", hand.handText, re.DOTALL) hand.addStreets(m) - + + #Needs to return a list in the format + # ['player1name', 'player2name', ...] where player1name is the sb and player2name is bb, + # addtional players are assumed to post a bb oop + + def readButton(self, hand): + m = self.re_Button.search(hand.handText) + if m: + hand.buttonpos = int(m.group('BUTTON')) + else: + log.info(_('readButton: not found')) def readCommunityCards(self, hand, street): print hand.streets.group(street) @@ -218,6 +241,19 @@ class OnGame(HandHistoryConverter): for a in self.re_PostBoth.finditer(hand.handText): hand.addBlind(a.group('PNAME'), 'small & big blinds', a.group('SBBB')) + def readAntes(self, hand): + log.debug(_("reading antes")) + m = self.re_Antes.finditer(hand.handText) + for player in m: + #~ logging.debug("hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE'))) + hand.addAnte(player.group('PNAME'), player.group('ANTE')) + + def readBringIn(self, hand): + m = self.re_BringIn.search(hand.handText,re.DOTALL) + if m: + #~ logging.debug("readBringIn: %s for %s" %(m.group('PNAME'), m.group('BRINGIN'))) + hand.addBringIn(m.group('PNAME'), m.group('BRINGIN')) + def readHeroCards(self, hand): m = self.re_HeroCards.search(hand.handText) if(m == None):