"""
Ch8 Q5(b)
Monte Carlo card game
Straigt Flush
"""

def card():
    import numpy as np
    result =[]
    suit = ["S","H","D","C"]
    rank = ["A","2","3","4","5","6","7","8","9","T","J","Q","K"]
    
    for i in suit:
        for j in rank:
            result.append(i+j)
    output = []
    while len(output) <5:
        pick = np.random.choice(result)
        result.remove(pick)
        output.append(pick)
        
    return output

# the above function is from part(a)

hand = card()
print(hand)

def flush_straight(hand):
    rank = ["A","2","3","4","5","6","7","8","9","T","J","Q","K"]
    flush = True
    straight = False
    
    #check for flush
    for i in range(1,len(hand)):
        if hand[i][0] != hand[0][0]:
            flush = False
    #check for straight
    order = [] #Start a list to store numerical values of the cards
    for i in range(0,len(hand)):
        order.append(rank.index(hand[i][1])) #list.index() tells the location in the list
        order.sort() #sort the list in an asending order
        
    if order[4]-order[3]==1 & order[3]-order[2]==1 & order[2]-order[1]==1 & order[1]-order[0]==1:
        straight = True   #This takes care of any ordinary straight
    if order[0]==0 & order[4]==12 & order[3]==11 & order[2]==10 & order[1]==9:
        straight = True  #This takes care of AKQJT
            
            
    if flush and straight:
        return True
    else:
        return False
    
print(flush_straight(hand))
        




            

