def find_high_card(cards):
    PokerCard.cardsRank(cards)
    try:
        return cards[0:5]
    except:
        print("No Cards in the List")
        return []
def find_straight(cards):
    PokerCard.cardsRank(cards)
    #hasStraight = False
    StraightList = []
    prevCard = cards[0]
    StraightList.append(prevCard)
    for card in cards[1:]:

        #check if current one is next to prevCard
        if prevCard - card > 1:
            # current one is more than 2 notch less, straight is broken
            StraightList = []
            StraightList.append(card)
        elif prevCard - card == 1:
            StraightList.append(card)
        else:
            #same rank, skip
            pass

        prevCard = card

        if len(StraightList) == 5:
            #found the fifth one
            #hasStraight = True
            return StraightList

        if ((len(StraightList) == 4) & (StraightList[0].rank == '5') &
            (cards[0].rank == '1')):
            StraightList.append(cards[0])
            return StraightList

    return []
def find_two_pairs(cards):
    """
    Find best two pairs + one highest ranked cards

    Parameters
    ----------
    cards : TYPE
        DESCRIPTION.

    Returns
    -------
    pairsHeads : TYPE
        DESCRIPTION.

    """
    PokerCard.cardsRank(cards)
    PairsList = []

    try:
        prevCard = cards[0]
    except:
        return []

    PairsList.append(prevCard)

    for card in cards[1:]:

        #check if current one is next to prevCard
        if prevCard - card == 0:
            PairsList.append(card)
            break
        else:
            PairsList = []
            PairsList.append(card)

        prevCard = card

    AnotherPairs = []
    if len(PairsList) == 2:
        prevCard = cards[0]
        for card in cards[1:]:
            if ((prevCard - card == 0) & (card - PairsList[0] != 0)):
                AnotherPairs.append(prevCard)
                AnotherPairs.append(card)
                break
            else:
                prevCard = card

    TwoPairs = []
    TwoPairs = TwoPairs + PairsList + AnotherPairs

    if len(TwoPairs) == 4:
        for card in cards:
            if ((card - PairsList[0] != 0) & (card - AnotherPairs[0] != 0)):
                TwoPairs.append(card)
                break

        return TwoPairs
    else:
        return []
def find_set(cards):
    """
    Find best three cards with same rank + two highest ranked cards

    Parameters
    ----------
    cards : TYPE
        DESCRIPTION.

    Returns
    -------
    TYPE
        DESCRIPTION.

    """
    PokerCard.cardsRank(cards)
    SetList = []

    try:
        prevCard = cards[0]
    except:
        return []

    SetList.append(prevCard)

    for card in cards[1:]:

        #check if current one is next to prevCard
        if prevCard - card == 0:
            SetList.append(card)
        else:
            SetList = []
            SetList.append(card)

        prevCard = card

        if len(SetList) == 3:
            break

    if len(SetList) == 3:
        for card in cards:
            if card - SetList[0] != 0:
                SetList.append(card)

            if len(SetList) == 5:
                return SetList

        return []
    else:
        return []
def find_pair(cards):
    """
    Find best pair of cards + three highest ranked cards

    Parameters
    ----------
    cards : TYPE
        DESCRIPTION.

    Returns
    -------
    prevCard : TYPE
        DESCRIPTION.

    """
    PokerCard.cardsRank(cards)
    PairsList = []

    try:
        prevCard = cards[0]
    except:
        return []

    PairsList.append(prevCard)

    for card in cards[1:]:

        #check if current one is next to prevCard
        if prevCard - card == 0:
            PairsList.append(card)
            break
        else:
            PairsList = []
            PairsList.append(card)

        prevCard = card

    if len(PairsList) == 2:
        for card in cards:
            if card - PairsList[0] != 0:
                PairsList.append(card)

            if len(PairsList) == 5:
                return PairsList

        return []
    else:
        return []
def find_straight_flush(cards):
    """
    Find Straight Flush

    Parameters
    ----------
    cards : TYPE
        DESCRIPTION.

    Returns
    -------
    SFList : TYPE
        DESCRIPTION.

    """
    PokerCard.cardsRankBySuitRank(cards)
    SFList = []
    prevCard = cards[0]
    SFList.append(prevCard)
    for card in cards[1:]:

        #check if current one is next to prevCard
        if ((prevCard == card) and (prevCard - card == 1)):
            SFList.append(card)
        else:
            SFList = []
            SFList.append(card)

        prevCard = card

        if len(SFList) == 5:
            #found the Set
            return SFList

    index = 0
    while ((len(SFList) == 4) & (SFList[0].rank == '5') &
           (cards[index].rank == '1') & (index < len(cards))):
        if (cards[index] == SFList[0]):
            SFList.append(cards[index])
            return SFList
        else:
            index = index + 1

    return []
def find_quad(cards):
    """
    Find best quads + one high card

    Parameters
    ----------
    cards : TYPE
        DESCRIPTION.

    Returns
    -------
    QuadList : TYPE
        DESCRIPTION.

    """
    PokerCard.cardsRank(cards)
    QuadList = []
    prevCard = cards[0]
    QuadList.append(prevCard)
    for card in cards[1:]:

        #check if current one is next to prevCard
        if prevCard - card != 0:
            QuadList = []
            QuadList.append(card)
        else:
            QuadList.append(card)

        prevCard = card

        if len(QuadList) == 4:
            #found the Set
            break

    if len(QuadList) == 4:
        for card in cards:
            if card - QuadList[0] != 0:
                QuadList.append(card)
                return QuadList
    else:
        return []
def find_flush(cards):
    PokerCard.cardsRankBySuitRank(cards)
    FlushList = []
    prevCard = cards[0]
    FlushList.append(prevCard)
    for card in cards[1:]:

        #check if current one is next to prevCard
        if prevCard == card:
            FlushList.append(card)
        else:
            FlushList = []
            FlushList.append(card)

        prevCard = card

        if len(FlushList) == 5:
            #found the Set
            return FlushList

    return []