From 021b9934eab2804009183ccce90ced20c9ba712f Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 14 Jul 2009 19:18:38 -0400 Subject: [PATCH 01/15] Fix writing of mixed tournament hands. Other minor changes. --- pyfpdb/Hand.py | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 1846b240..a14ecaeb 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -545,22 +545,25 @@ Map the tuple self.gametype onto the pokerstars string describing it return ("%s: stands pat" %(act[0])) def getStakesAsString(self): - retstring = "%s%s/%s%s" % (self.SYMBOL[self.gametype['currency']], self.sb, self.SYMBOL[self.gametype['currency']], self.bb) - return retstring + """Return a string of the stakes of the current hand.""" + return "%s%s/%s%s" % (self.sym, self.sb, self.sym, self.bb) def writeGameLine(self): -# print >>fh, ("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET'))) - game_string = "PokerStars Game #%s: " % self.handid - if self.tourNo != None: - game_string = game_string + "Tournament #%s, %s %s - Level %s (%s) - " % (self.tourNo, + """Return the first HH line for the current hand.""" + gs = "PokerStars Game #%s: " % self.handid + + if self.tourNo != None and self.mixed != None: # mixed tournament + gs = gs + "Tournament #%s, %s %s (%s) - Level %s (%s) - " % (self.tourNo, self.buyin, self.MS[self.mixed], self.getGameTypeAsString(), self.level, self.getStakesAsString()) + elif self.tourNo != None: # all other tournaments + gs = gs + "Tournament #%s, %s %s - Level %s (%s) - " % (self.tourNo, self.buyin, self.getGameTypeAsString(), self.level, self.getStakesAsString()) - elif self.mixed != None: - game_string = game_string + " %s (%s, %s) - " % (self.MS[self.mixed], + elif self.mixed != None: # all other mixed games + gs = gs + " %s (%s, %s) - " % (self.MS[self.mixed], self.getGameTypeAsString(), self.getStakesAsString()) - else: - game_string = game_string + " %s (%s) - " % (self.getGameTypeAsString(), self.getStakesAsString()) - game_string = game_string + datetime.datetime.strftime(self.starttime,'%Y/%m/%d %H:%M:%S ET') - return game_string + else: # non-mixed cash games + gs = gs + " %s (%s) - " % (self.getGameTypeAsString(), self.getStakesAsString()) + + return gs + datetime.datetime.strftime(self.starttime,'%Y/%m/%d %H:%M:%S ET') def writeTableLine(self): @@ -723,12 +726,10 @@ class HoldemOmahaHand(Hand): def writeHand(self, fh=sys.__stdout__): # PokerStars format. -# print >>fh, ("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET'))) + self.sym = self.SYMBOL[self.gametype['currency']] # save typing! delete this attr when done print >>fh, self.writeGameLine() print >>fh, self.writeTableLine() -# print >>fh, ("Table '%s' %d-max Seat #%s is the button" %(self.tablename, self.maxseats, self.buttonpos)) - players_who_act_preflop = set(([x[0] for x in self.actions['PREFLOP']]+[x[0] for x in self.actions['BLINDSANTES']])) logging.debug(self.actions['PREFLOP']) for player in [x for x in self.players if x[1] in players_who_act_preflop]: @@ -972,9 +973,8 @@ class DrawHand(Hand): def writeHand(self, fh=sys.__stdout__): # PokerStars format. -# print >>fh, _("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, time.strftime('%Y/%m/%d %H:%M:%S ET', self.starttime))) + self.sym = self.SYMBOL[self.gametype['currency']] # save typing! delete this attr when done print >>fh, self.writeGameLine() -# print >>fh, _("Table '%s' %d-max Seat #%s is the button" %(self.tablename, self.maxseats, self.buttonpos)) print >>fh, self.writeTableLine() players_who_act_ondeal = set(([x[0] for x in self.actions['DEAL']]+[x[0] for x in self.actions['BLINDSANTES']])) @@ -1188,16 +1188,14 @@ Add a complete on [street] by [player] to [amountTo] def writeHand(self, fh=sys.__stdout__): # PokerStars format. -# print >>fh, _("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, time.strftime('%Y/%m/%d - %H:%M:%S (ET)', self.starttime))) # TODO: # Hole cards are not currently correctly written. Currently the down cards for non-heros # are shown in the "dealt to" lines. They should be hidden in those lines. I tried to fix # but mind got boggled, will try again. -# print >>fh, _("%s Game #%s: %s ($%s/$%s) - %s" %("PokerStars", self.handid, self.getGameTypeAsString(), self.sb, self.bb, datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET'))) + self.sym = self.SYMBOL[self.gametype['currency']] # save typing! delete this attr when done print >>fh, self.writeGameLine() print >>fh, self.writeTableLine() -# print >>fh, _("Table '%s' %d-max Seat #%s is the button" %(self.tablename, self.maxseats, self.buttonpos)) players_who_post_antes = set([x[0] for x in self.actions['ANTES']]) From 0e76c3a6767e24e3ad7089558e396f4678d9ec34 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 Jul 2009 11:48:58 -0400 Subject: [PATCH 02/15] Fix findHeroCards() for empty streets. --- pyfpdb/PokerStarsToFpdb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 5661e16e..dbed145b 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -299,6 +299,7 @@ follow : whether to tail -f the input""" for street, text in hand.streets.iteritems(): if street in ('PREFLOP', 'DEAL'): continue # already done these + if hand.streets[street] == None: continue # don't regex a None m = self.re_HeroCards.finditer(hand.streets[street]) for found in m: player = found.group('PNAME') @@ -398,7 +399,7 @@ follow : whether to tail -f the input""" def readShowdownActions(self, hand): -# TODO: pick up mucks also +# TODO: pick up mucks also?? for shows in self.re_ShowdownAction.finditer(hand.handText): cards = shows.group('CARDS').split(' ') hand.addShownCards(cards, shows.group('PNAME')) From bd2db9861210d673d012c03569e837a704beba59 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 Jul 2009 11:50:27 -0400 Subject: [PATCH 03/15] Housecleaning. Refactoring writeHand() = not finished. --- pyfpdb/Hand.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index a14ecaeb..8cac4e7a 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -32,7 +32,7 @@ import pprint import DerivedStats import Card -class Hand: +class Hand(object): ###############################################################3 # Class Variables @@ -575,6 +575,13 @@ Map the tuple self.gametype onto the pokerstars string describing it return table_string + def writeHand(self, fh=sys.__stdout__): + # PokerStars format. + self.sym = self.SYMBOL[self.gametype['currency']] # save typing! delete this attr when done + print >>fh, self.writeGameLine() + print >>fh, self.writeTableLine() + + class HoldemOmahaHand(Hand): def __init__(self, hhc, sitename, gametype, handText, builtFrom = "HHC", handid=None): if gametype['base'] != 'hold': @@ -726,9 +733,7 @@ class HoldemOmahaHand(Hand): def writeHand(self, fh=sys.__stdout__): # PokerStars format. - self.sym = self.SYMBOL[self.gametype['currency']] # save typing! delete this attr when done - print >>fh, self.writeGameLine() - print >>fh, self.writeTableLine() + super(HoldemOmahaHand, self).writeHand(fh) players_who_act_preflop = set(([x[0] for x in self.actions['PREFLOP']]+[x[0] for x in self.actions['BLINDSANTES']])) logging.debug(self.actions['PREFLOP']) @@ -973,9 +978,7 @@ class DrawHand(Hand): def writeHand(self, fh=sys.__stdout__): # PokerStars format. - self.sym = self.SYMBOL[self.gametype['currency']] # save typing! delete this attr when done - print >>fh, self.writeGameLine() - print >>fh, self.writeTableLine() + super(DrawHand, self).writeHand(fh) players_who_act_ondeal = set(([x[0] for x in self.actions['DEAL']]+[x[0] for x in self.actions['BLINDSANTES']])) @@ -1193,9 +1196,7 @@ Add a complete on [street] by [player] to [amountTo] # Hole cards are not currently correctly written. Currently the down cards for non-heros # are shown in the "dealt to" lines. They should be hidden in those lines. I tried to fix # but mind got boggled, will try again. - self.sym = self.SYMBOL[self.gametype['currency']] # save typing! delete this attr when done - print >>fh, self.writeGameLine() - print >>fh, self.writeTableLine() + super(StudHand, self).writeHand(fh) players_who_post_antes = set([x[0] for x in self.actions['ANTES']]) From 427999b69cbb2c4b0afa3ed8807d10d66847c728 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 Jul 2009 21:22:07 -0400 Subject: [PATCH 04/15] Correctly write stud holecards in writeHand(). --- pyfpdb/Hand.py | 58 +++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 8c1e2173..fbb4b491 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -286,6 +286,7 @@ If a player has None chips he won't be added.""" def setCommunityCards(self, street, cards): logging.debug("setCommunityCards %s %s" %(street, cards)) self.board[street] = [self.card(c) for c in cards] +# print "DEBUG: self.board: %s" % self.board def card(self,c): """upper case the ranks but not suits, 'atjqk' => 'ATJQK'""" @@ -1060,7 +1061,7 @@ class StudHand(Hand): self.actionStreets = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] self.streetList = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] # a list of the observed street names in order - self.holeStreets = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] + self.holeStreets = ['THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] Hand.__init__(self, sitename, gametype, handText) self.sb = gametype['sb'] self.bb = gametype['bb'] @@ -1097,9 +1098,9 @@ class StudHand(Hand): else: # self.addHoleCards('PREFLOP', player, open=[], closed=cards, shown=shown, mucked=mucked, dealt=dealt) self.addHoleCards('THIRD', player, open=[cards[2]], closed=cards[0:2], shown=shown, mucked=mucked) - self.addHoleCards('FOURTH', player, open=[cards[3]], closed=[], shown=shown, mucked=mucked) - self.addHoleCards('FIFTH', player, open=[cards[4]], closed=[], shown=shown, mucked=mucked) - self.addHoleCards('SIXTH', player, open=[cards[5]], closed=[], shown=shown, mucked=mucked) + self.addHoleCards('FOURTH', player, open=[cards[3]], closed=[cards[2]], shown=shown, mucked=mucked) + self.addHoleCards('FIFTH', player, open=[cards[4]], closed=cards[2:4], shown=shown, mucked=mucked) + self.addHoleCards('SIXTH', player, open=[cards[5]], closed=cards[2:5], shown=shown, mucked=mucked) self.addHoleCards('SEVENTH', player, open=[], closed=[cards[6]], shown=shown, mucked=mucked) @@ -1216,7 +1217,8 @@ Add a complete on [street] by [player] to [amountTo] 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 "") +# print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(closed) + "] " if closed else " ", "[" + " ".join(open) + "]" if open else "") + print >>fh, self.writeHoleCards('THIRD', player) for act in self.actions['THIRD']: #FIXME: Need some logic here for bringin vs completes print >>fh, self.actionString(act) @@ -1226,15 +1228,10 @@ Add a complete on [street] by [player] to [amountTo] #~ print >>fh, _("*** 4TH STREET ***") for player in [x[1] for x in self.players if x[1] in players_who_post_antes]: if player in self.holecards['FOURTH']: - old = [] - (o,c) = self.holecards['THIRD'][player] - if o:old.extend(o) - if c:old.extend(c) - new = self.holecards['FOURTH'][player][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 "") + print >>fh, self.writeHoleCards('FOURTH', player) for act in self.actions['FOURTH']: print >>fh, self.actionString(act) @@ -1243,16 +1240,10 @@ Add a complete on [street] by [player] to [amountTo] #~ print >>fh, _("*** 5TH STREET ***") for player in [x[1] for x in self.players if x[1] in players_who_post_antes]: if self.holecards['FIFTH'].has_key(player): - old = [] - for street in ('THIRD','FOURTH'): - (o,c) = self.holecards[street][player] - if o:old.extend(o) - if c:old.extend(c) - new = self.holecards['FIFTH'][player][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 "") + print >>fh, self.writeHoleCards('FIFTH', player) for act in self.actions['FIFTH']: print >>fh, self.actionString(act) @@ -1261,16 +1252,10 @@ Add a complete on [street] by [player] to [amountTo] #~ print >>fh, _("*** 6TH STREET ***") for player in [x[1] for x in self.players if x[1] in players_who_post_antes]: if self.holecards['SIXTH'].has_key(player): - old = [] - for street in ('THIRD','FOURTH','FIFTH'): - (o,c) = self.holecards[street][player] - if o:old.extend(o) - if c:old.extend(c) - new = self.holecards['SIXTH'][player][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 "") + print >>fh, self.writeHoleCards('SIXTH', player) for act in self.actions['SIXTH']: print >>fh, self.actionString(act) @@ -1279,17 +1264,11 @@ Add a complete on [street] by [player] to [amountTo] # 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 ***") + print >>fh, _("*** RIVER ***") for player in [x[1] for x in self.players if x[1] in players_who_post_antes]: if self.holecards['SEVENTH'].has_key(player): - old = [] - for street in ('THIRD','FOURTH','FIFTH','SIXTH'): - (o,c) = self.holecards[street][player] - if o:old.extend(o) - if c:old.extend(c) - new = self.holecards['SEVENTH'][player][0] - if new: - print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(old) + "] " if old else " ", "[" + " ".join(new) + "]" if new else "") + if self.writeHoleCards('SEVENTH', player): + print >>fh, self.writeHoleCards('SEVENTH', player) for act in self.actions['SEVENTH']: print >>fh, self.actionString(act) @@ -1341,6 +1320,17 @@ Add a complete on [street] by [player] to [amountTo] print >>fh, "\n\n" + def writeHoleCards(self, street, player): + hc = "Dealt to %s [" % player + if street == 'THIRD': + if player == self.hero: + return hc + " ".join(self.holecards[street][player][1]) + " " + " ".join(self.holecards[street][player][0]) + ']' + else: + return hc + " ".join(self.holecards[street][player][0]) + ']' + + if street == 'SEVENTH' and player != self.hero: return # only write 7th st line for hero, LDO + return hc + " ".join(self.holecards[street][player][1]) + "][" + " ".join(self.holecards[street][player][0]) + "]" + def join_holecards(self, player): holecards = [] for street in self.holeStreets: From 12db3c0d55b660c6f9045d3373f856f930411c5d Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 Jul 2009 21:46:45 -0400 Subject: [PATCH 05/15] Add a space to make stud holecard printing perfect. --- pyfpdb/Hand.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index fbb4b491..c97e88f1 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -733,6 +733,7 @@ class HoldemOmahaHand(Hand): def writeHand(self, fh=sys.__stdout__): # PokerStars format. +# TODO: board cards (in summary) not printed in correct order super(HoldemOmahaHand, self).writeHand(fh) players_who_act_preflop = set(([x[0] for x in self.actions['PREFLOP']]+[x[0] for x in self.actions['BLINDSANTES']])) @@ -1329,7 +1330,7 @@ Add a complete on [street] by [player] to [amountTo] return hc + " ".join(self.holecards[street][player][0]) + ']' if street == 'SEVENTH' and player != self.hero: return # only write 7th st line for hero, LDO - return hc + " ".join(self.holecards[street][player][1]) + "][" + " ".join(self.holecards[street][player][0]) + "]" + return hc + " ".join(self.holecards[street][player][1]) + "] [" + " ".join(self.holecards[street][player][0]) + "]" def join_holecards(self, player): holecards = [] From 3253d5a234a4f68e8b0de7ef63ad04f1bc1f84b6 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 Jul 2009 22:11:23 -0400 Subject: [PATCH 06/15] Get stud shown cards right in writeHand(). --- pyfpdb/Hand.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index c97e88f1..95fd74a5 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -1336,7 +1336,15 @@ Add a complete on [street] by [player] to [amountTo] holecards = [] for street in self.holeStreets: if self.holecards[street].has_key(player): - holecards = holecards + self.holecards[street][player][0] + if street == 'THIRD': + holecards = holecards + self.holecards[street][player][1] + self.holecards[street][player][0] + elif street == 'SEVENTH': + if player == self.hero: + holecards = holecards + self.holecards[street][player][0] + else: + holecards = holecards + self.holecards[street][player][1] + else: + holecards = holecards + self.holecards[street][player][0] return " ".join(holecards) class Pot(object): From e0dc556a679e7b6991a68db05c04c9d31f0c2218 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 Jul 2009 22:15:20 -0400 Subject: [PATCH 07/15] Clean up some methods previously commented out. --- pyfpdb/Hand.py | 92 -------------------------------------------------- 1 file changed, 92 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 95fd74a5..f5a07644 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -905,21 +905,6 @@ class DrawHand(Hand): self.addHoleCards('DRAWTHREE', player, open=[], closed=cards, shown=shown, mucked=mucked, dealt=dealt) -# def addDrawHoleCards(self, newcards, oldcards, player, street, shown=False): -# """\ -#Assigns observed holecards to a player. -#cards list of card bigrams e.g. ['2h','Jc'] -#player (string) name of player -#""" -# try: -# self.checkPlayerExists(player) -## if shown and len(cardset) > 0: -## self.shown.add(player) -# self.holecards[street][player] = (newcards,oldcards) -# except FpdbParseError, e: -# print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) - - def discardDrawHoleCards(self, cards, player, street): logging.debug("discardDrawHoleCards '%s' '%s' '%s'" % (cards, player, street)) self.discards[street][player] = set([cards]) @@ -935,48 +920,6 @@ class DrawHand(Hand): self.actions[street].append(act) -# def addShownCards(self, cards, player, holeandboard=None, shown=False, mucked=False): -# """\ -#For when a player shows cards for any reason (for showdown or out of choice). -#Card ranks will be uppercased -#""" -# logging.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard)) -# if cards is not None: -# self.shown.add(player) -# self.addHoleCards(cards,player) -# elif holeandboard is not None: -# holeandboard = set([self.card(c) for c in holeandboard]) -# board = set([c for s in self.board.values() for c in s]) -# self.addHoleCards(holeandboard.difference(board),player,shown=True) - - -# def addHoleCards(self, cards, player, shown, mucked, dealt=False): -# """\ -#Assigns observed holecards to a player. -#cards list of card bigrams e.g. ['2h','Jc'] -#player (string) name of player -#shown whether they were revealed at showdown -#mucked whether they were mucked at showdown -#dealt whether they were seen in a 'dealt to' line -#""" -## I think this only gets called for shown cards. -# logging.debug("addHoleCards %s %s" % (cards, player)) -# try: -# self.checkPlayerExists(player) -# except FpdbParseError, e: -# print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) -# return -# -# if dealt: -# self.dealt.add(player) -# if shown: -# self.shown.add(player) -# if mucked: -# self.mucked.add(player) -# if player != self.hero: #skip hero, we know his cards -# print "player, cards =", player, cards -# self.holecards[self.holeStreets[-1]][player] = (cards, set([])) - def writeHand(self, fh=sys.__stdout__): # PokerStars format. super(DrawHand, self).writeHand(fh) @@ -1122,41 +1065,6 @@ closed likewise, but known only to player except FpdbParseError, e: print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) -# def addHoleCards(self, cards, player, shown, mucked, dealt=False): -# """\ -#Assigns observed holecards to a player. -#cards list of card bigrams e.g. ['2h','Jc'] -#player (string) name of player -#shown whether they were revealed at showdown -#mucked whether they were mucked at showdown -#dealt whether they were seen in a 'dealt to' line -#""" -## -## For stud games we just need to do the routine setting of shown/mucked/etc -## and then update the cards 'THIRD' and 'SEVENTH' -# logging.debug("addHoleCards %s %s" % (cards, player)) -# try: -# self.checkPlayerExists(player) -# except FpdbParseError, e: -# print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) -# return -# -# if dealt: -# self.dealt.add(player) -# if shown: -# self.shown.add(player) -# if mucked: -# self.mucked.add(player) -# if player == self.hero: -# if len(cards) > 2: -# self.holecards['THIRD'][player] = ([cards[0:3]], []) -# if len(cards) > 6: -# self.holecards['SEVENTH'][player] = ([cards[6]], []) -# else: -# if len(cards) > 2: -# self.holecards['THIRD'][player] = ([cards[0]], cards[1:3]) -# if len(cards) > 6: -# self.holecards['SEVENTH'][player] = ([], [cards[6]]) # TODO: def addComplete(self, player, amount): def addComplete(self, street, player, amountTo): # assert street=='THIRD' From 889aea48b6805ab42121048a17c264a85842b3c4 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 Jul 2009 22:30:41 -0400 Subject: [PATCH 08/15] Make the board in the summary of flop games print in the right order. --- pyfpdb/Hand.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index f5a07644..65745c2c 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -808,8 +808,8 @@ class HoldemOmahaHand(Hand): print >>fh, "%s | Rake $%.2f" % (self.pot, self.rake) board = [] - for s in self.board.values(): - board += s + for street in ["FLOP", "TURN", "RIVER"]: + board += self.board[street] if board: # sometimes hand ends preflop without a board print >>fh, ("Board [%s]" % (" ".join(board))) From b5b0b6a7b70a791124fb0f29d9b79bf487e440de Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 Jul 2009 23:04:16 -0400 Subject: [PATCH 09/15] Get rid of hard wired $ in writeHand. Replace with appropriate symbol based on ring, tournament, play, etc. --- pyfpdb/Hand.py | 54 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 65745c2c..5f2174b8 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -523,22 +523,22 @@ Map the tuple self.gametype onto the pokerstars string describing it elif act[1] == 'checks': return ("%s: checks " %(act[0])) elif act[1] == 'calls': - return ("%s: calls $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) + return ("%s: calls %s%s%s" %(act[0], self.sym, act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'bets': - return ("%s: bets $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) + return ("%s: bets %s%s%s" %(act[0], self.sym, act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'raises': - return ("%s: raises $%s to $%s%s" %(act[0], act[2], act[3], ' and is all-in' if act[5] else '')) + return ("%s: raises %s%s to %s%s%s" %(act[0], self.sym, act[2], self.sym, act[3], ' and is all-in' if act[5] else '')) elif act[1] == 'completea': - return ("%s: completes to $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) + return ("%s: completes to %s%s%s" %(act[0], self.sym, act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'posts': if(act[2] == "small blind"): - return ("%s: posts small blind $%s%s" %(act[0], act[3], ' and is all-in' if act[4] else '')) + return ("%s: posts small blind %s%s%s" %(act[0], self.sym, act[3], ' and is all-in' if act[4] else '')) elif(act[2] == "big blind"): - return ("%s: posts big blind $%s%s" %(act[0], act[3], ' and is all-in' if act[4] else '')) + return ("%s: posts big blind %s%s%s" %(act[0], self.sym, act[3], ' and is all-in' if act[4] else '')) elif(act[2] == "both"): - return ("%s: posts small & big blinds $%s%s" %(act[0], act[3], ' and is all-in' if act[4] else '')) + return ("%s: posts small & big blinds %s%s%s" %(act[0], self.sym, act[3], ' and is all-in' if act[4] else '')) elif act[1] == 'bringin': - return ("%s: brings in for $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) + return ("%s: brings in for %s%s%s" %(act[0], self.sym, act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'discards': return ("%s: discards %s %s%s" %(act[0], act[2], 'card' if act[2] == 1 else 'cards' , " [" + " ".join(self.discards[act[0]]['DRAWONE']) + "]" if self.hero == act[0] else '')) elif act[1] == 'stands pat': @@ -645,8 +645,8 @@ class HoldemOmahaHand(Hand): def render_stack(context,data): pat = context.tag.patternGenerator('list_item') for player in data: - x = "Seat %s: %s ($%s in chips) " %(player[0], player[1], - player[2]) + x = "Seat %s: %s (%s%s in chips) " %(player[0], player[1], + self.sym, player[2]) context.tag[ pat().fillSlots('playerStack', x)] return context.tag @@ -800,12 +800,12 @@ class HoldemOmahaHand(Hand): # Immediately before the summary. # The current importer uses those lines for importing winning rather than the summary for name in self.pot.returned: - print >>fh, ("Uncalled bet ($%s) returned to %s" %(self.pot.returned[name],name)) + print >>fh, ("Uncalled bet (%s%s) returned to %s" %(self.sym, self.pot.returned[name],name)) for entry in self.collected: - print >>fh, ("%s collected $%s from x pot" %(entry[0], entry[1])) + print >>fh, ("%s collected %s%s from x pot" %(entry[0], self.sym, entry[1])) print >>fh, ("*** SUMMARY ***") - print >>fh, "%s | Rake $%.2f" % (self.pot, self.rake) + print >>fh, "%s | Rake %s%.2f" % (self.pot, self.sym, self.rake) board = [] for street in ["FLOP", "TURN", "RIVER"]: @@ -817,9 +817,9 @@ class HoldemOmahaHand(Hand): seatnum = player[0] name = player[1] if name in self.collectees and name in self.shown: - print >>fh, ("Seat %d: %s showed [%s] and won ($%s)" % (seatnum, name, " ".join(self.holecards['PREFLOP'][name][1]), self.collectees[name])) + print >>fh, ("Seat %d: %s showed [%s] and won (%s%s)" % (seatnum, name, " ".join(self.holecards['PREFLOP'][name][1]), self.sym, self.collectees[name])) elif name in self.collectees: - print >>fh, ("Seat %d: %s collected ($%s)" % (seatnum, name, self.collectees[name])) + print >>fh, ("Seat %d: %s collected (%s%s)" % (seatnum, name, self.sym, self.collectees[name])) #~ elif name in self.shown: #~ print >>fh, _("Seat %d: %s showed [%s]" % (seatnum, name, " ".join(self.holecards[name]['PREFLOP']))) elif name in self.folded: @@ -928,11 +928,11 @@ class DrawHand(Hand): for player in [x for x in self.players if x[1] in players_who_act_ondeal]: #Only print stacks of players who do something on deal - print >>fh, _("Seat %s: %s ($%s in chips) " %(player[0], player[1], player[2])) + print >>fh, _("Seat %s: %s (%s%s in chips) " %(player[0], player[1], self.sym, player[2])) if 'BLINDSANTES' in self.actions: for act in self.actions['BLINDSANTES']: - print >>fh, _("%s: %s %s $%s" %(act[0], act[1], act[2], act[3])) + print >>fh, _("%s: %s %s %s%s" %(act[0], act[1], act[2], self.sym, act[3])) if 'DEAL' in self.actions: print >>fh, _("*** DEALING HANDS ***") @@ -985,12 +985,12 @@ class DrawHand(Hand): # Immediately before the summary. # The current importer uses those lines for importing winning rather than the summary for name in self.pot.returned: - print >>fh, _("Uncalled bet ($%s) returned to %s" %(self.pot.returned[name],name)) + print >>fh, _("Uncalled bet (%s%s) returned to %s" %(self.sym, self.pot.returned[name],name)) for entry in self.collected: - print >>fh, _("%s collected $%s from x pot" %(entry[0], entry[1])) + print >>fh, _("%s collected %s%s from x pot" %(entry[0], self.sym, entry[1])) print >>fh, _("*** SUMMARY ***") - print >>fh, "%s | Rake $%.2f" % (self.pot, self.rake) + print >>fh, "%s | Rake %s%.2f" % (self.pot, self.sym, self.rake) print >>fh, "\n\n" @@ -1111,11 +1111,11 @@ Add a complete on [street] by [player] to [amountTo] for player in [x for x in self.players if x[1] in players_who_post_antes]: #Only print stacks of players who do something preflop - print >>fh, _("Seat %s: %s ($%s)" %(player[0], player[1], player[2])) + print >>fh, _("Seat %s: %s (%s%s)" %(player[0], player[1], self.sym, player[2])) if 'ANTES' in self.actions: for act in self.actions['ANTES']: - print >>fh, _("%s: posts the ante $%s" %(act[0], act[3])) + print >>fh, _("%s: posts the ante %s%s" %(act[0], self.sym, act[3])) if 'THIRD' in self.actions: dealt = 0 @@ -1196,12 +1196,12 @@ Add a complete on [street] by [player] to [amountTo] # Immediately before the summary. # The current importer uses those lines for importing winning rather than the summary for name in self.pot.returned: - print >>fh, _("Uncalled bet ($%s) returned to %s" %(self.pot.returned[name],name)) + print >>fh, _("Uncalled bet (%s%s) returned to %s" %(self.sym, self.pot.returned[name],name)) for entry in self.collected: - print >>fh, _("%s collected $%s from x pot" %(entry[0], entry[1])) + print >>fh, _("%s collected %s%s from x pot" %(entry[0], self.sym, entry[1])) print >>fh, _("*** SUMMARY ***") - print >>fh, "%s | Rake $%.2f" % (self.pot, self.rake) + print >>fh, "%s | Rake %s%.2f" % (self.pot, self.sym, self.rake) #print >>fh, _("Total pot $%s | Rake $%.2f" % (self.totalpot, self.rake)) # TODO: side pots board = [] @@ -1214,9 +1214,9 @@ Add a complete on [street] by [player] to [amountTo] seatnum = player[0] name = player[1] if name in self.collectees and name in self.shown: - print >>fh, _("Seat %d: %s showed [%s] and won ($%s)" % (seatnum, name, self.join_holecards(name), self.collectees[name])) + print >>fh, _("Seat %d: %s showed [%s] and won (%s%s)" % (seatnum, name, self.join_holecards(name), self.sym, self.collectees[name])) elif name in self.collectees: - print >>fh, _("Seat %d: %s collected ($%s)" % (seatnum, name, self.collectees[name])) + print >>fh, _("Seat %d: %s collected (%s%s)" % (seatnum, name, self.sym, self.collectees[name])) elif name in self.shown: print >>fh, _("Seat %d: %s showed [%s]" % (seatnum, name, self.join_holecards(name))) elif name in self.mucked: From 52fcbd79667ef4556e8b898bf8ae8e702f4d4953 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 15 Jul 2009 23:40:07 -0400 Subject: [PATCH 10/15] Remove completed TODOs(plenty left!). Remove obsolete comments. --- pyfpdb/Hand.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 5f2174b8..d4a1ca44 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -81,7 +81,6 @@ class Hand(object): self.holecards[street] = {} # dict from player names to holecards self.discards[street] = {} # dict from player names to dicts by street ... of tuples ... of discarded holecards # Collections indexed by player names -# self.holecards = {} # dict from player names to dicts by street ... of tuples ... of holecards self.stacks = {} self.collected = [] #list of ? self.collectees = {} # dict from player names to amounts collected (?) @@ -92,7 +91,6 @@ class Hand(object): self.shown = set() # cards were shown self.mucked = set() # cards were mucked at showdown -# self.action = [] # Things to do with money self.pot = Pot() self.totalpot = None @@ -733,7 +731,6 @@ class HoldemOmahaHand(Hand): def writeHand(self, fh=sys.__stdout__): # PokerStars format. -# TODO: board cards (in summary) not printed in correct order super(HoldemOmahaHand, self).writeHand(fh) players_who_act_preflop = set(([x[0] for x in self.actions['PREFLOP']]+[x[0] for x in self.actions['BLINDSANTES']])) @@ -859,8 +856,6 @@ class DrawHand(Hand): # Read actions in street order for street in self.streetList: if self.streets[street]: - # hhc.readCommunityCards(self, street) -# hhc.readDrawCards(self, street) hhc.readAction(self, street) hhc.readCollectPot(self) hhc.readShownCards(self) @@ -1020,13 +1015,11 @@ class StudHand(Hand): hhc.readAntes(self) hhc.readBringIn(self) hhc.readHeroCards(self) - #hhc.readShowdownActions(self) # not done yet # Read actions in street order for street in self.streetList: if self.streets[street]: logging.debug(street) logging.debug(self.streets[street]) -# hhc.readStudPlayerCards(self, street) hhc.readAction(self, street) hhc.readCollectPot(self) hhc.readShownCards(self) # not done yet @@ -1040,7 +1033,6 @@ class StudHand(Hand): if shown: self.shown.add(player) if mucked: self.mucked.add(player) else: -# self.addHoleCards('PREFLOP', player, open=[], closed=cards, shown=shown, mucked=mucked, dealt=dealt) self.addHoleCards('THIRD', player, open=[cards[2]], closed=cards[0:2], shown=shown, mucked=mucked) self.addHoleCards('FOURTH', player, open=[cards[3]], closed=[cards[2]], shown=shown, mucked=mucked) self.addHoleCards('FIFTH', player, open=[cards[4]], closed=cards[2:4], shown=shown, mucked=mucked) @@ -1060,8 +1052,6 @@ closed likewise, but known only to player try: self.checkPlayerExists(player) self.holecards[street][player] = (open, closed) -# cards = set([self.card(c) for c in cards]) -# self.holecards[player].update(cards) except FpdbParseError, e: print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) @@ -1101,17 +1091,13 @@ Add a complete on [street] by [player] to [amountTo] def writeHand(self, fh=sys.__stdout__): # PokerStars format. -# TODO: -# Hole cards are not currently correctly written. Currently the down cards for non-heros -# are shown in the "dealt to" lines. They should be hidden in those lines. I tried to fix -# but mind got boggled, will try again. super(StudHand, self).writeHand(fh) players_who_post_antes = set([x[0] for x in self.actions['ANTES']]) for player in [x for x in self.players if x[1] in players_who_post_antes]: #Only print stacks of players who do something preflop - print >>fh, _("Seat %s: %s (%s%s)" %(player[0], player[1], self.sym, player[2])) + print >>fh, _("Seat %s: %s (%s%s in chips)" %(player[0], player[1], self.sym, player[2])) if 'ANTES' in self.actions: for act in self.actions['ANTES']: @@ -1202,7 +1188,7 @@ Add a complete on [street] by [player] to [amountTo] print >>fh, _("*** SUMMARY ***") print >>fh, "%s | Rake %s%.2f" % (self.pot, self.sym, self.rake) - #print >>fh, _("Total pot $%s | Rake $%.2f" % (self.totalpot, self.rake)) # TODO: side pots +# TODO: side pots board = [] for s in self.board.values(): From 2fa37813491447fd18fa02b963d65927528c115c Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 16 Jul 2009 00:54:09 -0400 Subject: [PATCH 11/15] Make euros print as $ in writeHand. --- pyfpdb/Hand.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index d4a1ca44..6355eef4 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -38,7 +38,7 @@ class Hand(object): # Class Variables UPS = {'a':'A', 't':'T', 'j':'J', 'q':'Q', 'k':'K', 'S':'s', 'C':'c', 'H':'h', 'D':'d'} LCS = {'H':'h', 'D':'d', 'C':'c', 'S':'s'} - SYMBOL = {'USD': '$', 'EUR': u'E', 'T$': '', 'play': ''} + SYMBOL = {'USD': '$', 'EUR': u'$', 'T$': '', 'play': ''} MS = {'horse' : 'HORSE', '8game' : '8-Game', 'hose' : 'HOSE'} From 26a199635382bc31f7a792d3b1922b96aa9972a1 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 16 Jul 2009 12:13:24 -0400 Subject: [PATCH 12/15] Change Pot object to support variable currency symbol. --- pyfpdb/Hand.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 6355eef4..67f565a7 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -96,6 +96,9 @@ class Hand(object): self.totalpot = None self.totalcollected = None self.rake = None + # currency symbol for this hand + self.sym = self.SYMBOL[self.gametype['currency']] # save typing! delete this attr when done + self.pot.setSym(self.sym) def __str__(self): vars = ( ("BB", self.bb), @@ -575,7 +578,6 @@ Map the tuple self.gametype onto the pokerstars string describing it def writeHand(self, fh=sys.__stdout__): # PokerStars format. - self.sym = self.SYMBOL[self.gametype['currency']] # save typing! delete this attr when done print >>fh, self.writeGameLine() print >>fh, self.writeTableLine() @@ -1249,6 +1251,10 @@ class Pot(object): self.committed = {} self.total = None self.returned = {} + self.sym = u'$' # this is the default currency symbol + + def setSym(self, sym): + self.sym = sym def addPlayer(self,player): self.committed[player] = Decimal(0) @@ -1300,16 +1306,16 @@ class Pot(object): raise FpdbParseError - +# TODO: This really neeads to be a loop to handle multiple side pots if len(self.pots) == 1: # (only use Total pot) - return "Total pot $%.2f" % (self.total,) + return "Total pot %s%.2f" % (self.sym, self.total,) elif len(self.pots) == 2: - return "Total pot $%.2f Main pot $%.2f. Side pot $%2.f." % (self.total, self.pots[0], self.pots[1]) + return "Total pot %s%.2f Main pot %s%.2f. Side pot %s%2.f." % (self.sym, self.total, self.sym, self.pots[0], self.sym, self.pots[1]) elif len(self.pots) == 3: - return "Total pot $%.2f Main pot $%.2f. Side pot-1 $%2.2f. Side pot-2 $%.2f." % (self.total, self.pots[0], self.pots[1], self.pots[2]) + return "Total pot %s%.2f Main pot $%.2f. Side pot-1 %s%2.2f. Side pot-2 %s%.2f." % (self.sym, self.total, self.sym, self.pots[0], self.sym, self.pots[1], self.sym, self.pots[2]) elif len(self.pots) == 0: # no small blind and walk in bb (hopefully) - return "Total pot $%.2f" % (self.total,) + return "Total pot %s%.2f" % (self.sym, self.total,) else: return ("too many pots.. no small blind and walk in bb?. self.pots: %s" %(self.pots)) # I don't know stars format for a walk in the bb when sb doesn't post. From 52ecc6450518281603e5e5adb4168216a6086529 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 17 Jul 2009 17:07:53 -0400 Subject: [PATCH 13/15] Update to work with recent Hand.py changes. --- pyfpdb/FulltiltToFpdb.py | 135 +++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 78 deletions(-) diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index f7b834a6..d9cc490d 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -27,10 +27,22 @@ from HandHistoryConverter import * class Fulltilt(HandHistoryConverter): # Static regexes - re_GameInfo = re.compile('- (?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+) (Ante \$(?P[.0-9]+) )?- (?P(No Limit|Pot Limit|Limit))? (?P(Hold\'em|Omaha Hi|Razz))') + re_GameInfo = re.compile('''-\s(?P\$|)? + (?P[.0-9]+)/ + \$?(?P[.0-9]+)\s + (Ante\s\$(?P[.0-9]+)\s)?-\s + (?P(No\sLimit|Pot\sLimit|Limit))?\s + (?P(Hold\'em|Omaha\sHi|Omaha\sH/L|7\sCard\sStud|Stud\sH/L|Razz)) + ''', re.VERBOSE) re_SplitHands = re.compile(r"\n\n+") re_TailSplitHands = re.compile(r"(\n\n+)") - re_HandInfo = re.compile('.*#(?P[0-9]+): Table (?P[- a-zA-Z]+) (\((?P.+)\) )?- \$?(?P[.0-9]+)/\$?(?P[.0-9]+) (Ante \$(?P[.0-9]+) )?- (?P[a-zA-Z\' ]+) - (?P.*)') + re_HandInfo = re.compile('''.*\#(?P[0-9]+):\s + Table\s(?P
[-\sa-zA-Z]+)\s + (\((?P.+)\)\s)?-\s + \$?(?P[.0-9]+)/\$?(?P[.0-9]+)\s(Ante\s\$(?P[.0-9]+)\s)?-\s + (?P[a-zA-Z\/\'\s]+)\s-\s + (?P.*) + ''', re.VERBOSE) re_Button = re.compile('^The button is in seat #(?P
[-\sa-zA-Z]+)\s + (?:(?P.+)\s\((?P\d+)\),\s)? + Table\s(?P
[-\s\da-zA-Z]+)\s (\((?P.+)\)\s)?-\s \$?(?P[.0-9]+)/\$?(?P[.0-9]+)\s(Ante\s\$(?P[.0-9]+)\s)?-\s (?P[a-zA-Z\/\'\s]+)\s-\s (?P.*) ''', re.VERBOSE) re_Button = re.compile('^The button is in seat #(?P