Hand: removed trailing spaces

This commit is contained in:
grindi 2009-08-12 01:13:07 +04:00
parent 2e60586e65
commit 9d193f236e

View File

@ -4,12 +4,12 @@
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, version 3 of the License.
#
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#
#You should have received a copy of the GNU Affero General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#In the "official" distribution you can find the license in
@ -120,7 +120,7 @@ class Hand(object):
("MIXED", self.mixed),
("LASTBET", self.lastBet),
("ACTION STREETS", self.actionStreets),
("STREETS", self.streets),
("STREETS", self.streets),
("ALL STREETS", self.allStreets),
("COMMUNITY STREETS", self.communityStreets),
("HOLE STREETS", self.holeStreets),
@ -133,7 +133,7 @@ class Hand(object):
("RAKE", self.rake),
("START TIME", self.starttime),
)
structs = ( ("PLAYERS", self.players),
("STACKS", self.stacks),
("POSTED", self.posted),
@ -200,10 +200,10 @@ db: a connected fpdb_db object"""
elif self.gametype['category'] in ['razz','27_3draw','badugi']:
hilo = "l"
gtid = db.insertGameTypes( (self.siteId, self.gametype['type'], self.gametype['base'],
gtid = db.insertGameTypes( (self.siteId, self.gametype['type'], self.gametype['base'],
self.gametype['category'], self.gametype['limitType'], hilo,
int(Decimal(self.gametype['sb'])*100), int(Decimal(self.gametype['bb'])*100), 0, 0) )
# HudCache data to come from DerivedStats class
# HandsActions - all actions for all players for all streets - self.actions
@ -275,8 +275,8 @@ db: a connected fpdb_db object"""
def select(self, handId):
""" Function to create Hand object from database """
def addPlayer(self, seat, name, chips):
@ -332,7 +332,7 @@ If a player has None chips he won't be added."""
self.stacks[player] -= Decimal(ante)
act = (player, 'posts', "ante", ante, self.stacks[player]==0)
self.actions['ANTES'].append(act)
#~ self.lastBet['ANTES'] = Decimal(ante)
#~ self.lastBet['ANTES'] = Decimal(ante)
self.pot.addMoney(player, Decimal(ante))
def addBlind(self, player, blindtype, amount):
@ -377,22 +377,22 @@ If a player has None chips he won't be added."""
act = (player, 'calls', amount, self.stacks[player]==0)
self.actions[street].append(act)
self.pot.addMoney(player, Decimal(amount))
def addRaiseBy(self, street, player, amountBy):
"""\
Add a raise by amountBy on [street] by [player]
Add a raise by amountBy on [street] by [player]
"""
#Given only the amount raised by, the amount of the raise can be calculated by
# working out how much this player has already in the pot
# working out how much this player has already in the pot
# (which is the sum of self.bets[street][player])
# and how much he needs to call to match the previous player
# and how much he needs to call to match the previous player
# (which is tracked by self.lastBet)
# let Bp = previous bet
# let Bp = previous bet
# Bc = amount player has committed so far
# Rb = raise by
# then: C = Bp - Bc (amount to call)
# Rt = Bp + Rb (raise to)
#
#
amountBy = re.sub(u',', u'', amountBy) #some sites have commas
self.checkPlayerExists(player)
Rb = Decimal(amountBy)
@ -400,7 +400,7 @@ Add a raise by amountBy on [street] by [player]
Bc = reduce(operator.add, self.bets[street][player], 0)
C = Bp - Bc
Rt = Bp + Rb
self._addRaise(street, player, C, Rb, Rt)
#~ self.bets[street][player].append(C + Rb)
#~ self.stacks[player] -= (C + Rb)
@ -418,7 +418,7 @@ For sites which by "raises x" mean "calls and raises putting a total of x in the
C = Bp - Bc
Rb = CRb - C
Rt = Bp + Rb
self._addRaise(street, player, C, Rb, Rt)
def addRaiseTo(self, street, player, amountTo):
@ -443,9 +443,9 @@ Add a raise on [street] by [player] to [amountTo]
self.actions[street].append(act)
self.lastBet[street] = Rt # TODO check this is correct
self.pot.addMoney(player, C+Rb)
def addBet(self, street, player, amount):
log.debug("%s %s bets %s" %(street, player, amount))
amount = re.sub(u',', u'', amount) #some sites have commas
@ -463,7 +463,7 @@ Add a raise on [street] by [player] to [amountTo]
self.checkPlayerExists(player)
act = (player, 'stands pat')
self.actions[street].append(act)
def addFold(self, street, player):
log.debug("%s %s folds" % (street, player))
@ -471,7 +471,7 @@ Add a raise on [street] by [player] to [amountTo]
self.folded.add(player)
self.pot.addFold(player)
self.actions[street].append((player, 'folds'))
def addCheck(self, street, player):
#print "DEBUG: %s %s checked" % (street, player)
@ -506,7 +506,7 @@ Card ranks will be uppercased
def totalPot(self):
"""If all bets and blinds have been added, totals up the total pot size"""
# This gives us the total amount put in the pot
if self.totalpot is None:
self.pot.end()
@ -590,14 +590,14 @@ Map the tuple self.gametype onto the pokerstars string describing it
def writeGameLine(self):
"""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,
gs = gs + "Tournament #%s, %s %s - Level %s (%s) - " % (self.tourNo,
self.buyin, self.getGameTypeAsString(), self.level, self.getStakesAsString())
elif self.mixed != None: # all other mixed games
gs = gs + " %s (%s, %s) - " % (self.MS[self.mixed],
gs = gs + " %s (%s, %s) - " % (self.MS[self.mixed],
self.getGameTypeAsString(), self.getStakesAsString())
else: # non-mixed cash games
gs = gs + " %s (%s) - " % (self.getGameTypeAsString(), self.getStakesAsString())
@ -616,8 +616,8 @@ Map the tuple self.gametype onto the pokerstars string describing it
def writeHand(self, fh=sys.__stdout__):
# PokerStars format.
print >>fh, self.writeGameLine()
print >>fh, self.writeTableLine()
print >>fh, self.writeGameLine()
print >>fh, self.writeTableLine()
class HoldemOmahaHand(Hand):
@ -632,9 +632,9 @@ class HoldemOmahaHand(Hand):
Hand.__init__(self, sitename, gametype, handText, builtFrom = "HHC")
self.sb = gametype['sb']
self.bb = gametype['bb']
#Populate a HoldemOmahaHand
#Generally, we call 'read' methods here, which get the info according to the particular filter (hhc)
#Generally, we call 'read' methods here, which get the info according to the particular filter (hhc)
# which then invokes a 'addXXX' callback
if builtFrom == "HHC":
hhc.readHandInfo(self)
@ -667,7 +667,7 @@ class HoldemOmahaHand(Hand):
else:
log.warning("HoldemOmahaHand.__init__:Neither HHC nor DB+handid provided")
pass
def addShownCards(self, cards, player, shown=True, mucked=False, dealt=False):
if player == self.hero: # we have hero's cards just update shown/mucked
@ -710,7 +710,7 @@ class HoldemOmahaHand(Hand):
]
)
if street in self.actionStreets and self.actions[street]:
lines.append(
lines.append(
T.ol(class_='actions', data=self.actions[street], render=render_action) [
T.li(pattern='list_item')[ T.slot(name='action') ]
]
@ -744,8 +744,8 @@ class HoldemOmahaHand(Hand):
context.tag[ pat().fillSlots('action', x)]
return context.tag
s = T.p[
T.h1[
s = T.p[
T.h1[
T.span(class_='site')["%s Game #%s]" % ('PokerStars', self.handid)],
T.span(class_='type_limit')[ "%s ($%s/$%s)" %(self.getGameTypeAsString(), self.sb, self.bb) ],
T.span(class_='date')[ datetime.datetime.strftime(self.starttime,'%Y/%m/%d - %H:%M:%S ET') ]
@ -771,7 +771,7 @@ class HoldemOmahaHand(Hand):
return str(tidy.parseString(flat.flatten(s), **options))
def writeHand(self, fh=sys.__stdout__):
# PokerStars format.
super(HoldemOmahaHand, self).writeHand(fh)
@ -785,7 +785,7 @@ class HoldemOmahaHand(Hand):
if self.actions['BLINDSANTES']:
for act in self.actions['BLINDSANTES']:
print >>fh, self.actionString(act)
print >>fh, ("*** HOLE CARDS ***")
for player in self.dealt:
print >>fh, ("Dealt to %s [%s]" %(player, " ".join(self.holecards['PREFLOP'][player][1])))
@ -831,7 +831,7 @@ class HoldemOmahaHand(Hand):
numOfHoleCardsNeeded = 2
if len(self.holecards['PREFLOP'][name]) == numOfHoleCardsNeeded:
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
# s0rrow collected $5.15 from side pot
@ -873,7 +873,7 @@ class HoldemOmahaHand(Hand):
print >>fh, ("Seat %d: %s mucked" % (seatnum, name))
print >>fh, "\n\n"
class DrawHand(Hand):
def __init__(self, hhc, sitename, gametype, handText, builtFrom = "HHC"):
if gametype['base'] != 'draw':
@ -918,8 +918,8 @@ class DrawHand(Hand):
# - this is a bet of 1 sb, as yet uncalled.
# Player in the big blind posts
# - this is a call of 1 sb and a raise to 1 bb
#
#
log.debug("addBlind: %s posts %s, %s" % (player, blindtype, amount))
if player is not None:
self.bets['DEAL'][player].append(Decimal(amount))
@ -929,7 +929,7 @@ class DrawHand(Hand):
self.actions['BLINDSANTES'].append(act)
self.pot.addMoney(player, Decimal(amount))
if blindtype == 'big blind':
self.lastBet['DEAL'] = Decimal(amount)
self.lastBet['DEAL'] = Decimal(amount)
elif blindtype == 'both':
# extra small blind is 'dead'
self.lastBet['DEAL'] = Decimal(self.bb)
@ -1051,7 +1051,7 @@ class StudHand(Hand):
self.sb = gametype['sb']
self.bb = gametype['bb']
#Populate the StudHand
#Generally, we call a 'read' method here, which gets the info according to the particular filter (hhc)
#Generally, we call a 'read' method here, which gets the info according to the particular filter (hhc)
# which then invokes a 'addXXX' callback
if builtFrom == "HHC":
hhc.readHandInfo(self)
@ -1126,7 +1126,7 @@ Add a complete on [street] by [player] to [amountTo]
#~ self.actions[street].append(act)
#~ self.lastBet[street] = Rt # TODO check this is correct
#~ self.pot.addMoney(player, C+Rb)
def addBringIn(self, player, bringin):
if player is not None:
log.debug("Bringin: %s, %s" % (player , bringin))
@ -1137,12 +1137,12 @@ Add a complete on [street] by [player] to [amountTo]
self.lastBet['THIRD'] = Decimal(bringin)
self.pot.addMoney(player, Decimal(bringin))
def writeHand(self, fh=sys.__stdout__):
# PokerStars format.
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]:
@ -1273,7 +1273,7 @@ Add a complete on [street] by [player] to [amountTo]
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
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):
@ -1303,14 +1303,14 @@ class Pot(object):
def setSym(self, sym):
self.sym = sym
def addPlayer(self,player):
self.committed[player] = Decimal(0)
def addFold(self, player):
# addFold must be called when a player folds
self.contenders.discard(player)
def addMoney(self, player, amount):
# addMoney must be called for any actions that put money in the pot, in the order they occur
self.contenders.add(player)
@ -1318,7 +1318,7 @@ class Pot(object):
def end(self):
self.total = sum(self.committed.values())
# Return any uncalled bet.
committed = sorted([ (v,k) for (k,v) in self.committed.items()])
lastbet = committed[-1][0] - committed[-2][0]
@ -1336,7 +1336,7 @@ class Pot(object):
self.pots = []
while len(commitsall) > 0:
commitslive = [(v,k) for (v,k) in commitsall if k in self.contenders]
v1 = commitslive[0][0]
v1 = commitslive[0][0]
self.pots += [sum([min(v,v1) for (v,k) in commitsall])]
commitsall = [((v-v1),k) for (v,k) in commitsall if v-v1 >0]
@ -1346,7 +1346,7 @@ class Pot(object):
# and y+z+r = x
# for example:
# Total pot $124.30 Main pot $98.90. Side pot $23.40. | Rake $2
def __str__(self):
if self.sym is None:
self.sym = "C"
@ -1354,17 +1354,17 @@ class Pot(object):
print "call Pot.end() before printing pot total"
# NB if I'm sure end() is idempotent, call it here.
raise FpdbParseError
ret = "Total pot %s%.2f" % (self.sym, self.total)
if len(self.pots) < 2:
return ret;
ret += " Main pot %s%.2f" % (self.sym, self.pots[0])
return ret + ''.join([ (" Side pot %s%.2f." % (self.sym, self.pots[x]) ) for x in xrange(1, len(self.pots)) ])
def assemble(cnxn, handid):
c = cnxn.cursor()
# We need at least sitename, gametype, handid
# for the Hand.__init__
c.execute("""
@ -1407,10 +1407,10 @@ limit 1""", {'handid':handid})
h.setCommunityCards('FLOP', cards[0:3])
if cards[3]:
h.setCommunityCards('TURN', [cards[3]])
if cards[4]:
if cards[4]:
h.setCommunityCards('RIVER', [cards[4]])
#[Card.valueSuitFromCard(x) for x in cards]
# HandInfo : HID, TABLE
# BUTTON - why is this treated specially in Hand?
# answer: it is written out in hand histories
@ -1428,7 +1428,7 @@ WHERE h.id = %(handid)s
h.handid = res[0]
h.tablename = res[1]
h.starttime = res[2] # automatically a datetime
# PlayerStacks
c.execute("""
SELECT
@ -1453,7 +1453,7 @@ and p.id = hp.playerid
h.addCollectPot(name, winnings)
if position == 'B':
h.buttonpos = seat
# actions
c.execute("""
@ -1501,7 +1501,7 @@ ORDER BY
#hc.readShownCards(self)
h.totalPot()
h.rake = h.totalpot - h.totalcollected
return h