Exemplo n.º 1
0
def get_straight(straights: List[Card_Deck.Card], cards: Card_Deck, greater: bool=True) -> List[Card_Deck.Card]:
    """Get 5 consecutive cards in a deck with a given card

    Args:
        straights (List[Card_Deck.Card]): first card
        cards: (List[Card_Deck.Card]): deck of card
        greater (bool, optional): whether to get bigger or lower consecutive numbers. Defaults to True.

    Returns:
        Card_Deck: a list of consecutive numbers
    """
    if greater:
        while len(straights) <= 5:
            current_count = straights[-1].value + 1
            for idx, card in enumerate(cards.cards):
                if card.value == current_count:
                    straights.append(card)
                    break
    else:
        while len(straights) <= 5:
            if straights[0].value == 1:
                current_count = 13
            else:
                current_count = straights[-1].value - 1
            for idx, card in enumerate(cards.cards):
                if card.value == current_count:
                    straights.append(card)
                    break
    for _ in range(2):
        straights.append(cards.deal())
Exemplo n.º 2
0
    def get_straight(self,
                     straights: List[Card_Deck.Card],
                     cards: Card_Deck,
                     greater: bool = True) -> List[Card_Deck.Card]:
        """Get 7 cards that consist of 5 consecutive cards in a deck with a given card

        Args:
            straights (List[Card_Deck.Card]): first card
            cards: (List[Card_Deck.Card]): deck of card
            greater (bool, optional): whether to get bigger or lower consecutive numbers. Defaults to True.

        Returns:
            Card_Deck: a list of consecutive numbers
        """
        current_value = straights[0].value
        if 13 - current_value <= 4:
            max_val = 13
        else:
            max_val = current_value + 5
        if current_value - 4 <= 0:
            min_val = 0
        else:
            min_val = current_value - 4
        initial_value_to_pick = np.random.randint(min_val, max_val, 1)[0]
        if initial_value_to_pick > current_value:
            values_to_pick = list(
                range(initial_value_to_pick - 4, initial_value_to_pick + 1))
            logger.debug(f"Lower pick from: {values_to_pick}")
            straights = [
                cards.Card(x, np.random.choice(list(cards.SUITS.keys())))
                for x in values_to_pick
            ]
        else:
            values_to_pick = list(
                range(initial_value_to_pick, initial_value_to_pick + 5))
            logger.debug(f"Higher pick from: {values_to_pick}")
            straights = [
                cards.Card(x, np.random.choice(list(cards.SUITS.keys())))
                for x in values_to_pick
            ]
        while len(straights) < 7:
            potential_card = cards.deal()
            if potential_card.value not in values_to_pick:
                straights.append(potential_card)
                values_to_pick.append(potential_card.value)
        return straights
Exemplo n.º 3
0
def get_same_suits(same_suits: List[Card_Deck.Card], cards: Card_Deck)-> List[Card_Deck.Card]:
    """Return a list that contains five cards of the same suit

    Args:
        same_suits (List[Card_Deck.Card]): list that contain the first card
        cards (Card_Deck): deck of cards

    Returns:
        List[Card_Deck.Card]: list that contain at least 5 cards of the same suit
    """
    first_suit: str = same_suits[0].suit
    while len(same_suits) < 5:
        for idx, card in enumerate(cards.cards):
            if card.suit == first_suit:
                same_suits.append(card)
    for _ in range(2):
        same_suits.append(cards.deal())
    return same_suits