2010-09-23 18:31:17 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2011-03-10 06:16:31 +01:00
|
|
|
# Copyright 2008-2011, Carl Gherardi
|
2010-09-23 18:31:17 +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.
|
|
|
|
#
|
|
|
|
# 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 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
|
|
|
|
########################################################################
|
|
|
|
|
2010-09-28 05:41:27 +02:00
|
|
|
import L10n
|
|
|
|
_ = L10n.get_translation()
|
|
|
|
|
2010-09-23 18:31:17 +02:00
|
|
|
import sys
|
|
|
|
import exceptions
|
|
|
|
|
|
|
|
import logging
|
|
|
|
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
|
|
|
|
|
|
|
|
import Configuration
|
|
|
|
from HandHistoryConverter import *
|
2011-02-25 20:18:12 +01:00
|
|
|
from decimal_wrapper import Decimal
|
2010-09-23 18:31:17 +02:00
|
|
|
import time
|
|
|
|
|
|
|
|
# Winamax HH Format
|
|
|
|
|
|
|
|
class Winamax(HandHistoryConverter):
|
|
|
|
def Trace(f):
|
|
|
|
def my_f(*args, **kwds):
|
|
|
|
print ( "entering " + f.__name__)
|
|
|
|
result= f(*args, **kwds)
|
|
|
|
print ( "exiting " + f.__name__)
|
|
|
|
return result
|
|
|
|
my_f.__name = f.__name__
|
|
|
|
my_f.__doc__ = f.__doc__
|
|
|
|
return my_f
|
|
|
|
|
|
|
|
filter = "Winamax"
|
|
|
|
siteName = "Winamax"
|
|
|
|
filetype = "text"
|
|
|
|
codepage = ("utf8", "cp1252")
|
2010-09-29 18:40:02 +02:00
|
|
|
siteId = 14 # Needs to match id entry in Sites database
|
2010-09-23 18:31:17 +02:00
|
|
|
|
|
|
|
mixes = { } # Legal mixed games
|
|
|
|
sym = {'USD': "\$", 'CAD': "\$", 'T$': "", "EUR": "\xe2\x82\xac", "GBP": "\xa3"} # ADD Euro, Sterling, etc HERE
|
|
|
|
substitutions = {
|
|
|
|
'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes
|
|
|
|
'LS' : "\$|\xe2\x82\xac|" # legal currency symbols - Euro(cp1252, utf-8)
|
|
|
|
}
|
|
|
|
|
|
|
|
limits = { 'no limit':'nl', 'pot limit' : 'pl','LIMIT':'fl'}
|
|
|
|
|
|
|
|
games = { # base, category
|
|
|
|
"Holdem" : ('hold','holdem'),
|
|
|
|
'Omaha' : ('hold','omahahi'),
|
|
|
|
# 'Omaha Hi/Lo' : ('hold','omahahilo'),
|
|
|
|
# 'Razz' : ('stud','razz'),
|
|
|
|
# 'RAZZ' : ('stud','razz'),
|
|
|
|
# '7 Card Stud' : ('stud','studhi'),
|
2010-10-06 10:22:51 +02:00
|
|
|
# 'SEVEN_CARD_STUD_HI_LO' : ('stud','studhilo'),
|
2010-09-23 18:31:17 +02:00
|
|
|
# 'Badugi' : ('draw','badugi'),
|
|
|
|
# 'Triple Draw 2-7 Lowball' : ('draw','27_3draw'),
|
|
|
|
# '5 Card Draw' : ('draw','fivedraw')
|
|
|
|
}
|
|
|
|
|
|
|
|
# Static regexes
|
|
|
|
# ***** End of hand R5-75443872-57 *****
|
|
|
|
re_SplitHands = re.compile(r'\n\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Winamax Poker - CashGame - HandId: #279823-223-1285031451 - Holdem no limit (0.02€/0.05€) - 2010/09/21 03:10:51 UTC
|
2010-10-08 06:26:24 +02:00
|
|
|
# Table: 'Charenton-le-Pont' 9-max (real money) Seat #5 is the button
|
2010-09-23 18:31:17 +02:00
|
|
|
re_HandInfo = re.compile(u"""
|
2010-11-26 05:45:41 +01:00
|
|
|
\s*Winamax\sPoker\s-\s
|
|
|
|
(?P<RING>CashGame)?
|
|
|
|
(?P<TOUR>Tournament\s
|
|
|
|
(?P<TOURNAME>.+)?\s
|
|
|
|
buyIn:\s(?P<BUYIN>(?P<BIAMT>[%(LS)s\d\,]+)?\s\+?\s(?P<BIRAKE>[%(LS)s\d\,]+)?\+?(?P<BOUNTY>[%(LS)s\d\.]+)?\s?(?P<TOUR_ISO>%(LEGAL_ISO)s)?|Gratuit|Ticket\suniquement)?\s
|
|
|
|
(level:\s(?P<LEVEL>\d+))?
|
|
|
|
.*)?
|
2011-01-27 03:45:12 +01:00
|
|
|
\s-\sHandId:\s\#(?P<HID1>\d+)-(?P<HID2>\d+)-(?P<HID3>\d+).*\s # REB says: HID3 is the correct hand number
|
2010-09-23 18:31:17 +02:00
|
|
|
(?P<GAME>Holdem|Omaha)\s
|
|
|
|
(?P<LIMIT>no\slimit|pot\slimit)\s
|
|
|
|
\(
|
2010-11-26 05:45:41 +01:00
|
|
|
(((%(LS)s)?(?P<ANTE>[.0-9]+)(%(LS)s)?)/)?
|
2010-09-23 18:31:17 +02:00
|
|
|
((%(LS)s)?(?P<SB>[.0-9]+)(%(LS)s)?)/
|
|
|
|
((%(LS)s)?(?P<BB>[.0-9]+)(%(LS)s)?)
|
|
|
|
\)\s-\s
|
|
|
|
(?P<DATETIME>.*)
|
2010-11-26 05:45:41 +01:00
|
|
|
Table:\s\'(?P<TABLE>[^(]+)
|
|
|
|
(.(?P<TOURNO>\d+).\#(?P<TABLENO>\d+))?.*
|
|
|
|
\'
|
|
|
|
\s(?P<MAXPLAYER>\d+)\-max
|
2010-09-23 18:31:17 +02:00
|
|
|
""" % substitutions, re.MULTILINE|re.DOTALL|re.VERBOSE)
|
|
|
|
|
|
|
|
re_TailSplitHands = re.compile(r'\n\s*\n')
|
|
|
|
re_Button = re.compile(r'Seat\s#(?P<BUTTON>\d+)\sis\sthe\sbutton')
|
|
|
|
re_Board = re.compile(r"\[(?P<CARDS>.+)\]")
|
2011-02-04 10:18:10 +01:00
|
|
|
re_Total = re.compile(r"Total pot (?P<TOTAL>[\.\d]+).*(No rake|Rake (?P<RAKE>[\.\d]+))" % substitutions)
|
2010-09-23 18:31:17 +02:00
|
|
|
|
|
|
|
# 2010/09/21 03:10:51 UTC
|
|
|
|
re_DateTime = re.compile("""
|
|
|
|
(?P<Y>[0-9]{4})/
|
|
|
|
(?P<M>[0-9]+)/
|
|
|
|
(?P<D>[0-9]+)\s
|
|
|
|
(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[0-9]+)\s
|
|
|
|
UTC
|
|
|
|
""", re.MULTILINE|re.VERBOSE)
|
|
|
|
|
2010-10-08 06:26:24 +02:00
|
|
|
# Seat 1: some_player (5€)
|
|
|
|
# Seat 2: some_other_player21 (6.33€)
|
|
|
|
|
2010-09-23 18:31:17 +02:00
|
|
|
re_PlayerInfo = re.compile(u'Seat\s(?P<SEAT>[0-9]+):\s(?P<PNAME>.*)\s\((%(LS)s)?(?P<CASH>[.0-9]+)(%(LS)s)?\)' % substitutions)
|
|
|
|
|
|
|
|
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'
|
|
|
|
# we need to recompile the player regexs.
|
|
|
|
# TODO: should probably rename re_HeroCards and corresponding method,
|
|
|
|
# since they are used to find all cards on lines starting with "Dealt to:"
|
|
|
|
# They still identify the hero.
|
|
|
|
self.compiledPlayers = players
|
|
|
|
#ANTES/BLINDS
|
|
|
|
#helander2222 posts blind ($0.25), lopllopl posts blind ($0.50).
|
|
|
|
player_re = "(?P<PNAME>" + "|".join(map(re.escape, players)) + ")"
|
|
|
|
subst = {'PLYR': player_re, 'CUR': self.sym[hand.gametype['currency']]}
|
|
|
|
self.re_PostSB = re.compile('%(PLYR)s posts small blind (%(CUR)s)?(?P<SB>[\.0-9]+)(%(CUR)s)?' % subst, re.MULTILINE)
|
|
|
|
self.re_PostBB = re.compile('%(PLYR)s posts big blind (%(CUR)s)?(?P<BB>[\.0-9]+)(%(CUR)s)?' % subst, re.MULTILINE)
|
2010-10-08 08:56:32 +02:00
|
|
|
self.re_DenySB = re.compile('(?P<PNAME>.*) deny SB' % subst, re.MULTILINE)
|
2010-11-26 05:45:41 +01:00
|
|
|
self.re_Antes = re.compile(r"^%(PLYR)s posts ante (%(CUR)s)?(?P<ANTE>[\.0-9]+)(%(CUR)s)?" % subst, re.MULTILINE)
|
|
|
|
self.re_BringIn = re.compile(r"^%(PLYR)s brings[- ]in( low|) for (%(CUR)s)?(?P<BRINGIN>[\.0-9]+(%(CUR)s)?)" % subst, re.MULTILINE)
|
2010-09-23 18:31:17 +02:00
|
|
|
self.re_PostBoth = re.compile('(?P<PNAME>.*): posts small \& big blind \( (%(CUR)s)?(?P<SBBB>[\.0-9]+)(%(CUR)s)?\)' % subst)
|
|
|
|
self.re_PostDead = re.compile('(?P<PNAME>.*) posts dead blind \((%(CUR)s)?(?P<DEAD>[\.0-9]+)(%(CUR)s)?\)' % subst, re.MULTILINE)
|
|
|
|
self.re_HeroCards = re.compile('Dealt\sto\s%(PLYR)s\s\[(?P<CARDS>.*)\]' % subst)
|
|
|
|
|
|
|
|
self.re_Action = re.compile('(, )?(?P<PNAME>.*?)(?P<ATYPE> bets| checks| raises| calls| folds)( (%(CUR)s)?(?P<BET>[\d\.]+)(%(CUR)s)?)?( and is all-in)?' % subst)
|
2010-10-08 06:26:24 +02:00
|
|
|
self.re_ShowdownAction = re.compile('(?P<PNAME>[^\(\)\n]*) (\((small blind|big blind|button)\) )?shows \[(?P<CARDS>.+)\]')
|
2010-09-23 18:31:17 +02:00
|
|
|
|
|
|
|
self.re_CollectPot = re.compile('\s*(?P<PNAME>.*)\scollected\s(%(CUR)s)?(?P<POT>[\.\d]+)(%(CUR)s)?.*' % subst)
|
|
|
|
self.re_ShownCards = re.compile("^Seat (?P<SEAT>[0-9]+): %(PLYR)s showed \[(?P<CARDS>.*)\].*" % subst, re.MULTILINE)
|
|
|
|
self.re_sitsOut = re.compile('(?P<PNAME>.*) sits out')
|
|
|
|
|
|
|
|
def readSupportedGames(self):
|
|
|
|
return [
|
|
|
|
["ring", "hold", "fl"],
|
|
|
|
["ring", "hold", "nl"],
|
|
|
|
["ring", "hold", "pl"],
|
2010-11-26 05:45:41 +01:00
|
|
|
["tour", "hold", "fl"],
|
|
|
|
["tour", "hold", "nl"],
|
|
|
|
["tour", "hold", "pl"],
|
2010-09-23 18:31:17 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def determineGameType(self, handText):
|
|
|
|
# Inspect the handText and return the gametype dict
|
|
|
|
# gametype dict is: {'limitType': xxx, 'base': xxx, 'category': xxx}
|
|
|
|
info = {}
|
|
|
|
|
|
|
|
m = self.re_HandInfo.search(handText)
|
|
|
|
if not m:
|
|
|
|
tmp = handText[0:100]
|
2011-03-10 04:29:16 +01:00
|
|
|
log.error(_("Unable to recognise gametype from: '%s'") % tmp)
|
2010-09-23 18:31:17 +02:00
|
|
|
log.error(_("determineGameType: Raising FpdbParseError"))
|
|
|
|
raise FpdbParseError(_("Unable to recognise gametype from: '%s'") % tmp)
|
|
|
|
|
|
|
|
mg = m.groupdict()
|
|
|
|
|
2010-11-26 05:45:41 +01:00
|
|
|
if mg.get('TOUR'):
|
|
|
|
info['type'] = 'tour'
|
|
|
|
elif mg.get('RING'):
|
|
|
|
info['type'] = 'ring'
|
|
|
|
|
2010-09-23 18:31:17 +02:00
|
|
|
info['currency'] = 'EUR'
|
|
|
|
|
|
|
|
if 'LIMIT' in mg:
|
|
|
|
if mg['LIMIT'] in self.limits:
|
|
|
|
info['limitType'] = self.limits[mg['LIMIT']]
|
|
|
|
else:
|
|
|
|
tmp = handText[0:100]
|
2011-03-10 04:36:20 +01:00
|
|
|
log.error(_("limit not found in self.limits(%s). hand: '%s'") % (str(mg),tmp))
|
2010-09-23 18:31:17 +02:00
|
|
|
log.error(_("determineGameType: Raising FpdbParseError"))
|
|
|
|
raise FpdbParseError(_("limit not found in self.limits(%s). hand: '%s'") % (str(mg),tmp))
|
|
|
|
if 'GAME' in mg:
|
|
|
|
(info['base'], info['category']) = self.games[mg['GAME']]
|
|
|
|
if 'SB' in mg:
|
|
|
|
info['sb'] = mg['SB']
|
|
|
|
if 'BB' in mg:
|
|
|
|
info['bb'] = mg['BB']
|
|
|
|
|
|
|
|
return info
|
|
|
|
|
|
|
|
def readHandInfo(self, hand):
|
|
|
|
info = {}
|
|
|
|
m = self.re_HandInfo.search(hand.handText)
|
|
|
|
|
|
|
|
if m:
|
|
|
|
info.update(m.groupdict())
|
|
|
|
|
|
|
|
#log.debug("readHandInfo: %s" % info)
|
|
|
|
for key in info:
|
|
|
|
if key == 'DATETIME':
|
|
|
|
a = self.re_DateTime.search(info[key])
|
|
|
|
if a:
|
|
|
|
datetimestr = "%s/%s/%s %s:%s:%s" % (a.group('Y'),a.group('M'), a.group('D'), a.group('H'),a.group('MIN'),a.group('S'))
|
|
|
|
else:
|
|
|
|
datetimestr = "2010/Jan/01 01:01:01"
|
2011-03-10 04:15:53 +01:00
|
|
|
log.error(_("readHandInfo: DATETIME not matched: '%s'") % info[key])
|
2011-02-28 06:36:23 +01:00
|
|
|
#print "DEBUG: readHandInfo: DATETIME not matched: '%s'" % info[key]
|
|
|
|
hand.startTime = datetime.datetime.strptime(datetimestr, "%Y/%m/%d %H:%M:%S")
|
2010-10-08 06:26:24 +02:00
|
|
|
hand.startTime = HandHistoryConverter.changeTimezone(hand.startTime, "CET", "UTC")
|
2011-02-03 16:19:39 +01:00
|
|
|
if key == 'HID1':
|
|
|
|
# Need to remove non-alphanumerics for MySQL
|
2011-01-27 03:45:12 +01:00
|
|
|
# hand.handid = "1%.9d%s%s"%(int(info['HID2']),info['HID1'],info['HID3'])
|
2011-02-03 16:19:39 +01:00
|
|
|
hand.handid = "%s%s%s"%(int(info['HID2']),info['HID1'],info['HID3'])
|
|
|
|
if len (hand.handid) > 19:
|
2011-02-04 10:18:10 +01:00
|
|
|
hand.handid = "%s%s" % (int(info['HID2']), int(info['HID3']))
|
2011-02-03 16:19:39 +01:00
|
|
|
|
|
|
|
# if key == 'HID3':
|
|
|
|
# hand.handid = int(info['HID3']) # correct hand no (REB)
|
2010-11-26 05:45:41 +01:00
|
|
|
if key == 'TOURNO':
|
|
|
|
hand.tourNo = info[key]
|
2010-09-23 18:31:17 +02:00
|
|
|
if key == 'TABLE':
|
|
|
|
hand.tablename = info[key]
|
2011-02-27 00:49:16 +01:00
|
|
|
# TODO: long-term solution for table naming on Winamax.
|
|
|
|
if hand.tablename.endswith(u'No Limit Hold\'em'):
|
|
|
|
hand.tablename = hand.tablename[:-len(u'No Limit Hold\'em')] + u'NLHE'
|
2011-01-27 03:45:12 +01:00
|
|
|
if key == 'MAXPLAYER' and info[key] != None:
|
|
|
|
hand.maxseats = int(info[key])
|
2010-09-23 18:31:17 +02:00
|
|
|
|
2010-11-26 05:45:41 +01:00
|
|
|
if key == 'BUYIN':
|
|
|
|
if hand.tourNo!=None:
|
|
|
|
#print "DEBUG: info['BUYIN']: %s" % info['BUYIN']
|
|
|
|
#print "DEBUG: info['BIAMT']: %s" % info['BIAMT']
|
|
|
|
#print "DEBUG: info['BIRAKE']: %s" % info['BIRAKE']
|
|
|
|
#print "DEBUG: info['BOUNTY']: %s" % info['BOUNTY']
|
|
|
|
for k in ['BIAMT','BIRAKE']:
|
|
|
|
if k in info.keys() and info[k]:
|
|
|
|
info[k] = info[k].replace(',','.')
|
|
|
|
|
|
|
|
if info[key] == 'Freeroll':
|
|
|
|
hand.buyin = 0
|
|
|
|
hand.fee = 0
|
|
|
|
hand.buyinCurrency = "FREE"
|
|
|
|
else:
|
|
|
|
if info[key].find("$")!=-1:
|
|
|
|
hand.buyinCurrency="USD"
|
|
|
|
elif info[key].find(u"€")!=-1:
|
|
|
|
hand.buyinCurrency="EUR"
|
|
|
|
elif info[key].find("FPP")!=-1:
|
|
|
|
hand.buyinCurrency="PSFP"
|
|
|
|
else:
|
|
|
|
#FIXME: handle other currencies, FPP, play money
|
2011-03-12 21:47:14 +01:00
|
|
|
raise FpdbParseError(_("Failed to detect currency. Hand ID: %s: '%s'") % (hand.handid, info[key]))
|
2010-11-26 05:45:41 +01:00
|
|
|
|
|
|
|
info['BIAMT'] = info['BIAMT'].strip(u'$€FPP')
|
|
|
|
|
|
|
|
if hand.buyinCurrency!="PSFP":
|
|
|
|
if info['BOUNTY'] != None:
|
|
|
|
# There is a bounty, Which means we need to switch BOUNTY and BIRAKE values
|
|
|
|
tmp = info['BOUNTY']
|
|
|
|
info['BOUNTY'] = info['BIRAKE']
|
|
|
|
info['BIRAKE'] = tmp
|
|
|
|
info['BOUNTY'] = info['BOUNTY'].strip(u'$€') # Strip here where it isn't 'None'
|
|
|
|
hand.koBounty = int(100*Decimal(info['BOUNTY']))
|
|
|
|
hand.isKO = True
|
|
|
|
else:
|
|
|
|
hand.isKO = False
|
|
|
|
|
|
|
|
info['BIRAKE'] = info['BIRAKE'].strip(u'$€')
|
2011-02-27 00:49:16 +01:00
|
|
|
|
|
|
|
# TODO: Is this correct? Old code tried to
|
|
|
|
# conditionally multiply by 100, but we
|
|
|
|
# want hand.buyin in 100ths of
|
|
|
|
# dollars/euros (so hand.buyin = 90 for $0.90 BI).
|
|
|
|
hand.buyin = int(100 * Decimal(info['BIAMT']))
|
|
|
|
hand.fee = int(100 * Decimal(info['BIRAKE']))
|
2010-11-26 05:45:41 +01:00
|
|
|
else:
|
|
|
|
hand.buyin = int(Decimal(info['BIAMT']))
|
|
|
|
hand.fee = 0
|
|
|
|
|
|
|
|
if key == 'LEVEL':
|
|
|
|
hand.level = info[key]
|
|
|
|
|
2011-01-27 21:09:50 +01:00
|
|
|
m = self.re_Button.search(hand.handText)
|
|
|
|
hand.buttonpos = m.groupdict().get('BUTTON', None)
|
|
|
|
|
2010-09-23 18:31:17 +02:00
|
|
|
hand.mixed = None
|
|
|
|
|
|
|
|
def readPlayerStacks(self, hand):
|
2011-03-10 04:15:53 +01:00
|
|
|
log.debug(_("readplayerstacks: re is '%s'") % self.re_PlayerInfo)
|
2010-09-23 18:31:17 +02:00
|
|
|
m = self.re_PlayerInfo.finditer(hand.handText)
|
|
|
|
for a in m:
|
|
|
|
hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), a.group('CASH'))
|
|
|
|
|
|
|
|
|
|
|
|
def markStreets(self, hand):
|
|
|
|
m = re.search(r"\*\*\* ANTE\/BLINDS \*\*\*(?P<PREFLOP>.+(?=\*\*\* FLOP \*\*\*)|.+)"
|
|
|
|
r"(\*\*\* FLOP \*\*\*(?P<FLOP> \[\S\S \S\S \S\S\].+(?=\*\*\* TURN \*\*\*)|.+))?"
|
2010-10-05 11:17:39 +02:00
|
|
|
r"(\*\*\* TURN \*\*\* \[\S\S \S\S \S\S](?P<TURN>\[\S\S\].+(?=\*\*\* RIVER \*\*\*)|.+))?"
|
|
|
|
r"(\*\*\* RIVER \*\*\* \[\S\S \S\S \S\S \S\S](?P<RIVER>\[\S\S\].+))?", hand.handText,re.DOTALL)
|
2010-09-23 18:31:17 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
hand.addStreets(m)
|
2010-10-08 06:26:24 +02:00
|
|
|
# print "adding street", m.group(0)
|
|
|
|
# print "---"
|
2010-09-23 18:31:17 +02:00
|
|
|
except:
|
2010-10-10 17:29:52 +02:00
|
|
|
print (_("Failed to add streets. handtext=%s"))
|
2010-09-23 18:31:17 +02:00
|
|
|
|
|
|
|
#Needs to return a list in the format
|
|
|
|
# ['player1name', 'player2name', ...] where player1name is the sb and player2name is bb,
|
|
|
|
# addtional players are assumed to post a bb oop
|
|
|
|
|
|
|
|
def readButton(self, hand):
|
|
|
|
m = self.re_Button.search(hand.handText)
|
|
|
|
if m:
|
|
|
|
hand.buttonpos = int(m.group('BUTTON'))
|
2011-03-10 04:15:53 +01:00
|
|
|
log.debug(_('readButton: button on pos %d') % hand.buttonpos)
|
2010-09-23 18:31:17 +02:00
|
|
|
else:
|
|
|
|
log.warning(_('readButton: not found'))
|
|
|
|
|
|
|
|
# def readCommunityCards(self, hand, street):
|
|
|
|
# #print hand.streets.group(street)
|
|
|
|
# if street in ('FLOP','TURN','RIVER'): # a list of streets which get dealt community cards (i.e. all but PREFLOP)
|
|
|
|
# m = self.re_Board.search(hand.streets.group(street))
|
|
|
|
# hand.setCommunityCards(street, m.group('CARDS').split(','))
|
|
|
|
|
|
|
|
def readCommunityCards(self, hand, street): # street has been matched by markStreets, so exists in this hand
|
|
|
|
if street in ('FLOP','TURN','RIVER'): # a list of streets which get dealt community cards (i.e. all but PREFLOP)
|
|
|
|
#print "DEBUG readCommunityCards:", street, hand.streets.group(street)
|
|
|
|
m = self.re_Board.search(hand.streets[street])
|
|
|
|
hand.setCommunityCards(street, m.group('CARDS').split(' '))
|
|
|
|
|
|
|
|
def readBlinds(self, hand):
|
2010-10-08 08:56:32 +02:00
|
|
|
if not self.re_DenySB.search(hand.handText):
|
|
|
|
try:
|
|
|
|
m = self.re_PostSB.search(hand.handText)
|
|
|
|
hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB'))
|
|
|
|
except exceptions.AttributeError: # no small blind
|
|
|
|
log.warning( _("readBlinds in noSB exception - no SB created")+str(sys.exc_info()) )
|
|
|
|
#hand.addBlind(None, None, None)
|
2010-09-23 18:31:17 +02:00
|
|
|
for a in self.re_PostBB.finditer(hand.handText):
|
|
|
|
hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB'))
|
|
|
|
for a in self.re_PostDead.finditer(hand.handText):
|
|
|
|
#print "DEBUG: Found dead blind: addBlind(%s, 'secondsb', %s)" %(a.group('PNAME'), a.group('DEAD'))
|
|
|
|
hand.addBlind(a.group('PNAME'), 'secondsb', a.group('DEAD'))
|
|
|
|
for a in self.re_PostBoth.finditer(hand.handText):
|
|
|
|
hand.addBlind(a.group('PNAME'), 'small & big blinds', a.group('SBBB'))
|
|
|
|
|
|
|
|
def readAntes(self, hand):
|
|
|
|
log.debug(_("reading antes"))
|
|
|
|
m = self.re_Antes.finditer(hand.handText)
|
|
|
|
for player in m:
|
|
|
|
#~ logging.debug("hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE')))
|
|
|
|
hand.addAnte(player.group('PNAME'), player.group('ANTE'))
|
|
|
|
|
|
|
|
def readBringIn(self, hand):
|
|
|
|
m = self.re_BringIn.search(hand.handText,re.DOTALL)
|
|
|
|
if m:
|
|
|
|
#~ logging.debug("readBringIn: %s for %s" %(m.group('PNAME'), m.group('BRINGIN')))
|
|
|
|
hand.addBringIn(m.group('PNAME'), m.group('BRINGIN'))
|
|
|
|
|
|
|
|
def readHeroCards(self, hand):
|
|
|
|
# streets PREFLOP, PREDRAW, and THIRD are special cases beacause
|
|
|
|
# we need to grab hero's cards
|
|
|
|
for street in ('PREFLOP', 'DEAL', 'BLINDSANTES'):
|
|
|
|
if street in hand.streets.keys():
|
|
|
|
m = self.re_HeroCards.finditer(hand.streets[street])
|
|
|
|
if m == []:
|
2011-03-10 04:15:53 +01:00
|
|
|
log.debug(_("No hole cards found for %s") % street)
|
2010-09-23 18:31:17 +02:00
|
|
|
for found in m:
|
|
|
|
hand.hero = found.group('PNAME')
|
|
|
|
newcards = found.group('CARDS').split(' ')
|
2010-10-08 06:26:24 +02:00
|
|
|
# print "DEBUG: addHoleCards(%s, %s, %s)" %(street, hand.hero, newcards)
|
2010-09-23 18:31:17 +02:00
|
|
|
hand.addHoleCards(street, hand.hero, closed=newcards, shown=False, mucked=False, dealt=True)
|
2011-03-10 04:15:53 +01:00
|
|
|
log.debug(_("Hero cards %s: %s") % (hand.hero, newcards))
|
2010-09-23 18:31:17 +02:00
|
|
|
|
|
|
|
def readAction(self, hand, street):
|
|
|
|
m = self.re_Action.finditer(hand.streets[street])
|
|
|
|
for action in m:
|
|
|
|
acts = action.groupdict()
|
|
|
|
if action.group('ATYPE') == ' raises':
|
|
|
|
hand.addRaiseBy( street, action.group('PNAME'), action.group('BET') )
|
|
|
|
elif action.group('ATYPE') == ' calls':
|
|
|
|
hand.addCall( street, action.group('PNAME'), action.group('BET') )
|
|
|
|
elif action.group('ATYPE') == ' bets':
|
|
|
|
hand.addBet( street, action.group('PNAME'), action.group('BET') )
|
|
|
|
elif action.group('ATYPE') == ' folds':
|
|
|
|
hand.addFold( street, action.group('PNAME'))
|
|
|
|
elif action.group('ATYPE') == ' checks':
|
|
|
|
hand.addCheck( street, action.group('PNAME'))
|
|
|
|
elif action.group('ATYPE') == ' discards':
|
|
|
|
hand.addDiscard(street, action.group('PNAME'), action.group('BET'), action.group('DISCARDED'))
|
|
|
|
elif action.group('ATYPE') == ' stands pat':
|
|
|
|
hand.addStandsPat( street, action.group('PNAME'))
|
|
|
|
else:
|
2011-03-10 05:14:16 +01:00
|
|
|
log.fatal(_("DEBUG: ") + _("unimplemented readAction: '%s' '%s'") % (action.group('PNAME'),action.group('ATYPE')))
|
2010-10-08 06:26:24 +02:00
|
|
|
# print "Processed %s"%acts
|
|
|
|
# print "committed=",hand.pot.committed
|
2010-09-23 18:31:17 +02:00
|
|
|
|
|
|
|
def readShowdownActions(self, hand):
|
|
|
|
for shows in self.re_ShowdownAction.finditer(hand.handText):
|
2011-03-10 04:15:53 +01:00
|
|
|
log.debug(_("add show actions %s") % shows)
|
2010-09-23 18:31:17 +02:00
|
|
|
cards = shows.group('CARDS')
|
|
|
|
cards = cards.split(' ')
|
2010-10-08 06:26:24 +02:00
|
|
|
# print "DEBUG: addShownCards(%s, %s)" %(cards, shows.group('PNAME'))
|
2010-09-23 18:31:17 +02:00
|
|
|
hand.addShownCards(cards, shows.group('PNAME'))
|
|
|
|
|
|
|
|
def readCollectPot(self,hand):
|
2010-10-08 06:26:24 +02:00
|
|
|
# Winamax has unfortunately thinks that a sidepot is created
|
|
|
|
# when there is uncalled money in the pot - something that can
|
|
|
|
# only happen when a player is all-in
|
|
|
|
|
2010-10-08 08:56:32 +02:00
|
|
|
# Becuase of this, we need to do the same calculations as class Pot()
|
|
|
|
# and determine if the amount returned is the same as the amount collected
|
|
|
|
# if so then the collected line is invalid
|
|
|
|
|
|
|
|
total = sum(hand.pot.committed.values()) + sum(hand.pot.common.values())
|
|
|
|
|
|
|
|
# Return any uncalled bet.
|
2010-10-08 06:26:24 +02:00
|
|
|
committed = sorted([ (v,k) for (k,v) in hand.pot.committed.items()])
|
2010-10-08 08:56:32 +02:00
|
|
|
#print "DEBUG: committed: %s" % committed
|
|
|
|
returned = {}
|
2010-10-08 06:26:24 +02:00
|
|
|
lastbet = committed[-1][0] - committed[-2][0]
|
|
|
|
if lastbet > 0: # uncalled
|
|
|
|
returnto = committed[-1][1]
|
2010-10-08 08:56:32 +02:00
|
|
|
#print "DEBUG: returning %f to %s" % (lastbet, returnto)
|
|
|
|
total -= lastbet
|
|
|
|
returned[returnto] = lastbet
|
|
|
|
|
|
|
|
collectees = []
|
|
|
|
|
2011-02-04 10:18:10 +01:00
|
|
|
tp = self.re_Total.search(hand.handText)
|
|
|
|
rake = tp.group('RAKE')
|
|
|
|
if rake == None:
|
|
|
|
rake = 0
|
2010-10-08 08:56:32 +02:00
|
|
|
for m in self.re_CollectPot.finditer(hand.handText):
|
|
|
|
collectees.append([m.group('PNAME'), m.group('POT')])
|
|
|
|
|
2011-02-23 05:30:48 +01:00
|
|
|
#print "DEBUG: Total pot: %s" % tp.groupdict()
|
|
|
|
#print "DEBUG: According to pot: %s" % total
|
|
|
|
#print "DEBUG: Rake: %s" % rake
|
|
|
|
|
2011-02-04 10:18:10 +01:00
|
|
|
if len(collectees) == 1:
|
|
|
|
plyr, p = collectees[0]
|
|
|
|
# p may be wrong, use calculated total - rake
|
|
|
|
p = total - Decimal(rake)
|
|
|
|
#print "DEBUG: len1: addCollectPot(%s,%s)" %(plyr, p)
|
|
|
|
hand.addCollectPot(player=plyr,pot=p)
|
|
|
|
else:
|
|
|
|
for plyr, p in collectees:
|
2011-02-23 05:30:48 +01:00
|
|
|
if plyr in returned.keys():
|
2011-02-04 10:18:10 +01:00
|
|
|
p = Decimal(p) - returned[plyr]
|
|
|
|
if p > 0:
|
|
|
|
#print "DEBUG: addCollectPot(%s,%s)" %(plyr, p)
|
|
|
|
hand.addCollectPot(player=plyr,pot=p)
|
2010-09-23 18:31:17 +02:00
|
|
|
|
|
|
|
def readShownCards(self,hand):
|
|
|
|
for m in self.re_ShownCards.finditer(hand.handText):
|
2011-03-10 04:15:53 +01:00
|
|
|
log.debug(_("Read shown cards: %s") % m.group(0))
|
2010-09-23 18:31:17 +02:00
|
|
|
cards = m.group('CARDS')
|
|
|
|
cards = cards.split(' ') # needs to be a list, not a set--stud needs the order
|
|
|
|
(shown, mucked) = (False, False)
|
|
|
|
if m.group('CARDS') is not None:
|
|
|
|
shown = True
|
|
|
|
hand.addShownCards(cards=cards, player=m.group('PNAME'), shown=shown, mucked=mucked)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
c = Configuration.Config()
|
|
|
|
if len(sys.argv) == 1:
|
|
|
|
testfile = "regression-test-files/ongame/nlhe/ong NLH handhq_0.txt"
|
|
|
|
else:
|
|
|
|
testfile = sys.argv[1]
|
|
|
|
e = Winamax(c, testfile)
|