Changeset 3 for hand.py

Show
Ignore:
Timestamp:
01/22/08 19:39:53 (4 years ago)
Author:
mike
Message:

added some permutation function and some checking on hands

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • hand.py

    r2 r3  
     1import deck 
     2 
     3 
     4#for all these functions, make sure cards are sorted DESCENDING!!!! 
     5 
     6def is_n_kinds(cards): 
     7    highest_n = 0    #greatest num in a row 
     8    current_n = 0 
     9    highest_card = None  #highest card for greatest num in a row 
     10    last = 1 
     11    for (a,b) in cards[1:] 
     12 
     13def is_flush(cards): 
     14    last=cards[0][1] 
     15    flush = True 
     16    for (a,b) in cards[1:]: 
     17        if b != last: 
     18            flush = False 
     19            break 
     20    if flush: return ["flush", cards[0][0]] #return highest card 
     21    else: return None 
     22 
     23def is_straight(cards): 
     24    last=cards[0][0] 
     25    straight = True 
     26    for (a,b) in cards[1:]: 
     27        if a != last-1: 
     28            straight = False 
     29            last = a 
     30            break 
     31    if straight: return ["straight", cards[0][0]] #return highest card 
     32    else: return None 
     33 
     34 
    135def combNoReplace(cards, n): 
    236    if n==0: yield [] 
     
    438        for i in xrange(len(cards)-n+1): 
    539            for cc in combNoReplace(cards[i+1:],n-1): 
     40                #Aces can have 2 values 
     41                if cards[i]==deck.cards.index("A"): yield [-1]+cc 
    642                yield [cards[i]]+cc 
    743 
    8  
    9 def permutations( set, n ): 
    10     if n==0: yield [] 
    11     else: 
    12         for i in xrange(len(items)): 
    13             for ss in selections(items, n-1): 
    14                 yield [items[i]]+ss 
    15