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

This commit is contained in:
Worros 2009-07-04 14:51:55 +08:00
commit 89b410a766
5 changed files with 89 additions and 29 deletions

View File

@ -302,7 +302,8 @@ class Database:
fpdb_simple.fillCardArrays(len(names), base, category, card_values, card_suits)
hands_id = fpdb_simple.storeHands(self.backend, db, cursor, site_hand_no, gametype_id
,hand_start_time, names, tableName, maxSeats, hudImportData)
,hand_start_time, names, tableName, maxSeats, hudImportData
,(None, None, None, None, None), (None, None, None, None, None))
#print "before calling store_hands_players_stud, antes:", antes
hands_players_ids = fpdb_simple.store_hands_players_stud(self.backend, db, cursor, hands_id, player_ids

View File

@ -26,6 +26,7 @@ import operator
import time,datetime
from copy import deepcopy
from Exceptions import *
import pprint
import DerivedStats
import Card
@ -74,6 +75,7 @@ class Hand:
self.folded = set()
self.dealt = set() # 'dealt to' line to be printed
self.shown = set() # cards were shown
self.mucked = set() # cards were mucked at showdown
# self.action = []
# Things to do with money
@ -83,8 +85,49 @@ class Hand:
self.rake = None
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 + "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
def insert(self, db):
@ -493,12 +536,13 @@ class HoldemOmahaHand(Hand):
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.
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
"""
logging.debug("addHoleCards %s %s" % (cards, player))
@ -515,23 +559,25 @@ dealt whether they were seen in a 'dealt to' line
self.dealt.add(player)
if shown:
self.shown.add(player)
if mucked:
self.mucked.add(player)
if player in self.holecards['PREFLOP']:
self.holecards['PREFLOP'][player].update(cardset)
else:
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).
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=True)
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=True)
self.addHoleCards(holeandboard.difference(board),player,shown, mucked)
def writeHTMLHand(self, fh=sys.__stdout__):
@ -915,6 +961,11 @@ class StudHand(Hand):
def __init__(self, hhc, sitename, gametype, handText, builtFrom = "HHC"):
if gametype['base'] != 'stud':
pass # or indeed don't pass and complain instead
self.allStreets = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH']
self.communityStreets = []
self.actionStreets = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH']
self.streetList = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH'] # a list of the observed street names in order
self.holeStreets = ['ANTES','THIRD','FOURTH','FIFTH','SIXTH','SEVENTH']
Hand.__init__(self, sitename, gametype, handText)
@ -956,7 +1007,7 @@ closed likewise, but known only to player
logging.debug("addPlayerCards %s, o%s x%s" % (player, open, closed))
try:
self.checkPlayerExists(player)
self.holecards[player][street] = (open, closed)
self.holecards[street][player] = (open, closed)
# cards = set([self.card(c) for c in cards])
# self.holecards[player].update(cards)
except FpdbParseError, e:
@ -1014,8 +1065,8 @@ Add a complete on [street] by [player] to [amountTo]
dealt = 0
#~ print >>fh, _("*** 3RD STREET ***")
for player in [x[1] for x in self.players if x[1] in players_who_post_antes]:
if 'THIRD' in self.holecards[player]:
(open, closed) = self.holecards[player]['THIRD']
if self.holecards['THIRD'].has_key(player):
(open, closed) = self.holecards['THIRD'][player]
dealt+=1
if dealt==1:
print >>fh, _("*** 3RD STREET ***")
@ -1028,12 +1079,12 @@ Add a complete on [street] by [player] to [amountTo]
dealt = 0
#~ print >>fh, _("*** 4TH STREET ***")
for player in [x[1] for x in self.players if x[1] in players_who_post_antes]:
if 'FOURTH' in self.holecards[player]:
if player in self.holecards['FOURTH']:
old = []
(o,c) = self.holecards[player]['THIRD']
(o,c) = self.holecards['THIRD'][player]
if o:old.extend(o)
if c:old.extend(c)
new = self.holecards[player]['FOURTH'][0]
new = self.holecards['FOURTH'][player][0]
dealt+=1
if dealt==1:
print >>fh, _("*** 4TH STREET ***")
@ -1045,13 +1096,13 @@ Add a complete on [street] by [player] to [amountTo]
dealt = 0
#~ print >>fh, _("*** 5TH STREET ***")
for player in [x[1] for x in self.players if x[1] in players_who_post_antes]:
if 'FIFTH' in self.holecards[player]:
if self.holecards['FIFTH'].has_key(player):
old = []
for street in ('THIRD','FOURTH'):
(o,c) = self.holecards[player][street]
(o,c) = self.holecards[street][player]
if o:old.extend(o)
if c:old.extend(c)
new = self.holecards[player]['FIFTH'][0]
new = self.holecards['FIFTH'][player][0]
dealt+=1
if dealt==1:
print >>fh, _("*** 5TH STREET ***")
@ -1063,13 +1114,13 @@ Add a complete on [street] by [player] to [amountTo]
dealt = 0
#~ print >>fh, _("*** 6TH STREET ***")
for player in [x[1] for x in self.players if x[1] in players_who_post_antes]:
if 'SIXTH' in self.holecards[player]:
if self.holecards['SIXTH'].has_key(player):
old = []
for street in ('THIRD','FOURTH','FIFTH'):
(o,c) = self.holecards[player][street]
(o,c) = self.holecards[street][player]
if o:old.extend(o)
if c:old.extend(c)
new = self.holecards[player]['SIXTH'][0]
new = self.holecards['SIXTH'][player][0]
dealt += 1
if dealt == 1:
print >>fh, _("*** 6TH STREET ***")
@ -1084,13 +1135,13 @@ Add a complete on [street] by [player] to [amountTo]
# i.e. are all but one players folded; is there an allin showdown; and all that.
print >>fh, _("*** 7TH STREET ***")
for player in [x[1] for x in self.players if x[1] in players_who_post_antes]:
if 'SEVENTH' in self.holecards[player]:
if self.holecards['SEVENTH'].has_key(player):
old = []
for street in ('THIRD','FOURTH','FIFTH','SIXTH'):
(o,c) = self.holecards[player][street]
(o,c) = self.holecards[street][player]
if o:old.extend(o)
if c:old.extend(c)
new = self.holecards[player]['SEVENTH'][0]
new = self.holecards['SEVENTH'][player][0]
if new:
print >>fh, _("Dealt to %s:%s%s") % (player, " [" + " ".join(old) + "] " if old else " ", "[" + " ".join(new) + "]" if new else "")
for act in self.actions['SEVENTH']:

View File

@ -448,7 +448,8 @@ class Flop_Mucked(Aux_Seats):
container.move(self.positions[i][0], self.positions[i][1]) # here is where I move back
self.displayed = True
if i != "common":
self.m_windows[i].eb.set_tooltip_text(self.hud.stat_dict[i]['screen_name'])
id = self.get_id_from_seat(i)
self.m_windows[i].eb.set_tooltip_text(self.hud.stat_dict[id]['screen_name'])
def update_gui(self, new_hand_id):
"""Prepare and show the mucked cards."""
@ -458,7 +459,7 @@ class Flop_Mucked(Aux_Seats):
n_sd = 0
for (i, cards) in self.hud.cards.iteritems():
n_cards = self.has_cards(cards)
if n_cards > 0:
if n_cards > 0 and i != 'common':
n_sd = n_sd + 1
if n_sd < 2:
print "skipping, n_sd =", n_sd

View File

@ -26,7 +26,7 @@ from HandHistoryConverter import *
class PokerStars(HandHistoryConverter):
# Static regexes
re_GameInfo = re.compile("PokerStars Game #(?P<HID>[0-9]+):\s+(HORSE)? \(?(?P<GAME>Hold\'em|Razz|7 Card Stud|7 Card Stud Hi/Lo|Omaha|Omaha Hi/Lo|Badugi) (?P<LIMIT>No Limit|Limit|Pot Limit),? \(?(?P<CURRENCY>\$|)?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+)\) - (?P<DATETIME>.*$)", re.MULTILINE)
re_GameInfo = re.compile("PokerStars Game #(?P<HID>[0-9]+):\s+(?P<MIXED>HORSE|8\-Game|HOSE)? \(?(?P<GAME>Hold\'em|Razz|7 Card Stud|7 Card Stud Hi/Lo|Omaha|Omaha Hi/Lo|Badugi) (?P<LIMIT>No Limit|Limit|Pot Limit),? \(?(?P<CURRENCY>\$|)?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+)\) - (?P<DATETIME>.*$)", re.MULTILINE)
re_SplitHands = re.compile('\n\n+')
re_TailSplitHands = re.compile('(\n\n\n+)')
re_HandInfo = re.compile("^Table \'(?P<TABLE>[- a-zA-Z]+)\'(?P<TABLEATTRIBUTES>.+?$)?", re.MULTILINE)
@ -66,8 +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_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_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):
return [["ring", "hold", "nl"],
@ -89,6 +88,7 @@ follow : whether to tail -f the input"""
# translations from captured groups to our info strings
limits = { 'No Limit':'nl', 'Pot Limit':'pl', 'Limit':'fl' }
mixes = { 'HORSE': 'horse', '8-Game': '8game', 'HOSE': 'hose'}
games = { # base, category
"Hold'em" : ('hold','holdem'),
'Omaha' : ('hold','omahahi'),
@ -109,6 +109,8 @@ follow : whether to tail -f the input"""
info['bb'] = mg['BB']
if 'CURRENCY' in mg:
info['currency'] = currencies[mg['CURRENCY']]
if 'MIXED' in mg:
info['mixedType'] = mixes[mg['MIXED']]
# NB: SB, BB must be interpreted as blinds or bets depending on limit type.
return info
@ -222,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'))
hand.addHoleCards(cards, m.group('PNAME'), shown=False, mucked=False)
def readDrawCards(self, hand, street):
logging.debug("readDrawCards")
@ -316,7 +318,12 @@ follow : whether to tail -f the input"""
if m.group('CARDS') is not None:
cards = m.group('CARDS')
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__":
parser = OptionParser()

View File

@ -369,7 +369,7 @@ def clean_title(name):
for pattern in [' \(6 max\)', ' \(heads up\)', ' \(deep\)',
' \(deep hu\)', ' \(deep 6\)', ' \(2\)',
' \(edu\)', ' \(edu, 6 max\)', ' \(6\)',
' \(speed\)',
' \(speed\)', 'special', 'newVPP',
' no all-in', ' fast', ',', ' 50BB min', '50bb min', '\s+$']:
name = re.sub(pattern, '', name)
name = name.rstrip()