Carbon/Merge: Fix blind reading

The new Merge network format has a timestamp in the blind line

Also made some of the error reporting more consistent with other parsers
This commit is contained in:
Worros 2010-09-17 11:44:58 +08:00
parent fbfaf0176c
commit 14bd767603

View File

@ -85,8 +85,8 @@ class Carbon(HandHistoryConverter):
# The following are also static regexes: there is no need to call # The following are also static regexes: there is no need to call
# compilePlayerRegexes (which does nothing), since players are identified # compilePlayerRegexes (which does nothing), since players are identified
# not by name but by seat number # not by name but by seat number
re_PostSB = re.compile(r'<event sequence="[0-9]+" type="(SMALL_BLIND|RETURN_BLIND)" player="(?P<PSEAT>[0-9])" amount="(?P<SB>[.0-9]+)"/>', re.MULTILINE) re_PostSB = re.compile(r'<event sequence="[0-9]+" type="(SMALL_BLIND|RETURN_BLIND)" (?P<TIMESTAMP>timestamp="[0-9]+" )?player="(?P<PSEAT>[0-9])" amount="(?P<SB>[.0-9]+)"/>', re.MULTILINE)
re_PostBB = re.compile(r'<event sequence="[0-9]+" type="(BIG_BLIND|INITIAL_BLIND)" player="(?P<PSEAT>[0-9])" amount="(?P<BB>[.0-9]+)"/>', re.MULTILINE) re_PostBB = re.compile(r'<event sequence="[0-9]+" type="(BIG_BLIND|INITIAL_BLIND)" (?P<TIMESTAMP>timestamp="[0-9]+" )?player="(?P<PSEAT>[0-9])" amount="(?P<BB>[.0-9]+)"/>', re.MULTILINE)
re_PostBoth = re.compile(r'<event sequence="[0-9]+" type="(RETURN_BLIND)" player="(?P<PSEAT>[0-9])" amount="(?P<SBBB>[.0-9]+)"/>', re.MULTILINE) re_PostBoth = re.compile(r'<event sequence="[0-9]+" type="(RETURN_BLIND)" player="(?P<PSEAT>[0-9])" amount="(?P<SBBB>[.0-9]+)"/>', re.MULTILINE)
#re_Antes = ??? #re_Antes = ???
#re_BringIn = ??? #re_BringIn = ???
@ -170,7 +170,7 @@ or None if we fail to get the info """
if m is None: if m is None:
logging.info(_("Didn't match re_HandInfo")) logging.info(_("Didn't match re_HandInfo"))
logging.info(hand.handText) logging.info(hand.handText)
return None raise FpdbParseError("No match in readHandInfo.")
logging.debug("HID %s-%s, Table %s" % (m.group('HID1'), logging.debug("HID %s-%s, Table %s" % (m.group('HID1'),
m.group('HID2'), m.group('TABLE')[:-1])) m.group('HID2'), m.group('TABLE')[:-1]))
hand.handid = m.group('HID1') + m.group('HID2') hand.handid = m.group('HID1') + m.group('HID2')
@ -181,7 +181,7 @@ or None if we fail to get the info """
# Check that the hand is complete up to the awarding of the pot; if # Check that the hand is complete up to the awarding of the pot; if
# not, the hand is unparseable # not, the hand is unparseable
if self.re_EndOfHand.search(hand.handText) is None: if self.re_EndOfHand.search(hand.handText) is None:
raise FpdbParseError(hid=m.group('HID1') + "-" + m.group('HID2')) raise FpdbParseError("readHandInfo failed: HID: '%s' HID2: '%s'" %(m.group('HID1'), m.group('HID2')))
def readPlayerStacks(self, hand): def readPlayerStacks(self, hand):
m = self.re_PlayerInfo.finditer(hand.handText) m = self.re_PlayerInfo.finditer(hand.handText)
@ -221,15 +221,13 @@ or None if we fail to get the info """
pass # ??? pass # ???
def readBlinds(self, hand): def readBlinds(self, hand):
try: for a in self.re_PostSB.finditer(hand.handText):
m = self.re_PostSB.search(hand.handText) #print "DEBUG: found sb: '%s' '%s'" %(self.playerNameFromSeatNo(a.group('PSEAT'), hand), a.group('SB'))
hand.addBlind(self.playerNameFromSeatNo(m.group('PSEAT'), hand), hand.addBlind(self.playerNameFromSeatNo(a.group('PSEAT'), hand),'small blind', a.group('SB'))
'small blind', m.group('SB'))
except: # no small blind
hand.addBlind(None, None, None)
for a in self.re_PostBB.finditer(hand.handText): for a in self.re_PostBB.finditer(hand.handText):
hand.addBlind(self.playerNameFromSeatNo(a.group('PSEAT'), hand), #print "DEBUG: found bb: '%s' '%s'" %(self.playerNameFromSeatNo(a.group('PSEAT'), hand), a.group('BB'))
'big blind', a.group('BB')) hand.addBlind(self.playerNameFromSeatNo(a.group('PSEAT'), hand), 'big blind', a.group('BB'))
for a in self.re_PostBoth.finditer(hand.handText): for a in self.re_PostBoth.finditer(hand.handText):
bb = Decimal(self.info['bb']) bb = Decimal(self.info['bb'])
amount = Decimal(a.group('SBBB')) amount = Decimal(a.group('SBBB'))