2010-08-19 07:23:42 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2008-2010, Carl Gherardi
|
|
|
|
#
|
|
|
|
# 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-23 08:31:16 +02:00
|
|
|
import L10n
|
|
|
|
_ = L10n.get_translation()
|
|
|
|
|
2010-08-19 07:23:42 +02:00
|
|
|
import sys
|
2010-08-29 00:49:37 +02:00
|
|
|
import exceptions
|
|
|
|
|
|
|
|
import logging
|
|
|
|
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
|
|
|
|
log = logging.getLogger("parser")
|
|
|
|
|
|
|
|
|
2010-08-19 07:23:42 +02:00
|
|
|
import Configuration
|
|
|
|
from HandHistoryConverter import *
|
2011-02-25 20:18:12 +01:00
|
|
|
from decimal_wrapper import Decimal
|
2010-08-20 11:10:38 +02:00
|
|
|
|
2010-08-19 07:23:42 +02:00
|
|
|
# OnGame HH Format
|
|
|
|
|
|
|
|
class OnGame(HandHistoryConverter):
|
2010-08-31 23:44:41 +02:00
|
|
|
filter = "OnGame"
|
2010-08-20 10:51:41 +02:00
|
|
|
filetype = "text"
|
|
|
|
codepage = ("utf8", "cp1252")
|
|
|
|
siteId = 5 # Needs to match id entry in Sites database
|
|
|
|
|
2010-08-21 22:10:21 +02:00
|
|
|
mixes = { } # Legal mixed games
|
2010-12-19 09:30:11 +01:00
|
|
|
sym = {'USD': "\$", 'CAD': "\$", 'T$': "", "EUR": u"\u20ac", "GBP": "\xa3"} # ADD Euro, Sterling, etc HERE
|
2010-08-20 11:59:52 +02:00
|
|
|
substitutions = {
|
|
|
|
'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes
|
2010-12-19 09:30:11 +01:00
|
|
|
'LS' : u"\$|\xe2\x82\xac|\u20ac" # legal currency symbols - Euro(cp1252, utf-8)
|
2010-08-20 11:59:52 +02:00
|
|
|
}
|
2010-12-19 09:30:11 +01:00
|
|
|
currencies = { u'\u20ac':'EUR', u'\xe2\x82\xac':'EUR', '$':'USD', '':'T$' }
|
2010-08-20 11:59:52 +02:00
|
|
|
|
2011-02-08 04:09:57 +01:00
|
|
|
limits = { 'NO_LIMIT':'nl', 'POT_LIMIT':'pl', 'LIMIT':'fl'}
|
2010-08-20 11:59:52 +02:00
|
|
|
|
|
|
|
games = { # base, category
|
|
|
|
"TEXAS_HOLDEM" : ('hold','holdem'),
|
2010-09-30 11:53:52 +02:00
|
|
|
'OMAHA_HI' : ('hold','omahahi'),
|
2010-08-20 11:59:52 +02:00
|
|
|
# 'Omaha Hi/Lo' : ('hold','omahahilo'),
|
|
|
|
# 'Razz' : ('stud','razz'),
|
|
|
|
# 'RAZZ' : ('stud','razz'),
|
2010-09-30 11:53:52 +02:00
|
|
|
'SEVEN_CARD_STUD' : ('stud','studhi'),
|
2010-09-04 19:14:57 +02:00
|
|
|
'SEVEN_CARD_STUD_HI_LO' : ('stud','studhilo'),
|
2010-08-20 11:59:52 +02:00
|
|
|
# 'Badugi' : ('draw','badugi'),
|
|
|
|
# 'Triple Draw 2-7 Lowball' : ('draw','27_3draw'),
|
2010-09-30 12:01:47 +02:00
|
|
|
'FIVE_CARD_DRAW' : ('draw','fivedraw')
|
2010-08-20 11:59:52 +02:00
|
|
|
}
|
|
|
|
|
2010-08-20 10:51:41 +02:00
|
|
|
# Static regexes
|
2010-08-21 14:44:01 +02:00
|
|
|
# ***** End of hand R5-75443872-57 *****
|
|
|
|
re_SplitHands = re.compile(u'\*\*\*\*\*\sEnd\sof\shand\s[-A-Z\d]+.*\n(?=\*)')
|
2010-08-20 11:59:52 +02:00
|
|
|
|
2011-02-13 15:04:09 +01:00
|
|
|
#TODO: detect play money
|
|
|
|
# "Play money" rather than "Real money" and set currency accordingly
|
2010-08-20 11:59:52 +02:00
|
|
|
re_HandInfo = re.compile(u"""
|
|
|
|
\*\*\*\*\*\sHistory\sfor\shand\s(?P<HID>[-A-Z\d]+).*
|
|
|
|
Start\shand:\s(?P<DATETIME>.*)
|
2011-02-13 15:04:09 +01:00
|
|
|
Table:\s(\[SPEED\]\s)?(?P<TABLE>[-\'\w\s]+)\s\[\d+\]\s\(
|
2010-08-20 11:59:52 +02:00
|
|
|
(
|
2011-02-08 04:09:57 +01:00
|
|
|
(?P<LIMIT>NO_LIMIT|Limit|LIMIT|Pot\sLimit|POT_LIMIT)\s
|
2010-09-30 12:01:47 +02:00
|
|
|
(?P<GAME>TEXAS_HOLDEM|OMAHA_HI|SEVEN_CARD_STUD|SEVEN_CARD_STUD_HI_LO|RAZZ|FIVE_CARD_DRAW)\s
|
2010-12-19 09:30:11 +01:00
|
|
|
(?P<CURRENCY>%(LS)s|)?(?P<SB>[.0-9]+)/
|
2010-08-29 00:49:37 +02:00
|
|
|
(%(LS)s)?(?P<BB>[.0-9]+)
|
2010-08-20 11:59:52 +02:00
|
|
|
)?
|
2011-02-13 15:04:09 +01:00
|
|
|
""" % substitutions, re.MULTILINE|re.DOTALL|re.VERBOSE)
|
2010-08-20 14:10:52 +02:00
|
|
|
|
2010-08-21 22:10:21 +02:00
|
|
|
re_TailSplitHands = re.compile(u'(\*\*\*\*\*\sEnd\sof\shand\s[-A-Z\d]+.*\n)(?=\*)')
|
|
|
|
re_Button = re.compile('Button: seat (?P<BUTTON>\d+)', re.MULTILINE) # Button: seat 2
|
|
|
|
re_Board = re.compile(r"\[(?P<CARDS>.+)\]")
|
|
|
|
|
2010-08-20 14:10:52 +02:00
|
|
|
# Wed Aug 18 19:45:30 GMT+0100 2010
|
|
|
|
re_DateTime = re.compile("""
|
|
|
|
[a-zA-Z]{3}\s
|
|
|
|
(?P<M>[a-zA-Z]{3})\s
|
2010-09-08 10:05:04 +02:00
|
|
|
(?P<D>[0-9]+)\s
|
2010-08-21 22:10:21 +02:00
|
|
|
(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[0-9]+)\s
|
|
|
|
(?P<OFFSET>\w+[-+]\d+)\s
|
2010-08-20 14:10:52 +02:00
|
|
|
(?P<Y>[0-9]{4})
|
|
|
|
""", re.MULTILINE|re.VERBOSE)
|
2010-08-19 07:23:42 +02:00
|
|
|
|
2010-08-20 10:51:41 +02:00
|
|
|
#Seat 1: .Lucchess ($4.17 in chips)
|
2010-08-29 00:49:37 +02:00
|
|
|
#Seat 1: phantomaas ($27.11)
|
|
|
|
#Seat 5: mleo17 ($9.37)
|
|
|
|
re_PlayerInfo = re.compile(u'Seat (?P<SEAT>[0-9]+):\s(?P<PNAME>.*)\s\((%(LS)s)?(?P<CASH>[.0-9]+)\)' % substitutions)
|
2010-08-19 07:23:42 +02:00
|
|
|
|
2010-08-20 14:10:52 +02:00
|
|
|
def compilePlayerRegexs(self, hand):
|
2010-08-20 23:32:14 +02:00
|
|
|
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.
|
2010-08-21 22:10:21 +02:00
|
|
|
self.compiledPlayers = players
|
2010-08-20 23:32:14 +02:00
|
|
|
|
|
|
|
#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']]}
|
2010-08-29 00:49:37 +02:00
|
|
|
self.re_PostSB = re.compile('(?P<PNAME>.*) posts small blind \((%(CUR)s)?(?P<SB>[\.0-9]+)\)' % subst, re.MULTILINE)
|
2010-09-11 05:56:00 +02:00
|
|
|
self.re_PostBB = re.compile('(?P<PNAME>.*) posts big blind \((%(CUR)s)?(?P<BB>[\.0-9]+)\)' % subst, re.MULTILINE)
|
2010-08-29 00:49:37 +02:00
|
|
|
self.re_Antes = re.compile(r"^%(PLYR)s: posts the ante (%(CUR)s)?(?P<ANTE>[\.0-9]+)" % subst, re.MULTILINE)
|
|
|
|
self.re_BringIn = re.compile(r"^%(PLYR)s: brings[- ]in( low|) for (%(CUR)s)?(?P<BRINGIN>[\.0-9]+)" % subst, re.MULTILINE)
|
2010-09-15 07:25:44 +02:00
|
|
|
self.re_PostBoth = re.compile('(?P<PNAME>.*): posts small \& big blind \( (%(CUR)s)?(?P<SBBB>[\.0-9]+)\)' % subst)
|
|
|
|
self.re_PostDead = re.compile('(?P<PNAME>.*) posts dead blind \((%(CUR)s)?(?P<DEAD>[\.0-9]+)\)' % subst, re.MULTILINE)
|
2010-08-23 07:50:04 +02:00
|
|
|
self.re_HeroCards = re.compile('Dealing\sto\s%(PLYR)s:\s\[(?P<CARDS>.*)\]' % subst)
|
2010-08-20 23:32:14 +02:00
|
|
|
|
|
|
|
#lopllopl checks, Eurolll checks, .Lucchess checks.
|
2010-08-29 00:49:37 +02:00
|
|
|
#chumley. calls $0.25
|
2010-12-19 08:59:10 +01:00
|
|
|
self.re_Action = re.compile('(, )?(?P<PNAME>.*?)(?P<ATYPE> bets| checks| raises| calls| folds)( (%(CUR)s)?(?P<BET>[\d\.]+))?( and is all-in)?' % subst)
|
2010-08-21 22:10:21 +02:00
|
|
|
#self.re_Board = re.compile(r"\[board cards (?P<CARDS>.+) \]")
|
2010-08-20 23:32:14 +02:00
|
|
|
|
|
|
|
#Uchilka shows [ KC,JD ]
|
2010-08-21 22:10:21 +02:00
|
|
|
self.re_ShowdownAction = re.compile('(?P<PNAME>.*) shows \[ (?P<CARDS>.+) \]')
|
2010-08-20 23:32:14 +02:00
|
|
|
|
2010-08-29 00:49:37 +02:00
|
|
|
#Main pot: $3.57 won by mleo17 ($3.40)
|
|
|
|
#Side pot 1: $3.26 won by maac_5 ($3.10)
|
|
|
|
#Main pot: $2.87 won by maac_5 ($1.37), sagi34 ($1.36)
|
|
|
|
self.re_Pot = re.compile('(Main|Side)\spot(\s\d+)?:\s.*won\sby\s(?P<POT>.*$)', re.MULTILINE)
|
|
|
|
self.re_CollectPot = re.compile('\s*(?P<PNAME>.*)\s\((%(CUR)s)?(?P<POT>[\.\d]+)\)' % subst)
|
|
|
|
#Seat 5: mleo17 ($3.40), net: +$2.57, [Jd, Qd] (TWO_PAIR QUEEN, JACK)
|
|
|
|
self.re_ShownCards = re.compile("^Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(.*\), net:.* \[(?P<CARDS>.*)\].*" % subst, re.MULTILINE)
|
2010-08-21 22:10:21 +02:00
|
|
|
self.re_sitsOut = re.compile('(?P<PNAME>.*) sits out')
|
2010-08-20 14:10:52 +02:00
|
|
|
|
2010-08-19 07:23:42 +02:00
|
|
|
def readSupportedGames(self):
|
2010-08-20 12:05:25 +02:00
|
|
|
return [
|
|
|
|
["ring", "hold", "fl"],
|
2011-02-08 04:09:57 +01:00
|
|
|
["ring", "hold", "pl"],
|
2010-08-20 12:05:25 +02:00
|
|
|
["ring", "hold", "nl"],
|
2010-09-04 19:14:57 +02:00
|
|
|
["ring", "stud", "fl"],
|
2010-09-30 12:01:47 +02:00
|
|
|
["ring", "draw", "fl"],
|
2010-08-20 12:05:25 +02:00
|
|
|
]
|
2010-08-19 07:23:42 +02:00
|
|
|
|
2010-08-20 10:51:41 +02:00
|
|
|
def determineGameType(self, handText):
|
2010-08-20 11:59:52 +02:00
|
|
|
# Inspect the handText and return the gametype dict
|
|
|
|
# gametype dict is: {'limitType': xxx, 'base': xxx, 'category': xxx}
|
|
|
|
info = {}
|
2010-08-19 07:23:42 +02:00
|
|
|
|
2010-08-20 10:51:41 +02:00
|
|
|
m = self.re_HandInfo.search(handText)
|
2010-08-20 11:10:38 +02:00
|
|
|
if not m:
|
|
|
|
tmp = handText[0:100]
|
|
|
|
log.error(_("determineGameType: Unable to recognise gametype from: '%s'") % tmp)
|
|
|
|
log.error(_("determineGameType: Raising FpdbParseError"))
|
|
|
|
raise FpdbParseError(_("Unable to recognise gametype from: '%s'") % tmp)
|
|
|
|
|
2010-08-20 11:59:52 +02:00
|
|
|
mg = m.groupdict()
|
2011-02-08 04:09:57 +01:00
|
|
|
#print "DEBUG: mg: %s" % mg
|
2010-08-20 11:59:52 +02:00
|
|
|
|
|
|
|
info['type'] = 'ring'
|
2010-12-19 09:30:11 +01:00
|
|
|
if 'CURRENCY' in mg:
|
|
|
|
info['currency'] = self.currencies[mg['CURRENCY']]
|
2010-08-20 11:59:52 +02:00
|
|
|
|
|
|
|
if 'LIMIT' in mg:
|
2010-08-29 00:49:37 +02:00
|
|
|
if mg['LIMIT'] in self.limits:
|
|
|
|
info['limitType'] = self.limits[mg['LIMIT']]
|
|
|
|
else:
|
|
|
|
tmp = handText[0:100]
|
|
|
|
log.error(_("determineGameType: limit not found in self.limits(%s). hand: '%s'") % (str(mg),tmp))
|
|
|
|
log.error(_("determineGameType: Raising FpdbParseError"))
|
|
|
|
raise FpdbParseError(_("limit not found in self.limits(%s). hand: '%s'") % (str(mg),tmp))
|
2010-08-20 11:59:52 +02:00
|
|
|
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']
|
|
|
|
|
2010-08-29 00:49:37 +02:00
|
|
|
#log.debug("determinegametype: returning "+str(info))
|
2010-08-20 11:59:52 +02:00
|
|
|
return info
|
2010-08-19 07:23:42 +02:00
|
|
|
|
|
|
|
def readHandInfo(self, hand):
|
2010-08-20 14:10:52 +02:00
|
|
|
info = {}
|
|
|
|
m = self.re_HandInfo.search(hand.handText)
|
|
|
|
|
|
|
|
if m:
|
|
|
|
info.update(m.groupdict())
|
|
|
|
|
2010-08-29 00:49:37 +02:00
|
|
|
#log.debug("readHandInfo: %s" % info)
|
2010-08-20 14:10:52 +02:00
|
|
|
for key in info:
|
|
|
|
if key == 'DATETIME':
|
|
|
|
#'Wed Aug 18 19:45:30 GMT+0100 2010
|
|
|
|
# %a %b %d %H:%M:%S %z %Y
|
|
|
|
#hand.startTime = time.strptime(m.group('DATETIME'), "%a %b %d %H:%M:%S GMT%z %Y")
|
|
|
|
# Stupid library doesn't seem to support %z (http://docs.python.org/library/time.html?highlight=strptime#time.strptime)
|
|
|
|
# So we need to re-interpret te string to be useful
|
2010-09-07 19:08:23 +02:00
|
|
|
a = self.re_DateTime.search(info[key])
|
|
|
|
if a:
|
2010-08-21 14:44:01 +02:00
|
|
|
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'))
|
2010-08-21 22:10:21 +02:00
|
|
|
tzoffset = a.group('OFFSET')
|
2010-09-07 19:08:23 +02:00
|
|
|
else:
|
2010-09-08 10:02:18 +02:00
|
|
|
datetimestr = "2010/Jan/01 01:01:01"
|
2010-09-07 19:08:23 +02:00
|
|
|
log.error(_("readHandInfo: DATETIME not matched: '%s'" % info[key]))
|
2010-09-08 10:02:18 +02:00
|
|
|
print "DEBUG: readHandInfo: DATETIME not matched: '%s'" % info[key]
|
2010-09-07 19:08:23 +02:00
|
|
|
# TODO: Manually adjust time against OFFSET
|
2010-08-21 14:44:01 +02:00
|
|
|
hand.startTime = datetime.datetime.strptime(datetimestr, "%Y/%b/%d %H:%M:%S") # also timezone at end, e.g. " ET"
|
2010-08-21 22:10:21 +02:00
|
|
|
hand.startTime = HandHistoryConverter.changeTimezone(hand.startTime, tzoffset, "UTC")
|
2010-08-20 14:10:52 +02:00
|
|
|
if key == 'HID':
|
|
|
|
hand.handid = info[key]
|
OnGame: remove non-digits from hand id
Fixing email reported error with MySQL:
fpdb starting ...Traceback (most recent call last):
File "GuiBulkImport.pyc", line 107, in load_clicked
File "fpdb_import.pyc", line 251, in runImport
File "fpdb_import.pyc", line 314, in importFiles
File "fpdb_import.pyc", line 482, in import_file_dict
File "Hand.pyc", line 273, in insert
File "Database.pyc", line 1651, in storeHand
File "MySQLdb\cursors.pyc", line 174, in execute
File "MySQLdb\connections.pyc", line 36, in defaulterrorhandler
_mysql_exceptions.OperationalError: (1366, "Incorrect integer value: 'R5-79731715-280' for column 'siteHandNo' at row 1")
2010-09-09 04:31:40 +02:00
|
|
|
# Need to remove non-alphanumerics for MySQL
|
|
|
|
hand.handid = hand.handid.replace('R','')
|
|
|
|
hand.handid = hand.handid.replace('-','')
|
2010-08-20 14:10:52 +02:00
|
|
|
if key == 'TABLE':
|
|
|
|
hand.tablename = info[key]
|
|
|
|
|
|
|
|
# TODO: These
|
|
|
|
hand.buttonpos = 1
|
2010-09-11 08:11:40 +02:00
|
|
|
hand.maxseats = None # Set to None - Hand.py will guessMaxSeats()
|
2010-08-20 14:10:52 +02:00
|
|
|
hand.mixed = None
|
2010-08-19 07:23:42 +02:00
|
|
|
|
|
|
|
def readPlayerStacks(self, hand):
|
2010-08-29 00:49:37 +02:00
|
|
|
#log.debug("readplayerstacks: re is '%s'" % self.re_PlayerInfo)
|
2010-08-20 14:10:52 +02:00
|
|
|
m = self.re_PlayerInfo.finditer(hand.handText)
|
2010-08-19 07:23:42 +02:00
|
|
|
for a in m:
|
|
|
|
hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), a.group('CASH'))
|
|
|
|
|
|
|
|
def markStreets(self, hand):
|
2010-09-30 11:53:52 +02:00
|
|
|
if hand.gametype['base'] in ("hold"):
|
|
|
|
m = re.search(r"pocket cards(?P<PREFLOP>.+(?= Dealing flop )|.+(?=Summary))"
|
2010-08-21 22:10:21 +02:00
|
|
|
r"( Dealing flop (?P<FLOP>\[\S\S, \S\S, \S\S\].+(?= Dealing turn)|.+(?=Summary)))?"
|
|
|
|
r"( Dealing turn (?P<TURN>\[\S\S\].+(?= Dealing river)|.+(?=Summary)))?"
|
|
|
|
r"( Dealing river (?P<RIVER>\[\S\S\].+(?=Summary)))?", hand.handText, re.DOTALL)
|
2010-09-30 11:53:52 +02:00
|
|
|
elif hand.gametype['base'] in ("stud"):
|
|
|
|
m = re.search(r"(?P<ANTES>.+(?=Dealing pocket cards)|.+)"
|
|
|
|
r"(Dealing pocket cards(?P<THIRD>.+(?=Dealing 4th street)|.+))?"
|
|
|
|
r"(Dealing 4th street(?P<FOURTH>.+(?=Dealing 5th street)|.+))?"
|
|
|
|
r"(Dealing 5th street(?P<FIFTH>.+(?=Dealing 6th street)|.+))?"
|
|
|
|
r"(Dealing 6th street(?P<SIXTH>.+(?=Dealing river)|.+))?"
|
|
|
|
r"(Dealing river(?P<SEVENTH>.+))?", hand.handText,re.DOTALL)
|
2010-09-30 12:01:47 +02:00
|
|
|
elif hand.gametype['base'] in ("draw"):
|
|
|
|
m = re.search(r"(?P<PREDEAL>.+(?=Dealing pocket cards)|.+)"
|
|
|
|
r"(Dealing pocket cards(?P<DEAL>.+(?=\*\*\* FIRST DRAW \*\*\*)|.+))?"
|
|
|
|
r"(\*\*\* FIRST DRAW \*\*\*(?P<DRAWONE>.+(?=\*\*\* SECOND DRAW \*\*\*)|.+))?"
|
|
|
|
r"(\*\*\* SECOND DRAW \*\*\*(?P<DRAWTWO>.+(?=\*\*\* THIRD DRAW \*\*\*)|.+))?"
|
|
|
|
r"(\*\*\* THIRD DRAW \*\*\*(?P<DRAWTHREE>.+))?", hand.handText,re.DOTALL)
|
2010-08-19 07:23:42 +02:00
|
|
|
|
|
|
|
hand.addStreets(m)
|
2010-08-20 23:32:14 +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'))
|
|
|
|
else:
|
|
|
|
log.info(_('readButton: not found'))
|
2010-08-19 07:23:42 +02:00
|
|
|
|
2010-08-21 22:10:21 +02:00
|
|
|
# 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
|
2010-08-19 07:23:42 +02:00
|
|
|
if street in ('FLOP','TURN','RIVER'): # a list of streets which get dealt community cards (i.e. all but PREFLOP)
|
2010-08-21 22:10:21 +02:00
|
|
|
#print "DEBUG readCommunityCards:", street, hand.streets.group(street)
|
|
|
|
m = self.re_Board.search(hand.streets[street])
|
|
|
|
hand.setCommunityCards(street, m.group('CARDS').split(', '))
|
2010-08-19 07:23:42 +02:00
|
|
|
|
|
|
|
def readBlinds(self, hand):
|
|
|
|
try:
|
2010-08-20 14:10:52 +02:00
|
|
|
m = self.re_PostSB.search(hand.handText)
|
2010-08-19 07:23:42 +02:00
|
|
|
hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB'))
|
2010-08-29 00:49:37 +02:00
|
|
|
except exceptions.AttributeError: # no small blind
|
|
|
|
log.debug( _("readBlinds in noSB exception - no SB created")+str(sys.exc_info()) )
|
|
|
|
#hand.addBlind(None, None, None)
|
2010-08-20 14:10:52 +02:00
|
|
|
for a in self.re_PostBB.finditer(hand.handText):
|
2010-08-19 07:23:42 +02:00
|
|
|
hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB'))
|
2010-09-15 07:25:44 +02:00
|
|
|
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'))
|
2010-08-20 14:10:52 +02:00
|
|
|
for a in self.re_PostBoth.finditer(hand.handText):
|
2010-08-19 07:23:42 +02:00
|
|
|
hand.addBlind(a.group('PNAME'), 'small & big blinds', a.group('SBBB'))
|
|
|
|
|
2010-08-20 23:32:14 +02:00
|
|
|
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'))
|
|
|
|
|
2010-08-19 07:23:42 +02:00
|
|
|
def readHeroCards(self, hand):
|
2010-08-23 07:50:04 +02:00
|
|
|
# streets PREFLOP, PREDRAW, and THIRD are special cases beacause
|
|
|
|
# we need to grab hero's cards
|
|
|
|
for street in ('PREFLOP', 'DEAL'):
|
|
|
|
if street in hand.streets.keys():
|
|
|
|
m = self.re_HeroCards.finditer(hand.streets[street])
|
2010-09-30 11:53:52 +02:00
|
|
|
for found in m:
|
|
|
|
hand.hero = found.group('PNAME')
|
|
|
|
newcards = found.group('CARDS').split(', ')
|
|
|
|
hand.addHoleCards(street, hand.hero, closed=newcards, shown=False, mucked=False, dealt=True)
|
2010-08-19 07:23:42 +02:00
|
|
|
|
2010-08-21 22:10:21 +02:00
|
|
|
def readAction(self, hand, street):
|
|
|
|
m = self.re_Action.finditer(hand.streets[street])
|
|
|
|
for action in m:
|
2010-12-19 04:29:00 +01:00
|
|
|
#acts = action.groupdict()
|
2011-02-07 17:25:25 +01:00
|
|
|
#print "readaction: acts: %s" %acts
|
2010-08-21 22:10:21 +02:00
|
|
|
if action.group('ATYPE') == ' raises':
|
2011-02-07 17:25:25 +01:00
|
|
|
hand.addRaiseTo( street, action.group('PNAME'), action.group('BET') )
|
2010-08-21 22:10:21 +02:00
|
|
|
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:
|
|
|
|
print _("DEBUG: unimplemented readAction: '%s' '%s'") %(action.group('PNAME'),action.group('ATYPE'),)
|
|
|
|
|
2010-08-19 07:23:42 +02:00
|
|
|
def readShowdownActions(self, hand):
|
2010-08-20 14:10:52 +02:00
|
|
|
for shows in self.re_ShowdownAction.finditer(hand.handText):
|
2010-08-19 07:23:42 +02:00
|
|
|
cards = shows.group('CARDS')
|
|
|
|
cards = set(cards.split(','))
|
|
|
|
hand.addShownCards(cards, shows.group('PNAME'))
|
|
|
|
|
|
|
|
def readCollectPot(self,hand):
|
2010-08-29 00:49:37 +02:00
|
|
|
for m in self.re_Pot.finditer(hand.handText):
|
|
|
|
for splitpot in m.group('POT').split(','):
|
|
|
|
for m in self.re_CollectPot.finditer(splitpot):
|
|
|
|
hand.addCollectPot(player=m.group('PNAME'),pot=m.group('POT'))
|
2010-08-19 07:23:42 +02:00
|
|
|
|
|
|
|
def readShownCards(self,hand):
|
2010-08-29 00:49:37 +02:00
|
|
|
for m in self.re_ShownCards.finditer(hand.handText):
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2010-08-19 07:23:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
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 = OnGame(c, testfile)
|
|
|
|
e.processFile()
|
|
|
|
print str(e)
|