From 8911790408e34d49bfb07f22d89b44f30245a520 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 11 Sep 2010 16:11:16 +0800 Subject: [PATCH] iPoker: Update from initial Carbon template determineGameType: partially functional readHandInfo: partially functional readPlayerStacks: Done compilePlayerRegexes: Skipped markStreets: done for Stud readAntes: Needs doing readBlinds: Needs doing readBringIn: Needs doing ... readAction: Partially complete --- pyfpdb/iPokerToFpdb.py | 101 ++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 61 deletions(-) diff --git a/pyfpdb/iPokerToFpdb.py b/pyfpdb/iPokerToFpdb.py index 900b28ed..6714af7d 100644 --- a/pyfpdb/iPokerToFpdb.py +++ b/pyfpdb/iPokerToFpdb.py @@ -23,16 +23,8 @@ # # TODO: # -# -- No siteID assigned -# -- No support for games other than NL hold 'em cash. Hand histories for other -# games required -# -- No support for limit hold 'em yet, though this would be easy to add # -- No support for tournaments (see also the last item below) # -- Assumes that the currency of ring games is USD -# -- Only works for 'gametype="2"'. What is 'gametype'? -# -- Only accepts 'realmoney="true"' -# -- A hand's time-stamp does not record seconds past the minute (a -# limitation of the history format) # -- No support for a bring-in or for antes (is the latter in fact unnecessary # for hold 'em on Carbon?) # -- hand.maxseats can only be guessed at @@ -77,23 +69,19 @@ class iPoker(HandHistoryConverter): re_SplitHands = re.compile(r'\n+(?=)') re_GameInfo = re.compile(r'(?P[a-zA-Z0-9 ]+) \$(?P[.0-9]+)/\$(?P[.0-9]+)', re.MULTILINE) -# \$(?P[.0-9]+)\/\$(?P[.0-9]+)<\/gametype>', re.MULTILINE) - re_HandInfo = re.compile(r'[0-9]+)">\s+\s+(?P[-: 0-9]+)', re.MULTILINE) re_Button = re.compile(r'') - re_PlayerInfo = re.compile(r'', re.MULTILINE) + re_PlayerInfo = re.compile(r'', re.MULTILINE) re_PostBB = re.compile(r'', re.MULTILINE) re_PostBoth = re.compile(r'', re.MULTILINE) #re_Antes = ??? #re_BringIn = ??? re_HeroCards = re.compile(r'timestamp="[0-9]+" )?player="(?P[0-9])"( amount="(?P[.0-9]+)")?/>', re.MULTILINE) + re_Action = re.compile(r'', re.MULTILINE) re_CollectPot = re.compile(r'', re.MULTILINE) @@ -110,8 +98,11 @@ class iPoker(HandHistoryConverter): return p[1] def readSupportedGames(self): - return [["ring", "hold", "nl"], - ["tour", "hold", "nl"]] + return [ + ["ring", "stud", "fl"], + #["ring", "hold", "nl"], + #["tour", "hold", "nl"] + ] def determineGameType(self, handText): """return dict with keys/values: @@ -144,6 +135,7 @@ or None if we fail to get the info """ self.info = {} mg = m.groupdict() + print "DEBUG: m.groupdict(): %s" % mg limits = { 'No Limit':'nl', 'Limit':'fl' } games = { # base, category @@ -171,24 +163,21 @@ or None if we fail to get the info """ def readHandInfo(self, hand): m = self.re_HandInfo.search(hand.handText) if m is None: - logging.info(_("Didn't match re_HandInfo")) + logging.error(_("Didn't match re_HandInfo")) logging.info(hand.handText) - return None - logging.debug("HID %s-%s, Table %s" % (m.group('HID1'), - m.group('HID2'), m.group('TABLE')[:-1])) - hand.handid = m.group('HID1') + m.group('HID2') - hand.tablename = m.group('TABLE')[:-1] - hand.maxseats = 2 # This value may be increased as necessary - hand.startTime = datetime.datetime.strptime(m.group('DATETIME')[:12], - '%Y%m%d%H%M') - # Check that the hand is complete up to the awarding of the pot; if - # not, the hand is unparseable - if self.re_EndOfHand.search(hand.handText) is None: - raise FpdbParseError(hid=m.group('HID1') + "-" + m.group('HID2')) + raise FpdbParseError(_("Didn't match re_HandInfo")) + mg = m.groupdict() + print "DEBUG: m.groupdict(): %s" % mg + hand.handid = m.group('HID') + #hand.tablename = m.group('TABLE')[:-1] + hand.maxseats = None + hand.startTime = datetime.datetime.strptime(m.group('DATETIME'), '%Y-%m-%d %H:%M:%S') def readPlayerStacks(self, hand): m = self.re_PlayerInfo.finditer(hand.handText) for a in m: + ag = a.groupdict() + print "DEBUG: ag: %s" %ag seatno = int(a.group('SEAT')) # It may be necessary to adjust 'hand.maxseats', which is an # educated guess, starting with 2 (indicating a heads-up table) and @@ -202,12 +191,18 @@ or None if we fail to get the info """ hand.maxseats = 9 else: hand.maxseats = 6 - if a.group('DEALTIN') == "true": - hand.addPlayer(seatno, a.group('PNAME'), a.group('CASH')) + + hand.addPlayer(seatno, a.group('PNAME'), a.group('CASH')) def markStreets(self, hand): - #if hand.gametype['base'] == 'hold': - m = re.search(r'(?P.+(?=(?P.+(?=(?P.+(?=(?P.+))?', hand.handText, re.DOTALL) + if hand.gametype['base'] in ('stud'): + m = re.search(r'(?P.+(?=)|.+)' + r'((?P.+(?=)|.+))?' + r'((?P.+(?=)|.+))?' + r'((?P.+(?=)|.+))?' + r'((?P.+(?=)|.+))?' + r'((?P.+))?', hand.handText,re.DOTALL) + hand.addStreets(m) def readCommunityCards(self, hand, street): @@ -224,27 +219,11 @@ or None if we fail to get the info """ pass # ??? def readBlinds(self, hand): - try: - m = self.re_PostSB.search(hand.handText) - hand.addBlind(self.playerNameFromSeatNo(m.group('PSEAT'), hand), - 'small blind', m.group('SB')) - except: # no small blind - hand.addBlind(None, None, None) + m = self.re_PostSB.search(hand.handText) + hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB')) for a in self.re_PostBB.finditer(hand.handText): - hand.addBlind(self.playerNameFromSeatNo(a.group('PSEAT'), hand), - 'big blind', a.group('BB')) - for a in self.re_PostBoth.finditer(hand.handText): - bb = Decimal(self.info['bb']) - amount = Decimal(a.group('SBBB')) - if amount < bb: - hand.addBlind(self.playerNameFromSeatNo(a.group('PSEAT'), - hand), 'small blind', a.group('SBBB')) - elif amount == bb: - hand.addBlind(self.playerNameFromSeatNo(a.group('PSEAT'), - hand), 'big blind', a.group('SBBB')) - else: - hand.addBlind(self.playerNameFromSeatNo(a.group('PSEAT'), - hand), 'both', a.group('SBBB')) + hand.addBlind(m.group('PNAME'), 'big blind', a.group('BB')) + #for a in self.re_PostBoth.finditer(hand.handText): def readButton(self, hand): hand.buttonpos = int(self.re_Button.search(hand.handText).group('BUTTON')) @@ -261,24 +240,24 @@ or None if we fail to get the info """ logging.debug("readAction (%s)" % street) m = self.re_Action.finditer(hand.streets[street]) for action in m: + ag = action.groupdict() + print "DEBUG: action.groupdict: %s" % ag logging.debug("%s %s" % (action.group('ATYPE'), action.groupdict())) - player = self.playerNameFromSeatNo(action.group('PSEAT'), hand) if action.group('ATYPE') == 'RAISE': hand.addCallandRaise(street, player, action.group('BET')) - elif action.group('ATYPE') == 'CALL': - hand.addCall(street, player, action.group('BET')) + elif action.group('ATYPE') == '3': # Believe this is 'call' + hand.addCall(street, action.group('PNAME'), action.group('BET')) elif action.group('ATYPE') == 'BET': hand.addBet(street, player, action.group('BET')) - elif action.group('ATYPE') in ('FOLD', 'SIT_OUT'): - hand.addFold(street, player) + elif action.group('ATYPE') == '0': # Belive this is 'fold' + hand.addFold(street, action.group('PNAME')) elif action.group('ATYPE') == 'CHECK': hand.addCheck(street, player) elif action.group('ATYPE') == 'ALL_IN': hand.addAllIn(street, player, action.group('BET')) else: - logging.debug(_("Unimplemented readAction: %s %s" - % (action.group('PSEAT'),action.group('ATYPE'),))) + logging.error(_("Unimplemented readAction: %s" % (ag))) def readShowdownActions(self, hand): for shows in self.re_ShowdownAction.finditer(hand.handText):