Changeset 22

Show
Ignore:
Timestamp:
02/04/08 08:53:57 (11 months ago)
Author:
mike
Message:

Added hand formatting for text output

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • hand.py

    r21 r22  
    1111                "straight_flush" ] 
    1212 
    13 #def format_hand(hand): 
     13def format_hand(hand): 
     14    #TODO add Ace support 
     15    kickers  = [deck.CARDS[c] for c in hand[1] if c >= 0] 
     16    name = HAND_ORDERS(hand[0]) 
     17    if name == "high_card": 
     18        return "high card (%s) with kickers (%s)" % (kickers.pop(0),kickers) 
     19    elif name == "pair": 
     20        return "pair of (%s)'s with kickers (%s)" % (kickers.pop(0),kickers) 
     21    elif name == "two_pair": 
     22        return "two pair of (%s)'s and (%s)'s with kickers (%s)" % (kickers.pop(0),kickers.pop(0),kickers) 
     23    elif name == "four_of_a_kind": 
     24        return "four of a kind (%s) with kickers (%s)" % (kickers.pop(0),kickers) 
     25    elif name == "three_of_a_kind": 
     26        return "three of a kind (%s) with kickers (%s)" % (kickers.pop(0),kickers) 
     27    elif name == "flush": 
     28        return "flush with high card (%s)" % (kickers.pop(0)) 
     29    elif name == "straight_flush": 
     30        return "straight flush with high card (%s)" % (kickers.pop(0)) 
     31    elif name == "straight": 
     32        return "straight with high card (%s)" % (kickers.pop(0)) 
     33    elif name == "full_house": 
     34        return "full house with (%s) over (%s)" % (kickers.pop(0),kickers.pop(0)) 
     35    else: return "???" 
     36 
     37 
    1438#input all 7 cards 
    1539def best_hand(cards): 
  • holdemtable.py

    r21 r22  
    138138            hands.sort(cmp = lambda a,b: cmp(a[1],b[1])) 
    139139            winner = hands.pop() 
    140             print "%s winds the hand with %s" % (winner[0], hand.HAND_ORDERS[winner[1][0]]) 
     140            print "%s withs with %s" % (winner[0],hand.format_hand(winner[1])) 
    141141 
    142142