From d2f5633384174fa9964739e0571cc05deff97d10 Mon Sep 17 00:00:00 2001 From: Erki Ferenc Date: Tue, 28 Sep 2010 15:46:51 +0200 Subject: [PATCH] PartyPoker: improved handling of players with zero or unknown stacks --- pyfpdb/PartyPokerToFpdb.py | 43 ++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/pyfpdb/PartyPokerToFpdb.py b/pyfpdb/PartyPokerToFpdb.py index a96308c0..aee095b8 100755 --- a/pyfpdb/PartyPokerToFpdb.py +++ b/pyfpdb/PartyPokerToFpdb.py @@ -348,19 +348,19 @@ class PartyPoker(HandHistoryConverter): def readPlayerStacks(self, hand): log.debug("readPlayerStacks") m = self.re_PlayerInfo.finditer(hand.handText) - players = [] + maxKnownStack = 0 + zeroStackPlayers = [] for a in m: - hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), - clearMoneyString(a.group('CASH'))) - - # detecting new active players without a seat - # and new active players with zero stack + if a.group('CASH') > '0': + #record max known stack for use with players with unknown stack + maxKnownStack = max(a.group('CASH'),maxKnownStack) + hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), clearMoneyString(a.group('CASH'))) + else: + #zero stacked players are added later + zeroStackPlayers.append([int(a.group('SEAT')), a.group('PNAME'), clearMoneyString(a.group('CASH'))]) if hand.gametype['type'] == 'ring': - re_JoiningPlayers = re.compile(r"(?P.*) has joined the table") - re_BBPostingPlayers = re.compile(r"(?P.*) posts big blind") - seatedPlayers = list([(f[1]) for f in hand.players]) - + #finds first vacant seat after an exact seat def findFirstEmptySeat(startSeat): while startSeat in occupiedSeats: if startSeat >= hand.maxseats: @@ -368,14 +368,25 @@ class PartyPoker(HandHistoryConverter): startSeat += 1 return startSeat + re_JoiningPlayers = re.compile(r"(?P.*) has joined the table") + re_BBPostingPlayers = re.compile(r"(?P.*) posts big blind") + match_JoiningPlayers = re_JoiningPlayers.findall(hand.handText) match_BBPostingPlayers = re_BBPostingPlayers.findall(hand.handText) - ringLimit = self.re_GameInfoRing.search(hand.handText).groupdict()['RINGLIMIT'] - unseatedActivePlayers = list(set(match_BBPostingPlayers) - set(seatedPlayers)) - for player in seatedPlayers: - if hand.stacks[player] == 0 and player in match_BBPostingPlayers: - hand.stacks[player] = Decimal(ringLimit) + #add every player with zero stack, but: + #if a zero stacked player is just joined the table in this very hand then set his stack to maxKnownStack + for p in zeroStackPlayers: + if p[1] in match_JoiningPlayers: + p[2] = clearMoneyString(maxKnownStack) + hand.addPlayer(p[0],p[1],p[2]) + + seatedPlayers = list([(f[1]) for f in hand.players]) + + #it works for all known cases as of 2010-09-28 + #should be refined with using match_ActivePlayers instead of match_BBPostingPlayers + #as a leaving and rejoining player could be active without posting a BB (sample HH needed) + unseatedActivePlayers = list(set(match_BBPostingPlayers) - set(seatedPlayers)) if unseatedActivePlayers: for player in unseatedActivePlayers: @@ -384,7 +395,7 @@ class PartyPoker(HandHistoryConverter): occupiedSeats = list([(f[0]) for f in hand.players]) occupiedSeats.sort() newPlayerSeat = findFirstEmptySeat(previousBBPosterSeat) - hand.addPlayer(newPlayerSeat,player,clearMoneyString(ringLimit)) + hand.addPlayer(newPlayerSeat,player,clearMoneyString(maxKnownStack)) def markStreets(self, hand): m = re.search(