Changeset 4

Show
Ignore:
Timestamp:
01/22/08 20:41:20 (4 years ago)
Author:
mike
Message:

added pair, full house, straight, and flush checking, now just need to add comparison algos

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • hand.py

    r3 r4  
    33 
    44#for all these functions, make sure cards are sorted DESCENDING!!!! 
    5  
    6 def 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:] 
    125 
    136def is_flush(cards): 
     
    3225    else: return None 
    3326 
     27def is_n_kinds(cards): 
     28    highest_n = 1   #greatest num in a row 
     29    current_n = 1 
     30    highest_card = None  #highest card for greatest num in a row 
     31    last = cards[0][0] 
     32    for (a,b) in cards[1:]: 
     33        if a == last: 
     34            current_n += 1 
     35            if current_n > highest_n: 
     36                highest_n = current_n 
     37                highest_card = a 
     38    if highest_n == 1: return ["high"]+cards 
     39    #check for full house 
     40    elif highest_n == 2: 
     41        #this is the hand withotu the pairs 
     42        whats_left = [x for x in cards if x != highest_card] 
     43        #now check if it's two pair 
     44        ret = is_n_kinds(whats_left) 
     45 
     46        #if the subset is a pair then this is a two pair 
     47        if ret[0] == "pair": return ["two_pair",highest_card]+ret[1:]  
     48        else: return ["pair",highest_card]+whats_left 
     49    elif highest_n == 3: 
     50        whats_left = [x for x in cards if x != highest_card] 
     51        #now check if it's a full house 
     52        ret = is_n_kinds(whats_left) 
     53        if ret[0] == "pair": return ["full_house",highest_card]+ret[1:]  
     54        #well, it's just a 3 of a kind then 
     55        else: return ["three_of_a_kind",highest_card]+whats_left 
     56    elif highest_n == 4: 
     57        whats_left = [x for x in cards if x != highest_card] 
     58        return ["four_of_a_kind",highest_card]+whats_left 
     59    #we shouldn't get to this point 
     60    assert(False) 
    3461 
    3562def combNoReplace(cards, n):