Merge branch 'master' of git://git.assembla.com/free_poker_tools

This commit is contained in:
Worros 2009-07-07 21:28:54 +08:00
commit c3d463b689
3 changed files with 68 additions and 20 deletions

View File

@ -409,6 +409,20 @@ Add a raise on [street] by [player] to [amountTo]
self.collectees[player] += Decimal(pot)
def addShownCards(self, cards, player, holeandboard=None, shown=True, 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.addHoleCards(cards,player,shown, mucked)
elif holeandboard is not None:
holeandboard = set([self.card(c) for c in holeandboard])
board = set([c for s in self.board.values() for c in s])
self.addHoleCards(holeandboard.difference(board),player,shown, mucked)
def totalPot(self):
"""If all bets and blinds have been added, totals up the total pot size"""
@ -566,20 +580,6 @@ dealt whether they were seen in a 'dealt to' line
else:
self.holecards['PREFLOP'][player] = cardset
def addShownCards(self, cards, player, holeandboard=None, shown=True, 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.addHoleCards(cards,player,shown, mucked)
elif holeandboard is not None:
holeandboard = set([self.card(c) for c in holeandboard])
board = set([c for s in self.board.values() for c in s])
self.addHoleCards(holeandboard.difference(board),player,shown, mucked)
def writeHTMLHand(self, fh=sys.__stdout__):
from nevow import tags as T
from nevow import flat
@ -771,6 +771,8 @@ Card ranks will be uppercased
else:
if name in self.shown:
print >>fh, ("Seat %d: %s showed [%s] and lost with..." % (seatnum, name, " ".join(self.holecards['PREFLOP'][name])))
elif name in self.mucked:
print >>fh, ("Seat %d: %s mucked [%s] " % (seatnum, name, " ".join(self.holecards['PREFLOP'][name])))
else:
print >>fh, ("Seat %d: %s mucked" % (seatnum, name))
@ -990,7 +992,7 @@ class StudHand(Hand):
hhc.readStudPlayerCards(self, street)
hhc.readAction(self, street)
hhc.readCollectPot(self)
#hhc.readShownCards(self) # not done yet
hhc.readShownCards(self) # not done yet
self.totalPot() # finalise it (total the pot)
hhc.getRake(self)
elif builtFrom == "DB":
@ -1013,6 +1015,42 @@ 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
"""
#
# 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]])
# TODO: def addComplete(self, player, amount):
def addComplete(self, street, player, amountTo):
# assert street=='THIRD'
@ -1045,6 +1083,7 @@ 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.
# 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)))
@ -1180,11 +1219,13 @@ Add a complete on [street] by [player] to [amountTo]
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[name]), self.collectees[name]))
print >>fh, _("Seat %d: %s showed [%s] and won ($%s)" % (seatnum, name, self.join_holecards(name), 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:
print >>fh, _("Seat %d: %s showed [%s]" % (seatnum, name, " ".join(self.holecards[name])))
print >>fh, _("Seat %d: %s showed [%s]" % (seatnum, name, self.join_holecards(name)))
elif name in self.mucked:
print >>fh, _("Seat %d: %s mucked [%s]" % (seatnum, name, self.join_holecards(name)))
elif name in self.folded:
print >>fh, _("Seat %d: %s folded" % (seatnum, name))
else:
@ -1193,6 +1234,12 @@ Add a complete on [street] by [player] to [amountTo]
print >>fh, "\n\n"
def join_holecards(self, player):
holecards = []
for street in self.holeStreets:
if self.holecards[street].has_key(player):
holecards = holecards + self.holecards[street][player][0]
return " ".join(holecards)
class Pot(object):

View File

@ -238,6 +238,7 @@ which it expects to find at self.re_TailSplitHands -- see for e.g. Everleaf.py.
logging.info("Unsupported game type: %s" % gametype)
if hand:
# print hand
hand.writeHand(self.out_fh)
else:
logging.info("Unsupported game type: %s" % gametype)

View File

@ -109,7 +109,7 @@ follow : whether to tail -f the input"""
info['bb'] = mg['BB']
if 'CURRENCY' in mg:
info['currency'] = currencies[mg['CURRENCY']]
if 'MIXED' in mg:
if 'MIXED' in mg and mg['MIXED'] != None:
info['mixedType'] = mixes[mg['MIXED']]
# NB: SB, BB must be interpreted as blinds or bets depending on limit type.
@ -224,7 +224,7 @@ follow : whether to tail -f the input"""
# Also works with Omaha hands.
cards = m.group('NEWCARDS')
cards = set(cards.split(' '))
hand.addHoleCards(cards, m.group('PNAME'), shown=False, mucked=False)
hand.addHoleCards(cards, m.group('PNAME'), shown=False, mucked=False, dealt=True)
def readDrawCards(self, hand, street):
logging.debug("readDrawCards")
@ -317,7 +317,7 @@ follow : whether to tail -f the input"""
for m in self.re_ShownCards.finditer(hand.handText):
if m.group('CARDS') is not None:
cards = m.group('CARDS')
cards = set(cards.split(' '))
cards = cards.split(' ') # needs to be a list, not a set--stud needs the order
(shown, mucked) = (False, False)
if m.group('SHOWED') == "showed": shown = True