2008-12-16 15:45:58 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# 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
|
|
|
|
########################################################################
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import Configuration
|
|
|
|
from HandHistoryConverter import *
|
|
|
|
|
2009-02-22 10:07:11 +01:00
|
|
|
# FullTilt HH Format converter
|
2008-12-16 15:45:58 +01:00
|
|
|
|
|
|
|
class FullTilt(HandHistoryConverter):
|
2009-02-25 15:35:28 +01:00
|
|
|
|
|
|
|
# Static regexes
|
|
|
|
re_GameInfo = re.compile('- \$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) (Ante \$(?P<ANTE>[.0-9]+) )?- (?P<LTYPE>(No|Pot)? )?Limit (?P<GAME>(Hold\'em|Omaha|Razz))')
|
|
|
|
re_SplitHands = re.compile(r"\n\n+")
|
|
|
|
re_HandInfo = re.compile('.*#(?P<HID>[0-9]+): Table (?P<TABLE>[- a-zA-Z]+) (\((?P<TABLEATTRIBUTES>.+)\) )?- \$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) (Ante \$(?P<ANTE>[.0-9]+) )?- (?P<GAMETYPE>[a-zA-Z\' ]+) - (?P<DATETIME>.*)')
|
|
|
|
re_Button = re.compile('^The button is in seat #(?P<BUTTON>\d+)')
|
|
|
|
re_PlayerInfo = re.compile('Seat (?P<SEAT>[0-9]+): (?P<PNAME>.*) \(\$(?P<CASH>[.0-9]+)\)\n')
|
|
|
|
re_Board = re.compile(r"\[(?P<CARDS>.+)\]")
|
|
|
|
|
2008-12-16 15:45:58 +01:00
|
|
|
def __init__(self, config, file):
|
|
|
|
print "Initialising FullTilt converter class"
|
|
|
|
HandHistoryConverter.__init__(self, config, file, sitename="FullTilt") # Call super class init.
|
|
|
|
self.sitename = "FullTilt"
|
|
|
|
self.setFileType("text", "cp1252")
|
2009-02-22 04:42:16 +01:00
|
|
|
|
2009-02-25 15:35:28 +01:00
|
|
|
def compilePlayerRegexs(self):
|
2009-02-22 04:42:16 +01:00
|
|
|
player_re = "(?P<PNAME>" + "|".join(map(re.escape, self.players)) + ")"
|
2009-02-25 15:14:42 +01:00
|
|
|
print "DEBUG player_re: " + player_re
|
|
|
|
self.re_PostSB = re.compile(r"^%s posts the small blind of \$?(?P<SB>[.0-9]+)" % player_re, re.MULTILINE)
|
|
|
|
self.re_PostBB = re.compile(r"^%s posts (the big blind of )?\$?(?P<BB>[.0-9]+)" % player_re, re.MULTILINE)
|
|
|
|
self.re_BringIn = re.compile(r"^%s brings in for \$?(?P<BRINGIN>[.0-9]+)" % player_re, re.MULTILINE)
|
|
|
|
self.re_PostBoth = re.compile(r"^%s posts small \& big blinds \[\$? (?P<SBBB>[.0-9]+)" % player_re, re.MULTILINE)
|
|
|
|
self.re_HeroCards = re.compile(r"^Dealt to %s \[(?P<CARDS>.*)\]( \[(?P<NEWCARD>.*)\])?" % player_re, re.MULTILINE)
|
|
|
|
self.re_Action = re.compile(r"^%s(?P<ATYPE> bets| checks| raises to| calls| folds)(\s\$(?P<BET>[.\d]+))?" % player_re, re.MULTILINE)
|
|
|
|
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(r"^%s sits out" % player_re, re.MULTILINE)
|
|
|
|
self.re_ShownCards = re.compile(r"^Seat (?P<SEAT>[0-9]+): %s \(.*\) showed \[(?P<CARDS>.*)\].*" % player_re, re.MULTILINE)
|
2009-02-22 04:42:16 +01:00
|
|
|
|
2008-12-16 15:45:58 +01:00
|
|
|
|
|
|
|
def readSupportedGames(self):
|
2009-02-22 10:07:11 +01:00
|
|
|
return [["ring", "hold", "nl"],
|
2009-02-23 11:24:21 +01:00
|
|
|
["ring", "hold", "pl"],
|
2009-02-24 17:17:25 +01:00
|
|
|
["ring", "razz", "fl"],
|
2009-02-22 10:07:11 +01:00
|
|
|
["ring", "omaha", "pl"]
|
|
|
|
]
|
2008-12-16 15:45:58 +01:00
|
|
|
|
|
|
|
def determineGameType(self):
|
|
|
|
# Cheating with this regex, only support nlhe at the moment
|
2009-02-22 10:07:11 +01:00
|
|
|
# Full Tilt Poker Game #10777181585: Table Deerfly (deep 6) - $0.01/$0.02 - Pot Limit Omaha Hi - 2:24:44 ET - 2009/02/22
|
|
|
|
# Full Tilt Poker Game #10773265574: Table Butte (6 max) - $0.01/$0.02 - Pot Limit Hold'em - 21:33:46 ET - 2009/02/21
|
|
|
|
# Full Tilt Poker Game #9403951181: Table CR - tay - $0.05/$0.10 - No Limit Hold'em - 9:40:20 ET - 2008/12/09
|
|
|
|
structure = "" # nl, pl, cn, cp, fl
|
|
|
|
game = ""
|
|
|
|
|
2008-12-16 15:45:58 +01:00
|
|
|
|
2009-02-22 04:42:16 +01:00
|
|
|
m = self.re_GameInfo.search(self.obs)
|
2009-02-24 18:05:51 +01:00
|
|
|
if m.group('LTYPE') == "No ":
|
2009-02-22 10:07:11 +01:00
|
|
|
structure = "nl"
|
2009-02-24 18:05:51 +01:00
|
|
|
elif m.group('LTYPE') == "Pot ":
|
2009-02-22 10:07:11 +01:00
|
|
|
structure = "pl"
|
2009-02-25 13:34:05 +01:00
|
|
|
elif m.group('LTYPE') == None:
|
2009-02-24 17:17:25 +01:00
|
|
|
structure = "fl"
|
2009-02-22 10:07:11 +01:00
|
|
|
|
|
|
|
if m.group('GAME') == "Hold\'em":
|
|
|
|
game = "hold"
|
2009-02-24 17:17:25 +01:00
|
|
|
elif m.group('GAME') == "Omaha":
|
2009-02-22 10:07:11 +01:00
|
|
|
game = "omahahi"
|
2009-02-24 17:17:25 +01:00
|
|
|
elif m.group('GAME') == "Razz":
|
|
|
|
game = "razz"
|
2009-02-25 13:34:05 +01:00
|
|
|
|
|
|
|
print m.groups()
|
|
|
|
|
2009-02-22 10:07:11 +01:00
|
|
|
gametype = ["ring", game, structure, m.group('SB'), m.group('BB')]
|
2008-12-16 15:45:58 +01:00
|
|
|
|
|
|
|
return gametype
|
|
|
|
|
|
|
|
def readHandInfo(self, hand):
|
2009-02-22 04:42:16 +01:00
|
|
|
m = self.re_HandInfo.search(hand.string,re.DOTALL)
|
2008-12-16 15:45:58 +01:00
|
|
|
#print m.groups()
|
|
|
|
hand.handid = m.group('HID')
|
|
|
|
hand.tablename = m.group('TABLE')
|
2008-12-17 00:23:33 +01:00
|
|
|
hand.starttime = time.strptime(m.group('DATETIME'), "%H:%M:%S ET - %Y/%m/%d")
|
2008-12-16 15:45:58 +01:00
|
|
|
# These work, but the info is already in the Hand class - should be used for tourneys though.
|
|
|
|
# m.group('SB')
|
|
|
|
# m.group('BB')
|
|
|
|
# m.group('GAMETYPE')
|
|
|
|
|
|
|
|
# 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
|
|
|
|
# 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 = "%d/%02d/%02d %d:%02d:%02d ET" %(int(m.group('YEAR')), int(m.group('MON')), int(m.group('DAY')),
|
|
|
|
##int(m.group('HR')), int(m.group('MIN')), int(m.group('SEC')))
|
2008-12-16 15:45:58 +01:00
|
|
|
#FIXME: hand.buttonpos = int(m.group('BUTTON'))
|
|
|
|
|
|
|
|
def readPlayerStacks(self, hand):
|
2009-02-22 04:42:16 +01:00
|
|
|
m = self.re_PlayerInfo.finditer(hand.string)
|
2008-12-16 15:45:58 +01:00
|
|
|
players = []
|
|
|
|
for a in m:
|
|
|
|
hand.addPlayer(int(a.group('SEAT')), a.group('PNAME'), a.group('CASH'))
|
|
|
|
|
|
|
|
def markStreets(self, hand):
|
|
|
|
# PREFLOP = ** Dealing down cards **
|
|
|
|
# This re fails if, say, river is missing; then we don't get the ** that starts the river.
|
|
|
|
|
2009-02-24 17:17:25 +01:00
|
|
|
if self.gametype[1] == "hold" or self.gametype[1] == "omaha":
|
|
|
|
m = re.search(r"\*\*\* HOLE CARDS \*\*\*(?P<PREFLOP>.+(?=\*\*\* FLOP \*\*\*)|.+)"
|
2008-12-16 18:26:58 +01:00
|
|
|
r"(\*\*\* FLOP \*\*\*(?P<FLOP> \[\S\S \S\S \S\S\].+(?=\*\*\* TURN \*\*\*)|.+))?"
|
|
|
|
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.string,re.DOTALL)
|
2009-02-24 17:17:25 +01:00
|
|
|
elif self.gametype[1] == "razz":
|
2009-02-24 18:05:51 +01:00
|
|
|
m = re.search(r"(?P<ANTES>.+(?=\*\*\* 3RD STREET \*\*\*)|.+)"
|
|
|
|
r"(\*\*\* 3RD STREET \*\*\*(?P<THIRD>.+(?=\*\*\* 4TH STREET \*\*\*)|.+))?"
|
|
|
|
r"(\*\*\* 4TH STREET \*\*\*(?P<FOURTH>.+(?=\*\*\* 5TH STREET \*\*\*)|.+))?"
|
|
|
|
r"(\*\*\* 5TH STREET \*\*\*(?P<FIFTH>.+(?=\*\*\* 6TH STREET \*\*\*)|.+))?"
|
|
|
|
r"(\*\*\* 6TH STREET \*\*\*(?P<SIXTH>.+(?=\*\*\* 7TH STREET \*\*\*)|.+))?"
|
|
|
|
r"(\*\*\* 7TH STREET \*\*\*(?P<SEVENTH>.+))?", hand.string,re.DOTALL)
|
2008-12-16 15:45:58 +01:00
|
|
|
hand.addStreets(m)
|
|
|
|
|
2008-12-16 18:26:58 +01:00
|
|
|
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)
|
2008-12-16 22:08:10 +01:00
|
|
|
#print "DEBUG readCommunityCards:", street, hand.streets.group(street)
|
2009-02-22 04:42:16 +01:00
|
|
|
m = self.re_Board.search(hand.streets.group(street))
|
2008-12-16 18:26:58 +01:00
|
|
|
hand.setCommunityCards(street, m.group('CARDS').split(' '))
|
|
|
|
|
2008-12-16 15:45:58 +01:00
|
|
|
|
|
|
|
def readBlinds(self, hand):
|
|
|
|
try:
|
2009-02-22 04:42:16 +01:00
|
|
|
m = self.re_PostSB.search(hand.string)
|
2008-12-16 15:45:58 +01:00
|
|
|
hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB'))
|
|
|
|
except: # no small blind
|
|
|
|
hand.addBlind(None, None, None)
|
2009-02-22 04:42:16 +01:00
|
|
|
for a in self.re_PostBB.finditer(hand.string):
|
2008-12-16 15:45:58 +01:00
|
|
|
hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB'))
|
2009-02-22 04:42:16 +01:00
|
|
|
for a in self.re_PostBoth.finditer(hand.string):
|
2008-12-16 15:45:58 +01:00
|
|
|
hand.addBlind(a.group('PNAME'), 'small & big blinds', a.group('SBBB'))
|
|
|
|
|
2009-02-24 17:17:25 +01:00
|
|
|
def readAntes(self, hand):
|
|
|
|
print "DEBUG: reading antes"
|
|
|
|
print "DEBUG: FIXME reading antes"
|
|
|
|
|
|
|
|
def readBringIn(self, hand):
|
|
|
|
print "DEBUG: reading bring in"
|
|
|
|
# print hand.string
|
2009-02-24 17:27:10 +01:00
|
|
|
m = self.re_BringIn.search(hand.string,re.DOTALL)
|
2009-02-24 17:17:25 +01:00
|
|
|
print "DEBUG: Player bringing in: %s for %s" %(m.group('PNAME'), m.group('BRINGIN'))
|
|
|
|
|
|
|
|
def readButton(self, hand):
|
|
|
|
hand.buttonpos = int(self.re_Button.search(hand.string).group('BUTTON'))
|
|
|
|
|
2008-12-16 15:45:58 +01:00
|
|
|
def readHeroCards(self, hand):
|
2009-02-22 04:42:16 +01:00
|
|
|
m = self.re_HeroCards.search(hand.string)
|
2008-12-16 15:45:58 +01:00
|
|
|
if(m == None):
|
|
|
|
#Not involved in hand
|
|
|
|
hand.involved = False
|
|
|
|
else:
|
|
|
|
hand.hero = m.group('PNAME')
|
|
|
|
# "2c, qh" -> set(["2c","qc"])
|
|
|
|
# Also works with Omaha hands.
|
|
|
|
cards = m.group('CARDS')
|
2008-12-16 18:26:58 +01:00
|
|
|
cards = set(cards.split(' '))
|
2008-12-16 15:45:58 +01:00
|
|
|
hand.addHoleCards(cards, m.group('PNAME'))
|
|
|
|
|
2009-02-25 11:32:12 +01:00
|
|
|
def readPlayerCards(self, hand, street):
|
|
|
|
#Used for stud hands - borrows the HeroCards regex for now.
|
|
|
|
m = self.re_HeroCards.finditer(hand.streets.group(street))
|
|
|
|
print "DEBUG: razz/stud readPlayerCards"
|
|
|
|
print "DEBUG: STREET: %s", street
|
|
|
|
for player in m:
|
|
|
|
print player.groups()
|
|
|
|
#hand.hero = m.group('PNAME')
|
|
|
|
# "2c, qh" -> set(["2c","qc"])
|
|
|
|
# Also works with Omaha hands.
|
|
|
|
cards = player.group('CARDS')
|
|
|
|
print "DEBUG: PNAME: %s CARDS: %s" %(player.group('PNAME'), player.group('CARDS'))
|
|
|
|
cards = set(cards.split(' '))
|
|
|
|
# hand.addHoleCards(cards, m.group('PNAME'))
|
|
|
|
|
2008-12-16 15:45:58 +01:00
|
|
|
def readAction(self, hand, street):
|
2009-02-22 04:42:16 +01:00
|
|
|
m = self.re_Action.finditer(hand.streets.group(street))
|
2008-12-16 15:45:58 +01:00
|
|
|
for action in m:
|
|
|
|
if action.group('ATYPE') == ' raises to':
|
|
|
|
hand.addRaiseTo( 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'))
|
|
|
|
else:
|
|
|
|
print "DEBUG: unimplemented readAction: %s %s" %(action.group('PNAME'),action.group('ATYPE'),)
|
2008-12-16 18:26:58 +01:00
|
|
|
|
2008-12-16 15:45:58 +01:00
|
|
|
|
|
|
|
def readShowdownActions(self, hand):
|
2009-02-22 04:42:16 +01:00
|
|
|
for shows in self.re_ShowdownAction.finditer(hand.string):
|
2008-12-16 15:45:58 +01:00
|
|
|
cards = shows.group('CARDS')
|
2008-12-16 18:26:58 +01:00
|
|
|
cards = set(cards.split(' '))
|
2008-12-16 15:45:58 +01:00
|
|
|
hand.addShownCards(cards, shows.group('PNAME'))
|
|
|
|
|
|
|
|
def readCollectPot(self,hand):
|
2009-02-22 04:42:16 +01:00
|
|
|
for m in self.re_CollectPot.finditer(hand.string):
|
2008-12-16 18:26:58 +01:00
|
|
|
hand.addCollectPot(player=m.group('PNAME'),pot=m.group('POT'))
|
|
|
|
|
|
|
|
def readShownCards(self,hand):
|
2009-02-22 04:42:16 +01:00
|
|
|
for m in self.re_ShownCards.finditer(hand.string):
|
2008-12-16 15:45:58 +01:00
|
|
|
if m.group('CARDS') is not None:
|
|
|
|
cards = m.group('CARDS')
|
2008-12-16 18:26:58 +01:00
|
|
|
cards = set(cards.split(' '))
|
|
|
|
hand.addShownCards(cards=cards, player=m.group('PNAME'))
|
2008-12-16 15:45:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
c = Configuration.Config()
|
|
|
|
if len(sys.argv) == 1:
|
2009-02-24 17:17:25 +01:00
|
|
|
testfile = "regression-test-files/fulltilt/razz/FT20090223 Danville - $0.50-$1 Ante $0.10 - Limit Razz.txt"
|
2008-12-16 15:45:58 +01:00
|
|
|
else:
|
|
|
|
testfile = sys.argv[1]
|
|
|
|
print "Converting: ", testfile
|
|
|
|
e = FullTilt(c, testfile)
|
|
|
|
e.processFile()
|
|
|
|
print str(e)
|