From bb38d7e1dd2c89f8ebeff980e8ecfc6bc8d44b5a Mon Sep 17 00:00:00 2001 From: Worros Date: Mon, 30 Nov 2009 14:20:48 +0800 Subject: [PATCH] [NEWIMPORT] Clean up HandsPlayers.cardX fetching --- pyfpdb/DerivedStats.py | 27 +++++------------------ pyfpdb/Hand.py | 50 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/pyfpdb/DerivedStats.py b/pyfpdb/DerivedStats.py index c5575ddc..c244f019 100644 --- a/pyfpdb/DerivedStats.py +++ b/pyfpdb/DerivedStats.py @@ -143,28 +143,11 @@ class DerivedStats(): self.calcCBets(hand) - #default_holecards = ["Xx", "Xx", "Xx", "Xx"] - #if hand.gametype['base'] == "hold": - # pass - #elif hand.gametype['base'] == "stud": - # pass - #else: - # # Flop hopefully... - # pass - - for street in hand.holeStreets: - for player in hand.players: - for i in range(1,8): self.handsplayers[player[1]]['card%d' % i] = 0 - #print "DEBUG: hand.holecards[%s]: %s" % (street, hand.holecards[street]) - if player[1] in hand.holecards[street].keys() and hand.gametype['base'] == "hold": - self.handsplayers[player[1]]['card1'] = Card.encodeCard(hand.holecards[street][player[1]][1][0]) - self.handsplayers[player[1]]['card2'] = Card.encodeCard(hand.holecards[street][player[1]][1][1]) - try: - self.handsplayers[player[1]]['card3'] = Card.encodeCard(hand.holecards[street][player[1]][1][2]) - self.handsplayers[player[1]]['card4'] = Card.encodeCard(hand.holecards[street][player[1]][1][3]) - except IndexError: - # Just means no player cards for that street/game - continue - pass + 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'] + for i, card in enumerate(hcs[:7], 1): + self.handsplayers[player[1]]['card%s' % i] = Card.encodeCard(card) def assembleHudCache(self, hand): pass diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 6242d866..efa9c0b6 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -668,6 +668,27 @@ class HoldemOmahaHand(Hand): tmp5 = 0 return (tmp1,tmp2,tmp3,tmp4,tmp5) + def join_holecards(self, player, asList=False): + """With asList = True it returns the set cards for a player including down cards if they aren't know""" + # FIXME: This should actually return + hcs = [u'0x', u'0x', u'0x', u'0x'] + + for street in self.holeStreets: + if player in self.holecards[street].keys(): + hcs[0] = self.holecards[street][player][1][0] + hcs[1] = self.holecards[street][player][1][1] + try: + hcs[2] = self.holecards[street][player][1][2] + hcs[3] = self.holecards[street][player][1][3] + except IndexError: + pass + + if asList == False: + return " ".join(hcs) + else: + return hcs + + def writeHTMLHand(self): from nevow import tags as T from nevow import flat @@ -968,6 +989,16 @@ class DrawHand(Hand): # showdownPot INT, /* pot size at sd/street7 */ return (0,0,0,0,0) + def join_holecards(self, player, asList=False): + """With asList = True it returns the set cards for a player including down cards if they aren't know""" + # FIXME: This should actually return + holecards = [u'0x', u'0x', u'0x', u'0x', u'0x'] + + if asList == False: + return " ".join(holecards) + else: + return holecards + def writeHand(self, fh=sys.__stdout__): # PokerStars format. @@ -1294,7 +1325,9 @@ Add a complete on [street] by [player] to [amountTo] if street == 'SEVENTH' and player != self.hero: return # only write 7th st line for hero, LDO return hc + " ".join(self.holecards[street][player][1]) + "] [" + " ".join(self.holecards[street][player][0]) + "]" - def join_holecards(self, player): + def join_holecards(self, player, asList=False): + """Function returns a string for the stud writeHand method by default + With asList = True it returns the set cards for a player including down cards if they aren't know""" holecards = [] for street in self.holeStreets: if self.holecards[street].has_key(player): @@ -1307,7 +1340,20 @@ Add a complete on [street] by [player] to [amountTo] holecards = holecards + self.holecards[street][player][1] else: holecards = holecards + self.holecards[street][player][0] - return " ".join(holecards) + + if asList == False: + return " ".join(holecards) + else: + if player == self.hero or len(holecards) == 7: + return holecards + elif len(holecards) <= 4: + #Non hero folded before showdown, add first two downcards + holecards = [u'0x', u'0x'] + holecards + else: + log.warning("join_holecards: # of holecards should be either < 4, 4 or 7 - 5 and 6 should be impossible for anyone who is not a hero") + log.warning("join_holcards: holecards(%s): %s" %(player, holecards)) + return holecards + class Pot(object):