From 988a7e3eb5af3532f40c5727004730cc2b0c8356 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Tue, 16 Dec 2008 04:29:11 +0000 Subject: [PATCH] Added 'and is all-in' logic. Altered to read actions in correct street order. hand.streetList must be set correctly for different types of games. --- pyfpdb/EverleafToFpdb.py | 3 +-- pyfpdb/Hand.py | 40 ++++++++++++++++++++++++---------- pyfpdb/HandHistoryConverter.py | 6 +++-- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py index a34f2a63..9942105d 100755 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -209,11 +209,10 @@ class Everleaf(HandHistoryConverter): if __name__ == "__main__": c = Configuration.Config() - if sys.argv[0] == '': + if len(sys.argv) == 1: testfile = "regression-test-files/everleaf/Speed_Kuala_full.txt" else: testfile = sys.argv[1] - print "Converting: ", testfile e = Everleaf(c, testfile) e.processFile() print str(e) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index d746f3ab..a91038f6 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -28,6 +28,7 @@ import codecs from decimal import Decimal import operator from time import time +from copy import deepcopy class Hand: # def __init__(self, sitename, gametype, sb, bb, string): @@ -38,7 +39,7 @@ class Hand: self.gametype = gametype self.string = string - self.streetList = ['BLINDS','PREFLOP','FLOP','TURN','RIVER'] # a list of the observed street names in order + self.streetList = ['PREFLOP','FLOP','TURN','RIVER'] # a list of the observed street names in order self.handid = 0 self.sb = gametype[3] @@ -77,6 +78,8 @@ class Hand: # dict from player names to lists of hole cards self.holecards = {} + + self.stacks = {} # dict from player names to amounts collected self.collected = {} @@ -106,6 +109,7 @@ chips (string) the chips the player has at the start of the hand (can be None) If a player has None chips he won't be added.""" if chips is not None: self.players.append([seat, name, chips]) + self.stacks[name] = Decimal(chips) self.holecards[name] = set() for street in self.streetList: self.bets[street][name] = [] @@ -176,7 +180,9 @@ Card ranks will be uppercased # if player is None, it's a missing small blind. if player is not None: self.bets['PREFLOP'][player].append(Decimal(amount)) - self.actions['PREFLOP'] += [(player, 'posts', blindtype, amount)] + self.stacks[player] -= Decimal(amount) + print "DEBUG %s stack %s" % (player, self.stacks[player]) + self.actions['PREFLOP'] += [(player, 'posts', blindtype, amount, self.stacks[player]==0)] if blindtype == 'big blind': self.lastBet['PREFLOP'] = Decimal(amount) elif blindtype == 'small & big blinds': @@ -191,7 +197,9 @@ Card ranks will be uppercased if amount is not None: self.bets[street][player].append(Decimal(amount)) #self.lastBet[street] = Decimal(amount) - self.actions[street] += [(player, 'calls', amount)] + self.stacks[player] -= Decimal(amount) + self.actions[street] += [(player, 'calls', amount, self.stacks[player]==0)] + def addRaiseTo(self, street, player, amountTo): """\ @@ -208,13 +216,19 @@ Add a raise on [street] by [player] to [amountTo] self.lastBet[street] = Decimal(amountTo) amountBy = Decimal(amountTo) - amountToCall self.bets[street][player].append(amountBy+amountToCall) - self.actions[street] += [(player, 'raises', amountBy, amountTo, amountToCall)] + self.stacks[player] -= (Decimal(amountBy)+Decimal(amountToCall)) + print "DEBUG %s stack %s" % (player, self.stacks[player]) + self.actions[street] += [(player, 'raises', amountBy, amountTo, amountToCall, self.stacks[player]==0)] + def addBet(self, street, player, amount): self.checkPlayerExists(player) self.bets[street][player].append(Decimal(amount)) - self.actions[street] += [(player, 'bets', amount)] + self.stacks[player] -= Decimal(amount) + print "DEBUG %s stack %s" % (player, self.stacks[player]) + self.actions[street] += [(player, 'bets', amount, self.stacks[player]==0)] self.lastBet[street] = Decimal(amount) + def addFold(self, street, player): self.checkPlayerExists(player) @@ -246,9 +260,10 @@ Add a raise on [street] by [player] to [amountTo] self.totalpot += reduce(operator.add, self.bets[street][player], 0) print "conventional totalpot:", self.totalpot + + self.totalpot = 0 - - print self.actions + for street in self.actions: uncalled = 0 calls = [0] @@ -278,6 +293,7 @@ Add a raise on [street] by [player] to [amountTo] self.totalpot -= (uncalled - max(calls)) print "new totalpot:", self.totalpot + if self.totalcollected is None: self.totalcollected = 0; for amount in self.collected.values(): @@ -417,15 +433,15 @@ Map the tuple self.gametype onto the pokerstars string describing it def printActionLine(self, act, fh): if act[1] == 'folds': - print >>fh, _("%s: folds" %(act[0])) + print >>fh, _("%s: folds " %(act[0])) elif act[1] == 'checks': - print >>fh, _("%s: checks" %(act[0])) + print >>fh, _("%s: checks " %(act[0])) if act[1] == 'calls': - print >>fh, _("%s: calls $%s" %(act[0], act[2])) + print >>fh, _("%s: calls $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) if act[1] == 'bets': - print >>fh, _("%s: bets $%s" %(act[0], act[2])) + print >>fh, _("%s: bets $%s%s" %(act[0], act[2], ' and is all-in' if act[3] else '')) if act[1] == 'raises': - print >>fh, _("%s: raises $%s to $%s" %(act[0], act[2], act[3])) + print >>fh, _("%s: raises $%s to $%s%s" %(act[0], act[2], act[3], ' and is all-in' if act[5] else '')) # going to use pokereval to figure out hands at some point. # these functions are copied from pokergame.py diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 256de673..858c18b3 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -115,13 +115,15 @@ class HandHistoryConverter: print "\nInput:\n"+hand.string self.readHandInfo(hand) self.readPlayerStacks(hand) + print "DEBUG", hand.stacks self.markStreets(hand) self.readBlinds(hand) self.readHeroCards(hand) # want to generalise to draw games self.readCommunityCards(hand) # read community cards self.readShowdownActions(hand) - # Read action (Note: no guarantee this is in hand order. - for street in hand.streets.groupdict(): + + # Read actions in street order + for street in hand.streetList: # go through them in order if hand.streets.group(street) is not None: self.readAction(hand, street)