From 0058f47775ed2e3d17459a02d7ee5390c6dc7495 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Wed, 11 Mar 2009 16:51:58 +0000 Subject: [PATCH 1/2] fulltilt razz. is this complete? can you check whether it imports? --- pyfpdb/EverleafToFpdb.py | 2 +- pyfpdb/FulltiltToFpdb.py | 4 +- pyfpdb/Hand.py | 99 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 94 insertions(+), 11 deletions(-) diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py index 97b636c2..feff7175 100755 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -297,7 +297,7 @@ or None if we fail to get the info """ if __name__ == "__main__": parser = OptionParser() - parser.add_option("-i", "--input", dest="ipath", help="parse input hand history", default="regression-test-files/everleaf/studhi/Plymouth.txt") + parser.add_option("-i", "--input", dest="ipath", help="parse input hand history", default="-") parser.add_option("-o", "--output", dest="opath", help="output translation to", default="-") parser.add_option("-f", "--follow", dest="follow", help="follow (tail -f) the input", action="store_true", default=False) parser.add_option("-q", "--quiet", diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index 6ba128fc..e585c67a 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -60,7 +60,7 @@ follow : whether to tail -f the input""" self.re_BringIn = re.compile(r"^%s brings in for \$?(?P[.0-9]+)" % player_re, re.MULTILINE) self.re_PostBoth = re.compile(r"^%s posts small \& big blinds \[\$? (?P[.0-9]+)" % player_re, re.MULTILINE) self.re_HeroCards = re.compile(r"^Dealt to %s(?: \[(?P.+?)\])?( \[(?P.+?)\])" % player_re, re.MULTILINE) - self.re_Action = re.compile(r"^%s(?P bets| checks| raises to| calls| folds)(\s\$(?P[.\d]+))?" % player_re, re.MULTILINE) + self.re_Action = re.compile(r"^%s(?P bets| checks| raises to| completes it to| calls| folds)(\s\$(?P[.\d]+))?" % player_re, re.MULTILINE) self.re_ShowdownAction = re.compile(r"^%s shows \[(?P.*)\]" % player_re, re.MULTILINE) self.re_CollectPot = re.compile(r"^Seat (?P[0-9]+): %s (\(button\) |\(small blind\) |\(big blind\) )?(collected|showed \[.*\] and won) \(\$(?P[.\d]+)\)(, mucked| with.*)" % player_re, re.MULTILINE) self.re_SitsOut = re.compile(r"^%s sits out" % player_re, re.MULTILINE) @@ -265,6 +265,8 @@ follow : whether to tail -f the input""" for action in m: if action.group('ATYPE') == ' raises to': hand.addRaiseTo( street, action.group('PNAME'), action.group('BET') ) + if action.group('ATYPE') == ' completes it to': + hand.addComplete( 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': diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index b72ef9f1..6f06572d 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -129,6 +129,7 @@ If a player has None chips he won't be added.""" self.stacks[player] -= Decimal(ante) act = (player, 'posts', "ante", ante, self.stacks[player]==0) self.actions['ANTES'].append(act) + #~ self.lastBet['ANTES'] = Decimal(ante) self.pot.addMoney(player, Decimal(ante)) def addBlind(self, player, blindtype, amount): @@ -355,6 +356,8 @@ Map the tuple self.gametype onto the pokerstars string describing it print >>fh, _("%s: bets $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'raises': print >>fh, _("%s: raises $%s to $%s%s" %(act[0], act[2], act[3], ' and is all-in' if act[5] else '')) + elif act[1] == 'completea': + print >>fh, _("%s: completes to $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'posts': if(act[2] == "small blind"): print >>fh, _("%s: posts small blind $%s" %(act[0], act[3])) @@ -362,7 +365,8 @@ Map the tuple self.gametype onto the pokerstars string describing it print >>fh, _("%s: posts big blind $%s" %(act[0], act[3])) elif(act[2] == "both"): print >>fh, _("%s: posts small & big blinds $%s" %(act[0], act[3])) - + elif act[1] == 'bringin': + print >>fh, _("%s: brings in for $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) class HoldemOmahaHand(Hand): def __init__(self, hhc, sitename, gametype, handText): if gametype['base'] != 'hold': @@ -596,13 +600,35 @@ closed likewise, but known only to player except FpdbParseError, e: print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) + # TODO: def addComplete(self, player, amount): + def addComplete(self, street, player, amountTo): + # assert street=='THIRD' + # This needs to be called instead of addRaiseTo, and it needs to take account of self.lastBet['THIRD'] to determine the raise-by size + """\ +Add a complete on [street] by [player] to [amountTo] +""" + self.checkPlayerExists(player) + Bp = self.lastBet['THIRD'] + Bc = reduce(operator.add, self.bets[street][player], 0) + Rt = Decimal(amountTo) + C = Bp - Bc + Rb = Rt - C + self._addRaise(street, player, C, Rb, Rt) + #~ self.bets[street][player].append(C + Rb) + #~ self.stacks[player] -= (C + Rb) + #~ act = (player, 'raises', Rb, Rt, C, self.stacks[player]==0) + #~ self.actions[street].append(act) + #~ self.lastBet[street] = Rt # TODO check this is correct + #~ self.pot.addMoney(player, C+Rb) + def addBringIn(self, player, bringin): if player is not None: logging.debug("Bringin: %s, %s" % (player , bringin)) self.bets['THIRD'][player].append(Decimal(bringin)) self.stacks[player] -= Decimal(bringin) - act = (player, 'bringin', "bringin", bringin, self.stacks[player]==0) + act = (player, 'bringin', bringin, self.stacks[player]==0) self.actions['THIRD'].append(act) + self.lastBet['THIRD'] = Decimal(bringin) self.pot.addMoney(player, Decimal(bringin)) def writeHand(self, fh=sys.__stdout__): @@ -621,33 +647,88 @@ closed likewise, but known only to player print >>fh, _("%s: posts the ante $%s" %(act[0], act[3])) if 'THIRD' in self.actions: - print >>fh, _("*** 3RD STREET ***") + dealt = 0 + #~ print >>fh, _("*** 3RD STREET ***") for player in [x[1] for x in self.players if x[1] in players_who_post_antes]: - print player, self.holecards[player] if 'THIRD' in self.holecards[player]: - (closed, open) = self.holecards[player]['THIRD'] - print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(closed) + "]" if closed else " ", " [" + " ".join(open) + "]" if open else " ") + (open, closed) = self.holecards[player]['THIRD'] + dealt+=1 + if dealt==1: + print >>fh, _("*** 3RD STREET ***") + print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(closed) + "] " if closed else " ", "[" + " ".join(open) + "]" if open else "") for act in self.actions['THIRD']: #FIXME: Need some logic here for bringin vs completes self.printActionLine(act, fh) if 'FOURTH' in self.actions: - print >>fh, _("*** 4TH STREET ***") + dealt = 0 + #~ print >>fh, _("*** 4TH STREET ***") + for player in [x[1] for x in self.players if x[1] in players_who_post_antes]: + if 'FOURTH' in self.holecards[player]: + old = [] + (o,c) = self.holecards[player]['THIRD'] + if o:old.extend(o) + if c:old.extend(c) + new = self.holecards[player]['FOURTH'][0] + dealt+=1 + if dealt==1: + print >>fh, _("*** 4TH STREET ***") + print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(old) + "] " if old else " ", "[" + " ".join(new) + "]" if new else "") for act in self.actions['FOURTH']: self.printActionLine(act, fh) if 'FIFTH' in self.actions: - print >>fh, _("*** 5TH STREET ***") + dealt = 0 + #~ print >>fh, _("*** 5TH STREET ***") + for player in [x[1] for x in self.players if x[1] in players_who_post_antes]: + if 'FIFTH' in self.holecards[player]: + old = [] + for street in ('THIRD','FOURTH'): + (o,c) = self.holecards[player][street] + if o:old.extend(o) + if c:old.extend(c) + new = self.holecards[player]['FIFTH'][0] + dealt+=1 + if dealt==1: + print >>fh, _("*** 5TH STREET ***") + print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(old) + "] " if old else " ", "[" + " ".join(new) + "]" if new else "") for act in self.actions['FIFTH']: self.printActionLine(act, fh) if 'SIXTH' in self.actions: - print >>fh, _("*** 6TH STREET ***") + dealt = 0 + #~ print >>fh, _("*** 6TH STREET ***") + for player in [x[1] for x in self.players if x[1] in players_who_post_antes]: + if 'SIXTH' in self.holecards[player]: + old = [] + for street in ('THIRD','FOURTH','FIFTH'): + (o,c) = self.holecards[player][street] + if o:old.extend(o) + if c:old.extend(c) + new = self.holecards[player]['SIXTH'][0] + dealt += 1 + if dealt == 1: + print >>fh, _("*** 6TH STREET ***") + print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(old) + "] " if old else " ", "[" + " ".join(new) + "]" if new else "") for act in self.actions['SIXTH']: self.printActionLine(act, fh) if 'SEVENTH' in self.actions: + # OK. It's possible that they're all in at an earlier street, but only closed cards are dealt. + # Then we have no 'dealt to' lines, no action lines, but still 7th street should appear. + # The only way I can see to know whether to print this line is by knowing the state of the hand + # i.e. are all but one players folded; is there an allin showdown; and all that. print >>fh, _("*** 7TH STREET ***") + for player in [x[1] for x in self.players if x[1] in players_who_post_antes]: + if 'SEVENTH' in self.holecards[player]: + old = [] + for street in ('THIRD','FOURTH','FIFTH','SIXTH'): + (o,c) = self.holecards[player][street] + if o:old.extend(o) + if c:old.extend(c) + new = self.holecards[player]['SEVENTH'][0] + if new: + print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(old) + "] " if old else " ", "[" + " ".join(new) + "]" if new else "") for act in self.actions['SEVENTH']: self.printActionLine(act, fh) From 89bb8e3d69a6af7b57772e34fb57c037f1f63f30 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Wed, 11 Mar 2009 18:40:17 +0000 Subject: [PATCH 2/2] stars stud sometimes says 'brings-in', 'brings in', 'brings in low' fewer negative rakes appearing. --- pyfpdb/EverleafToFpdb.py | 2 +- pyfpdb/Hand.py | 18 ++++++++++++------ pyfpdb/PokerStarsToFpdb.py | 16 ++++++++-------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py index feff7175..18466edc 100755 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -264,7 +264,7 @@ or None if we fail to get the info """ elif action.group('ATYPE') == ' checks': hand.addCheck( street, action.group('PNAME')) elif action.group('ATYPE') == ' complete to': - hand.addCallandRaise( street, action.group('PNAME'), action.group('BET')) + hand.addComplete( street, action.group('PNAME'), action.group('BET')) else: logging.debug("Unimplemented readAction: %s %s" %(action.group('PNAME'),action.group('ATYPE'),)) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 6f06572d..f77b9425 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -124,6 +124,7 @@ If a player has None chips he won't be added.""" return c def addAnte(self, player, ante): + logging.debug("%s %s antes %s" % ('ANTES', player, ante)) if player is not None: self.bets['ANTES'][player].append(Decimal(ante)) self.stacks[player] -= Decimal(ante) @@ -160,6 +161,7 @@ If a player has None chips he won't be added.""" def addCall(self, street, player=None, amount=None): + logging.debug("%s %s calls %s" %(street, player, amount)) # Potentially calculate the amount of the call if not supplied # corner cases include if player would be all in if amount is not None: @@ -193,10 +195,11 @@ Add a raise by amountBy on [street] by [player] C = Bp - Bc Rt = Bp + Rb - self.bets[street][player].append(C + Rb) - self.stacks[player] -= (C + Rb) - self.actions[street] += [(player, 'raises', Rb, Rt, C, self.stacks[player]==0)] - self.lastBet[street] = Rt + self._addRaise(street, player, C, Rb, Rt) + #~ self.bets[street][player].append(C + Rb) + #~ self.stacks[player] -= (C + Rb) + #~ self.actions[street] += [(player, 'raises', Rb, Rt, C, self.stacks[player]==0)] + #~ self.lastBet[street] = Rt def addCallandRaise(self, street, player, amount): """\ @@ -225,6 +228,7 @@ Add a raise on [street] by [player] to [amountTo] self._addRaise(street, player, C, Rb, Rt) def _addRaise(self, street, player, C, Rb, Rt): + logging.debug("%s %s raise %s" %(street, player, Rt)) self.bets[street][player].append(C + Rb) self.stacks[player] -= (C + Rb) act = (player, 'raises', Rb, Rt, C, self.stacks[player]==0) @@ -235,6 +239,7 @@ Add a raise on [street] by [player] to [amountTo] def addBet(self, street, player, amount): + logging.debug("%s %s bets %s" %(street, player, amount)) self.checkPlayerExists(player) self.bets[street][player].append(Decimal(amount)) self.stacks[player] -= Decimal(amount) @@ -246,7 +251,7 @@ Add a raise on [street] by [player] to [amountTo] def addFold(self, street, player): - #print "DEBUG: %s %s folded" % (street, player) + logging.debug("%s %s folds" % (street, player)) self.checkPlayerExists(player) self.folded.add(player) self.pot.addFold(player) @@ -260,7 +265,7 @@ Add a raise on [street] by [player] to [amountTo] def addCollectPot(self,player, pot): - #print "DEBUG: %s collected %s" % (player, pot) + logging.debug("%s collected %s" % (player, pot)) self.checkPlayerExists(player) self.collected = self.collected + [[player, pot]] if player not in self.collectees: @@ -607,6 +612,7 @@ closed likewise, but known only to player """\ Add a complete on [street] by [player] to [amountTo] """ + logging.debug("%s %s completes %s" % (street, player, amountTo)) self.checkPlayerExists(player) Bp = self.lastBet['THIRD'] Bc = reduce(operator.add, self.bets[street][player], 0) diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index b437e4ce..05027121 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -100,12 +100,12 @@ follow : whether to tail -f the input""" self.re_PostSB = re.compile(r"^%s: posts small blind \$?(?P[.0-9]+)" % player_re, re.MULTILINE) self.re_PostBB = re.compile(r"^%s: posts big blind \$?(?P[.0-9]+)" % player_re, re.MULTILINE) self.re_Antes = re.compile(r"^%s: posts the ante \$?(?P[.0-9]+)" % player_re, re.MULTILINE) - self.re_BringIn = re.compile(r"^%s: brings-in low for \$?(?P[.0-9]+)" % player_re, re.MULTILINE) + self.re_BringIn = re.compile(r"^%s: brings[- ]in( low|) for \$?(?P[.0-9]+)" % player_re, re.MULTILINE) self.re_PostBoth = re.compile(r"^%s: posts small \& big blinds \[\$? (?P[.0-9]+)" % player_re, re.MULTILINE) self.re_HeroCards = re.compile(r"^Dealt to %s(?: \[(?P.+?)\])?( \[(?P.+?)\])" % player_re, re.MULTILINE) - self.re_Action = re.compile(r"^%s:(?P bets| checks| raises| calls| folds)( \$(?P[.\d]+))?" % player_re, re.MULTILINE) + self.re_Action = re.compile(r"^%s:(?P bets| checks| raises| calls| folds)( \$(?P[.\d]+))?( to \$(?P[.\d]+))?" % player_re, re.MULTILINE) self.re_ShowdownAction = re.compile(r"^%s: shows \[(?P.*)\]" % player_re, re.MULTILINE) - self.re_CollectPot = re.compile(r"Seat (?P[0-9]+): %s (\(button\) |\(small blind\) |\(big blind\) )?(collected|showed \[.*\] and won) \(\$(?P[.\d]+)\)(, mucked| with.*)" % player_re, re.MULTILINE) + self.re_CollectPot = re.compile(r"Seat (?P[0-9]+): %s (\(button\) |\(small blind\) |\(big blind\) )?(collected|showed \[.*\] and won) \(\$(?P[.\d]+)\)(, mucked| with.*|)" % player_re, re.MULTILINE) self.re_sitsOut = re.compile("^%s sits out" % player_re, re.MULTILINE) self.re_ShownCards = re.compile("^Seat (?P[0-9]+): %s \(.*\) showed \[(?P.*)\].*" % player_re, re.MULTILINE) @@ -197,8 +197,8 @@ follow : whether to tail -f the input""" r"(\*\*\* 3rd STREET \*\*\*(?P.+(?=\*\*\* 4th STREET \*\*\*)|.+))?" r"(\*\*\* 4th STREET \*\*\*(?P.+(?=\*\*\* 5th STREET \*\*\*)|.+))?" r"(\*\*\* 5th STREET \*\*\*(?P.+(?=\*\*\* 6th STREET \*\*\*)|.+))?" - r"(\*\*\* 6th STREET \*\*\*(?P.+(?=\*\*\* 7th STREET \*\*\*)|.+))?" - r"(\*\*\* 7th STREET \*\*\*(?P.+))?", hand.handText,re.DOTALL) + r"(\*\*\* 6th STREET \*\*\*(?P.+(?=\*\*\* RIVER \*\*\*)|.+))?" + r"(\*\*\* RIVER \*\*\*(?P.+))?", hand.handText,re.DOTALL) hand.addStreets(m) def readCommunityCards(self, hand, street): # street has been matched by markStreets, so exists in this hand @@ -211,13 +211,13 @@ follow : whether to tail -f the input""" logging.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'))) + #~ 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'))) + #~ logging.debug("readBringIn: %s for %s" %(m.group('PNAME'), m.group('BRINGIN'))) hand.addBringIn(m.group('PNAME'), m.group('BRINGIN')) def readBlinds(self, hand): @@ -249,7 +249,7 @@ follow : whether to tail -f the input""" logging.debug("readStudPlayerCards") m = self.re_HeroCards.finditer(hand.streets[street]) for player in m: - logging.debug(player.groupdict()) + #~ logging.debug(player.groupdict()) (pname, oldcards, newcards) = (player.group('PNAME'), player.group('OLDCARDS'), player.group('NEWCARDS')) if oldcards: oldcards = [c.strip() for c in oldcards.split(' ')]