from Blackjack import *

def RandomAgent(state):  
    return random.randint(1,2)  ## hit or STAND

def HitAgent(state):  
    return HIT

def StandAgent(state):  
    return STAND

def OptimalAgent(state):  
    bj = Blackjack()

    ## Get a list of your total hand value(s), e.g. [18] or [11 21]
    myHand = bj.Count(state.playerCards)

    ## Returns the int value of the dealer's single showing card,
    ## e.g. 5 for a Five, 10 for Jack-King, 11 for an Ace
    dealerCard = max(bj.Count([state.dealerCards[0]]))

    if len(myHand) > 1:
        ## You have a 'soft' hand (hand containing an ace)
        if max(myHand) >= 19:
            ## Your total is 19 or 20 (aces can be worth 1 or 11)
            return STAND
        elif max(myHand) == 18 and dealerCard <= 8:
            return STAND
    else:
        myHand = myHand[0]

        if myHand >= 17:
            return STAND
        elif myHand >= 13 and dealerCard <= 6:
            return STAND
        elif myHand == 12 and dealerCard >= 4 and dealerCard <= 6:
            return STAND

    return HIT