示例#1
0
def get_cards_grouped_by_value(hand):
    card_groups = {}
    for card in hand:
        card_value = cardGame.getCardValue(card, ACE_HIGH)
        if card_value not in card_groups:
            card_groups[card_value] = [card]
        else:
            card_groups[card_value].append(card)
    return card_groups
示例#2
0
def get_straight_from_hand(hand):
    hand_copy = hand.copy()
    hand_has_two_card = cardGame.doesHandContainValue(hand, 2)
    # if hand has a two card then treat Ace has low card to check for straight
    if hand_has_two_card:
        cardGame.sortHandByRank(hand_copy, aceHigh=False)
        last_card_value = cardGame.getCardValue(hand_copy[0], aceHigh=False)
    else:
        cardGame.sortHandByRank(hand_copy, ACE_HIGH)
        last_card_value = cardGame.getCardValue(hand_copy[0], ACE_HIGH)

    for i in range(1, len(hand)):
        card_value = cardGame.getCardValue(hand_copy[i], ACE_HIGH)
        if not card_value == last_card_value + 1:
            return ()  # if no straight don't return any cards
        last_card_value = card_value

    return tuple(hand_copy)
示例#3
0
def getNextLowerAndUpperCard(suit, cards):
    """ Gets the next lower and highest card.
        Assumes cards are sorted from lowest to highest value
        Return list """
    if len(cards) == 0:
        return None
    cardsToReturn = []
    lowestCard = cards[0]
    highestCard = cards[-1]
    lowestCardValue = cardGame.getCardValue(lowestCard, ACE_HIGH)[1:]
    # don't add a lower card if one doesn't exist
    if lowestCardValue > 1:
        cardsToReturn.append(
            cardGame.convertCardToRank(suit + str(lowestCardValue - 1)))
    highestCardValue = cardGame.getCardValue(highestCard, ACE_HIGH)
    # don't add a higher card if one doesn't exist
    if highestCardValue < 13:
        cardsToReturn.append(
            cardGame.convertCardToRank(suit + str(highestCardValue + 1)))
    return cardsToReturn
示例#4
0
def get_card_value_from_list_of_cards(group):
    # get first card from group - all cards in group have same value
    return cardGame.getCardValue(group[0], ACE_HIGH)
示例#5
0
def get_higher_card(card_one, card_two):
    card_one_value = cardGame.getCardValue(card_one, ACE_HIGH)
    card_two_value = cardGame.getCardValue(card_two, ACE_HIGH)
    return card_one if card_one_value >= card_two_value else card_two