redo changes to checkPositions, and such

This commit is contained in:
eblade 2008-12-18 15:42:46 -05:00
parent 9263aa998e
commit 2ccd00d3fd
2 changed files with 597 additions and 29 deletions

View File

@ -391,7 +391,8 @@ def checkPositions(positions):
pass
### RHH modified to allow for "position 9" here (pos==9 is when you're a dead hand before the BB
if (pos!="B" and pos!="S" and pos!=0 and pos!=1 and pos!=2 and pos!=3 and pos!=4 and pos!=5 and pos!=6 and pos!=7 and pos!=9):
### eric - position 8 could be valid - if only one blind is posted, but there's still 10 people, ie a sitout is present, and the small is dead...
if not (pos == "B" or pos == "S" or (pos >= 0 and pos <= 9)):
raise FpdbError("invalid position found in checkPositions. i: "+str(i)+" position: "+str(pos))
#end def fpdb_simple.checkPositions
@ -1229,7 +1230,11 @@ def parsePositions (hand, names):
if (bb!=-1):
bb=recognisePlayerNo(bb, names, "bet")
<<<<<<< HEAD:pyfpdb/fpdb_simple.py
# print "sb = ", sb, "bb = ", bb
=======
print "sb = ", sb, "bb = ", bb
>>>>>>> 1de3446... remove spurious window realize from popup_window as well:pyfpdb/fpdb_simple.py
if bb == sb:
sbExists = False
sb = -1
@ -1279,7 +1284,11 @@ def parsePositions (hand, names):
print "parsePositions names:",names
print "result:",positions
raise FpdbError ("failed to read positions")
<<<<<<< HEAD:pyfpdb/fpdb_simple.py
# print str(positions), "\n"
=======
print str(positions), "\n"
>>>>>>> 1de3446... remove spurious window realize from popup_window as well:pyfpdb/fpdb_simple.py
return positions
#end def parsePositions
@ -1749,6 +1758,7 @@ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
result.append( getLastInsertId(backend, conn, cursor) ) # mysql only
return result
#end def store_hands_players_stud_tourney
<<<<<<< HEAD:pyfpdb/fpdb_simple.py
def generateHudCacheData(player_ids, base, category, action_types, allIns, actionTypeByNo
,winnings, totalWinnings, positions, actionTypes, actionAmounts, antes):
@ -2320,6 +2330,564 @@ sure to also change the following storage method and table_viewer.prepare_data i
result['street4CheckCallRaiseChance']=street4CheckCallRaiseChance
result['street4CheckCallRaiseDone']=street4CheckCallRaiseDone
return result
=======
def generateHudCacheData(player_ids, base, category, action_types, allIns, actionTypeByNo, winnings, totalWinnings, positions):
"""calculates data for the HUD during import. IMPORTANT: if you change this method make sure to also change the following storage method and table_viewer.prepare_data if necessary"""
#setup subarrays of the result dictionary.
street0VPI=[]
street0Aggr=[]
street0_3B4BChance=[]
street0_3B4BDone=[]
street1Seen=[]
street2Seen=[]
street3Seen=[]
street4Seen=[]
sawShowdown=[]
street1Aggr=[]
street2Aggr=[]
street3Aggr=[]
street4Aggr=[]
otherRaisedStreet1=[]
otherRaisedStreet2=[]
otherRaisedStreet3=[]
otherRaisedStreet4=[]
foldToOtherRaisedStreet1=[]
foldToOtherRaisedStreet2=[]
foldToOtherRaisedStreet3=[]
foldToOtherRaisedStreet4=[]
wonWhenSeenStreet1=[]
wonAtSD=[]
stealAttemptChance=[]
stealAttempted=[]
hudDataPositions=[]
firstPfRaiseByNo=-1
firstPfRaiserId=-1
firstPfRaiserNo=-1
firstPfCallByNo=-1
firstPfCallerId=-1
for i in range(len(actionTypeByNo[0])):
if actionTypeByNo[0][i][1]=="bet":
firstPfRaiseByNo=i
firstPfRaiserId=actionTypeByNo[0][i][0]
for j in range(len(player_ids)):
if player_ids[j]==firstPfRaiserId:
firstPfRaiserNo=j
break
break
for i in range(len(actionTypeByNo[0])):
if actionTypeByNo[0][i][1]=="call":
firstPfCallByNo=i
firstPfCallerId=actionTypeByNo[0][i][0]
break
cutoffId=-1
buttonId=-1
sbId=-1
bbId=-1
if base=="hold":
for player in range(len(positions)):
if positions==1:
cutoffId=player_ids[player]
if positions==0:
buttonId=player_ids[player]
if positions=='S':
sbId=player_ids[player]
if positions=='B':
bbId=player_ids[player]
someoneStole=False
#run a loop for each player preparing the actual values that will be commited to SQL
for player in range (len(player_ids)):
#set default values
myStreet0VPI=False
myStreet0Aggr=False
myStreet0_3B4BChance=False
myStreet0_3B4BDone=False
myStreet1Seen=False
myStreet2Seen=False
myStreet3Seen=False
myStreet4Seen=False
mySawShowdown=False
myStreet1Aggr=False
myStreet2Aggr=False
myStreet3Aggr=False
myStreet4Aggr=False
myOtherRaisedStreet1=False
myOtherRaisedStreet2=False
myOtherRaisedStreet3=False
myOtherRaisedStreet4=False
myFoldToOtherRaisedStreet1=False
myFoldToOtherRaisedStreet2=False
myFoldToOtherRaisedStreet3=False
myFoldToOtherRaisedStreet4=False
myWonWhenSeenStreet1=0.0
myWonAtSD=0.0
myStealAttemptChance=False
myStealAttempted=False
#calculate VPIP and PFR
street=0
heroPfRaiseCount=0
for count in range (len(action_types[street][player])):#finally individual actions
currentAction=action_types[street][player][count]
if currentAction=="bet":
myStreet0Aggr=True
if (currentAction=="bet" or currentAction=="call"):
myStreet0VPI=True
#PF3B4BChance and PF3B4B
pfFold=-1
pfRaise=-1
if firstPfRaiseByNo!=-1:
for i in range(len(actionTypeByNo[0])):
if actionTypeByNo[0][i][0]==player_ids[player]:
if actionTypeByNo[0][i][1]=="bet" and pfRaise==-1 and i>firstPfRaiseByNo:
pfRaise=i
if actionTypeByNo[0][i][1]=="fold" and pfFold==-1:
pfFold=i
if pfFold==-1 or pfFold>firstPfRaiseByNo:
myStreet0_3B4BChance=True
if pfRaise>firstPfRaiseByNo:
myStreet0_3B4BDone=True
#steal calculations
if base=="hold":
if len(player_ids)>=5: #no point otherwise
if positions[player]==1:
if firstPfRaiserId==player_ids[player]:
myStealAttemptChance=True
myStealAttempted=True
elif firstPfRaiserId==buttonId or firstPfRaiserId==sbId or firstPfRaiserId==bbId or firstPfRaiserId==-1:
myStealAttemptChance=True
if positions[player]==0:
if firstPfRaiserId==player_ids[player]:
myStealAttemptChance=True
myStealAttempted=True
elif firstPfRaiserId==sbId or firstPfRaiserId==bbId or firstPfRaiserId==-1:
myStealAttemptChance=True
if positions[player]=='S':
if firstPfRaiserId==player_ids[player]:
myStealAttemptChance=True
myStealAttempted=True
elif firstPfRaiserId==bbId or firstPfRaiserId==-1:
myStealAttemptChance=True
if positions[player]=='B':
pass
if myStealAttempted:
someoneStole=True
#calculate saw* values
isAllIn=False
for i in range(len(allIns[0][player])):
if allIns[0][player][i]:
isAllIn=True
if (len(action_types[1][player])>0 or isAllIn):
myStreet1Seen=True
for i in range(len(allIns[1][player])):
if allIns[1][player][i]:
isAllIn=True
if (len(action_types[2][player])>0 or isAllIn):
myStreet2Seen=True
for i in range(len(allIns[2][player])):
if allIns[2][player][i]:
isAllIn=True
if (len(action_types[3][player])>0 or isAllIn):
myStreet3Seen=True
#print "base:", base
if base=="hold":
mySawShowdown=True
for count in range (len(action_types[3][player])):
if action_types[3][player][count]=="fold":
mySawShowdown=False
else:
#print "in else"
for i in range(len(allIns[3][player])):
if allIns[3][player][i]:
isAllIn=True
if (len(action_types[4][player])>0 or isAllIn):
#print "in if"
myStreet4Seen=True
mySawShowdown=True
for count in range (len(action_types[4][player])):
if action_types[4][player][count]=="fold":
mySawShowdown=False
#flop stuff
street=1
if myStreet1Seen:
for count in range(len(action_types[street][player])):
if action_types[street][player][count]=="bet":
myStreet1Aggr=True
for otherPlayer in range (len(player_ids)):
if player==otherPlayer:
pass
else:
for countOther in range (len(action_types[street][otherPlayer])):
if action_types[street][otherPlayer][countOther]=="bet":
myOtherRaisedStreet1=True
for countOtherFold in range (len(action_types[street][player])):
if action_types[street][player][countOtherFold]=="fold":
myFoldToOtherRaisedStreet1=True
#turn stuff - copy of flop with different vars
street=2
if myStreet2Seen:
for count in range(len(action_types[street][player])):
if action_types[street][player][count]=="bet":
myStreet2Aggr=True
for otherPlayer in range (len(player_ids)):
if player==otherPlayer:
pass
else:
for countOther in range (len(action_types[street][otherPlayer])):
if action_types[street][otherPlayer][countOther]=="bet":
myOtherRaisedStreet2=True
for countOtherFold in range (len(action_types[street][player])):
if action_types[street][player][countOtherFold]=="fold":
myFoldToOtherRaisedStreet2=True
#river stuff - copy of flop with different vars
street=3
if myStreet3Seen:
for count in range(len(action_types[street][player])):
if action_types[street][player][count]=="bet":
myStreet3Aggr=True
for otherPlayer in range (len(player_ids)):
if player==otherPlayer:
pass
else:
for countOther in range (len(action_types[street][otherPlayer])):
if action_types[street][otherPlayer][countOther]=="bet":
myOtherRaisedStreet3=True
for countOtherFold in range (len(action_types[street][player])):
if action_types[street][player][countOtherFold]=="fold":
myFoldToOtherRaisedStreet3=True
#stud river stuff - copy of flop with different vars
street=4
if myStreet4Seen:
for count in range(len(action_types[street][player])):
if action_types[street][player][count]=="bet":
myStreet4Aggr=True
for otherPlayer in range (len(player_ids)):
if player==otherPlayer:
pass
else:
for countOther in range (len(action_types[street][otherPlayer])):
if action_types[street][otherPlayer][countOther]=="bet":
myOtherRaisedStreet4=True
for countOtherFold in range (len(action_types[street][player])):
if action_types[street][player][countOtherFold]=="fold":
myFoldToOtherRaisedStreet4=True
if winnings[player]!=0:
if myStreet1Seen:
myWonWhenSeenStreet1=winnings[player]/float(totalWinnings)
if mySawShowdown:
myWonAtSD=myWonWhenSeenStreet1
#add each value to the appropriate array
street0VPI.append(myStreet0VPI)
street0Aggr.append(myStreet0Aggr)
street0_3B4BChance.append(myStreet0_3B4BChance)
street0_3B4BDone.append(myStreet0_3B4BDone)
street1Seen.append(myStreet1Seen)
street2Seen.append(myStreet2Seen)
street3Seen.append(myStreet3Seen)
street4Seen.append(myStreet4Seen)
sawShowdown.append(mySawShowdown)
street1Aggr.append(myStreet1Aggr)
street2Aggr.append(myStreet2Aggr)
street3Aggr.append(myStreet3Aggr)
street4Aggr.append(myStreet4Aggr)
otherRaisedStreet1.append(myOtherRaisedStreet1)
otherRaisedStreet2.append(myOtherRaisedStreet2)
otherRaisedStreet3.append(myOtherRaisedStreet3)
otherRaisedStreet4.append(myOtherRaisedStreet4)
foldToOtherRaisedStreet1.append(myFoldToOtherRaisedStreet1)
foldToOtherRaisedStreet2.append(myFoldToOtherRaisedStreet2)
foldToOtherRaisedStreet3.append(myFoldToOtherRaisedStreet3)
foldToOtherRaisedStreet4.append(myFoldToOtherRaisedStreet4)
wonWhenSeenStreet1.append(myWonWhenSeenStreet1)
wonAtSD.append(myWonAtSD)
stealAttemptChance.append(myStealAttemptChance)
stealAttempted.append(myStealAttempted)
if base=="hold":
pos=positions[player]
if pos=='B':
hudDataPositions.append('B')
elif pos=='S':
hudDataPositions.append('S')
elif pos==0:
hudDataPositions.append('D')
elif pos==1:
hudDataPositions.append('C')
elif pos>=2 and pos<=4:
hudDataPositions.append('M')
elif pos>=5 and pos<=8:
hudDataPositions.append('E')
### RHH Added this elif to handle being a dead hand before the BB (pos==9)
elif pos==9:
hudDataPositions.append('X')
else:
raise FpdbError("invalid position")
elif base=="stud":
#todo: stud positions and steals
pass
#add each array to the to-be-returned dictionary
result={'street0VPI':street0VPI}
result['street0Aggr']=street0Aggr
result['street0_3B4BChance']=street0_3B4BChance
result['street0_3B4BDone']=street0_3B4BDone
result['street1Seen']=street1Seen
result['street2Seen']=street2Seen
result['street3Seen']=street3Seen
result['street4Seen']=street4Seen
result['sawShowdown']=sawShowdown
result['street1Aggr']=street1Aggr
result['otherRaisedStreet1']=otherRaisedStreet1
result['foldToOtherRaisedStreet1']=foldToOtherRaisedStreet1
result['street2Aggr']=street2Aggr
result['otherRaisedStreet2']=otherRaisedStreet2
result['foldToOtherRaisedStreet2']=foldToOtherRaisedStreet2
result['street3Aggr']=street3Aggr
result['otherRaisedStreet3']=otherRaisedStreet3
result['foldToOtherRaisedStreet3']=foldToOtherRaisedStreet3
result['street4Aggr']=street4Aggr
result['otherRaisedStreet4']=otherRaisedStreet4
result['foldToOtherRaisedStreet4']=foldToOtherRaisedStreet4
result['wonWhenSeenStreet1']=wonWhenSeenStreet1
result['wonAtSD']=wonAtSD
result['stealAttemptChance']=stealAttemptChance
result['stealAttempted']=stealAttempted
#now the various steal values
foldBbToStealChance=[]
foldedBbToSteal=[]
foldSbToStealChance=[]
foldedSbToSteal=[]
for player in range (len(player_ids)):
myFoldBbToStealChance=False
myFoldedBbToSteal=False
myFoldSbToStealChance=False
myFoldedSbToSteal=False
if base=="hold":
if someoneStole and (positions[player]=='B' or positions[player]=='S') and firstPfRaiserId!=player_ids[player]:
street=0
for count in range (len(action_types[street][player])):#individual actions
if positions[player]=='B':
myFoldBbToStealChance=True
if action_types[street][player][count]=="fold":
myFoldedBbToSteal=True
if positions[player]=='S':
myFoldSbToStealChance=True
if action_types[street][player][count]=="fold":
myFoldedSbToSteal=True
foldBbToStealChance.append(myFoldBbToStealChance)
foldedBbToSteal.append(myFoldedBbToSteal)
foldSbToStealChance.append(myFoldSbToStealChance)
foldedSbToSteal.append(myFoldedSbToSteal)
result['foldBbToStealChance']=foldBbToStealChance
result['foldedBbToSteal']=foldedBbToSteal
result['foldSbToStealChance']=foldSbToStealChance
result['foldedSbToSteal']=foldedSbToSteal
#now CB
street1CBChance=[]
street1CBDone=[]
didStreet1CB=[]
for player in range (len(player_ids)):
myStreet1CBChance=False
myStreet1CBDone=False
if street0VPI[player]:
myStreet1CBChance=True
if street1Aggr[player]:
myStreet1CBDone=True
didStreet1CB.append(player_ids[player])
street1CBChance.append(myStreet1CBChance)
street1CBDone.append(myStreet1CBDone)
result['street1CBChance']=street1CBChance
result['street1CBDone']=street1CBDone
#now 2B
street2CBChance=[]
street2CBDone=[]
didStreet2CB=[]
for player in range (len(player_ids)):
myStreet2CBChance=False
myStreet2CBDone=False
if street1CBDone[player]:
myStreet2CBChance=True
if street2Aggr[player]:
myStreet2CBDone=True
didStreet2CB.append(player_ids[player])
street2CBChance.append(myStreet2CBChance)
street2CBDone.append(myStreet2CBDone)
result['street2CBChance']=street2CBChance
result['street2CBDone']=street2CBDone
#now 3B
street3CBChance=[]
street3CBDone=[]
didStreet3CB=[]
for player in range (len(player_ids)):
myStreet3CBChance=False
myStreet3CBDone=False
if street2CBDone[player]:
myStreet3CBChance=True
if street3Aggr[player]:
myStreet3CBDone=True
didStreet3CB.append(player_ids[player])
street3CBChance.append(myStreet3CBChance)
street3CBDone.append(myStreet3CBDone)
result['street3CBChance']=street3CBChance
result['street3CBDone']=street3CBDone
#and 4B
street4CBChance=[]
street4CBDone=[]
didStreet4CB=[]
for player in range (len(player_ids)):
myStreet4CBChance=False
myStreet4CBDone=False
if street3CBDone[player]:
myStreet4CBChance=True
if street4Aggr[player]:
myStreet4CBDone=True
didStreet4CB.append(player_ids[player])
street4CBChance.append(myStreet4CBChance)
street4CBDone.append(myStreet4CBDone)
result['street4CBChance']=street4CBChance
result['street4CBDone']=street4CBDone
result['position']=hudDataPositions
foldToStreet1CBChance=[]
foldToStreet1CBDone=[]
foldToStreet2CBChance=[]
foldToStreet2CBDone=[]
foldToStreet3CBChance=[]
foldToStreet3CBDone=[]
foldToStreet4CBChance=[]
foldToStreet4CBDone=[]
for player in range (len(player_ids)):
myFoldToStreet1CBChance=False
myFoldToStreet1CBDone=False
foldToStreet1CBChance.append(myFoldToStreet1CBChance)
foldToStreet1CBDone.append(myFoldToStreet1CBDone)
myFoldToStreet2CBChance=False
myFoldToStreet2CBDone=False
foldToStreet2CBChance.append(myFoldToStreet2CBChance)
foldToStreet2CBDone.append(myFoldToStreet2CBDone)
myFoldToStreet3CBChance=False
myFoldToStreet3CBDone=False
foldToStreet3CBChance.append(myFoldToStreet3CBChance)
foldToStreet3CBDone.append(myFoldToStreet3CBDone)
myFoldToStreet4CBChance=False
myFoldToStreet4CBDone=False
foldToStreet4CBChance.append(myFoldToStreet4CBChance)
foldToStreet4CBDone.append(myFoldToStreet4CBDone)
if len(didStreet1CB)>=1:
generateFoldToCB(1, player_ids, didStreet1CB, street1CBDone, foldToStreet1CBChance, foldToStreet1CBDone, actionTypeByNo)
if len(didStreet2CB)>=1:
generateFoldToCB(2, player_ids, didStreet2CB, street2CBDone, foldToStreet2CBChance, foldToStreet2CBDone, actionTypeByNo)
if len(didStreet3CB)>=1:
generateFoldToCB(3, player_ids, didStreet3CB, street3CBDone, foldToStreet3CBChance, foldToStreet3CBDone, actionTypeByNo)
if len(didStreet4CB)>=1:
generateFoldToCB(4, player_ids, didStreet4CB, street4CBDone, foldToStreet4CBChance, foldToStreet4CBDone, actionTypeByNo)
result['foldToStreet1CBChance']=foldToStreet1CBChance
result['foldToStreet1CBDone']=foldToStreet1CBDone
result['foldToStreet2CBChance']=foldToStreet2CBChance
result['foldToStreet2CBDone']=foldToStreet2CBDone
result['foldToStreet3CBChance']=foldToStreet3CBChance
result['foldToStreet3CBDone']=foldToStreet3CBDone
result['foldToStreet4CBChance']=foldToStreet4CBChance
result['foldToStreet4CBDone']=foldToStreet4CBDone
totalProfit=[]
street1CheckCallRaiseChance=[]
street1CheckCallRaiseDone=[]
street2CheckCallRaiseChance=[]
street2CheckCallRaiseDone=[]
street3CheckCallRaiseChance=[]
street3CheckCallRaiseDone=[]
street4CheckCallRaiseChance=[]
street4CheckCallRaiseDone=[]
for player in range (len(player_ids)):
myTotalProfit=0
myStreet1CheckCallRaiseChance=False
myStreet1CheckCallRaiseDone=False
myStreet2CheckCallRaiseChance=False
myStreet2CheckCallRaiseDone=False
myStreet3CheckCallRaiseChance=False
myStreet3CheckCallRaiseDone=False
myStreet4CheckCallRaiseChance=False
myStreet4CheckCallRaiseDone=False
totalProfit.append(myTotalProfit)
street1CheckCallRaiseChance.append(myStreet1CheckCallRaiseChance)
street1CheckCallRaiseDone.append(myStreet1CheckCallRaiseDone)
street2CheckCallRaiseChance.append(myStreet2CheckCallRaiseChance)
street2CheckCallRaiseDone.append(myStreet2CheckCallRaiseDone)
street3CheckCallRaiseChance.append(myStreet3CheckCallRaiseChance)
street3CheckCallRaiseDone.append(myStreet3CheckCallRaiseDone)
street4CheckCallRaiseChance.append(myStreet4CheckCallRaiseChance)
street4CheckCallRaiseDone.append(myStreet4CheckCallRaiseDone)
result['totalProfit']=totalProfit
result['street1CheckCallRaiseChance']=street1CheckCallRaiseChance
result['street1CheckCallRaiseDone']=street1CheckCallRaiseDone
result['street2CheckCallRaiseChance']=street2CheckCallRaiseChance
result['street2CheckCallRaiseDone']=street2CheckCallRaiseDone
result['street3CheckCallRaiseChance']=street3CheckCallRaiseChance
result['street3CheckCallRaiseDone']=street3CheckCallRaiseDone
result['street4CheckCallRaiseChance']=street4CheckCallRaiseChance
result['street4CheckCallRaiseDone']=street4CheckCallRaiseDone
return result
>>>>>>> 1de3446... remove spurious window realize from popup_window as well:pyfpdb/fpdb_simple.py
#end def generateHudCacheData
def generateFoldToCB(street, playerIDs, didStreetCB, streetCBDone, foldToStreetCBChance, foldToStreetCBDone, actionTypeByNo):