Get mucked cards from Stars flop games. __str__ method for Hand.

This commit is contained in:
Ray 2009-07-03 18:59:50 -04:00
parent 3c2c328f5a
commit 9d7c370449
2 changed files with 60 additions and 8 deletions

View File

@ -26,6 +26,7 @@ import operator
import time,datetime import time,datetime
from copy import deepcopy from copy import deepcopy
from Exceptions import * from Exceptions import *
import pprint
import DerivedStats import DerivedStats
import Card import Card
@ -74,6 +75,7 @@ class Hand:
self.folded = set() self.folded = set()
self.dealt = set() # 'dealt to' line to be printed self.dealt = set() # 'dealt to' line to be printed
self.shown = set() # cards were shown self.shown = set() # cards were shown
self.mucked = set() # cards were mucked at showdown
# self.action = [] # self.action = []
# Things to do with money # Things to do with money
@ -83,8 +85,49 @@ class Hand:
self.rake = None self.rake = None
def __str__(self): def __str__(self):
vars = ( ("BB", self.bb),
("SB", self.sb),
("BUTTONPOS", self.buttonpos),
("HAND NO.", self.handid),
("SITE", self.sitename),
("TABLE NAME", self.tablename),
("HERO", self.hero),
("MAXSEATS", self.maxseats),
("LASTBET", self.lastBet),
("ACTION STREETS", self.actionStreets),
("STREETS", self.streets),
("ALL STREETS", self.allStreets),
("COMMUNITY STREETS", self.communityStreets),
("HOLE STREETS", self.holeStreets),
("COUNTED SEATS", self.counted_seats),
("DEALT", self.dealt),
("SHOWN", self.shown),
("MUCKED", self.mucked),
("TOTAL POT", self.totalpot),
("TOTAL COLLECTED", self.totalcollected),
("RAKE", self.rake),
("START TIME", self.starttime),
)
structs = ( ("PLAYERS", self.players),
("STACKS", self.stacks),
("POSTED", self.posted),
("POT", self.pot),
("SEATING", self.seating),
("GAMETYPE", self.gametype),
("ACTION", self.actions),
("COLLECTEES", self.collectees),
("BETS", self.bets),
("BOARD", self.board),
("DISCARDS", self.discards),
("HOLECARDS", self.holecards),
)
str = '' str = ''
str = str + "Hand Object for %s at %s" % (self.handid, self.sitename) for (name, var) in vars:
str = str + "\n%s = " % name + pprint.pformat(var)
for (name, struct) in structs:
str = str + "\n%s =\n" % name + pprint.pformat(struct, 4)
return str return str
def insert(self, db): def insert(self, db):
@ -494,12 +537,13 @@ class HoldemOmahaHand(Hand):
pass pass
def addHoleCards(self, cards, player, shown=False, dealt=False): def addHoleCards(self, cards, player, shown, mucked, dealt=False):
"""\ """\
Assigns observed holecards to a player. Assigns observed holecards to a player.
cards list of card bigrams e.g. ['2h','Jc'] cards list of card bigrams e.g. ['2h','Jc']
player (string) name of player player (string) name of player
shown whether they were revealed at showdown shown whether they were revealed at showdown
mucked whether they were mucked at showdown
dealt whether they were seen in a 'dealt to' line dealt whether they were seen in a 'dealt to' line
""" """
logging.debug("addHoleCards %s %s" % (cards, player)) logging.debug("addHoleCards %s %s" % (cards, player))
@ -516,23 +560,25 @@ dealt whether they were seen in a 'dealt to' line
self.dealt.add(player) self.dealt.add(player)
if shown: if shown:
self.shown.add(player) self.shown.add(player)
if mucked:
self.mucked.add(player)
if player in self.holecards['PREFLOP']: if player in self.holecards['PREFLOP']:
self.holecards['PREFLOP'][player].update(cardset) self.holecards['PREFLOP'][player].update(cardset)
else: else:
self.holecards['PREFLOP'][player] = cardset self.holecards['PREFLOP'][player] = cardset
def addShownCards(self, cards, player, holeandboard=None): 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). For when a player shows cards for any reason (for showdown or out of choice).
Card ranks will be uppercased Card ranks will be uppercased
""" """
logging.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard)) logging.debug("addShownCards %s hole=%s all=%s" % (player, cards, holeandboard))
if cards is not None: if cards is not None:
self.addHoleCards(cards,player,shown=True) self.addHoleCards(cards,player,shown, mucked)
elif holeandboard is not None: elif holeandboard is not None:
holeandboard = set([self.card(c) for c in holeandboard]) holeandboard = set([self.card(c) for c in holeandboard])
board = set([c for s in self.board.values() for c in s]) board = set([c for s in self.board.values() for c in s])
self.addHoleCards(holeandboard.difference(board),player,shown=True) self.addHoleCards(holeandboard.difference(board),player,shown, mucked)
def writeHTMLHand(self, fh=sys.__stdout__): def writeHTMLHand(self, fh=sys.__stdout__):

View File

@ -66,7 +66,7 @@ follow : whether to tail -f the input"""
self.re_ShowdownAction = re.compile(r"^%s: shows \[(?P<CARDS>.*)\]" % player_re, re.MULTILINE) self.re_ShowdownAction = re.compile(r"^%s: shows \[(?P<CARDS>.*)\]" % player_re, re.MULTILINE)
self.re_CollectPot = re.compile(r"Seat (?P<SEAT>[0-9]+): %s (\(button\) |\(small blind\) |\(big blind\) )?(collected|showed \[.*\] and won) \(\$(?P<POT>[.\d]+)\)(, mucked| with.*|)" % player_re, re.MULTILINE) self.re_CollectPot = re.compile(r"Seat (?P<SEAT>[0-9]+): %s (\(button\) |\(small blind\) |\(big blind\) )?(collected|showed \[.*\] and won) \(\$(?P<POT>[.\d]+)\)(, mucked| with.*|)" % player_re, re.MULTILINE)
self.re_sitsOut = re.compile("^%s sits out" % player_re, re.MULTILINE) self.re_sitsOut = re.compile("^%s sits out" % player_re, re.MULTILINE)
self.re_ShownCards = re.compile("^Seat (?P<SEAT>[0-9]+): %s \(.*\) showed \[(?P<CARDS>.*)\].*" % player_re, re.MULTILINE) self.re_ShownCards = re.compile("^Seat (?P<SEAT>[0-9]+): %s \(.*\) (?P<SHOWED>showed|mucked) \[(?P<CARDS>.*)\].*" % player_re, re.MULTILINE)
def readSupportedGames(self): def readSupportedGames(self):
@ -222,7 +222,7 @@ follow : whether to tail -f the input"""
# Also works with Omaha hands. # Also works with Omaha hands.
cards = m.group('NEWCARDS') cards = m.group('NEWCARDS')
cards = set(cards.split(' ')) cards = set(cards.split(' '))
hand.addHoleCards(cards, m.group('PNAME')) hand.addHoleCards(cards, m.group('PNAME'), shown=False, mucked=False)
def readDrawCards(self, hand, street): def readDrawCards(self, hand, street):
logging.debug("readDrawCards") logging.debug("readDrawCards")
@ -314,9 +314,15 @@ follow : whether to tail -f the input"""
def readShownCards(self,hand): def readShownCards(self,hand):
for m in self.re_ShownCards.finditer(hand.handText): for m in self.re_ShownCards.finditer(hand.handText):
if m.group('CARDS') is not None: if m.group('CARDS') is not None:
print "SHOWED", m.group('SHOWED')
cards = m.group('CARDS') cards = m.group('CARDS')
cards = set(cards.split(' ')) cards = set(cards.split(' '))
hand.addShownCards(cards=cards, player=m.group('PNAME'))
(shown, mucked) = (False, False)
if m.group('SHOWED') == "showed": shown = True
elif m.group('SHOWED') == "mucked": mucked = True
hand.addShownCards(cards=cards, player=m.group('PNAME'), shown=shown, mucked=mucked)
if __name__ == "__main__": if __name__ == "__main__":
parser = OptionParser() parser = OptionParser()