2 # -*- coding: utf-8 -*-
4 # Copyright 2008-2011, Carl Gherardi
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ########################################################################
22 _
= L10n
.get_translation()
24 # TODO: straighten out discards for draw games
27 from HandHistoryConverter
import *
28 from decimal_wrapper
import Decimal
30 # PokerStars HH Format
32 class PokerStars(HandHistoryConverter
):
36 sitename
= "PokerStars"
38 codepage
= ("utf8", "cp1252")
39 siteId
= 2 # Needs to match id entry in Sites database
40 sym
= {'USD': "\$", 'CAD': "\$", 'T$': "", "EUR": "\xe2\x82\xac", "GBP": "\xa3", "play": ""} # ADD Euro, Sterling, etc HERE
42 'LEGAL_ISO' : "USD|EUR|GBP|CAD|FPP", # legal ISO currency codes
43 'LS' : u
"\$|\xe2\x82\xac|\u20ac|", # legal currency symbols - Euro(cp1252, utf-8)
44 'PLYR': r
'(?P<PNAME>.+?)',
45 'CUR': u
"(\$|\xe2\x82\xac|\u20ac|)",
48 # translations from captured groups to fpdb info strings
49 Lim_Blinds
= { '0.04': ('0.01', '0.02'), '0.08': ('0.02', '0.04'),
50 '0.10': ('0.02', '0.05'), '0.20': ('0.05', '0.10'),
51 '0.40': ('0.10', '0.20'), '0.50': ('0.10', '0.25'),
52 '1.00': ('0.25', '0.50'), '1': ('0.25', '0.50'),
53 '2.00': ('0.50', '1.00'), '2': ('0.50', '1.00'),
54 '4.00': ('1.00', '2.00'), '4': ('1.00', '2.00'),
55 '6.00': ('1.00', '3.00'), '6': ('1.00', '3.00'),
56 '8.00': ('2.00', '4.00'), '8': ('2.00', '4.00'),
57 '10.00': ('2.00', '5.00'), '10': ('2.00', '5.00'),
58 '20.00': ('5.00', '10.00'), '20': ('5.00', '10.00'),
59 '30.00': ('10.00', '15.00'), '30': ('10.00', '15.00'),
60 '40.00': ('10.00', '20.00'), '40': ('10.00', '20.00'),
61 '60.00': ('15.00', '30.00'), '60': ('15.00', '30.00'),
62 '80.00': ('20.00', '40.00'), '80': ('20.00', '40.00'),
63 '100.00': ('25.00', '50.00'), '100': ('25.00', '50.00'),
64 '200.00': ('50.00', '100.00'), '200': ('50.00', '100.00'),
65 '400.00': ('100.00', '200.00'), '400': ('100.00', '200.00'),
66 '800.00': ('200.00', '400.00'), '800': ('200.00', '400.00'),
67 '1000.00': ('250.00', '500.00'),'1000': ('250.00', '500.00')
70 limits
= { 'No Limit':'nl', 'Pot Limit':'pl', 'Limit':'fl', 'LIMIT':'fl' }
71 games
= { # base, category
72 "Hold'em" : ('hold','holdem'),
73 'Omaha' : ('hold','omahahi'),
74 'Omaha Hi/Lo' : ('hold','omahahilo'),
75 'Razz' : ('stud','razz'),
76 'RAZZ' : ('stud','razz'),
77 '7 Card Stud' : ('stud','studhi'),
78 '7 Card Stud Hi/Lo' : ('stud','studhilo'),
79 'Badugi' : ('draw','badugi'),
80 'Triple Draw 2-7 Lowball' : ('draw','27_3draw'),
81 'Single Draw 2-7 Lowball' : ('draw','27_1draw'),
82 '5 Card Draw' : ('draw','fivedraw')
88 'Mixed PLH/PLO': 'plh_plo',
89 'Mixed Omaha H/L': 'plo_lo',
90 'Mixed Hold\'em': 'mholdem',
91 'Triple Stud': '3stud'
93 currencies
= { u
'€':'EUR', '$':'USD', '':'T$' }
96 re_GameInfo
= re
.compile(u
"""
97 PokerStars(\sHome)?\sGame\s\#(?P<HID>[0-9]+):\s+
98 (\{.*\}\s+)?(Tournament\s\# # open paren of tournament info
100 # here's how I plan to use LS
101 (?P<BUYIN>(?P<BIAMT>[%(LS)s\d\.]+)?\+?(?P<BIRAKE>[%(LS)s\d\.]+)?\+?(?P<BOUNTY>[%(LS)s\d\.]+)?\s?(?P<TOUR_ISO>%(LEGAL_ISO)s)?|Freeroll)\s+)?
102 # close paren of tournament info
103 (?P<MIXED>HORSE|8\-Game|HOSE|Mixed\sOmaha\sH/L|Mixed\sHold\'em|Mixed\sPLH/PLO|Triple\sStud)?\s?\(?
104 (?P<GAME>Hold\'em|Razz|RAZZ|7\sCard\sStud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball|Single\sDraw\s2\-7\sLowball|5\sCard\sDraw)\s
105 (?P<LIMIT>No\sLimit|Limit|LIMIT|Pot\sLimit)\)?,?\s
107 (Match.*)? #TODO: waiting for reply from user as to what this means
108 (Level\s(?P<LEVEL>[IVXLC]+)\s)?
109 \(? # open paren of the stakes
110 (?P<CURRENCY>%(LS)s|)?
111 (?P<SB>[.0-9]+)/(%(LS)s)?
113 (?P<BLAH>\s-\s[%(LS)s\d\.]+\sCap\s-\s)? # Optional Cap part
114 \s?(?P<ISO>%(LEGAL_ISO)s)?
115 \) # close paren of the stakes
116 (?P<BLAH2>\s\[AAMS\sID:\s[A-Z0-9]+\])? # AAMS ID: in .it HH's
119 """ % substitutions
, re
.MULTILINE|re
.VERBOSE
)
121 re_PlayerInfo
= re
.compile(u
"""
122 ^Seat\s(?P<SEAT>[0-9]+):\s
124 \((%(LS)s)?(?P<CASH>[.0-9]+)\sin\schips\)""" % substitutions
,
125 re
.MULTILINE|re
.VERBOSE
)
127 re_HandInfo
= re
.compile("""
128 ^Table\s\'(?P<TABLE>[-\ \#a-zA-Z\d\']+)\'\s
129 ((?P<MAX>\d+)-max\s)?
130 (?P<PLAY>\(Play\sMoney\)\s)?
131 (Seat\s\#(?P<BUTTON>\d+)\sis\sthe\sbutton)?""",
132 re
.MULTILINE|re
.VERBOSE
)
134 re_SplitHands
= re
.compile('\n\n+')
135 re_TailSplitHands
= re
.compile('(\n\n\n+)')
136 re_Button
= re
.compile('Seat #(?P<BUTTON>\d+) is the button', re
.MULTILINE
)
137 re_Board
= re
.compile(r
"\[(?P<CARDS>.+)\]")
138 # self.re_setHandInfoRegex('.*#(?P<HID>[0-9]+): Table (?P<TABLE>[ a-zA-Z]+) - \$?(?P<SB>[.0-9]+)/\$?(?P<BB>[.0-9]+) - (?P<GAMETYPE>.*) - (?P<HR>[0-9]+):(?P<MIN>[0-9]+) ET - (?P<YEAR>[0-9]+)/(?P<MON>[0-9]+)/(?P<DAY>[0-9]+)Table (?P<TABLE>[ a-zA-Z]+)\nSeat (?P<BUTTON>[0-9]+)')
140 re_DateTime
= re
.compile("""(?P<Y>[0-9]{4})\/(?P<M>[0-9]{2})\/(?P<D>[0-9]{2})[\- ]+(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[0-9]+)""", re
.MULTILINE
)
141 # revised re including timezone (not currently used):
142 #re_DateTime = re.compile("""(?P<Y>[0-9]{4})\/(?P<M>[0-9]{2})\/(?P<D>[0-9]{2})[\- ]+(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[0-9]+) \(?(?P<TZ>[A-Z0-9]+)""", re.MULTILINE)
144 # These used to be compiled per player, but regression tests say
145 # we don't have to, and it makes life faster.
146 re_PostSB
= re
.compile(r
"^%(PLYR)s: posts small blind %(CUR)s(?P<SB>[.0-9]+)" % substitutions
, re
.MULTILINE
)
147 re_PostBB
= re
.compile(r
"^%(PLYR)s: posts big blind %(CUR)s(?P<BB>[.0-9]+)" % substitutions
, re
.MULTILINE
)
148 re_Antes
= re
.compile(r
"^%(PLYR)s: posts the ante %(CUR)s(?P<ANTE>[.0-9]+)" % substitutions
, re
.MULTILINE
)
149 re_BringIn
= re
.compile(r
"^%(PLYR)s: brings[- ]in( low|) for %(CUR)s(?P<BRINGIN>[.0-9]+)" % substitutions
, re
.MULTILINE
)
150 re_PostBoth
= re
.compile(r
"^%(PLYR)s: posts small \& big blinds %(CUR)s(?P<SBBB>[.0-9]+)" % substitutions
, re
.MULTILINE
)
151 re_HeroCards
= re
.compile(r
"^Dealt to %(PLYR)s(?: \[(?P<OLDCARDS>.+?)\])?( \[(?P<NEWCARDS>.+?)\])" % substitutions
, re
.MULTILINE
)
152 re_Action
= re
.compile(r
"""
153 ^%(PLYR)s:(?P<ATYPE>\sbets|\schecks|\sraises|\scalls|\sfolds|\sdiscards|\sstands\spat)
154 (\s%(CUR)s(?P<BET>[.\d]+))?(\sto\s%(CUR)s(?P<BETTO>[.\d]+))? # the number discarded goes in <BET>
155 \s*(and\sis\sall.in)?
156 (and\shas\sreached\sthe\s[%(CUR)s\d\.]+\scap)?
158 (\s\[(?P<CARDS>.+?)\])?\s*$"""
159 % substitutions
, re
.MULTILINE|re
.VERBOSE
)
160 re_ShowdownAction
= re
.compile(r
"^%s: shows \[(?P<CARDS>.*)\]" % substitutions
['PLYR'], re
.MULTILINE
)
161 re_sitsOut
= re
.compile("^%s sits out" % substitutions
['PLYR'], re
.MULTILINE
)
162 re_ShownCards
= re
.compile("^Seat (?P<SEAT>[0-9]+): %s (\(.*\) )?(?P<SHOWED>showed|mucked) \[(?P<CARDS>.*)\]( and won \([.\d]+\) with (?P<STRING>.*))?" % substitutions
['PLYR'], re
.MULTILINE
)
163 re_CollectPot
= re
.compile(r
"Seat (?P<SEAT>[0-9]+): %(PLYR)s (\(button\) |\(small blind\) |\(big blind\) |\(button\) \(small blind\) |\(button\) \(big blind\) )?(collected|showed \[.*\] and won) \(%(CUR)s(?P<POT>[.\d]+)\)(, mucked| with.*|)" % substitutions
, re
.MULTILINE
)
164 re_WinningRankOne
= re
.compile(u
"^%(PLYR)s wins the tournament and receives %(CUR)s(?P<AMT>[\.0-9]+) - congratulations!$" % substitutions
, re
.MULTILINE
)
165 re_WinningRankOther
= re
.compile(u
"^%(PLYR)s finished the tournament in (?P<RANK>[0-9]+)(st|nd|rd|th) place and received %(CUR)s(?P<AMT>[.0-9]+)\.$" % substitutions
, re
.MULTILINE
)
166 re_RankOther
= re
.compile(u
"^%(PLYR)s finished the tournament in (?P<RANK>[0-9]+)(st|nd|rd|th) place$" % substitutions
, re
.MULTILINE
)
168 def compilePlayerRegexs(self
, hand
):
171 def readSupportedGames(self
):
172 return [["ring", "hold", "nl"],
173 ["ring", "hold", "pl"],
174 ["ring", "hold", "fl"],
176 ["ring", "stud", "fl"],
178 ["ring", "draw", "fl"],
179 ["ring", "draw", "pl"],
180 ["ring", "draw", "nl"],
182 ["tour", "hold", "nl"],
183 ["tour", "hold", "pl"],
184 ["tour", "hold", "fl"],
186 ["tour", "stud", "fl"],
188 ["tour", "draw", "fl"],
189 ["tour", "draw", "pl"],
190 ["tour", "draw", "nl"],
193 def determineGameType(self
, handText
):
195 m
= self
.re_GameInfo
.search(handText
)
197 tmp
= handText
[0:150]
198 log
.error(_("Unable to recognise gametype from: '%s'") % tmp
)
199 log
.error("determineGameType: " + _("Raising FpdbParseError"))
200 raise FpdbParseError(_("Unable to recognise gametype from: '%s'") % tmp
)
204 info
['limitType'] = self
.limits
[mg
['LIMIT']]
206 (info
['base'], info
['category']) = self
.games
[mg
['GAME']]
208 info
['sb'] = mg
['SB']
210 info
['bb'] = mg
['BB']
212 info
['currency'] = self
.currencies
[mg
['CURRENCY']]
214 if mg
['MIXED'] is not None: info
['mix'] = self
.mixes
[mg
['MIXED']]
216 if 'TOURNO' in mg
and mg
['TOURNO'] is None:
217 info
['type'] = 'ring'
219 info
['type'] = 'tour'
221 if info
['limitType'] == 'fl' and info
['bb'] is not None and info
['type'] == 'ring':
223 info
['sb'] = self
.Lim_Blinds
[mg
['BB']][0]
224 info
['bb'] = self
.Lim_Blinds
[mg
['BB']][1]
226 log
.error(_("Lim_Blinds has no lookup for '%s'") % mg
['BB'])
227 log
.error("determineGameType: " + _("Raising FpdbParseError"))
228 raise FpdbParseError(_("Lim_Blinds has no lookup for '%s'") % mg
['BB'])
232 def readHandInfo(self
, hand
):
234 m
= self
.re_HandInfo
.search(hand
.handText
,re
.DOTALL
)
235 m2
= self
.re_GameInfo
.search(hand
.handText
)
236 if m
is None or m2
is None:
237 log
.error(_("No match in readHandInfo: '%s'") % hand
.handText
[0:100])
238 raise FpdbParseError(_("No match in readHandInfo: '%s'") % hand
.handText
[0:100])
240 info
.update(m
.groupdict())
241 info
.update(m2
.groupdict())
243 log
.debug("readHandInfo: %s" % info
)
245 if key
== 'DATETIME':
246 #2008/11/12 10:00:48 CET [2008/11/12 4:00:48 ET] # (both dates are parsed so ET date overrides the other)
247 #2008/08/17 - 01:14:43 (ET)
248 #2008/09/07 06:23:14 ET
249 m1
= self
.re_DateTime
.finditer(info
[key
])
250 datetimestr
= "2000/01/01 00:00:00" # default used if time not found
252 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'))
253 #tz = a.group('TZ') # just assume ET??
254 #print " tz = ", tz, " datetime =", datetimestr
255 hand
.startTime
= datetime
.datetime
.strptime(datetimestr
, "%Y/%m/%d %H:%M:%S") # also timezone at end, e.g. " ET"
256 hand
.startTime
= HandHistoryConverter
.changeTimezone(hand
.startTime
, "ET", "UTC")
258 hand
.handid
= info
[key
]
260 hand
.tourNo
= info
[key
]
262 if hand
.tourNo
!=None:
263 #print "DEBUG: info['BUYIN']: %s" % info['BUYIN']
264 #print "DEBUG: info['BIAMT']: %s" % info['BIAMT']
265 #print "DEBUG: info['BIRAKE']: %s" % info['BIRAKE']
266 #print "DEBUG: info['BOUNTY']: %s" % info['BOUNTY']
267 if info
[key
] == 'Freeroll':
270 hand
.buyinCurrency
= "FREE"
272 if info
[key
].find("$")!=-1:
273 hand
.buyinCurrency
="USD"
274 elif info
[key
].find(u
"€")!=-1:
275 hand
.buyinCurrency
="EUR"
276 elif info
[key
].find("FPP")!=-1:
277 hand
.buyinCurrency
="PSFP"
278 elif re
.match("^[0-9+]*$", info
[key
]):
279 hand
.buyinCurrency
="play"
281 #FIXME: handle other currencies, play money
282 raise FpdbParseError(_("Failed to detect currency.") + " " + _("Hand ID: %s: '%s'") % (hand
.handid
, info
[key
]))
284 info
['BIAMT'] = info
['BIAMT'].strip(u
'$€FPP')
286 if hand
.buyinCurrency
!="PSFP":
287 if info
['BOUNTY'] != None:
288 # There is a bounty, Which means we need to switch BOUNTY and BIRAKE values
290 info
['BOUNTY'] = info
['BIRAKE']
292 info
['BOUNTY'] = info
['BOUNTY'].strip(u
'$€') # Strip here where it isn't 'None'
293 hand
.koBounty
= int(100*Decimal(info
['BOUNTY']))
298 info
['BIRAKE'] = info
['BIRAKE'].strip(u
'$€')
300 hand
.buyin
= int(100*Decimal(info
['BIAMT']))
301 hand
.fee
= int(100*Decimal(info
['BIRAKE']))
303 hand
.buyin
= int(Decimal(info
['BIAMT']))
306 hand
.level
= info
[key
]
309 if hand
.tourNo
!= None:
310 hand
.tablename
= re
.split(" ", info
[key
])[1]
312 hand
.tablename
= info
[key
]
314 hand
.buttonpos
= info
[key
]
315 if key
== 'MAX' and info
[key
] != None:
316 hand
.maxseats
= int(info
[key
])
318 if key
== 'PLAY' and info
['PLAY'] is not None:
319 # hand.currency = 'play' # overrides previously set value
320 hand
.gametype
['currency'] = 'play'
322 def readButton(self
, hand
):
323 m
= self
.re_Button
.search(hand
.handText
)
325 hand
.buttonpos
= int(m
.group('BUTTON'))
327 log
.info(_('readButton: not found'))
329 def readPlayerStacks(self
, hand
):
330 log
.debug("readPlayerStacks")
331 m
= self
.re_PlayerInfo
.finditer(hand
.handText
)
333 hand
.addPlayer(int(a
.group('SEAT')), a
.group('PNAME'), a
.group('CASH'))
335 def markStreets(self
, hand
):
336 # PREFLOP = ** Dealing down cards **
337 # This re fails if, say, river is missing; then we don't get the ** that starts the river.
338 if hand
.gametype
['base'] in ("hold"):
339 m
= re
.search(r
"\*\*\* HOLE CARDS \*\*\*(?P<PREFLOP>.+(?=\*\*\* FLOP \*\*\*)|.+)"
340 r
"(\*\*\* FLOP \*\*\*(?P<FLOP> \[\S\S \S\S \S\S\].+(?=\*\*\* TURN \*\*\*)|.+))?"
341 r
"(\*\*\* TURN \*\*\* \[\S\S \S\S \S\S] (?P<TURN>\[\S\S\].+(?=\*\*\* RIVER \*\*\*)|.+))?"
342 r
"(\*\*\* RIVER \*\*\* \[\S\S \S\S \S\S \S\S] (?P<RIVER>\[\S\S\].+))?", hand
.handText
,re
.DOTALL
)
343 elif hand
.gametype
['base'] in ("stud"):
344 m
= re
.search(r
"(?P<ANTES>.+(?=\*\*\* 3rd STREET \*\*\*)|.+)"
345 r
"(\*\*\* 3rd STREET \*\*\*(?P<THIRD>.+(?=\*\*\* 4th STREET \*\*\*)|.+))?"
346 r
"(\*\*\* 4th STREET \*\*\*(?P<FOURTH>.+(?=\*\*\* 5th STREET \*\*\*)|.+))?"
347 r
"(\*\*\* 5th STREET \*\*\*(?P<FIFTH>.+(?=\*\*\* 6th STREET \*\*\*)|.+))?"
348 r
"(\*\*\* 6th STREET \*\*\*(?P<SIXTH>.+(?=\*\*\* RIVER \*\*\*)|.+))?"
349 r
"(\*\*\* RIVER \*\*\*(?P<SEVENTH>.+))?", hand
.handText
,re
.DOTALL
)
350 elif hand
.gametype
['base'] in ("draw"):
351 if hand
.gametype
['category'] in ('27_1draw', 'fivedraw'):
352 # There is no marker between deal and draw in Stars single draw games
353 # This unfortunately affects the accounting.
354 m
= re
.search(r
"(?P<PREDEAL>.+(?=\*\*\* DEALING HANDS \*\*\*)|.+)"
355 r
"(\*\*\* DEALING HANDS \*\*\*(?P<DEAL>.+(?=(: stands pat on|: discards))|.+))?"
356 r
"((: stands pat on|: discards)(?P<DRAWONE>.+))?", hand
.handText
,re
.DOTALL
)
358 m
= re
.search(r
"(?P<PREDEAL>.+(?=\*\*\* DEALING HANDS \*\*\*)|.+)"
359 r
"(\*\*\* DEALING HANDS \*\*\*(?P<DEAL>.+(?=\*\*\* FIRST DRAW \*\*\*)|.+))?"
360 r
"(\*\*\* FIRST DRAW \*\*\*(?P<DRAWONE>.+(?=\*\*\* SECOND DRAW \*\*\*)|.+))?"
361 r
"(\*\*\* SECOND DRAW \*\*\*(?P<DRAWTWO>.+(?=\*\*\* THIRD DRAW \*\*\*)|.+))?"
362 r
"(\*\*\* THIRD DRAW \*\*\*(?P<DRAWTHREE>.+))?", hand
.handText
,re
.DOTALL
)
365 def readCommunityCards(self
, hand
, street
): # street has been matched by markStreets, so exists in this hand
366 if street
in ('FLOP','TURN','RIVER'): # a list of streets which get dealt community cards (i.e. all but PREFLOP)
367 #print "DEBUG readCommunityCards:", street, hand.streets.group(street)
368 m
= self
.re_Board
.search(hand
.streets
[street
])
369 hand
.setCommunityCards(street
, m
.group('CARDS').split(' '))
371 def readAntes(self
, hand
):
372 log
.debug(_("reading antes"))
373 m
= self
.re_Antes
.finditer(hand
.handText
)
375 #~ logging.debug("hand.addAnte(%s,%s)" %(player.group('PNAME'), player.group('ANTE')))
376 hand
.addAnte(player
.group('PNAME'), player
.group('ANTE'))
378 def readBringIn(self
, hand
):
379 m
= self
.re_BringIn
.search(hand
.handText
,re
.DOTALL
)
381 #~ logging.debug("readBringIn: %s for %s" %(m.group('PNAME'), m.group('BRINGIN')))
382 hand
.addBringIn(m
.group('PNAME'), m
.group('BRINGIN'))
384 def readBlinds(self
, hand
):
386 for a
in self
.re_PostSB
.finditer(hand
.handText
):
388 hand
.addBlind(a
.group('PNAME'), 'small blind', a
.group('SB'))
391 # Post dead blinds as ante
392 hand
.addBlind(a
.group('PNAME'), 'secondsb', a
.group('SB'))
393 for a
in self
.re_PostBB
.finditer(hand
.handText
):
394 hand
.addBlind(a
.group('PNAME'), 'big blind', a
.group('BB'))
395 for a
in self
.re_PostBoth
.finditer(hand
.handText
):
396 hand
.addBlind(a
.group('PNAME'), 'both', a
.group('SBBB'))
398 def readHeroCards(self
, hand
):
399 # streets PREFLOP, PREDRAW, and THIRD are special cases beacause
400 # we need to grab hero's cards
401 for street
in ('PREFLOP', 'DEAL'):
402 if street
in hand
.streets
.keys():
403 m
= self
.re_HeroCards
.finditer(hand
.streets
[street
])
406 # hand.involved = False
408 hand
.hero
= found
.group('PNAME')
409 newcards
= found
.group('NEWCARDS').split(' ')
410 hand
.addHoleCards(street
, hand
.hero
, closed
=newcards
, shown
=False, mucked
=False, dealt
=True)
412 for street
, text
in hand
.streets
.iteritems():
413 if not text
or street
in ('PREFLOP', 'DEAL'): continue # already done these
414 m
= self
.re_HeroCards
.finditer(hand
.streets
[street
])
416 player
= found
.group('PNAME')
417 if found
.group('NEWCARDS') is None:
420 newcards
= found
.group('NEWCARDS').split(' ')
421 if found
.group('OLDCARDS') is None:
424 oldcards
= found
.group('OLDCARDS').split(' ')
426 if street
== 'THIRD' and len(newcards
) == 3: # hero in stud game
428 hand
.dealt
.add(player
) # need this for stud??
429 hand
.addHoleCards(street
, player
, closed
=newcards
[0:2], open=[newcards
[2]], shown
=False, mucked
=False, dealt
=False)
431 hand
.addHoleCards(street
, player
, open=newcards
, closed
=oldcards
, shown
=False, mucked
=False, dealt
=False)
434 def readAction(self
, hand
, street
):
435 m
= self
.re_Action
.finditer(hand
.streets
[street
])
437 acts
= action
.groupdict()
438 #print "DEBUG: acts: %s" %acts
439 if action
.group('ATYPE') == ' raises':
440 hand
.addRaiseBy( street
, action
.group('PNAME'), action
.group('BET') )
441 elif action
.group('ATYPE') == ' calls':
442 hand
.addCall( street
, action
.group('PNAME'), action
.group('BET') )
443 elif action
.group('ATYPE') == ' bets':
444 hand
.addBet( street
, action
.group('PNAME'), action
.group('BET') )
445 elif action
.group('ATYPE') == ' folds':
446 hand
.addFold( street
, action
.group('PNAME'))
447 elif action
.group('ATYPE') == ' checks':
448 hand
.addCheck( street
, action
.group('PNAME'))
449 elif action
.group('ATYPE') == ' discards':
450 hand
.addDiscard(street
, action
.group('PNAME'), action
.group('BET'), action
.group('CARDS'))
451 elif action
.group('ATYPE') == ' stands pat':
452 hand
.addStandsPat( street
, action
.group('PNAME'), action
.group('CARDS'))
454 print (_("DEBUG:") + " " + _("Unimplemented %s: '%s' '%s'") % ("readAction", action
.group('PNAME'), action
.group('ATYPE')))
457 def readShowdownActions(self
, hand
):
458 # TODO: pick up mucks also??
459 for shows
in self
.re_ShowdownAction
.finditer(hand
.handText
):
460 cards
= shows
.group('CARDS').split(' ')
461 hand
.addShownCards(cards
, shows
.group('PNAME'))
463 for winningrankone
in self
.re_WinningRankOne
.finditer(hand
.handText
):
464 hand
.addPlayerRank (winningrankone
.group('PNAME'),int(100*Decimal(winningrankone
.group('AMT'))),1)
466 for winningrankothers
in self
.re_WinningRankOther
.finditer(hand
.handText
):
467 hand
.addPlayerRank (winningrankothers
.group('PNAME'),int(100*Decimal(winningrankothers
.group('AMT'))),winningrankothers
.group('RANK'))
469 for rankothers
in self
.re_RankOther
.finditer(hand
.handText
):
470 hand
.addPlayerRank (rankothers
.group('PNAME'),0,rankothers
.group('RANK'))
472 def readCollectPot(self
,hand
):
473 for m
in self
.re_CollectPot
.finditer(hand
.handText
):
474 hand
.addCollectPot(player
=m
.group('PNAME'),pot
=m
.group('POT'))
476 def readShownCards(self
,hand
):
477 for m
in self
.re_ShownCards
.finditer(hand
.handText
):
478 if m
.group('CARDS') is not None:
479 cards
= m
.group('CARDS')
480 cards
= cards
.split(' ') # needs to be a list, not a set--stud needs the order
481 string
= m
.group('STRING')
483 (shown
, mucked
) = (False, False)
484 if m
.group('SHOWED') == "showed": shown
= True
485 elif m
.group('SHOWED') == "mucked": mucked
= True
487 #print "DEBUG: hand.addShownCards(%s, %s, %s, %s)" %(cards, m.group('PNAME'), shown, mucked)
488 hand
.addShownCards(cards
=cards
, player
=m
.group('PNAME'), shown
=shown
, mucked
=mucked
, string
=string
)