2008-11-07 09:47:00 +01:00
|
|
|
#!/usr/bin/env python
|
2009-01-21 17:31:39 +01:00
|
|
|
# -*- coding: iso-8859-15 -*-
|
2008-11-07 09:47:00 +01:00
|
|
|
# Copyright 2008, 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
|
|
|
|
########################################################################
|
|
|
|
|
2008-11-11 09:54:24 +01:00
|
|
|
import sys
|
2008-11-09 00:49:05 +01:00
|
|
|
import Configuration
|
2008-11-09 12:57:58 +01:00
|
|
|
from HandHistoryConverter import *
|
2009-02-20 23:22:36 +01:00
|
|
|
from time import strftime
|
2008-11-09 12:57:58 +01:00
|
|
|
|
2009-02-22 10:07:11 +01:00
|
|
|
# Class for converting Everleaf HH format.
|
2008-11-09 12:57:58 +01:00
|
|
|
|
2008-11-07 11:19:18 +01:00
|
|
|
class Everleaf(HandHistoryConverter):
|
2009-02-25 15:35:28 +01:00
|
|
|
|
|
|
|
# Static regexes
|
|
|
|
re_SplitHands = re.compile(r"\n\n+")
|
2009-02-28 04:34:41 +01:00
|
|
|
re_GameInfo = re.compile(r"^(Blinds )?\$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) ((?P<LTYPE>NL|PL) )?(?P<GAME>(Hold\'em|Omaha|7 Card Stud))", re.MULTILINE)
|
2009-02-28 04:45:44 +01:00
|
|
|
re_HandInfo = re.compile(r".*#(?P<HID>[0-9]+)\n.*\n(Blinds )?\$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) (?P<GAMETYPE>.*) - (?P<DATETIME>\d\d\d\d/\d\d/\d\d - \d\d:\d\d:\d\d)\nTable (?P<TABLE>[- a-zA-Z]+)")
|
2009-02-25 15:35:28 +01:00
|
|
|
re_Button = re.compile(r"^Seat (?P<BUTTON>\d+) is the button", re.MULTILINE)
|
|
|
|
re_PlayerInfo = re.compile(r"^Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\s+(\$ (?P<CASH>[.0-9]+) USD|new player|All-in) \)", re.MULTILINE)
|
|
|
|
re_Board = re.compile(r"\[ (?P<CARDS>.+) \]")
|
|
|
|
|
|
|
|
|
2008-12-06 15:15:41 +01:00
|
|
|
def __init__(self, config, file):
|
|
|
|
print "Initialising Everleaf converter class"
|
2008-12-08 07:23:50 +01:00
|
|
|
HandHistoryConverter.__init__(self, config, file, sitename="Everleaf") # Call super class init.
|
2008-12-06 15:15:41 +01:00
|
|
|
self.sitename = "Everleaf"
|
2008-12-10 17:30:57 +01:00
|
|
|
self.setFileType("text", "cp1252")
|
2009-02-20 17:29:52 +01:00
|
|
|
|
2009-02-25 15:35:28 +01:00
|
|
|
|
2009-02-20 23:22:36 +01:00
|
|
|
try:
|
2009-02-21 12:25:12 +01:00
|
|
|
self.ofile = os.path.join(self.hhdir, file.split(os.path.sep)[-2]+"-"+os.path.basename(file))
|
2009-02-20 23:22:36 +01:00
|
|
|
except:
|
|
|
|
self.ofile = os.path.join(self.hhdir, "x"+strftime("%d-%m-%y")+os.path.basename(file))
|
2009-02-20 17:29:52 +01:00
|
|
|
|
2009-02-25 15:35:28 +01:00
|
|
|
def compilePlayerRegexs(self):
|
2009-02-20 17:29:52 +01:00
|
|
|
player_re = "(?P<PNAME>" + "|".join(map(re.escape, self.players)) + ")"
|
2009-02-22 06:37:38 +01:00
|
|
|
#print "DEBUG player_re: " + player_re
|
2009-02-20 17:29:52 +01:00
|
|
|
self.re_PostSB = re.compile(r"^%s: posts small blind \[\$? (?P<SB>[.0-9]+)" % player_re, re.MULTILINE)
|
|
|
|
self.re_PostBB = re.compile(r"^%s: posts big blind \[\$? (?P<BB>[.0-9]+)" % player_re, re.MULTILINE)
|
2009-02-21 15:26:37 +01:00
|
|
|
self.re_PostBoth = re.compile(r"^%s: posts both blinds \[\$? (?P<SBBB>[.0-9]+)" % player_re, re.MULTILINE)
|
2009-02-20 17:29:52 +01:00
|
|
|
self.re_HeroCards = re.compile(r"^Dealt to %s \[ (?P<CARDS>.*) \]" % player_re, re.MULTILINE)
|
|
|
|
self.re_Action = re.compile(r"^%s(?P<ATYPE>: bets| checks| raises| calls| folds)(\s\[\$ (?P<BET>[.\d]+) (USD|EUR)\])?" % player_re, re.MULTILINE)
|
|
|
|
self.re_ShowdownAction = re.compile(r"^%s shows \[ (?P<CARDS>.*) \]" % player_re, re.MULTILINE)
|
|
|
|
self.re_CollectPot = re.compile(r"^%s wins \$ (?P<POT>[.\d]+) (USD|EUR)(.*?\[ (?P<CARDS>.*?) \])?" % player_re, re.MULTILINE)
|
|
|
|
self.re_SitsOut = re.compile(r"^%s sits out" % player_re, re.MULTILINE)
|
2008-12-06 15:15:41 +01:00
|
|
|
|
|
|
|
def readSupportedGames(self):
|
2009-02-23 13:56:33 +01:00
|
|
|
return [["ring", "hold", "nl"],
|
|
|
|
["ring", "hold", "pl"],
|
2009-03-01 15:05:21 +01:00
|
|
|
["ring", "omahahi", "pl"]
|
2009-02-22 10:21:49 +01:00
|
|
|
]
|
2008-12-06 15:15:41 +01:00
|
|
|
|
|
|
|
def determineGameType(self):
|
|
|
|
# Cheating with this regex, only support nlhe at the moment
|
2009-02-22 10:21:49 +01:00
|
|
|
# Blinds $0.50/$1 PL Omaha - 2008/12/07 - 21:59:48
|
|
|
|
# Blinds $0.05/$0.10 NL Hold'em - 2009/02/21 - 11:21:57
|
|
|
|
# $0.25/$0.50 7 Card Stud - 2008/12/05 - 21:43:59
|
2009-02-25 21:25:58 +01:00
|
|
|
|
|
|
|
# Tourney:
|
|
|
|
# Everleaf Gaming Game #75065769
|
|
|
|
# ***** Hand history for game #75065769 *****
|
|
|
|
# Blinds 10/20 NL Hold'em - 2009/02/25 - 17:30:32
|
|
|
|
# Table 2
|
|
|
|
|
2009-02-22 10:21:49 +01:00
|
|
|
structure = "" # nl, pl, cn, cp, fl
|
|
|
|
game = ""
|
|
|
|
|
2009-02-20 17:29:52 +01:00
|
|
|
m = self.re_GameInfo.search(self.obs)
|
2009-02-25 12:01:44 +01:00
|
|
|
if m == None:
|
|
|
|
return None
|
2009-02-22 10:21:49 +01:00
|
|
|
if m.group('LTYPE') == "NL":
|
|
|
|
structure = "nl"
|
|
|
|
elif m.group('LTYPE') == "PL":
|
|
|
|
structure = "pl"
|
2009-02-23 00:03:19 +01:00
|
|
|
else:
|
|
|
|
structure = "fl" # we don't support it, but there should be how to detect it at least.
|
2009-02-22 10:21:49 +01:00
|
|
|
|
|
|
|
if m.group('GAME') == "Hold\'em":
|
|
|
|
game = "hold"
|
2009-02-25 12:01:44 +01:00
|
|
|
elif m.group('GAME') == "Omaha":
|
2009-02-22 10:21:49 +01:00
|
|
|
game = "omahahi"
|
2009-02-25 12:01:44 +01:00
|
|
|
elif m.group('GAME') == "7 Card Stud":
|
|
|
|
game = "studhi" # Everleaf currently only does Hi stud
|
2009-02-22 10:21:49 +01:00
|
|
|
|
|
|
|
gametype = ["ring", game, structure, m.group('SB'), m.group('BB')]
|
|
|
|
|
2008-12-06 15:15:41 +01:00
|
|
|
return gametype
|
|
|
|
|
|
|
|
def readHandInfo(self, hand):
|
2009-02-20 17:29:52 +01:00
|
|
|
m = self.re_HandInfo.search(hand.string)
|
2009-02-21 14:31:57 +01:00
|
|
|
if(m == None):
|
|
|
|
print "DEBUG: re_HandInfo.search failed: '%s'" %(hand.string)
|
2008-12-06 15:15:41 +01:00
|
|
|
hand.handid = m.group('HID')
|
|
|
|
hand.tablename = m.group('TABLE')
|
2009-03-03 01:51:18 +01:00
|
|
|
hand.maxseats = 6 # assume 6-max unless we have proof it's a larger/smaller game, since everleaf doesn't give seat max info
|
2008-11-12 05:12:18 +01:00
|
|
|
# These work, but the info is already in the Hand class - should be used for tourneys though.
|
2008-11-10 14:02:56 +01:00
|
|
|
# m.group('SB')
|
|
|
|
# m.group('BB')
|
|
|
|
# m.group('GAMETYPE')
|
|
|
|
|
|
|
|
# Believe Everleaf time is GMT/UTC, no transation necessary
|
2008-11-14 06:02:38 +01:00
|
|
|
# Stars format (Nov 10 2008): 2008/11/07 12:38:49 CET [2008/11/07 7:38:49 ET]
|
|
|
|
# or : 2008/11/07 12:38:49 ET
|
2008-11-10 14:02:56 +01:00
|
|
|
# Not getting it in my HH files yet, so using
|
|
|
|
# 2008/11/10 3:58:52 ET
|
|
|
|
#TODO: Do conversion from GMT to ET
|
|
|
|
#TODO: Need some date functions to convert to different timezones (Date::Manip for perl rocked for this)
|
2008-12-17 00:23:33 +01:00
|
|
|
hand.starttime = time.strptime(m.group('DATETIME'), "%Y/%m/%d - %H:%M:%S")
|
2008-11-10 14:02:56 +01:00
|
|
|
|
2008-12-06 15:15:41 +01:00
|
|
|
def readPlayerStacks(self, hand):
|
2009-02-20 17:29:52 +01:00
|
|
|
m = self.re_PlayerInfo.finditer(hand.string)
|
2008-12-06 15:15:41 +01:00
|
|
|
for a in m:
|
2009-02-25 12:01:44 +01:00
|
|
|
seatnum = int(a.group('SEAT'))
|
|
|
|
hand.addPlayer(seatnum, a.group('PNAME'), a.group('CASH'))
|
|
|
|
if seatnum > 6:
|
2009-03-03 01:51:18 +01:00
|
|
|
hand.maxseats = 10 # everleaf currently does 2/6/10 games, so if seats > 6 are in use, it must be 10-max.
|
2009-02-25 12:01:44 +01:00
|
|
|
# TODO: implement lookup list by table-name to determine maxes, then fall back to 6 default/10 here, if there's no entry in the list?
|
|
|
|
|
2009-02-20 17:29:52 +01:00
|
|
|
|
2008-12-06 15:15:41 +01:00
|
|
|
def markStreets(self, hand):
|
|
|
|
# PREFLOP = ** Dealing down cards **
|
2008-12-10 00:30:58 +01:00
|
|
|
# This re fails if, say, river is missing; then we don't get the ** that starts the river.
|
|
|
|
#m = re.search('(\*\* Dealing down cards \*\*\n)(?P<PREFLOP>.*?\n\*\*)?( Dealing Flop \*\* \[ (?P<FLOP1>\S\S), (?P<FLOP2>\S\S), (?P<FLOP3>\S\S) \])?(?P<FLOP>.*?\*\*)?( Dealing Turn \*\* \[ (?P<TURN1>\S\S) \])?(?P<TURN>.*?\*\*)?( Dealing River \*\* \[ (?P<RIVER1>\S\S) \])?(?P<RIVER>.*)', hand.string,re.DOTALL)
|
|
|
|
|
|
|
|
m = re.search(r"\*\* Dealing down cards \*\*(?P<PREFLOP>.+(?=\*\* Dealing Flop \*\*)|.+)"
|
2008-12-16 18:14:37 +01:00
|
|
|
r"(\*\* Dealing Flop \*\*(?P<FLOP> \[ \S\S, \S\S, \S\S \].+(?=\*\* Dealing Turn \*\*)|.+))?"
|
|
|
|
r"(\*\* Dealing Turn \*\*(?P<TURN> \[ \S\S \].+(?=\*\* Dealing River \*\*)|.+))?"
|
|
|
|
r"(\*\* Dealing River \*\*(?P<RIVER> \[ \S\S \].+))?", hand.string,re.DOTALL)
|
2008-12-10 17:30:57 +01:00
|
|
|
|
2008-12-14 23:05:51 +01:00
|
|
|
hand.addStreets(m)
|
|
|
|
|
2008-12-06 15:15:41 +01:00
|
|
|
|
2008-12-16 18:14:37 +01:00
|
|
|
def readCommunityCards(self, hand, street): # street has been matched by markStreets, so exists in this hand
|
2009-02-22 06:37:38 +01:00
|
|
|
#print "DEBUG " + street + ":"
|
|
|
|
#print hand.streets.group(street) + "\n"
|
2008-12-16 18:14:37 +01:00
|
|
|
if street in ('FLOP','TURN','RIVER'): # a list of streets which get dealt community cards (i.e. all but PREFLOP)
|
2009-02-20 17:29:52 +01:00
|
|
|
m = self.re_Board.search(hand.streets.group(street))
|
2008-12-16 18:14:37 +01:00
|
|
|
hand.setCommunityCards(street, m.group('CARDS').split(', '))
|
2008-12-08 07:23:50 +01:00
|
|
|
|
2008-12-06 15:15:41 +01:00
|
|
|
def readBlinds(self, hand):
|
|
|
|
try:
|
2009-02-20 17:29:52 +01:00
|
|
|
m = self.re_PostSB.search(hand.string)
|
2008-12-14 23:05:51 +01:00
|
|
|
hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB'))
|
2009-02-20 17:29:52 +01:00
|
|
|
except Exception, e: # no small blind
|
2009-02-22 06:37:38 +01:00
|
|
|
#print e
|
2008-12-14 23:05:51 +01:00
|
|
|
hand.addBlind(None, None, None)
|
2009-02-20 17:29:52 +01:00
|
|
|
for a in self.re_PostBB.finditer(hand.string):
|
2008-12-14 23:05:51 +01:00
|
|
|
hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB'))
|
2009-02-20 17:29:52 +01:00
|
|
|
for a in self.re_PostBoth.finditer(hand.string):
|
2009-02-21 15:26:37 +01:00
|
|
|
hand.addBlind(a.group('PNAME'), 'both', a.group('SBBB'))
|
2008-12-06 15:15:41 +01:00
|
|
|
|
2009-02-25 15:35:28 +01:00
|
|
|
def readButton(self, hand):
|
|
|
|
hand.buttonpos = int(self.re_Button.search(hand.string).group('BUTTON'))
|
|
|
|
|
2008-12-06 15:15:41 +01:00
|
|
|
def readHeroCards(self, hand):
|
2009-02-20 17:29:52 +01:00
|
|
|
m = self.re_HeroCards.search(hand.string)
|
2008-12-06 15:15:41 +01:00
|
|
|
if(m == None):
|
|
|
|
#Not involved in hand
|
|
|
|
hand.involved = False
|
|
|
|
else:
|
|
|
|
hand.hero = m.group('PNAME')
|
2008-12-16 00:56:19 +01:00
|
|
|
# "2c, qh" -> set(["2c","qc"])
|
|
|
|
# Also works with Omaha hands.
|
|
|
|
cards = m.group('CARDS')
|
2009-02-26 17:04:08 +01:00
|
|
|
cards = cards.split(', ')
|
2008-12-16 00:56:19 +01:00
|
|
|
hand.addHoleCards(cards, m.group('PNAME'))
|
2008-12-06 15:15:41 +01:00
|
|
|
|
|
|
|
def readAction(self, hand, street):
|
2009-02-20 17:29:52 +01:00
|
|
|
m = self.re_Action.finditer(hand.streets.group(street))
|
2008-12-06 15:15:41 +01:00
|
|
|
for action in m:
|
2008-12-10 01:48:45 +01:00
|
|
|
if action.group('ATYPE') == ' raises':
|
2008-12-17 12:57:06 +01:00
|
|
|
hand.addCallandRaise( street, action.group('PNAME'), action.group('BET') )
|
2008-12-10 01:48:45 +01:00
|
|
|
elif action.group('ATYPE') == ' calls':
|
2008-12-06 15:15:41 +01:00
|
|
|
hand.addCall( street, action.group('PNAME'), action.group('BET') )
|
2008-12-10 01:48:45 +01:00
|
|
|
elif action.group('ATYPE') == ': bets':
|
2008-12-06 15:15:41 +01:00
|
|
|
hand.addBet( street, action.group('PNAME'), action.group('BET') )
|
2008-12-10 01:48:45 +01:00
|
|
|
elif action.group('ATYPE') == ' folds':
|
|
|
|
hand.addFold( street, action.group('PNAME'))
|
|
|
|
elif action.group('ATYPE') == ' checks':
|
|
|
|
hand.addCheck( street, action.group('PNAME'))
|
2008-12-06 15:15:41 +01:00
|
|
|
else:
|
2008-12-10 01:48:45 +01:00
|
|
|
print "DEBUG: unimplemented readAction: %s %s" %(action.group('PNAME'),action.group('ATYPE'),)
|
2008-12-06 15:15:41 +01:00
|
|
|
|
|
|
|
|
2008-12-08 07:23:50 +01:00
|
|
|
def readShowdownActions(self, hand):
|
2009-02-26 17:04:08 +01:00
|
|
|
"""Reads lines where holecards are reported in a showdown"""
|
2009-02-20 17:29:52 +01:00
|
|
|
for shows in self.re_ShowdownAction.finditer(hand.string):
|
2008-12-16 00:56:19 +01:00
|
|
|
cards = shows.group('CARDS')
|
2009-02-26 17:04:08 +01:00
|
|
|
cards = cards.split(', ')
|
2008-12-10 17:30:57 +01:00
|
|
|
hand.addShownCards(cards, shows.group('PNAME'))
|
|
|
|
|
2008-12-09 16:32:37 +01:00
|
|
|
def readCollectPot(self,hand):
|
2009-02-20 17:29:52 +01:00
|
|
|
for m in self.re_CollectPot.finditer(hand.string):
|
2008-12-16 18:14:37 +01:00
|
|
|
hand.addCollectPot(player=m.group('PNAME'),pot=m.group('POT'))
|
|
|
|
|
|
|
|
def readShownCards(self,hand):
|
2009-02-26 17:04:08 +01:00
|
|
|
"""Reads lines where hole & board cards are mixed to form a hand (summary lines)"""
|
2009-02-20 17:29:52 +01:00
|
|
|
for m in self.re_CollectPot.finditer(hand.string):
|
2008-12-16 00:56:19 +01:00
|
|
|
if m.group('CARDS') is not None:
|
|
|
|
cards = m.group('CARDS')
|
2009-02-26 17:04:08 +01:00
|
|
|
cards = cards.split(', ')
|
2008-12-11 18:31:58 +01:00
|
|
|
hand.addShownCards(cards=None, player=m.group('PNAME'), holeandboard=cards)
|
2008-12-16 18:14:37 +01:00
|
|
|
|
2008-12-14 20:25:04 +01:00
|
|
|
|
2008-12-08 07:23:50 +01:00
|
|
|
|
2008-11-07 11:19:18 +01:00
|
|
|
if __name__ == "__main__":
|
2008-12-06 15:15:41 +01:00
|
|
|
c = Configuration.Config()
|
2008-12-16 05:29:11 +01:00
|
|
|
if len(sys.argv) == 1:
|
2009-03-01 15:05:21 +01:00
|
|
|
testfile = "regression-test-files/everleaf/plo/Naos.txt"
|
2008-12-16 00:56:19 +01:00
|
|
|
else:
|
|
|
|
testfile = sys.argv[1]
|
|
|
|
e = Everleaf(c, testfile)
|
2008-12-06 15:15:41 +01:00
|
|
|
e.processFile()
|
|
|
|
print str(e)
|