From b37ddc5ace00dd1e49c0bd8f7b7f586d636edf33 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Fri, 19 Dec 2008 03:01:45 +0000 Subject: [PATCH 1/3] So close, yet so far. Need to calculate rake to output the side pots line correctly. --- pyfpdb/Hand.py | 152 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 148 insertions(+), 4 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index f4a7bec7..f06a7926 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -307,8 +307,13 @@ Add a raise on [street] by [player] to [amountTo] self.totalpot = 0 + #print "[POT] stack list" + #print dict([(player[1], Decimal(player[2])) for player in self.players]) + players_who_act_preflop = set([x[0] for x in self.actions['PREFLOP']]) + self.pot = Pot(players_who_act_preflop) - for street in self.actions: + #for street in self.actions: + for street in [x for x in self.streetList if x in self.actions]: uncalled = 0 calls = [0] for act in self.actions[street]: @@ -317,18 +322,30 @@ Add a raise on [street] by [player] to [amountTo] uncalled = Decimal(act[2]) # only the last bet or raise can be uncalled calls = [0] print "uncalled: ", uncalled + + self.pot.addMoney(act[0], Decimal(act[2])) + elif act[1] == 'raises': # [name, 'raises', amountby, amountto, amountcalled] print "calls %s and raises %s to %s" % (act[4],act[2],act[3]) self.totalpot += Decimal(act[2]) + Decimal(act[4]) calls = [0] uncalled = Decimal(act[2]) print "uncalled: ", uncalled + + self.pot.addMoney(act[0], Decimal(act[2])+Decimal(act[4])) + elif act[1] == 'calls': # [name, 'calls', amount] self.totalpot += Decimal(act[2]) calls = calls + [Decimal(act[2])] print "calls:", calls + + self.pot.addMoney(act[0], Decimal(act[2])) + elif act[1] == 'posts': self.totalpot += Decimal(act[3]) + + self.pot.addMoney(act[0], Decimal(act[3])) + if act[2] == 'big blind': # the bb gets called by out-of-blinds posts; but sb+bb only calls bb if uncalled == Decimal(act[3]): # a bb is already posted @@ -343,14 +360,15 @@ Add a raise on [street] by [player] to [amountTo] uncalled = Decimal(act[3]) calls = [0] pass - + elif act[1] == 'folds': + self.pot.addFold(act[0]) if uncalled > 0 and max(calls+[0]) < uncalled: print "DEBUG returning some bet, calls:", calls print "DEBUG returned: %.2f from %.2f" % ((uncalled - max(calls)), self.totalpot,) self.totalpot -= (uncalled - max(calls)) print "DEBUG new totalpot:", self.totalpot - + print "DEBUG new Pot.total:", self.pot if self.totalcollected is None: self.totalcollected = 0; @@ -446,7 +464,8 @@ Map the tuple self.gametype onto the pokerstars string describing it print >>fh, "DEBUG: what do they show" print >>fh, _("*** SUMMARY ***") - print >>fh, _("Total pot $%s | Rake $%.2f" % (self.totalpot, self.rake)) # TODO: side pots + print >>fh, "%s | Rake $%.2f" % (self.pot, self.rake) + #print >>fh, _("Total pot $%s | Rake $%.2f" % (self.totalpot, self.rake)) # TODO: side pots board = [] for s in self.board.values(): @@ -544,3 +563,128 @@ Map the tuple self.gametype onto the pokerstars string describing it class FpdbParseError(Exception): pass + +class Pot(object): + + def __init__(self, contenders): + self.contenders = contenders + self.committed = dict([(player,Decimal(0)) for player in contenders]) + self.total = Decimal(0) + + def addFold(self, player): + self.contenders.remove(player) + + def addMoney(self, player, amount): + self.committed[player] += amount + + def __str__(self): + self.total = sum(self.committed.values()) + committed = sorted([ (v,k) for (k,v) in self.committed.items()]) + lastbet = committed[-1][0] - committed[-2][0] + if lastbet > 0: # uncalled + returnto = committed[-1][1] + #print "returning %f to %s" % (lastbet, returnto) + self.total -= lastbet + self.committed[returnto] -= lastbet + + + + # now: for those contenders still contending.. + commitsall = sorted([(v,k) for (k,v) in self.committed.items() if v >0]) + + pots = [] + while len(commitsall) > 0: + commitslive = [(v,k) for (v,k) in commitsall if k in self.contenders] + v1 = commitslive[0][0] + pots += [sum([min(v,v1) for (v,k) in commitsall])] + #print "all: ", commitsall + #print "live:", commitslive + commitsall = [((v-v1),k) for (v,k) in commitsall if v-v1 >0] + + + #print "[**]", pots + + # TODO: I think rake gets taken out of the pots. + # so it goes: + # total pot x. main pot y, side pot z. | rake r + # and y+z+r = x + # for example: + # Total pot $124.30 Main pot $98.90. Side pot $23.40. | Rake $2 + # so....... that's tricky. + if len(pots) == 1: + return "Main pot $%.2f" % pots[0] + elif len(pots) == 2: + return "Main pot $%.2f, side pot $%2.f" % (pots[0],pots[1]) + elif len(pots) == 3: + return "Main pot $%.2f, side pot-1 $%2.f, side pot-2 $.2f" % (pots[0],pots[1],pots[2]) + else: + return "too many pots.. fix me" + + + + + #def addMoney(self, player, amount): + #uncalled = max(self.committed.values()) - self.committed[player] + + #if self.cap: + #overflow = self.committed[player] + amount - self.cap + #if overflow > 0: + #self.total += amount - overflow + #self.committed[player] = self.cap + #self.sidepot.addMoney(player, overflow) + #else: + ## because it was capped, we can only be calling here. + #self.calls.append(min(uncalled,amount)) + #self.committed[player] += amount + #self.total += amount + #else: + ## no player is currently all-in. + + #self.committed[player] += amount + #self.total += amount + + ## is this a new uncalled bet? + #r = amount - uncalled + #if r > 0: + #self.uncalled = (player, r) + #self.calls = [0] + #else: + #self.calls.append(amount + r) + + ## is this player all-in? + #if self.committed[player] == self.stacks[player]: + #self.cap = self.stacks[player] + #contenders = self.contenders[:] + #contenders.remove(player) + #sidepotstacks = dict([(player, self.stacks[player]-self.committed[player]) for player in contenders]) + #self.sidepot = Pot(contenders, sidepotstacks, self.sidepotnum+1) + #elif self.committed[player] > self.stacks[player]: + #print "ERROR %s problem" % (player,) + #print self.committed[player], self.stacks[player] + #raise FpdbParseError + + #def returnUncalled(self): + #print "[POT]" + #print "last bet", self.uncalled + #print "calls:", self.calls + #print + #if self.uncalled: + #if max(self.calls) < self.uncalled[1]: + #self.total -= self.uncalled[1] + #print "returned", self.uncalled[0],self.uncalled[1]-max(self.calls), "from", self.uncalled[1] + + + #def __str__(self): + #total = self.total + #if self.sidepotnum == 0: + #return "Main pot $%.2f%s" %(total, self.sidepot or '' ) + #elif self.sidepotnum > 0: + #if self.sidepot: + #return ", side pot-%d $%.2f%s" % (self.sidepotnum, total, self.sidepot) + #else: + #return ", side pot $%.2f." % (total,) + + + + + From 16f9906d84f9c407c69ddc4339a7e714f091988e Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Sat, 20 Dec 2008 02:22:21 +0000 Subject: [PATCH 2/3] pot total line output matches pokerstars better --- pyfpdb/Hand.py | 95 ++++++-------------------------------------------- 1 file changed, 10 insertions(+), 85 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index f06a7926..e33d2d0c 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -296,22 +296,20 @@ Add a raise on [street] by [player] to [amountTo] if self.totalpot is None: self.totalpot = 0 - # player names: - # print [x[1] for x in self.players] for player in [x[1] for x in self.players]: for street in self.streetList: - #print street, self.bets[street][player] self.totalpot += reduce(operator.add, self.bets[street][player], 0) print "DEBUG conventional totalpot:", self.totalpot self.totalpot = 0 - #print "[POT] stack list" - #print dict([(player[1], Decimal(player[2])) for player in self.players]) + players_who_act_preflop = set([x[0] for x in self.actions['PREFLOP']]) self.pot = Pot(players_who_act_preflop) + + # this can now be pruned substantially if Pot is working. #for street in self.actions: for street in [x for x in self.streetList if x in self.actions]: uncalled = 0 @@ -413,9 +411,7 @@ Map the tuple self.gametype onto the pokerstars string describing it 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']]) - #print players_who_act_preflop - #print [x[1] for x in self.players] - #print [x for x in self.players if x[1] in players_who_act_preflop] + for player in [x for x in self.players if x[1] in players_who_act_preflop]: #Only print stacks of players who do something preflop print >>fh, _("Seat %s: %s ($%s)" %(player[0], player[1], player[2])) @@ -524,10 +520,6 @@ Map the tuple self.gametype onto the pokerstars string describing it def bestHand(self, side, cards): return HandHistoryConverter.eval.best('hi', cards, []) - # from pokergame.py - def bestHandValue(self, side, serial): - (value, cards) = self.bestHand(side, serial) - return value # from pokergame.py # got rid of the _ for internationalisation @@ -611,80 +603,13 @@ class Pot(object): # for example: # Total pot $124.30 Main pot $98.90. Side pot $23.40. | Rake $2 # so....... that's tricky. - if len(pots) == 1: - return "Main pot $%.2f" % pots[0] + if len(pots) == 1: # (only use Total pot) + #return "Main pot $%.2f." % pots[0] + return "Total pot $%.2f" % (self.total,) elif len(pots) == 2: - return "Main pot $%.2f, side pot $%2.f" % (pots[0],pots[1]) + return "Total pot $%.2f Main pot $%.2f. Side pot $%2.f." % (self.total, pots[0],pots[1]) elif len(pots) == 3: - return "Main pot $%.2f, side pot-1 $%2.f, side pot-2 $.2f" % (pots[0],pots[1],pots[2]) + return "Total pot $%.2f Main pot $%.2f. Side pot-1 $%2.f. Side pot-2 $.2f." % (self.total, pots[0],pots[1],pots[2]) else: - return "too many pots.. fix me" - - - - - #def addMoney(self, player, amount): - #uncalled = max(self.committed.values()) - self.committed[player] - - #if self.cap: - #overflow = self.committed[player] + amount - self.cap - #if overflow > 0: - #self.total += amount - overflow - #self.committed[player] = self.cap - #self.sidepot.addMoney(player, overflow) - #else: - ## because it was capped, we can only be calling here. - #self.calls.append(min(uncalled,amount)) - #self.committed[player] += amount - #self.total += amount - #else: - ## no player is currently all-in. + return "too many pots.. fix me.", pots - #self.committed[player] += amount - #self.total += amount - - ## is this a new uncalled bet? - #r = amount - uncalled - #if r > 0: - #self.uncalled = (player, r) - #self.calls = [0] - #else: - #self.calls.append(amount + r) - - ## is this player all-in? - #if self.committed[player] == self.stacks[player]: - #self.cap = self.stacks[player] - #contenders = self.contenders[:] - #contenders.remove(player) - #sidepotstacks = dict([(player, self.stacks[player]-self.committed[player]) for player in contenders]) - #self.sidepot = Pot(contenders, sidepotstacks, self.sidepotnum+1) - #elif self.committed[player] > self.stacks[player]: - #print "ERROR %s problem" % (player,) - #print self.committed[player], self.stacks[player] - #raise FpdbParseError - - #def returnUncalled(self): - #print "[POT]" - #print "last bet", self.uncalled - #print "calls:", self.calls - #print - #if self.uncalled: - #if max(self.calls) < self.uncalled[1]: - #self.total -= self.uncalled[1] - #print "returned", self.uncalled[0],self.uncalled[1]-max(self.calls), "from", self.uncalled[1] - - - #def __str__(self): - #total = self.total - #if self.sidepotnum == 0: - #return "Main pot $%.2f%s" %(total, self.sidepot or '' ) - #elif self.sidepotnum > 0: - #if self.sidepot: - #return ", side pot-%d $%.2f%s" % (self.sidepotnum, total, self.sidepot) - #else: - #return ", side pot $%.2f." % (total,) - - - - - From 5d909fb64898330f4f16ea623b114480f0a4fa28 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 20 Dec 2008 12:20:18 +0900 Subject: [PATCH 3/3] Reapply stars regex changed reverted during a merge --- pyfpdb/fpdb_simple.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyfpdb/fpdb_simple.py b/pyfpdb/fpdb_simple.py index 6636c656..e1e0f737 100644 --- a/pyfpdb/fpdb_simple.py +++ b/pyfpdb/fpdb_simple.py @@ -1170,14 +1170,16 @@ def parseHandStartTime(topline, site): tmp=topline[pos1:pos2] isUTC=True else: - tmp=topline[-30:] + tmp=topline #print "parsehandStartTime, tmp:", tmp pos = tmp.find("-")+2 tmp = tmp[pos:] #Need to match either # 2008/09/07 06:23:14 ET or - # 2008/08/17 - 01:14:43 (ET) - m = re.match('(?P[0-9]{4})\/(?P[0-9]{2})\/(?P[0-9]{2})[\- ]+(?P
[0-9]{2}):(?P[0-9]{2}):(?P[0-9]{2})',tmp) + # 2008/08/17 - 01:14:43 (ET) or + # 2008/11/12 9:33:31 CET [2008/11/12 3:33:31 ET] + rexx = '(?P[0-9]{4})\/(?P[0-9]{2})\/(?P[0-9]{2})[\- ]+(?P
[0-9]+):(?P[0-9]+):(?P[0-9]+)' + m = re.search(rexx,tmp) #print "year:", int(m.group('YEAR')), "month", int(m.group('MON')), "day", int(m.group('DAY')), "hour", int(m.group('HR')), "minute", int(m.group('MIN')), "second", int(m.group('SEC')) result = datetime.datetime(int(m.group('YEAR')), int(m.group('MON')), int(m.group('DAY')), int(m.group('HR')), int(m.group('MIN')), int(m.group('SEC'))) else: