2010-07-08 20:01:03 +02:00
|
|
|
#!/usr/bin/python
|
2010-07-02 22:17:15 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-03-14 12:40:27 +01:00
|
|
|
|
2010-07-04 03:05:16 +02:00
|
|
|
#Copyright 2008-2010 Carl Gherardi
|
2009-03-14 12:40:27 +01:00
|
|
|
#This program is free software: you can redistribute it and/or modify
|
|
|
|
#it under the terms of the GNU Affero General Public License as published by
|
|
|
|
#the Free Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
#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 Affero General Public License
|
|
|
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-07-04 03:05:16 +02:00
|
|
|
#In the "official" distribution you can find the license in agpl-3.0.txt.
|
2009-03-14 12:40:27 +01:00
|
|
|
|
2009-08-06 01:08:53 +02:00
|
|
|
#fpdb modules
|
|
|
|
import Card
|
2009-12-16 15:48:38 +01:00
|
|
|
from decimal import Decimal
|
2009-08-06 01:08:53 +02:00
|
|
|
|
2009-11-24 10:55:00 +01:00
|
|
|
DEBUG = False
|
2009-11-06 11:39:59 +01:00
|
|
|
|
|
|
|
if DEBUG:
|
|
|
|
import pprint
|
|
|
|
pp = pprint.PrettyPrinter(indent=4)
|
|
|
|
|
|
|
|
|
2009-03-14 12:40:27 +01:00
|
|
|
class DerivedStats():
|
|
|
|
def __init__(self, hand):
|
|
|
|
self.hand = hand
|
|
|
|
|
2009-08-06 01:08:53 +02:00
|
|
|
self.hands = {}
|
|
|
|
self.handsplayers = {}
|
|
|
|
|
|
|
|
def getStats(self, hand):
|
|
|
|
|
|
|
|
for player in hand.players:
|
|
|
|
self.handsplayers[player[1]] = {}
|
2009-10-14 17:55:51 +02:00
|
|
|
#Init vars that may not be used, but still need to be inserted.
|
2009-11-06 12:13:52 +01:00
|
|
|
# All stud street4 need this when importing holdem
|
2009-11-06 11:39:59 +01:00
|
|
|
self.handsplayers[player[1]]['winnings'] = 0
|
2009-11-24 09:44:46 +01:00
|
|
|
self.handsplayers[player[1]]['rake'] = 0
|
2009-11-24 10:29:54 +01:00
|
|
|
self.handsplayers[player[1]]['totalProfit'] = 0
|
2009-11-06 12:13:52 +01:00
|
|
|
self.handsplayers[player[1]]['street4Seen'] = False
|
2009-10-14 17:55:51 +02:00
|
|
|
self.handsplayers[player[1]]['street4Aggr'] = False
|
2009-12-16 16:11:08 +01:00
|
|
|
self.handsplayers[player[1]]['wonWhenSeenStreet1'] = 0.0
|
2009-11-24 16:14:43 +01:00
|
|
|
self.handsplayers[player[1]]['sawShowdown'] = False
|
2009-12-16 15:58:54 +01:00
|
|
|
self.handsplayers[player[1]]['wonAtSD'] = 0.0
|
2009-12-22 10:20:07 +01:00
|
|
|
self.handsplayers[player[1]]['startCards'] = 0
|
2010-01-15 06:50:46 +01:00
|
|
|
self.handsplayers[player[1]]['position'] = 2
|
2010-01-15 12:42:24 +01:00
|
|
|
self.handsplayers[player[1]]['street0_3BChance'] = False
|
|
|
|
self.handsplayers[player[1]]['street0_3BDone'] = False
|
|
|
|
self.handsplayers[player[1]]['street0_4BChance'] = False
|
|
|
|
self.handsplayers[player[1]]['street0_4BDone'] = False
|
|
|
|
self.handsplayers[player[1]]['stealAttemptChance'] = False
|
|
|
|
self.handsplayers[player[1]]['stealAttempted'] = False
|
|
|
|
self.handsplayers[player[1]]['foldBbToStealChance'] = False
|
|
|
|
self.handsplayers[player[1]]['foldSbToStealChance'] = False
|
|
|
|
self.handsplayers[player[1]]['foldedSbToSteal'] = False
|
|
|
|
self.handsplayers[player[1]]['foldedBbToSteal'] = False
|
2009-11-24 17:57:14 +01:00
|
|
|
for i in range(5):
|
|
|
|
self.handsplayers[player[1]]['street%dCalls' % i] = 0
|
|
|
|
self.handsplayers[player[1]]['street%dBets' % i] = 0
|
2010-06-10 21:00:30 +02:00
|
|
|
self.handsplayers[player[1]]['street%dRaises' % i] = 0
|
2009-11-25 07:59:29 +01:00
|
|
|
for i in range(1,5):
|
|
|
|
self.handsplayers[player[1]]['street%dCBChance' %i] = False
|
|
|
|
self.handsplayers[player[1]]['street%dCBDone' %i] = False
|
2010-01-15 11:29:16 +01:00
|
|
|
self.handsplayers[player[1]]['street%dCheckCallRaiseChance' %i] = False
|
|
|
|
self.handsplayers[player[1]]['street%dCheckCallRaiseDone' %i] = False
|
2010-05-28 19:12:02 +02:00
|
|
|
self.handsplayers[player[1]]['otherRaisedStreet%d' %i] = False
|
|
|
|
self.handsplayers[player[1]]['foldToOtherRaisedStreet%d' %i] = False
|
2009-08-06 01:08:53 +02:00
|
|
|
|
2009-12-14 10:52:08 +01:00
|
|
|
#FIXME - Everything below this point is incomplete.
|
2009-12-14 12:03:01 +01:00
|
|
|
self.handsplayers[player[1]]['tourneyTypeId'] = 1
|
2009-12-14 10:52:08 +01:00
|
|
|
for i in range(1,5):
|
|
|
|
self.handsplayers[player[1]]['foldToStreet%dCBChance' %i] = False
|
|
|
|
self.handsplayers[player[1]]['foldToStreet%dCBDone' %i] = False
|
|
|
|
|
2009-08-06 01:08:53 +02:00
|
|
|
self.assembleHands(self.hand)
|
|
|
|
self.assembleHandsPlayers(self.hand)
|
2009-11-06 11:39:59 +01:00
|
|
|
|
2009-11-25 07:59:29 +01:00
|
|
|
|
2009-11-06 11:39:59 +01:00
|
|
|
if DEBUG:
|
|
|
|
print "Hands:"
|
|
|
|
pp.pprint(self.hands)
|
|
|
|
print "HandsPlayers:"
|
|
|
|
pp.pprint(self.handsplayers)
|
2009-08-06 01:08:53 +02:00
|
|
|
|
2009-10-06 12:30:52 +02:00
|
|
|
def getHands(self):
|
|
|
|
return self.hands
|
|
|
|
|
2009-10-14 14:20:17 +02:00
|
|
|
def getHandsPlayers(self):
|
|
|
|
return self.handsplayers
|
|
|
|
|
2009-08-06 01:08:53 +02:00
|
|
|
def assembleHands(self, hand):
|
|
|
|
self.hands['tableName'] = hand.tablename
|
|
|
|
self.hands['siteHandNo'] = hand.handid
|
|
|
|
self.hands['gametypeId'] = None # Leave None, handled later after checking db
|
|
|
|
self.hands['handStart'] = hand.starttime # format this!
|
|
|
|
self.hands['importTime'] = None
|
|
|
|
self.hands['seats'] = self.countPlayers(hand)
|
|
|
|
self.hands['maxSeats'] = hand.maxseats
|
2009-10-13 08:04:19 +02:00
|
|
|
self.hands['texture'] = None # No calculation done for this yet.
|
2009-10-06 12:30:52 +02:00
|
|
|
|
|
|
|
# This (i think...) is correct for both stud and flop games, as hand.board['street'] disappears, and
|
|
|
|
# those values remain default in stud.
|
2009-10-29 03:00:05 +01:00
|
|
|
boardcards = []
|
|
|
|
for street in hand.communityStreets:
|
|
|
|
boardcards += hand.board[street]
|
|
|
|
boardcards += [u'0x', u'0x', u'0x', u'0x', u'0x']
|
2009-10-06 12:30:52 +02:00
|
|
|
cards = [Card.encodeCard(c) for c in boardcards[0:5]]
|
|
|
|
self.hands['boardcard1'] = cards[0]
|
|
|
|
self.hands['boardcard2'] = cards[1]
|
|
|
|
self.hands['boardcard3'] = cards[2]
|
|
|
|
self.hands['boardcard4'] = cards[3]
|
|
|
|
self.hands['boardcard5'] = cards[4]
|
|
|
|
|
|
|
|
#print "DEBUG: self.getStreetTotals = (%s, %s, %s, %s, %s)" % hand.getStreetTotals()
|
2009-11-22 17:05:23 +01:00
|
|
|
totals = hand.getStreetTotals()
|
|
|
|
totals = [int(100*i) for i in totals]
|
|
|
|
self.hands['street1Pot'] = totals[0]
|
|
|
|
self.hands['street2Pot'] = totals[1]
|
|
|
|
self.hands['street3Pot'] = totals[2]
|
|
|
|
self.hands['street4Pot'] = totals[3]
|
|
|
|
self.hands['showdownPot'] = totals[4]
|
2009-10-06 12:30:52 +02:00
|
|
|
|
|
|
|
self.vpip(hand) # Gives playersVpi (num of players vpip)
|
2009-10-13 09:58:05 +02:00
|
|
|
#print "DEBUG: vpip: %s" %(self.hands['playersVpi'])
|
2009-10-08 12:01:49 +02:00
|
|
|
self.playersAtStreetX(hand) # Gives playersAtStreet1..4 and Showdown
|
2009-10-13 09:58:05 +02:00
|
|
|
#print "DEBUG: playersAtStreet 1:'%s' 2:'%s' 3:'%s' 4:'%s'" %(self.hands['playersAtStreet1'],self.hands['playersAtStreet2'],self.hands['playersAtStreet3'],self.hands['playersAtStreet4'])
|
|
|
|
self.streetXRaises(hand) # Empty function currently
|
2009-10-08 12:01:49 +02:00
|
|
|
|
2009-08-06 01:08:53 +02:00
|
|
|
def assembleHandsPlayers(self, hand):
|
2009-11-06 12:30:50 +01:00
|
|
|
#street0VPI/vpip already called in Hand
|
2009-11-24 16:14:43 +01:00
|
|
|
# sawShowdown is calculated in playersAtStreetX, as that calculation gives us a convenient list of names
|
|
|
|
|
2009-10-14 14:20:17 +02:00
|
|
|
#hand.players = [[seat, name, chips],[seat, name, chips]]
|
|
|
|
for player in hand.players:
|
|
|
|
self.handsplayers[player[1]]['seatNo'] = player[0]
|
2009-12-16 15:48:38 +01:00
|
|
|
self.handsplayers[player[1]]['startCash'] = int(100 * Decimal(player[2]))
|
2010-07-02 22:17:15 +02:00
|
|
|
self.handsplayers[player[1]]['sitout'] = False #TODO: implement actual sitout detection
|
2009-10-14 14:20:17 +02:00
|
|
|
|
2010-06-03 21:02:07 +02:00
|
|
|
# XXX: enumerate(list, start=x) is python 2.6 syntax; 'start'
|
|
|
|
#for i, street in enumerate(hand.actionStreets[2:], start=1):
|
2009-11-24 14:58:27 +01:00
|
|
|
for i, street in enumerate(hand.actionStreets[2:]):
|
|
|
|
self.seen(self.hand, i+1)
|
|
|
|
|
|
|
|
for i, street in enumerate(hand.actionStreets[1:]):
|
|
|
|
self.aggr(self.hand, i)
|
2009-11-24 17:57:14 +01:00
|
|
|
self.calls(self.hand, i)
|
|
|
|
self.bets(self.hand, i)
|
2010-05-28 02:31:04 +02:00
|
|
|
if i>0:
|
|
|
|
self.folds(self.hand, i)
|
2009-11-24 14:58:27 +01:00
|
|
|
|
2009-11-06 11:39:59 +01:00
|
|
|
# Winnings is a non-negative value of money collected from the pot, which already includes the
|
|
|
|
# rake taken out. hand.collectees is Decimal, database requires cents
|
|
|
|
for player in hand.collectees:
|
|
|
|
self.handsplayers[player]['winnings'] = int(100 * hand.collectees[player])
|
2009-11-24 09:44:46 +01:00
|
|
|
#FIXME: This is pretty dodgy, rake = hand.rake/#collectees
|
|
|
|
# You can really only pay rake when you collect money, but
|
|
|
|
# different sites calculate rake differently.
|
|
|
|
# Should be fine for split-pots, but won't be accurate for multi-way pots
|
|
|
|
self.handsplayers[player]['rake'] = int(100* hand.rake)/len(hand.collectees)
|
2009-11-24 14:58:27 +01:00
|
|
|
if self.handsplayers[player]['street1Seen'] == True:
|
2009-12-16 16:11:08 +01:00
|
|
|
self.handsplayers[player]['wonWhenSeenStreet1'] = 1.0
|
2009-11-24 16:23:21 +01:00
|
|
|
if self.handsplayers[player]['sawShowdown'] == True:
|
2009-12-16 15:58:54 +01:00
|
|
|
self.handsplayers[player]['wonAtSD'] = 1.0
|
2009-11-06 11:39:59 +01:00
|
|
|
|
2009-11-24 10:29:54 +01:00
|
|
|
for player in hand.pot.committed:
|
2010-02-18 16:17:08 +01:00
|
|
|
self.handsplayers[player]['totalProfit'] = int(self.handsplayers[player]['winnings'] - (100*hand.pot.committed[player])- (100*hand.pot.common[player]))
|
2009-11-24 10:29:54 +01:00
|
|
|
|
2009-11-25 07:59:29 +01:00
|
|
|
self.calcCBets(hand)
|
|
|
|
|
2009-11-30 07:20:48 +01:00
|
|
|
for player in hand.players:
|
|
|
|
hcs = hand.join_holecards(player[1], asList=True)
|
|
|
|
hcs = hcs + [u'0x', u'0x', u'0x', u'0x', u'0x']
|
2009-12-18 06:32:09 +01:00
|
|
|
#for i, card in enumerate(hcs[:7], 1): #Python 2.6 syntax
|
|
|
|
# self.handsplayers[player[1]]['card%s' % i] = Card.encodeCard(card)
|
|
|
|
for i, card in enumerate(hcs[:7]):
|
|
|
|
self.handsplayers[player[1]]['card%s' % (i+1)] = Card.encodeCard(card)
|
2009-12-22 10:20:07 +01:00
|
|
|
self.handsplayers[player[1]]['startCards'] = Card.calcStartCards(hand, player[1])
|
2009-12-14 10:52:08 +01:00
|
|
|
|
2010-01-15 06:50:46 +01:00
|
|
|
self.setPositions(hand)
|
2010-01-15 11:29:16 +01:00
|
|
|
self.calcCheckCallRaise(hand)
|
2010-01-15 12:42:24 +01:00
|
|
|
self.calc34BetStreet0(hand)
|
|
|
|
self.calcSteals(hand)
|
2009-12-05 13:15:28 +01:00
|
|
|
# Additional stats
|
|
|
|
# 3betSB, 3betBB
|
|
|
|
# Squeeze, Ratchet?
|
|
|
|
|
|
|
|
|
2010-01-15 06:50:46 +01:00
|
|
|
def setPositions(self, hand):
|
|
|
|
"""Sets the position for each player in HandsPlayers
|
|
|
|
any blinds are negative values, and the last person to act on the
|
|
|
|
first betting round is 0
|
|
|
|
NOTE: HU, both values are negative for non-stud games
|
|
|
|
NOTE2: I've never seen a HU stud match"""
|
|
|
|
# The position calculation must be done differently for Stud and other games as
|
|
|
|
# Stud the 'blind' acts first - in all other games they act last.
|
|
|
|
#
|
|
|
|
#This function is going to get it wrong when there in situations where there
|
|
|
|
# is no small blind. I can live with that.
|
|
|
|
actions = hand.actions[hand.holeStreets[0]]
|
2010-02-15 23:57:59 +01:00
|
|
|
# Note: pfbao list may not include big blind if all others folded
|
2010-01-15 06:50:46 +01:00
|
|
|
players = self.pfbao(actions)
|
2010-02-15 23:57:59 +01:00
|
|
|
|
2010-01-15 06:50:46 +01:00
|
|
|
if hand.gametype['base'] == 'stud':
|
2010-02-15 23:57:59 +01:00
|
|
|
positions = [7, 6, 5, 4, 3, 2, 1, 0, 'S', 'B']
|
|
|
|
seats = len(players)
|
|
|
|
map = []
|
2010-01-15 06:50:46 +01:00
|
|
|
# Could posibly change this to be either -2 or -1 depending if they complete or bring-in
|
|
|
|
# First player to act is -1, last player is 0 for 6 players it should look like:
|
|
|
|
# ['S', 4, 3, 2, 1, 0]
|
|
|
|
map = positions[-seats-1:-1] # Copy required positions from postions array anding in -1
|
|
|
|
map = map[-1:] + map[0:-1] # and move the -1 to the start of that array
|
|
|
|
|
2010-02-15 23:57:59 +01:00
|
|
|
for i, player in enumerate(players):
|
|
|
|
#print "player %s in posn %s" % (player, str(map[i]))
|
|
|
|
self.handsplayers[player]['position'] = map[i]
|
|
|
|
else:
|
|
|
|
# set blinds first, then others from pfbao list, avoids problem if bb
|
|
|
|
# is missing from pfbao list or if there is no small blind
|
|
|
|
bb = [x[0] for x in hand.actions[hand.actionStreets[0]] if x[2] == 'big blind']
|
|
|
|
sb = [x[0] for x in hand.actions[hand.actionStreets[0]] if x[2] == 'small blind']
|
|
|
|
# if there are > 1 sb or bb only the first is used!
|
|
|
|
if bb:
|
|
|
|
self.handsplayers[bb[0]]['position'] = 'B'
|
|
|
|
if bb[0] in players: players.remove(bb[0])
|
|
|
|
if sb:
|
|
|
|
self.handsplayers[sb[0]]['position'] = 'S'
|
|
|
|
if sb[0] in players: players.remove(sb[0])
|
|
|
|
|
|
|
|
#print "bb =", bb, "sb =", sb, "players =", players
|
|
|
|
for i,player in enumerate(reversed(players)):
|
2010-02-17 22:44:05 +01:00
|
|
|
self.handsplayers[player]['position'] = i
|
2009-12-05 13:15:28 +01:00
|
|
|
|
2009-10-13 11:30:49 +02:00
|
|
|
def assembleHudCache(self, hand):
|
2009-12-23 16:14:34 +01:00
|
|
|
# No real work to be done - HandsPlayers data already contains the correct info
|
2009-10-13 11:30:49 +02:00
|
|
|
pass
|
|
|
|
|
2009-08-06 01:08:53 +02:00
|
|
|
def vpip(self, hand):
|
|
|
|
vpipers = set()
|
|
|
|
for act in hand.actions[hand.actionStreets[1]]:
|
|
|
|
if act[1] in ('calls','bets', 'raises'):
|
|
|
|
vpipers.add(act[0])
|
|
|
|
|
|
|
|
self.hands['playersVpi'] = len(vpipers)
|
|
|
|
|
2009-10-14 14:28:07 +02:00
|
|
|
for player in hand.players:
|
|
|
|
if player[1] in vpipers:
|
2009-11-06 12:30:50 +01:00
|
|
|
self.handsplayers[player[1]]['street0VPI'] = True
|
2009-10-14 14:28:07 +02:00
|
|
|
else:
|
2009-11-06 12:30:50 +01:00
|
|
|
self.handsplayers[player[1]]['street0VPI'] = False
|
2009-10-14 14:28:07 +02:00
|
|
|
|
2009-10-08 12:01:49 +02:00
|
|
|
def playersAtStreetX(self, hand):
|
2009-10-09 13:39:05 +02:00
|
|
|
""" playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4/draw1 */"""
|
2009-10-08 12:01:49 +02:00
|
|
|
# self.actions[street] is a list of all actions in a tuple, contining the player name first
|
|
|
|
# [ (player, action, ....), (player2, action, ...) ]
|
|
|
|
# The number of unique players in the list per street gives the value for playersAtStreetXXX
|
|
|
|
|
2009-10-15 09:13:09 +02:00
|
|
|
# FIXME?? - This isn't couting people that are all in - at least showdown needs to reflect this
|
2010-02-16 00:37:34 +01:00
|
|
|
# ... new code below hopefully fixes this
|
2009-10-15 09:13:09 +02:00
|
|
|
|
2009-10-08 12:01:49 +02:00
|
|
|
self.hands['playersAtStreet1'] = 0
|
|
|
|
self.hands['playersAtStreet2'] = 0
|
|
|
|
self.hands['playersAtStreet3'] = 0
|
|
|
|
self.hands['playersAtStreet4'] = 0
|
|
|
|
self.hands['playersAtShowdown'] = 0
|
|
|
|
|
2010-02-16 00:37:34 +01:00
|
|
|
# alliners = set()
|
|
|
|
# for (i, street) in enumerate(hand.actionStreets[2:]):
|
|
|
|
# actors = set()
|
|
|
|
# for action in hand.actions[street]:
|
|
|
|
# if len(action) > 2 and action[-1]: # allin
|
|
|
|
# alliners.add(action[0])
|
|
|
|
# actors.add(action[0])
|
|
|
|
# if len(actors)==0 and len(alliners)<2:
|
|
|
|
# alliners = set()
|
|
|
|
# self.hands['playersAtStreet%d' % (i+1)] = len(set.union(alliners, actors))
|
|
|
|
#
|
|
|
|
# actions = hand.actions[hand.actionStreets[-1]]
|
|
|
|
# print "p_actions:", self.pfba(actions), "p_folds:", self.pfba(actions, l=('folds',)), "alliners:", alliners
|
|
|
|
# pas = set.union(self.pfba(actions) - self.pfba(actions, l=('folds',)), alliners)
|
|
|
|
|
|
|
|
p_in = set(x[1] for x in hand.players)
|
|
|
|
for (i, street) in enumerate(hand.actionStreets):
|
|
|
|
actions = hand.actions[street]
|
|
|
|
p_in = p_in - self.pfba(actions, l=('folds',))
|
|
|
|
self.hands['playersAtStreet%d' % (i-1)] = len(p_in)
|
|
|
|
|
|
|
|
self.hands['playersAtShowdown'] = len(p_in)
|
2009-11-24 16:14:43 +01:00
|
|
|
|
2009-12-06 15:52:45 +01:00
|
|
|
if self.hands['playersAtShowdown'] > 1:
|
2010-02-16 00:37:34 +01:00
|
|
|
for player in p_in:
|
2009-12-06 15:52:45 +01:00
|
|
|
self.handsplayers[player]['sawShowdown'] = True
|
2009-10-08 12:01:49 +02:00
|
|
|
|
|
|
|
def streetXRaises(self, hand):
|
|
|
|
# self.actions[street] is a list of all actions in a tuple, contining the action as the second element
|
|
|
|
# [ (player, action, ....), (player2, action, ...) ]
|
|
|
|
# No idea what this value is actually supposed to be
|
|
|
|
# In theory its "num small bets paid to see flop/street4, including blind" which makes sense for limit. Not so useful for nl
|
2009-10-13 08:04:19 +02:00
|
|
|
# Leaving empty for the moment,
|
2009-11-22 17:05:23 +01:00
|
|
|
|
|
|
|
for i in range(5): self.hands['street%dRaises' % i] = 0
|
|
|
|
|
|
|
|
for (i, street) in enumerate(hand.actionStreets[1:]):
|
|
|
|
self.hands['street%dRaises' % i] = len(filter( lambda action: action[1] in ('raises','bets'), hand.actions[street]))
|
2009-10-08 12:01:49 +02:00
|
|
|
|
2009-12-23 06:30:12 +01:00
|
|
|
def calcSteals(self, hand):
|
|
|
|
"""Fills stealAttempt(Chance|ed, fold(Bb|Sb)ToSteal(Chance|)
|
|
|
|
|
2010-02-03 01:48:45 +01:00
|
|
|
Steal attempt - open raise on positions 1 0 S - i.e. MP3, CO, BU, SB
|
2010-02-17 22:44:05 +01:00
|
|
|
(note: I don't think PT2 counts SB steals in HU hands, maybe we shouldn't?)
|
2009-12-23 06:30:12 +01:00
|
|
|
Fold to steal - folding blind after steal attemp wo any other callers or raisers
|
|
|
|
"""
|
2010-02-03 01:48:45 +01:00
|
|
|
steal_attempt = False
|
|
|
|
steal_positions = (1, 0, 'S')
|
2010-01-15 12:42:24 +01:00
|
|
|
if hand.gametype['base'] == 'stud':
|
2010-02-03 01:48:45 +01:00
|
|
|
steal_positions = (2, 1, 0)
|
2009-12-23 06:30:12 +01:00
|
|
|
for action in hand.actions[hand.actionStreets[1]]:
|
2010-01-15 12:42:24 +01:00
|
|
|
pname, act = action[0], action[1]
|
2010-02-03 01:48:45 +01:00
|
|
|
posn = self.handsplayers[pname]['position']
|
|
|
|
#print "\naction:", action[0], posn, type(posn), steal_attempt, act
|
|
|
|
if posn == 'B':
|
2010-01-15 12:42:24 +01:00
|
|
|
#NOTE: Stud games will never hit this section
|
2010-02-03 01:48:45 +01:00
|
|
|
self.handsplayers[pname]['foldBbToStealChance'] = steal_attempt
|
|
|
|
self.handsplayers[pname]['foldedBbToSteal'] = steal_attempt and act == 'folds'
|
2009-12-23 06:30:12 +01:00
|
|
|
break
|
2010-02-03 01:48:45 +01:00
|
|
|
elif posn == 'S':
|
|
|
|
self.handsplayers[pname]['foldSbToStealChance'] = steal_attempt
|
|
|
|
self.handsplayers[pname]['foldedSbToSteal'] = steal_attempt and act == 'folds'
|
2009-12-23 06:30:12 +01:00
|
|
|
|
2010-02-03 01:48:45 +01:00
|
|
|
if steal_attempt and act != 'folds':
|
2009-12-23 06:30:12 +01:00
|
|
|
break
|
|
|
|
|
2010-02-03 01:48:45 +01:00
|
|
|
if posn in steal_positions and not steal_attempt:
|
2010-01-15 12:42:24 +01:00
|
|
|
self.handsplayers[pname]['stealAttemptChance'] = True
|
2009-12-23 06:30:12 +01:00
|
|
|
if act in ('bets', 'raises'):
|
2010-01-15 12:42:24 +01:00
|
|
|
self.handsplayers[pname]['stealAttempted'] = True
|
2010-02-03 01:48:45 +01:00
|
|
|
steal_attempt = True
|
2010-02-15 00:26:47 +01:00
|
|
|
if act == 'calls':
|
|
|
|
break
|
2010-02-03 01:48:45 +01:00
|
|
|
|
|
|
|
if posn not in steal_positions and act != 'folds':
|
|
|
|
break
|
2009-12-23 06:30:12 +01:00
|
|
|
|
|
|
|
def calc34BetStreet0(self, hand):
|
|
|
|
"""Fills street0_(3|4)B(Chance|Done), other(3|4)BStreet0"""
|
|
|
|
bet_level = 1 # bet_level after 3-bet is equal to 3
|
|
|
|
for action in hand.actions[hand.actionStreets[1]]:
|
|
|
|
# FIXME: fill other(3|4)BStreet0 - i have no idea what does it mean
|
2010-01-15 12:42:24 +01:00
|
|
|
pname, aggr = action[0], action[1] in ('raises', 'bets')
|
2010-02-27 19:41:30 +01:00
|
|
|
self.handsplayers[pname]['street0_3BChance'] = self.handsplayers[pname]['street0_3BChance'] or bet_level == 2
|
2010-01-15 12:42:24 +01:00
|
|
|
self.handsplayers[pname]['street0_4BChance'] = bet_level == 3
|
2010-02-27 19:41:30 +01:00
|
|
|
self.handsplayers[pname]['street0_3BDone'] = self.handsplayers[pname]['street0_3BDone'] or (aggr and self.handsplayers[pname]['street0_3BChance'])
|
2010-01-15 12:42:24 +01:00
|
|
|
self.handsplayers[pname]['street0_4BDone'] = aggr and (self.handsplayers[pname]['street0_4BChance'])
|
2009-12-23 06:30:12 +01:00
|
|
|
if aggr:
|
|
|
|
bet_level += 1
|
|
|
|
|
|
|
|
|
2009-11-25 07:59:29 +01:00
|
|
|
def calcCBets(self, hand):
|
2009-12-23 06:30:12 +01:00
|
|
|
"""Fill streetXCBChance, streetXCBDone, foldToStreetXCBDone, foldToStreetXCBChance
|
2009-12-18 06:32:09 +01:00
|
|
|
|
2009-12-23 06:30:12 +01:00
|
|
|
Continuation Bet chance, action:
|
|
|
|
Had the last bet (initiative) on previous street, got called, close street action
|
|
|
|
Then no bets before the player with initiatives first action on current street
|
|
|
|
ie. if player on street-1 had initiative and no donkbets occurred
|
|
|
|
"""
|
2009-12-18 06:32:09 +01:00
|
|
|
# XXX: enumerate(list, start=x) is python 2.6 syntax; 'start'
|
|
|
|
# came there
|
|
|
|
#for i, street in enumerate(hand.actionStreets[2:], start=1):
|
2009-12-19 03:07:53 +01:00
|
|
|
for i, street in enumerate(hand.actionStreets[2:]):
|
2009-12-18 06:32:09 +01:00
|
|
|
name = self.lastBetOrRaiser(hand.actionStreets[i+1])
|
2009-11-25 07:59:29 +01:00
|
|
|
if name:
|
2009-12-18 06:32:09 +01:00
|
|
|
chance = self.noBetsBefore(hand.actionStreets[i+2], name)
|
2009-11-25 07:59:29 +01:00
|
|
|
if chance == True:
|
2010-04-16 00:16:26 +02:00
|
|
|
self.handsplayers[name]['street%dCBChance' % (i+1)] = True
|
2009-12-18 06:32:09 +01:00
|
|
|
self.handsplayers[name]['street%dCBDone' % (i+1)] = self.betStreet(hand.actionStreets[i+2], name)
|
2009-11-25 07:59:29 +01:00
|
|
|
|
2009-12-23 06:30:12 +01:00
|
|
|
def calcCheckCallRaise(self, hand):
|
|
|
|
"""Fill streetXCheckCallRaiseChance, streetXCheckCallRaiseDone
|
|
|
|
|
|
|
|
streetXCheckCallRaiseChance = got raise/bet after check
|
|
|
|
streetXCheckCallRaiseDone = checked. got raise/bet. didn't fold
|
|
|
|
|
|
|
|
CG: CheckCall would be a much better name for this.
|
|
|
|
"""
|
2010-06-03 21:02:07 +02:00
|
|
|
# XXX: enumerate(list, start=x) is python 2.6 syntax; 'start'
|
2010-01-16 06:55:01 +01:00
|
|
|
#for i, street in enumerate(hand.actionStreets[2:], start=1):
|
|
|
|
for i, street in enumerate(hand.actionStreets[2:]):
|
|
|
|
actions = hand.actions[hand.actionStreets[i+1]]
|
2009-12-23 06:30:12 +01:00
|
|
|
checkers = set()
|
|
|
|
initial_raiser = None
|
|
|
|
for action in actions:
|
|
|
|
pname, act = action[0], action[1]
|
|
|
|
if act in ('bets', 'raises') and initial_raiser is None:
|
|
|
|
initial_raiser = pname
|
2010-01-15 11:29:16 +01:00
|
|
|
elif act == 'checks' and initial_raiser is None:
|
2009-12-23 06:30:12 +01:00
|
|
|
checkers.add(pname)
|
|
|
|
elif initial_raiser is not None and pname in checkers:
|
2010-01-16 06:55:01 +01:00
|
|
|
self.handsplayers[pname]['street%dCheckCallRaiseChance' % (i+1)] = True
|
|
|
|
self.handsplayers[pname]['street%dCheckCallRaiseDone' % (i+1)] = act!='folds'
|
2009-12-23 06:30:12 +01:00
|
|
|
|
2009-11-06 12:13:52 +01:00
|
|
|
def seen(self, hand, i):
|
|
|
|
pas = set()
|
2009-11-06 12:30:50 +01:00
|
|
|
for act in hand.actions[hand.actionStreets[i+1]]:
|
2009-11-06 12:13:52 +01:00
|
|
|
pas.add(act[0])
|
|
|
|
|
|
|
|
for player in hand.players:
|
|
|
|
if player[1] in pas:
|
2010-02-14 17:01:36 +01:00
|
|
|
self.handsplayers[player[1]]['street%sSeen' % i] = True
|
2009-11-06 12:13:52 +01:00
|
|
|
else:
|
|
|
|
self.handsplayers[player[1]]['street%sSeen' % i] = False
|
|
|
|
|
2009-08-06 01:08:53 +02:00
|
|
|
def aggr(self, hand, i):
|
|
|
|
aggrers = set()
|
2010-05-28 02:31:04 +02:00
|
|
|
others = set()
|
2010-01-15 06:50:46 +01:00
|
|
|
# Growl - actionStreets contains 'BLINDSANTES', which isn't actually an action street
|
2010-06-03 21:02:07 +02:00
|
|
|
|
2010-05-28 02:31:04 +02:00
|
|
|
firstAggrMade=False
|
2010-01-15 06:50:46 +01:00
|
|
|
for act in hand.actions[hand.actionStreets[i+1]]:
|
2010-05-28 02:31:04 +02:00
|
|
|
if firstAggrMade:
|
|
|
|
others.add(act[0])
|
2009-12-26 10:18:05 +01:00
|
|
|
if act[1] in ('completes', 'bets', 'raises'):
|
2009-08-06 01:08:53 +02:00
|
|
|
aggrers.add(act[0])
|
2010-05-28 02:31:04 +02:00
|
|
|
firstAggrMade=True
|
2009-08-06 01:08:53 +02:00
|
|
|
|
|
|
|
for player in hand.players:
|
2010-01-15 06:50:46 +01:00
|
|
|
#print "DEBUG: actionStreet[%s]: %s" %(hand.actionStreets[i+1], i)
|
2009-08-06 01:08:53 +02:00
|
|
|
if player[1] in aggrers:
|
|
|
|
self.handsplayers[player[1]]['street%sAggr' % i] = True
|
|
|
|
else:
|
|
|
|
self.handsplayers[player[1]]['street%sAggr' % i] = False
|
2010-05-28 02:31:04 +02:00
|
|
|
|
|
|
|
if len(aggrers)>0 and i>0:
|
|
|
|
for playername in others:
|
|
|
|
self.handsplayers[playername]['otherRaisedStreet%s' % i] = True
|
|
|
|
#print "otherRaised detected on handid "+str(hand.handid)+" for "+playername+" on street "+str(i)
|
2009-03-14 12:40:27 +01:00
|
|
|
|
2010-06-03 21:02:07 +02:00
|
|
|
if i > 0 and len(aggrers) > 0:
|
2010-05-28 02:31:04 +02:00
|
|
|
for playername in others:
|
|
|
|
self.handsplayers[playername]['otherRaisedStreet%s' % i] = True
|
2010-06-03 21:02:07 +02:00
|
|
|
#print "DEBUG: otherRaised detected on handid %s for %s on actionStreet[%s]: %s"
|
|
|
|
# %(hand.handid, playername, hand.actionStreets[i+1], i)
|
2009-03-14 12:40:27 +01:00
|
|
|
|
2009-11-24 17:57:14 +01:00
|
|
|
def calls(self, hand, i):
|
|
|
|
callers = []
|
|
|
|
for act in hand.actions[hand.actionStreets[i+1]]:
|
|
|
|
if act[1] in ('calls'):
|
|
|
|
self.handsplayers[act[0]]['street%sCalls' % i] = 1 + self.handsplayers[act[0]]['street%sCalls' % i]
|
|
|
|
|
|
|
|
# CG - I'm sure this stat is wrong
|
|
|
|
# Best guess is that raise = 2 bets
|
|
|
|
def bets(self, hand, i):
|
|
|
|
for act in hand.actions[hand.actionStreets[i+1]]:
|
|
|
|
if act[1] in ('bets'):
|
|
|
|
self.handsplayers[act[0]]['street%sBets' % i] = 1 + self.handsplayers[act[0]]['street%sBets' % i]
|
2010-05-28 02:31:04 +02:00
|
|
|
|
|
|
|
def folds(self, hand, i):
|
|
|
|
for act in hand.actions[hand.actionStreets[i+1]]:
|
|
|
|
if act[1] in ('folds'):
|
|
|
|
if self.handsplayers[act[0]]['otherRaisedStreet%s' % i] == True:
|
|
|
|
self.handsplayers[act[0]]['foldToOtherRaisedStreet%s' % i] = True
|
2010-06-03 21:02:07 +02:00
|
|
|
#print "DEBUG: fold detected on handid %s for %s on actionStreet[%s]: %s"
|
|
|
|
# %(hand.handid, act[0],hand.actionStreets[i+1], i)
|
|
|
|
|
2009-08-06 01:08:53 +02:00
|
|
|
def countPlayers(self, hand):
|
2009-10-06 12:30:52 +02:00
|
|
|
pass
|
2009-11-22 17:05:23 +01:00
|
|
|
|
|
|
|
def pfba(self, actions, f=None, l=None):
|
|
|
|
"""Helper method. Returns set of PlayersFilteredByActions
|
|
|
|
|
|
|
|
f - forbidden actions
|
|
|
|
l - limited to actions
|
|
|
|
"""
|
|
|
|
players = set()
|
|
|
|
for action in actions:
|
|
|
|
if l is not None and action[1] not in l: continue
|
|
|
|
if f is not None and action[1] in f: continue
|
|
|
|
players.add(action[0])
|
|
|
|
return players
|
2009-11-25 07:59:29 +01:00
|
|
|
|
2010-01-15 06:50:46 +01:00
|
|
|
def pfbao(self, actions, f=None, l=None, unique=True):
|
|
|
|
"""Helper method. Returns set of PlayersFilteredByActionsOrdered
|
|
|
|
|
|
|
|
f - forbidden actions
|
|
|
|
l - limited to actions
|
|
|
|
"""
|
|
|
|
# Note, this is an adaptation of function 5 from:
|
|
|
|
# http://www.peterbe.com/plog/uniqifiers-benchmark
|
|
|
|
seen = {}
|
|
|
|
players = []
|
|
|
|
for action in actions:
|
|
|
|
if l is not None and action[1] not in l: continue
|
|
|
|
if f is not None and action[1] in f: continue
|
|
|
|
if action[0] in seen and unique: continue
|
|
|
|
seen[action[0]] = 1
|
|
|
|
players.append(action[0])
|
|
|
|
return players
|
2009-12-23 06:30:12 +01:00
|
|
|
|
|
|
|
def firstsBetOrRaiser(self, actions):
|
|
|
|
"""Returns player name that placed the first bet or raise.
|
|
|
|
|
|
|
|
None if there were no bets or raises on that street
|
|
|
|
"""
|
|
|
|
for act in actions:
|
|
|
|
if act[1] in ('bets', 'raises'):
|
|
|
|
return act[0]
|
|
|
|
return None
|
|
|
|
|
|
|
|
def lastBetOrRaiser(self, street):
|
|
|
|
"""Returns player name that placed the last bet or raise for that street.
|
|
|
|
None if there were no bets or raises on that street"""
|
|
|
|
lastbet = None
|
|
|
|
for act in self.hand.actions[street]:
|
|
|
|
if act[1] in ('bets', 'raises'):
|
|
|
|
lastbet = act[0]
|
|
|
|
return lastbet
|
|
|
|
|
|
|
|
|
2009-11-25 07:59:29 +01:00
|
|
|
def noBetsBefore(self, street, player):
|
|
|
|
"""Returns true if there were no bets before the specified players turn, false otherwise"""
|
|
|
|
betOrRaise = False
|
|
|
|
for act in self.hand.actions[street]:
|
|
|
|
#Must test for player first in case UTG
|
|
|
|
if act[0] == player:
|
|
|
|
betOrRaise = True
|
|
|
|
break
|
|
|
|
if act[1] in ('bets', 'raises'):
|
|
|
|
break
|
|
|
|
return betOrRaise
|
|
|
|
|
2009-12-23 06:30:12 +01:00
|
|
|
|
2009-11-25 07:59:29 +01:00
|
|
|
def betStreet(self, street, player):
|
|
|
|
"""Returns true if player bet/raised the street as their first action"""
|
|
|
|
betOrRaise = False
|
|
|
|
for act in self.hand.actions[street]:
|
2010-04-15 08:51:20 +02:00
|
|
|
if act[0] == player:
|
|
|
|
if act[1] in ('bets', 'raises'):
|
|
|
|
betOrRaise = True
|
|
|
|
else:
|
|
|
|
# player found but did not bet or raise as their first action
|
2010-04-15 09:48:57 +02:00
|
|
|
pass
|
2009-11-25 07:59:29 +01:00
|
|
|
break
|
2010-04-15 08:51:20 +02:00
|
|
|
#else:
|
|
|
|
# haven't found player's first action yet
|
2009-12-23 16:14:34 +01:00
|
|
|
return betOrRaise
|
2009-11-25 07:59:29 +01:00
|
|
|
|