diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index d6088b00..7d27828e 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -15,6 +15,8 @@ #In the "official" distribution you can find the license in #agpl-3.0.txt in the docs folder of the package. +# TODO: get writehand() encoding correct + import re import sys import traceback @@ -31,8 +33,15 @@ import DerivedStats import Card class Hand: + +###############################################################3 +# 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': ''} + MS = {'horse' : 'HORSE', '8game' : '8-Game', 'hose' : 'HOSE'} + + def __init__(self, sitename, gametype, handText, builtFrom = "HHC"): self.sitename = sitename self.stats = DerivedStats.DerivedStats(self) @@ -45,6 +54,10 @@ class Hand: self.maxseats = 10 self.counted_seats = 0 self.buttonpos = 0 + self.tourNo = None + self.buyin = None + self.level = None + self.mixed = None self.seating = [] self.players = [] self.posted = [] @@ -56,17 +69,19 @@ class Hand: self.actions = {} # [['mct','bets','$10'],['mika','folds'],['carlg','raises','$20']] self.board = {} # dict from street names to community cards self.holecards = {} + self.discards = {} for street in self.allStreets: self.streets[street] = "" # portions of the handText, filled by markStreets() + self.actions[street] = [] + for street in self.actionStreets: self.bets[street] = {} self.lastBet[street] = 0 - self.actions[street] = [] self.board[street] = [] + for street in self.holeStreets: 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.discards = {} # dict from player names to dicts by street ... of tuples ... of discarded holecards self.stacks = {} self.collected = [] #list of ? self.collectees = {} # dict from player names to amounts collected (?) @@ -93,6 +108,10 @@ class Hand: ("TABLE NAME", self.tablename), ("HERO", self.hero), ("MAXSEATS", self.maxseats), + ("TOURNAMENT NO", self.tourNo), + ("BUYIN", self.buyin), + ("LEVEL", self.level), + ("MIXED", self.mixed), ("LASTBET", self.lastBet), ("ACTION STREETS", self.actionStreets), ("STREETS", self.streets), @@ -130,6 +149,28 @@ class Hand: str = str + "\n%s =\n" % name + pprint.pformat(struct, 4) return str + def addHoleCards(self, street, player, open=[], closed=[], shown=False, mucked=False, 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 +""" +# logging.debug("addHoleCards %s %s" % (open + closed, 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) + + self.holecards[street][player] = [open, closed] + def insert(self, db): """ Function to insert Hand into database Should not commit, and do minimal selects. Callers may want to cache commits @@ -221,10 +262,10 @@ If a player has None chips he won't be added.""" self.players.append([seat, name, chips]) self.stacks[name] = Decimal(chips) self.pot.addPlayer(name) - for street in self.allStreets: + for street in self.actionStreets: self.bets[street][name] = [] #self.holecards[name] = {} # dict from street names. - self.discards[name] = {} # dict from street names. + #self.discards[name] = {} # dict from street names. def addStreets(self, match): @@ -446,7 +487,7 @@ Card ranks will be uppercased Map the tuple self.gametype onto the pokerstars string describing it """ # currently it appears to be something like ["ring", "hold", "nl", sb, bb]: - gs = {"holdem" : "Hold'em", + gs = {"holdem" : "Hold'em", "omahahi" : "Omaha", "omahahilo" : "Omaha Hi/Lo", "razz" : "Razz", @@ -466,7 +507,6 @@ Map the tuple self.gametype onto the pokerstars string describing it logging.debug("gametype: %s" %(self.gametype)) retstring = "%s %s" %(gs[self.gametype['category']], ls[self.gametype['limitType']]) - return retstring @@ -503,6 +543,33 @@ Map the tuple self.gametype onto the pokerstars string describing it elif act[1] == 'stands pat': 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 + + 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, + self.buyin, self.getGameTypeAsString(), self.level, self.getStakesAsString()) + elif self.mixed != None: + game_string = game_string + " %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 + + + def writeTableLine(self): + table_string = "Table \'%s\' %s-max" % (self.tablename, self.maxseats) + if self.gametype['currency'] == 'play': + table_string = table_string + " (Play Money)" + if self.buttonpos != None: + table_string = table_string + " Seat #%s is the button" % self.buttonpos + return table_string + class HoldemOmahaHand(Hand): def __init__(self, hhc, sitename, gametype, handText, builtFrom = "HHC", handid=None): @@ -550,35 +617,13 @@ class HoldemOmahaHand(Hand): pass - 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 -""" - 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 - - cardset = set((self.card(c) for c in cards)) - if len(cardset) == 0: - return - if dealt: - self.dealt.add(player) - if shown: - self.shown.add(player) - if mucked: - self.mucked.add(player) - if player in self.holecards['PREFLOP']: - self.holecards['PREFLOP'][player].update(cardset) + def addShownCards(self, cards, player, shown=True, mucked=False, dealt=False): + if player == self.hero: # we have hero's cards just update shown/mucked + if shown: self.shown.add(player) + if mucked: self.mucked.add(player) else: - self.holecards['PREFLOP'][player] = cardset + self.addHoleCards('PREFLOP', player, open=[], closed=cards, shown=shown, mucked=mucked, dealt=dealt) + def writeHTMLHand(self, fh=sys.__stdout__): from nevow import tags as T @@ -677,8 +722,11 @@ dealt whether they were seen in a 'dealt to' line 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'))) - print >>fh, ("Table '%s' %d-max Seat #%s is the button" %(self.tablename, self.maxseats, self.buttonpos)) +# 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'))) + 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']) @@ -692,10 +740,10 @@ dealt whether they were seen in a 'dealt to' line print >>fh, ("*** HOLE CARDS ***") for player in self.dealt: - print >>fh, ("Dealt to %s [%s]" %(player, " ".join(self.holecards['PREFLOP'][player]))) + print >>fh, ("Dealt to %s [%s]" %(player, " ".join(self.holecards['PREFLOP'][player][1]))) if self.hero == "": for player in self.shown.difference(self.dealt): - print >>fh, ("Dealt to %s [%s]" %(player, " ".join(self.holecards['PREFLOP'][player]))) + print >>fh, ("Dealt to %s [%s]" %(player, " ".join(self.holecards['PREFLOP'][player][1]))) if self.actions['PREFLOP']: for act in self.actions['PREFLOP']: @@ -734,7 +782,7 @@ dealt whether they were seen in a 'dealt to' line elif self.gametype['category'] in ('holdem'): numOfHoleCardsNeeded = 2 if len(self.holecards['PREFLOP'][name]) == numOfHoleCardsNeeded: - print >>fh, ("%s shows [%s] (a hand...)" % (name, " ".join(self.holecards['PREFLOP'][name]))) + print >>fh, ("%s shows [%s] (a hand...)" % (name, " ".join(self.holecards['PREFLOP'][name][1]))) # Current PS format has the lines: # Uncalled bet ($111.25) returned to s0rrow @@ -761,7 +809,7 @@ dealt whether they were seen in a 'dealt to' line 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]), self.collectees[name])) + print >>fh, ("Seat %d: %s showed [%s] and won ($%s)" % (seatnum, name, " ".join(self.holecards['PREFLOP'][name][1]), self.collectees[name])) elif name in self.collectees: print >>fh, ("Seat %d: %s collected ($%s)" % (seatnum, name, self.collectees[name])) #~ elif name in self.shown: @@ -770,9 +818,9 @@ dealt whether they were seen in a 'dealt to' line print >>fh, ("Seat %d: %s folded" % (seatnum, name)) else: if name in self.shown: - print >>fh, ("Seat %d: %s showed [%s] and lost with..." % (seatnum, name, " ".join(self.holecards['PREFLOP'][name]))) + print >>fh, ("Seat %d: %s showed [%s] and lost with..." % (seatnum, name, " ".join(self.holecards['PREFLOP'][name][1]))) elif name in self.mucked: - print >>fh, ("Seat %d: %s mucked [%s] " % (seatnum, name, " ".join(self.holecards['PREFLOP'][name]))) + print >>fh, ("Seat %d: %s mucked [%s] " % (seatnum, name, " ".join(self.holecards['PREFLOP'][name][1]))) else: print >>fh, ("Seat %d: %s mucked" % (seatnum, name)) @@ -783,8 +831,10 @@ class DrawHand(Hand): if gametype['base'] != 'draw': pass # or indeed don't pass and complain instead self.streetList = ['BLINDSANTES', 'DEAL', 'DRAWONE', 'DRAWTWO', 'DRAWTHREE'] + self.allStreets = ['BLINDSANTES', 'DEAL', 'DRAWONE', 'DRAWTWO', 'DRAWTHREE'] self.holeStreets = ['DEAL', 'DRAWONE', 'DRAWTWO', 'DRAWTHREE'] self.actionStreets = ['PREDEAL', 'DEAL', 'DRAWONE', 'DRAWTWO', 'DRAWTHREE'] + self.communityStreets = [] Hand.__init__(self, sitename, gametype, handText) self.sb = gametype['sb'] self.bb = gametype['bb'] @@ -796,12 +846,13 @@ class DrawHand(Hand): hhc.markStreets(self) hhc.readBlinds(self) hhc.readButton(self) + hhc.readHeroCards(self) hhc.readShowdownActions(self) # Read actions in street order for street in self.streetList: if self.streets[street]: # hhc.readCommunityCards(self, street) - hhc.readDrawCards(self, street) +# hhc.readDrawCards(self, street) hhc.readAction(self, street) hhc.readCollectPot(self) hhc.readShownCards(self) @@ -837,25 +888,33 @@ class DrawHand(Hand): #print "DEBUG: self.posted: %s" %(self.posted) + def addShownCards(self, cards, player, shown=True, mucked=False, dealt=False): + if player == self.hero: # we have hero's cards just update shown/mucked + if shown: self.shown.add(player) + if mucked: self.mucked.add(player) + else: +# TODO: Probably better to find the last street with action and add the hole cards to that street + 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[player][street] = (newcards,oldcards) - except FpdbParseError, e: - print "[ERROR] Tried to add holecards for unknown player: %s" % (player,) + +# 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[player][street] = set([cards]) + self.discards[street][player] = set([cards]) def addDiscard(self, street, player, num, cards): @@ -868,12 +927,12 @@ player (string) name of player self.actions[street].append(act) - def addShownCards(self, cards, player, holeandboard=None): - """\ -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)) +# 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) @@ -883,10 +942,39 @@ Card ranks will be uppercased # 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. - 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))) - print >>fh, _("Table '%s' %d-max Seat #%s is the button" %(self.tablename, self.maxseats, self.buttonpos)) +# 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))) + 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']])) @@ -912,8 +1000,8 @@ Card ranks will be uppercased for act in self.actions['DRAWONE']: print >>fh, self.actionString(act) if act[0] == self.hero and act[1] == 'discards': - (nc,oc) = self.holecards[act[0]]['DRAWONE'] - dc = self.discards[act[0]]['DRAWONE'] + (nc,oc) = self.holecards['DRAWONE'][act[0]] + dc = self.discards['DRAWONE'][act[0]] kc = oc - dc print >>fh, _("Dealt to %s [%s] [%s]" % (act[0], " ".join(kc), " ".join(nc))) @@ -922,8 +1010,8 @@ Card ranks will be uppercased for act in self.actions['DRAWTWO']: print >>fh, self.actionString(act) if act[0] == self.hero and act[1] == 'discards': - (nc,oc) = self.holecards[act[0]]['DRAWTWO'] - dc = self.discards[act[0]]['DRAWTWO'] + (nc,oc) = self.holecards['DRAWTWO'][act[0]] + dc = self.discards['DRAWTWO'][act[0]] kc = oc - dc print >>fh, _("Dealt to %s [%s] [%s]" % (act[0], " ".join(kc), " ".join(nc))) @@ -932,8 +1020,8 @@ Card ranks will be uppercased for act in self.actions['DRAWTHREE']: print >>fh, self.actionString(act) if act[0] == self.hero and act[1] == 'discards': - (nc,oc) = self.holecards[act[0]]['DRAWTHREE'] - dc = self.discards[act[0]]['DRAWTHREE'] + (nc,oc) = self.holecards['DRAWTHREE'][act[0]] + dc = self.discards['DRAWTHREE'][act[0]] kc = oc - dc print >>fh, _("Dealt to %s [%s] [%s]" % (act[0], " ".join(kc), " ".join(nc))) @@ -983,13 +1071,14 @@ class StudHand(Hand): hhc.markStreets(self) 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.readStudPlayerCards(self, street) hhc.readAction(self, street) hhc.readCollectPot(self) hhc.readShownCards(self) # not done yet @@ -998,6 +1087,19 @@ class StudHand(Hand): elif builtFrom == "DB": self.select("dummy") # Will need a handId + def addShownCards(self, cards, player, shown=True, mucked=False, dealt=False): + if player == self.hero: # we have hero's cards just update shown/mucked + 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=[], 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('SEVENTH', player, open=[], closed=[cards[6]], shown=shown, mucked=mucked) + + def addPlayerCards(self, player, street, open=[], closed=[]): """\ Assigns observed cards to a player. @@ -1015,42 +1117,41 @@ 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 -""" +# 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 # -# 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]]) - +# 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' @@ -1087,8 +1188,15 @@ 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))) - 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'))) - print >>fh, _("Table '%s' %d-max Seat #%s is the button" %(self.tablename, self.maxseats, self.buttonpos)) + +# 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'))) + 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']]) diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 45306281..b6fd09fb 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -18,6 +18,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ######################################################################## +# TODO: straighten out discards for draw games import sys from HandHistoryConverter import * @@ -25,16 +26,35 @@ from HandHistoryConverter import * class PokerStars(HandHistoryConverter): +############################################################ +# Class Variables + # Static regexes - re_GameInfo = re.compile("PokerStars Game #(?P[0-9]+):\s+(?PHORSE|8\-Game|HOSE)? \(?(?PHold\'em|Razz|7 Card Stud|7 Card Stud Hi/Lo|Omaha|Omaha Hi/Lo|Badugi) (?PNo Limit|Limit|Pot Limit),? \(?(?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+)\) - (?P.*$)", re.MULTILINE) + re_GameInfo = re.compile("""PokerStars\sGame\s\#(?P[0-9]+):\s+ + (Tournament\s\#(?P\d+),\s(?P[\$\+\d\.]+)\s)? + (?PHORSE|8\-Game|HOSE)?\s?\(? + (?PHold\'em|Razz|7\sCard Stud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball)\s + (?PNo\sLimit|Limit|Pot\sLimit),?\s + (-\sLevel\s(?P[IVXLC]+)\s)?\(? + (?P\$|)? + (?P[.0-9]+)/\$? + (?P[.0-9]+)\)\s-\s + (?P.*$)""", + re.MULTILINE|re.VERBOSE) re_SplitHands = re.compile('\n\n+') re_TailSplitHands = re.compile('(\n\n\n+)') - re_HandInfo = re.compile("^Table \'(?P[- a-zA-Z]+)\'(?P.+?$)?", re.MULTILINE) + re_HandInfo = re.compile("""^Table\s\'(?P
[-\ a-zA-Z\d]+)\'\s + ((?P\d+)-max\s)? + (?P\(Play\sMoney\)\s)? + (Seat\s\#(?P
[ a-zA-Z]+) - \$?(?P[.0-9]+)/\$?(?P[.0-9]+) - (?P.*) - (?P
[0-9]+):(?P[0-9]+) ET - (?P[0-9]+)/(?P[0-9]+)/(?P[0-9]+)Table (?P
[ a-zA-Z]+)\nSeat (?P