2010-07-04 03:05:16 +02:00
|
|
|
#!/usr/bin/env python2
|
2009-08-06 15:14:52 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2010-07-04 03:05:16 +02:00
|
|
|
# Copyright 2009-2010, Grigorij Indigirkin
|
2009-08-12 00:35:34 +02:00
|
|
|
#
|
2009-08-06 15:14:52 +02:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2009-08-12 00:35:34 +02:00
|
|
|
#
|
2009-08-06 15:14:52 +02:00
|
|
|
# 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.
|
2009-08-12 00:35:34 +02:00
|
|
|
#
|
2009-08-06 15:14:52 +02:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
########################################################################
|
|
|
|
|
|
|
|
import sys
|
|
|
|
from collections import defaultdict
|
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
from Exceptions import FpdbParseError
|
2009-08-06 15:14:52 +02:00
|
|
|
from HandHistoryConverter import *
|
|
|
|
|
|
|
|
# PartyPoker HH Format
|
|
|
|
|
2009-11-08 21:09:14 +01:00
|
|
|
class FpdbParseError(FpdbParseError):
|
|
|
|
"Usage: raise FpdbParseError(<msg>[, hh=<hh>][, hid=<hid>])"
|
2009-10-31 15:53:31 +01:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
def __init__(self, msg='', hh=None, hid=None):
|
2009-11-08 21:09:14 +01:00
|
|
|
return super(FpdbParseError, self).__init__(msg, hid=hid)
|
2009-10-31 15:53:31 +01:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
def wrapHh(self, hh):
|
|
|
|
return ("%(DELIMETER)s\n%(HH)s\n%(DELIMETER)s") % \
|
|
|
|
{'DELIMETER': '#'*50, 'HH': hh}
|
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
class PartyPoker(HandHistoryConverter):
|
2009-08-09 21:22:23 +02:00
|
|
|
sitename = "PartyPoker"
|
2009-08-09 16:19:43 +02:00
|
|
|
codepage = "cp1252"
|
2009-11-08 21:09:14 +01:00
|
|
|
siteId = 9
|
|
|
|
filetype = "text"
|
2009-08-06 15:14:52 +02:00
|
|
|
sym = {'USD': "\$", }
|
|
|
|
|
|
|
|
# Static regexes
|
|
|
|
# $5 USD NL Texas Hold'em - Saturday, July 25, 07:53:52 EDT 2009
|
|
|
|
# NL Texas Hold'em $1 USD Buy-in Trny:45685440 Level:8 Blinds-Antes(600/1 200 -50) - Sunday, May 17, 11:25:07 MSKS 2009
|
|
|
|
re_GameInfoRing = re.compile("""
|
2010-01-23 16:24:00 +01:00
|
|
|
(?P<CURRENCY>\$|)\s*(?P<RINGLIMIT>[.,0-9]+)([.,0-9/$]+)?\s*(?:USD)?\s*
|
|
|
|
(?P<LIMIT>(NL|PL|))\s*
|
2009-08-09 17:54:35 +02:00
|
|
|
(?P<GAME>(Texas\ Hold\'em|Omaha))
|
2009-08-06 15:14:52 +02:00
|
|
|
\s*\-\s*
|
|
|
|
(?P<DATETIME>.+)
|
|
|
|
""", re.VERBOSE)
|
|
|
|
re_GameInfoTrny = re.compile("""
|
2010-01-23 16:24:00 +01:00
|
|
|
(?P<LIMIT>(NL|PL|))\s*
|
2009-08-09 17:54:35 +02:00
|
|
|
(?P<GAME>(Texas\ Hold\'em|Omaha))\s+
|
2010-01-23 16:24:00 +01:00
|
|
|
(?:(?P<BUYIN>\$?[.,0-9]+)\s*(?P<BUYIN_CURRENCY>USD)?\s*Buy-in\s+)?
|
2009-08-06 15:14:52 +02:00
|
|
|
Trny:\s?(?P<TOURNO>\d+)\s+
|
|
|
|
Level:\s*(?P<LEVEL>\d+)\s+
|
2010-01-23 16:24:00 +01:00
|
|
|
((Blinds|Stakes)(?:-Antes)?)\(
|
|
|
|
(?P<SB>[.,0-9 ]+)\s*
|
|
|
|
/(?P<BB>[.,0-9 ]+)
|
|
|
|
(?:\s*-\s*(?P<ANTE>[.,0-9 ]+)\$?)?
|
2009-08-06 15:14:52 +02:00
|
|
|
\)
|
|
|
|
\s*\-\s*
|
|
|
|
(?P<DATETIME>.+)
|
|
|
|
""", re.VERBOSE)
|
|
|
|
re_Hid = re.compile("^Game \#(?P<HID>\d+) starts.")
|
|
|
|
|
|
|
|
re_PlayerInfo = re.compile("""
|
|
|
|
Seat\s(?P<SEAT>\d+):\s
|
|
|
|
(?P<PNAME>.*)\s
|
|
|
|
\(\s*\$?(?P<CASH>[0-9,.]+)\s*(?:USD|)\s*\)
|
2009-08-12 00:35:34 +02:00
|
|
|
""" ,
|
2009-08-06 15:14:52 +02:00
|
|
|
re.VERBOSE)
|
|
|
|
|
|
|
|
re_HandInfo = re.compile("""
|
2010-03-03 18:57:30 +01:00
|
|
|
^Table\s+(?P<TTYPE>[$a-zA-Z0-9 ]+)?\s+
|
2009-08-06 15:14:52 +02:00
|
|
|
(?: \#|\(|)(?P<TABLE>\d+)\)?\s+
|
2010-01-23 16:24:00 +01:00
|
|
|
(?:[a-zA-Z0-9 ]+\s+\#(?P<MTTTABLE>\d+).+)?
|
2009-12-21 02:21:41 +01:00
|
|
|
(\(No\sDP\)\s)?
|
2009-08-06 15:14:52 +02:00
|
|
|
\((?P<PLAY>Real|Play)\s+Money\)\s+ # FIXME: check if play money is correct
|
|
|
|
Seat\s+(?P<BUTTON>\d+)\sis\sthe\sbutton
|
2010-03-03 06:42:13 +01:00
|
|
|
\s+Total\s+number\s+of\s+players\s+\:\s+(?P<PLYRS>\d+)/?(?P<MAX>\d+)?
|
2009-08-12 00:35:34 +02:00
|
|
|
""",
|
2010-03-03 06:42:13 +01:00
|
|
|
re.VERBOSE|re.MULTILINE|re.DOTALL)
|
2009-08-06 15:14:52 +02:00
|
|
|
|
2009-11-08 21:09:14 +01:00
|
|
|
re_CountedSeats = re.compile("^Total\s+number\s+of\s+players\s*:\s*(?P<COUNTED_SEATS>\d+)", re.MULTILINE)
|
2009-08-06 15:14:52 +02:00
|
|
|
re_SplitHands = re.compile('\x00+')
|
|
|
|
re_TailSplitHands = re.compile('(\x00+)')
|
|
|
|
lineSplitter = '\n'
|
|
|
|
re_Button = re.compile('Seat (?P<BUTTON>\d+) is the button', re.MULTILINE)
|
|
|
|
re_Board = re.compile(r"\[(?P<CARDS>.+)\]")
|
2009-08-11 16:02:58 +02:00
|
|
|
re_NoSmallBlind = re.compile(
|
|
|
|
'^There is no Small Blind in this hand as the Big Blind '
|
|
|
|
'of the previous hand left the table', re.MULTILINE)
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
def allHandsAsList(self):
|
|
|
|
list = HandHistoryConverter.allHandsAsList(self)
|
2009-08-09 14:38:55 +02:00
|
|
|
if list is None:
|
2009-08-09 19:24:48 +02:00
|
|
|
return []
|
2009-08-06 15:14:52 +02:00
|
|
|
return filter(lambda text: len(text.strip()), list)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-09 19:24:48 +02:00
|
|
|
def guessMaxSeats(self, hand):
|
|
|
|
"""Return a guess at max_seats when not specified in HH."""
|
2010-03-03 21:08:00 +01:00
|
|
|
mo = self.maxOccSeat(hand)
|
|
|
|
if mo == 10: return mo
|
|
|
|
if mo == 2: return 2
|
|
|
|
if mo <= 6: return 6
|
|
|
|
# there are 9-max tables for cash and 10-max for tournaments
|
|
|
|
return 9 if hand.gametype['type']=='ring' else 10
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def compilePlayerRegexs(self, hand):
|
|
|
|
players = set([player[1] for player in hand.players])
|
|
|
|
if not players <= self.compiledPlayers: # x <= y means 'x is subset of y'
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
self.compiledPlayers = players
|
|
|
|
player_re = "(?P<PNAME>" + "|".join(map(re.escape, players)) + ")"
|
|
|
|
subst = {'PLYR': player_re, 'CUR_SYM': hand.SYMBOL[hand.gametype['currency']],
|
|
|
|
'CUR': hand.gametype['currency'] if hand.gametype['currency']!='T$' else ''}
|
2009-08-06 14:39:14 +02:00
|
|
|
for key in ('CUR_SYM', 'CUR'):
|
|
|
|
subst[key] = re.escape(subst[key])
|
2009-08-06 15:14:52 +02:00
|
|
|
self.re_PostSB = re.compile(
|
2010-01-23 16:24:00 +01:00
|
|
|
r"^%(PLYR)s posts small blind \[%(CUR_SYM)s(?P<SB>[.,0-9]+) ?%(CUR)s\]\." % subst,
|
2009-08-06 15:14:52 +02:00
|
|
|
re.MULTILINE)
|
|
|
|
self.re_PostBB = re.compile(
|
2009-11-08 21:09:14 +01:00
|
|
|
r"^%(PLYR)s posts big blind \[%(CUR_SYM)s(?P<BB>[.,0-9]+) ?%(CUR)s\]\." % subst,
|
2009-08-06 15:14:52 +02:00
|
|
|
re.MULTILINE)
|
2009-08-11 16:02:58 +02:00
|
|
|
self.re_PostDead = re.compile(
|
2009-08-12 00:35:34 +02:00
|
|
|
r"^%(PLYR)s posts big blind \+ dead \[(?P<BBNDEAD>[.,0-9]+) ?%(CUR_SYM)s\]\." % subst,
|
2009-08-11 16:02:58 +02:00
|
|
|
re.MULTILINE)
|
2009-08-06 15:14:52 +02:00
|
|
|
self.re_Antes = re.compile(
|
2010-01-23 16:24:00 +01:00
|
|
|
r"^%(PLYR)s posts ante \[%(CUR_SYM)s(?P<ANTE>[.,0-9]+) ?%(CUR)s\]" % subst,
|
2009-08-06 15:14:52 +02:00
|
|
|
re.MULTILINE)
|
|
|
|
self.re_HeroCards = re.compile(
|
|
|
|
r"^Dealt to %(PLYR)s \[\s*(?P<NEWCARDS>.+)\s*\]" % subst,
|
|
|
|
re.MULTILINE)
|
|
|
|
self.re_Action = re.compile(r"""
|
|
|
|
^%(PLYR)s\s+(?P<ATYPE>bets|checks|raises|calls|folds|is\sall-In)
|
|
|
|
(?:\s+\[%(CUR_SYM)s(?P<BET>[.,\d]+)\s*%(CUR)s\])?
|
2009-08-12 00:35:34 +02:00
|
|
|
""" % subst,
|
2009-08-06 15:14:52 +02:00
|
|
|
re.MULTILINE|re.VERBOSE)
|
|
|
|
self.re_ShownCards = re.compile(
|
2009-08-12 00:35:34 +02:00
|
|
|
r"^%s (?P<SHOWED>(?:doesn\'t )?shows?) " % player_re +
|
|
|
|
r"\[ *(?P<CARDS>.+) *\](?P<COMBINATION>.+)\.",
|
2009-08-06 15:14:52 +02:00
|
|
|
re.MULTILINE)
|
|
|
|
self.re_CollectPot = re.compile(
|
2009-08-10 16:13:39 +02:00
|
|
|
r"""^%(PLYR)s \s+ wins \s+
|
2009-08-12 00:35:34 +02:00
|
|
|
%(CUR_SYM)s(?P<POT>[.,\d]+)\s*%(CUR)s""" % subst,
|
2009-08-06 15:14:52 +02:00
|
|
|
re.MULTILINE|re.VERBOSE)
|
|
|
|
|
|
|
|
def readSupportedGames(self):
|
|
|
|
return [["ring", "hold", "nl"],
|
2009-08-09 17:54:35 +02:00
|
|
|
["ring", "hold", "pl"],
|
|
|
|
["ring", "hold", "fl"],
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
["tour", "hold", "nl"],
|
2009-08-09 17:54:35 +02:00
|
|
|
["tour", "hold", "pl"],
|
|
|
|
["tour", "hold", "fl"],
|
2009-08-06 15:14:52 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def _getGameType(self, handText):
|
2009-08-09 23:45:55 +02:00
|
|
|
if not hasattr(self, '_gameType'):
|
|
|
|
self._gameType = None
|
2009-08-06 15:14:52 +02:00
|
|
|
if self._gameType is None:
|
|
|
|
# let's determine whether hand is trny
|
|
|
|
# and whether 5-th line contains head line
|
|
|
|
headLine = handText.split(self.lineSplitter)[4]
|
|
|
|
for headLineContainer in headLine, handText:
|
|
|
|
for regexp in self.re_GameInfoTrny, self.re_GameInfoRing:
|
|
|
|
m = regexp.search(headLineContainer)
|
|
|
|
if m is not None:
|
|
|
|
self._gameType = m
|
|
|
|
return self._gameType
|
|
|
|
return self._gameType
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
def determineGameType(self, handText):
|
2009-08-06 15:55:53 +02:00
|
|
|
"""inspect the handText and return the gametype dict
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:55:53 +02:00
|
|
|
gametype dict is:
|
|
|
|
{'limitType': xxx, 'base': xxx, 'category': xxx}"""
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
info = {}
|
|
|
|
m = self._getGameType(handText)
|
|
|
|
if m is None:
|
|
|
|
return None
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
mg = m.groupdict()
|
|
|
|
# translations from captured groups to fpdb info strings
|
2009-08-09 17:54:35 +02:00
|
|
|
limits = { 'NL':'nl', 'PL':'pl', '':'fl' }
|
2009-08-06 15:14:52 +02:00
|
|
|
games = { # base, category
|
2009-08-12 00:35:34 +02:00
|
|
|
"Texas Hold'em" : ('hold','holdem'),
|
2009-08-09 17:54:35 +02:00
|
|
|
'Omaha' : ('hold','omahahi'),
|
2009-08-06 15:14:52 +02:00
|
|
|
}
|
|
|
|
currencies = { '$':'USD', '':'T$' }
|
|
|
|
|
|
|
|
for expectedField in ['LIMIT', 'GAME']:
|
|
|
|
if mg[expectedField] is None:
|
2009-11-08 21:09:14 +01:00
|
|
|
raise FpdbParseError( "Cannot fetch field '%s'" % expectedField)
|
2009-08-06 15:14:52 +02:00
|
|
|
try:
|
2009-08-09 17:54:35 +02:00
|
|
|
info['limitType'] = limits[mg['LIMIT'].strip()]
|
2009-08-06 15:14:52 +02:00
|
|
|
except:
|
2009-11-08 21:09:14 +01:00
|
|
|
raise FpdbParseError("Unknown limit '%s'" % mg['LIMIT'])
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
(info['base'], info['category']) = games[mg['GAME']]
|
|
|
|
except:
|
2009-11-08 21:09:14 +01:00
|
|
|
raise FpdbParseError("Unknown game type '%s'" % mg['GAME'])
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
if 'TOURNO' in mg:
|
|
|
|
info['type'] = 'tour'
|
|
|
|
else:
|
|
|
|
info['type'] = 'ring'
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
if info['type'] == 'ring':
|
|
|
|
info['sb'], info['bb'] = ringBlinds(mg['RINGLIMIT'])
|
2009-08-06 14:39:14 +02:00
|
|
|
info['currency'] = currencies[mg['CURRENCY']]
|
2009-08-06 15:14:52 +02:00
|
|
|
else:
|
2009-08-09 17:54:35 +02:00
|
|
|
info['sb'] = clearMoneyString(mg['SB'])
|
|
|
|
info['bb'] = clearMoneyString(mg['BB'])
|
2009-08-06 15:14:52 +02:00
|
|
|
info['currency'] = 'T$'
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
def readHandInfo(self, hand):
|
|
|
|
info = {}
|
2009-08-10 16:13:39 +02:00
|
|
|
try:
|
|
|
|
info.update(self.re_Hid.search(hand.handText).groupdict())
|
|
|
|
except:
|
2009-11-08 21:09:14 +01:00
|
|
|
raise FpdbParseError("Cannot read HID for current hand")
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
try:
|
|
|
|
info.update(self.re_HandInfo.search(hand.handText,re.DOTALL).groupdict())
|
|
|
|
except:
|
2009-11-08 21:09:14 +01:00
|
|
|
raise FpdbParseError("Cannot read Handinfo for current hand", hid = info['HID'])
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
try:
|
|
|
|
info.update(self._getGameType(hand.handText).groupdict())
|
|
|
|
except:
|
2009-11-08 21:09:14 +01:00
|
|
|
raise FpdbParseError("Cannot read GameType for current hand", hid = info['HID'])
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
|
2009-11-08 21:09:14 +01:00
|
|
|
m = self.re_CountedSeats.search(hand.handText)
|
|
|
|
if m: info.update(m.groupdict())
|
2009-08-09 14:38:55 +02:00
|
|
|
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-11 16:02:58 +02:00
|
|
|
# FIXME: it's dirty hack
|
|
|
|
# party doesnt subtract uncalled money from commited money
|
|
|
|
# so hand.totalPot calculation has to be redefined
|
|
|
|
from Hand import Pot, HoldemOmahaHand
|
|
|
|
def getNewTotalPot(origTotalPot):
|
|
|
|
def totalPot(self):
|
|
|
|
if self.totalpot is None:
|
|
|
|
self.pot.end()
|
|
|
|
self.totalpot = self.pot.total
|
|
|
|
for i,v in enumerate(self.collected):
|
|
|
|
if v[0] in self.pot.returned:
|
|
|
|
self.collected[i][1] = Decimal(v[1]) - self.pot.returned[v[0]]
|
2010-03-02 21:44:07 +01:00
|
|
|
self.collectees[v[0]] -= self.pot.returned[v[0]]
|
2010-03-04 14:11:50 +01:00
|
|
|
self.pot.returned[v[0]] = 0
|
2009-08-11 16:02:58 +02:00
|
|
|
return origTotalPot()
|
|
|
|
return totalPot
|
|
|
|
instancemethod = type(hand.totalPot)
|
|
|
|
hand.totalPot = instancemethod(getNewTotalPot(hand.totalPot), hand, HoldemOmahaHand)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-09 21:22:23 +02:00
|
|
|
log.debug("readHandInfo: %s" % info)
|
2009-08-06 15:14:52 +02:00
|
|
|
for key in info:
|
|
|
|
if key == 'DATETIME':
|
|
|
|
#Saturday, July 25, 07:53:52 EDT 2009
|
|
|
|
#Thursday, July 30, 21:40:41 MSKS 2009
|
2009-11-08 21:09:14 +01:00
|
|
|
#Sunday, October 25, 13:39:07 MSK 2009
|
2009-08-06 15:14:52 +02:00
|
|
|
m2 = re.search("\w+, (?P<M>\w+) (?P<D>\d+), (?P<H>\d+):(?P<MIN>\d+):(?P<S>\d+) (?P<TZ>[A-Z]+) (?P<Y>\d+)", info[key])
|
|
|
|
# we cant use '%B' due to locale problems
|
|
|
|
months = ['January', 'February', 'March', 'April','May', 'June',
|
|
|
|
'July','August','September','October','November','December']
|
|
|
|
month = months.index(m2.group('M')) + 1
|
|
|
|
datetimestr = "%s/%s/%s %s:%s:%s" % (m2.group('Y'), month,m2.group('D'),m2.group('H'),m2.group('MIN'),m2.group('S'))
|
|
|
|
hand.starttime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S")
|
2009-08-06 15:55:53 +02:00
|
|
|
# FIXME: some timezone correction required
|
2009-08-06 15:14:52 +02:00
|
|
|
#tzShift = defaultdict(lambda:0, {'EDT': -5, 'EST': -6, 'MSKS': 3})
|
|
|
|
#hand.starttime -= datetime.timedelta(hours=tzShift[m2.group('TZ')])
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
if key == 'HID':
|
|
|
|
hand.handid = info[key]
|
|
|
|
if key == 'TABLE':
|
|
|
|
hand.tablename = info[key]
|
2010-01-23 16:24:00 +01:00
|
|
|
if key == 'MTTTABLE':
|
|
|
|
if info[key] != None:
|
|
|
|
hand.tablename = info[key]
|
|
|
|
hand.tourNo = info['TABLE']
|
2009-08-06 15:14:52 +02:00
|
|
|
if key == 'BUTTON':
|
|
|
|
hand.buttonpos = info[key]
|
|
|
|
if key == 'TOURNO':
|
|
|
|
hand.tourNo = info[key]
|
2009-11-08 21:09:14 +01:00
|
|
|
if key == 'TABLE_ID_WRAPPER':
|
|
|
|
if info[key] == '#':
|
|
|
|
# FIXME: there is no such property in Hand class
|
|
|
|
self.isSNG = True
|
2009-08-06 15:14:52 +02:00
|
|
|
if key == 'BUYIN':
|
2009-08-10 16:13:39 +02:00
|
|
|
# FIXME: it's dirty hack T_T
|
2009-10-31 15:53:31 +01:00
|
|
|
# code below assumes that tournament rake is equal to zero
|
2010-01-23 16:24:00 +01:00
|
|
|
if info[key] == None:
|
|
|
|
hand.buyin = '$0+$0'
|
|
|
|
else:
|
|
|
|
cur = info[key][0] if info[key][0] not in '0123456789' else ''
|
|
|
|
hand.buyin = info[key] + '+%s0' % cur
|
2009-08-06 15:14:52 +02:00
|
|
|
if key == 'LEVEL':
|
|
|
|
hand.level = info[key]
|
|
|
|
if key == 'PLAY' and info['PLAY'] != 'Real':
|
2009-11-08 21:09:14 +01:00
|
|
|
# if realy party doesn's save play money hh
|
2009-08-06 15:14:52 +02:00
|
|
|
hand.gametype['currency'] = 'play'
|
2010-03-03 19:05:06 +01:00
|
|
|
if key == 'MAX' and info[key] is not None:
|
2010-03-03 06:42:13 +01:00
|
|
|
hand.maxseats = int(info[key])
|
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def readButton(self, hand):
|
|
|
|
m = self.re_Button.search(hand.handText)
|
|
|
|
if m:
|
|
|
|
hand.buttonpos = int(m.group('BUTTON'))
|
|
|
|
else:
|
2009-08-09 21:22:23 +02:00
|
|
|
log.info('readButton: not found')
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def readPlayerStacks(self, hand):
|
2009-08-09 21:22:23 +02:00
|
|
|
log.debug("readPlayerStacks")
|
2009-08-06 15:14:52 +02:00
|
|
|
m = self.re_PlayerInfo.finditer(hand.handText)
|
|
|
|
players = []
|
|
|
|
for a in m:
|
|
|
|
hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'),
|
2009-08-09 17:54:35 +02:00
|
|
|
clearMoneyString(a.group('CASH')))
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def markStreets(self, hand):
|
|
|
|
m = re.search(
|
|
|
|
r"\*{2} Dealing down cards \*{2}"
|
|
|
|
r"(?P<PREFLOP>.+?)"
|
|
|
|
r"(?:\*{2} Dealing Flop \*{2} (?P<FLOP>\[ \S\S, \S\S, \S\S \].+?))?"
|
|
|
|
r"(?:\*{2} Dealing Turn \*{2} (?P<TURN>\[ \S\S \].+?))?"
|
|
|
|
r"(?:\*{2} Dealing River \*{2} (?P<RIVER>\[ \S\S \].+?))?$"
|
|
|
|
, hand.handText,re.DOTALL)
|
|
|
|
hand.addStreets(m)
|
|
|
|
|
2009-08-12 00:35:34 +02:00
|
|
|
def readCommunityCards(self, hand, street):
|
|
|
|
if street in ('FLOP','TURN','RIVER'):
|
2009-08-06 15:14:52 +02:00
|
|
|
m = self.re_Board.search(hand.streets[street])
|
|
|
|
hand.setCommunityCards(street, renderCards(m.group('CARDS')))
|
|
|
|
|
|
|
|
def readAntes(self, hand):
|
2009-08-09 21:22:23 +02:00
|
|
|
log.debug("reading antes")
|
2009-08-06 15:14:52 +02:00
|
|
|
m = self.re_Antes.finditer(hand.handText)
|
|
|
|
for player in m:
|
|
|
|
hand.addAnte(player.group('PNAME'), player.group('ANTE'))
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
def readBlinds(self, hand):
|
|
|
|
noSmallBlind = bool(self.re_NoSmallBlind.search(hand.handText))
|
|
|
|
if hand.gametype['type'] == 'ring':
|
|
|
|
try:
|
|
|
|
assert noSmallBlind==False
|
2010-03-04 19:49:43 +01:00
|
|
|
liveBlind = True
|
|
|
|
for m in self.re_PostSB.finditer(hand.handText):
|
|
|
|
if liveBlind:
|
|
|
|
hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB'))
|
|
|
|
liveBlind = False
|
|
|
|
else:
|
|
|
|
# Post dead blinds as ante
|
|
|
|
hand.addBlind(m.group('PNAME'), 'secondsb', m.group('SB'))
|
2009-08-06 15:14:52 +02:00
|
|
|
except: # no small blind
|
|
|
|
hand.addBlind(None, None, None)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
for a in self.re_PostBB.finditer(hand.handText):
|
|
|
|
hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB'))
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-11 16:02:58 +02:00
|
|
|
deadFilter = lambda s: s.replace(',', '.')
|
|
|
|
for a in self.re_PostDead.finditer(hand.handText):
|
|
|
|
hand.addBlind(a.group('PNAME'), 'both', deadFilter(a.group('BBNDEAD')))
|
2009-08-12 00:35:34 +02:00
|
|
|
else:
|
2009-08-06 15:14:52 +02:00
|
|
|
# party doesn't track blinds for tournaments
|
|
|
|
# so there're some cra^Wcaclulations
|
|
|
|
if hand.buttonpos == 0:
|
|
|
|
self.readButton(hand)
|
|
|
|
# NOTE: code below depends on Hand's implementation
|
|
|
|
# playersMap - dict {seat: (pname,stack)}
|
2009-08-12 00:35:34 +02:00
|
|
|
playersMap = dict([(f[0], f[1:3]) for f in hand.players])
|
2009-08-06 15:14:52 +02:00
|
|
|
maxSeat = max(playersMap)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
def findFirstNonEmptySeat(startSeat):
|
|
|
|
while startSeat not in playersMap:
|
2009-08-12 00:35:34 +02:00
|
|
|
if startSeat >= maxSeat:
|
2009-08-06 15:14:52 +02:00
|
|
|
startSeat = 0
|
|
|
|
startSeat += 1
|
|
|
|
return startSeat
|
|
|
|
smartMin = lambda A,B: A if float(A) <= float(B) else B
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
if noSmallBlind:
|
|
|
|
hand.addBlind(None, None, None)
|
2009-08-11 16:02:58 +02:00
|
|
|
smallBlindSeat = int(hand.buttonpos)
|
2009-08-06 15:14:52 +02:00
|
|
|
else:
|
|
|
|
smallBlindSeat = findFirstNonEmptySeat(int(hand.buttonpos) + 1)
|
|
|
|
blind = smartMin(hand.sb, playersMap[smallBlindSeat][1])
|
|
|
|
hand.addBlind(playersMap[smallBlindSeat][0], 'small blind', blind)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
bigBlindSeat = findFirstNonEmptySeat(smallBlindSeat + 1)
|
|
|
|
blind = smartMin(hand.bb, playersMap[bigBlindSeat][1])
|
2009-08-10 16:13:39 +02:00
|
|
|
hand.addBlind(playersMap[bigBlindSeat][0], 'big blind', blind)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
def readHeroCards(self, hand):
|
2009-08-06 15:55:53 +02:00
|
|
|
# we need to grab hero's cards
|
2009-08-06 15:14:52 +02:00
|
|
|
for street in ('PREFLOP',):
|
|
|
|
if street in hand.streets.keys():
|
|
|
|
m = self.re_HeroCards.finditer(hand.streets[street])
|
|
|
|
for found in m:
|
|
|
|
hand.hero = found.group('PNAME')
|
|
|
|
newcards = renderCards(found.group('NEWCARDS'))
|
|
|
|
hand.addHoleCards(street, hand.hero, closed=newcards, shown=False, mucked=False, dealt=True)
|
|
|
|
|
|
|
|
def readAction(self, hand, street):
|
|
|
|
m = self.re_Action.finditer(hand.streets[street])
|
|
|
|
for action in m:
|
|
|
|
acts = action.groupdict()
|
2009-08-10 16:13:39 +02:00
|
|
|
playerName = action.group('PNAME')
|
|
|
|
amount = clearMoneyString(action.group('BET')) if action.group('BET') else None
|
|
|
|
actionType = action.group('ATYPE')
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
if actionType == 'is all-In':
|
|
|
|
# party's allin can mean either raise or bet or call
|
|
|
|
Bp = hand.lastBet[street]
|
|
|
|
if Bp == 0:
|
|
|
|
actionType = 'bets'
|
|
|
|
elif Bp < Decimal(amount):
|
|
|
|
actionType = 'raises'
|
|
|
|
else:
|
|
|
|
actionType = 'calls'
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-10 16:13:39 +02:00
|
|
|
if actionType == 'raises':
|
|
|
|
if street == 'PREFLOP' and \
|
2009-08-12 09:18:42 +02:00
|
|
|
playerName in [item[0] for item in hand.actions['BLINDSANTES'] if item[2]!='ante']:
|
2009-08-10 16:13:39 +02:00
|
|
|
# preflop raise from blind
|
2010-03-04 14:32:48 +01:00
|
|
|
hand.addCallandRaise( street, playerName, amount )
|
2009-08-10 16:13:39 +02:00
|
|
|
else:
|
|
|
|
hand.addCallandRaise( street, playerName, amount )
|
|
|
|
elif actionType == 'calls':
|
|
|
|
hand.addCall( street, playerName, amount )
|
|
|
|
elif actionType == 'bets':
|
|
|
|
hand.addBet( street, playerName, amount )
|
|
|
|
elif actionType == 'folds':
|
|
|
|
hand.addFold( street, playerName )
|
|
|
|
elif actionType == 'checks':
|
|
|
|
hand.addCheck( street, playerName )
|
2009-08-06 15:14:52 +02:00
|
|
|
else:
|
2009-11-08 21:09:14 +01:00
|
|
|
raise FpdbParseError(
|
2009-08-10 16:13:39 +02:00
|
|
|
"Unimplemented readAction: '%s' '%s'" % (playerName,actionType,),
|
2009-11-08 21:09:14 +01:00
|
|
|
hid = hand.hid, )
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def readShowdownActions(self, hand):
|
|
|
|
# all action in readShownCards
|
|
|
|
pass
|
|
|
|
|
|
|
|
def readCollectPot(self,hand):
|
|
|
|
for m in self.re_CollectPot.finditer(hand.handText):
|
2009-08-11 16:02:58 +02:00
|
|
|
hand.addCollectPot(player=m.group('PNAME'),pot=clearMoneyString(m.group('POT')))
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
def readShownCards(self,hand):
|
|
|
|
for m in self.re_ShownCards.finditer(hand.handText):
|
|
|
|
if m.group('CARDS') is not None:
|
|
|
|
cards = renderCards(m.group('CARDS'))
|
|
|
|
|
2009-10-31 15:53:31 +01:00
|
|
|
mucked = m.group('SHOWED') != "show"
|
2009-08-06 15:14:52 +02:00
|
|
|
|
2009-10-31 15:53:31 +01:00
|
|
|
hand.addShownCards(cards=cards, player=m.group('PNAME'), shown=True, mucked=mucked)
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-11-08 21:09:14 +01:00
|
|
|
@staticmethod
|
|
|
|
def getTableTitleRe(type, table_name=None, tournament = None, table_number=None):
|
|
|
|
"Returns string to search in windows titles"
|
|
|
|
if type=="tour":
|
2010-02-13 22:44:00 +01:00
|
|
|
TableName = table_name.split(" ")
|
|
|
|
print 'party', 'getTableTitleRe', "%s.+Table\s#%s" % (TableName[0], table_number)
|
|
|
|
return "%s.+Table\s#%s" % (TableName[0], table_number)
|
2009-11-08 21:09:14 +01:00
|
|
|
else:
|
|
|
|
print 'party', 'getTableTitleRe', table_number
|
|
|
|
return table_name
|
|
|
|
|
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
def ringBlinds(ringLimit):
|
2009-08-10 16:13:39 +02:00
|
|
|
"Returns blinds for current limit in cash games"
|
2009-08-09 17:54:35 +02:00
|
|
|
ringLimit = float(clearMoneyString(ringLimit))
|
2009-08-06 15:14:52 +02:00
|
|
|
if ringLimit == 5.: ringLimit = 4.
|
|
|
|
return ('%.2f' % (ringLimit/200.), '%.2f' % (ringLimit/100.) )
|
|
|
|
|
2009-08-09 17:54:35 +02:00
|
|
|
def clearMoneyString(money):
|
2009-08-10 16:13:39 +02:00
|
|
|
"Renders 'numbers' like '1 200' and '2,000'"
|
2009-08-06 15:14:52 +02:00
|
|
|
return money.replace(' ', '').replace(',', '')
|
|
|
|
|
|
|
|
def renderCards(string):
|
2009-08-10 16:13:39 +02:00
|
|
|
"Splits strings like ' Js, 4d '"
|
2009-08-06 15:14:52 +02:00
|
|
|
cards = string.strip().split(' ')
|
|
|
|
return filter(len, map(lambda x: x.strip(' ,'), cards))
|
2009-08-12 00:35:34 +02:00
|
|
|
|
2009-08-06 15:14:52 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = OptionParser()
|
2009-08-06 15:55:53 +02:00
|
|
|
parser.add_option("-i", "--input", dest="ipath", help="parse input hand history")
|
2009-08-06 15:14:52 +02:00
|
|
|
parser.add_option("-o", "--output", dest="opath", help="output translation to", default="-")
|
|
|
|
parser.add_option("-f", "--follow", dest="follow", help="follow (tail -f) the input", action="store_true", default=False)
|
|
|
|
parser.add_option("-q", "--quiet",
|
|
|
|
action="store_const", const=logging.CRITICAL, dest="verbosity", default=logging.INFO)
|
|
|
|
parser.add_option("-v", "--verbose",
|
|
|
|
action="store_const", const=logging.INFO, dest="verbosity")
|
|
|
|
parser.add_option("--vv",
|
|
|
|
action="store_const", const=logging.DEBUG, dest="verbosity")
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
e = PartyPoker(in_path = options.ipath, out_path = options.opath, follow = options.follow)
|