Esempio n. 1
0
def ask_for_cards() -> bool:
    card = ERROR
    card_already_ownd = 252
    while (card == ERROR) | (card == card_already_ownd):
        if (card != card_already_ownd):
            if player_count > 2:
                print("Who to ask (0 - {0}):".format(player_count - 2))
                asked_player = input_int(player_count - 2)
                if asked_player == ERROR:
                    error_occured()
                    continue
            else:
                asked_player = 0
            if asked_player >= current_player:
                asked_player += 1
        print("Which card are you asking for? (" \
            + HEARTS + " = H | " + SPADES + "︎ = S | " \
            + DIAMONDS + "︎ = D | " + CLUBS + " = C):")
        card = input_cards()
        if (card != ERROR) & (not (card in implementation.player_hands[current_player])):
            return implementation.ask_for_card(current_player, asked_player, card)
        elif (card != ERROR) & (card in implementation.player_hands[current_player]):
            print(COLORS["bell"] + "You already own that card!")
            card = card_already_ownd
        if card == ERROR:
            error_occured()
Esempio n. 2
0
def ask_for_card(player: int) -> bool:
    '''
    Function to let the AI ask for a card_type
    Picks a player at random, then looks what card type it has most of and
    asks for that card.
    Returns True if the asked player had that card.
    '''
    asked_player = 255
    while asked_player != player:
        # picks a random player, which is not the ai itself
        asked_player = randint(0, ui.player_count - 1)
    card_decider = [0] # needed to decide which card type to ask for
    for card_type in range(7, 15):
        card_counter = 0
        for item in range(len(implementation.player_hands[player])):
            if card_type == 11:
                card_type = "J"
            if card_type == 12:
                card_type = "Q"
            if card_type == 13:
                card_type = "K"
            if card_type == 14:
                card_type = "A"
            if str(card_type) in implementation.player_hands[player][item]:
                # counts how often a card type is in the ai's hand
                card_counter += 1
        if card_counter > card_decider[0]:
            # saves the card type that exists the most
            card_decider = [card_counter, card_type]
    cards_to_ask_for = [] # needed to determin which specific card to ask for
    for card_color in ["H", "D", "C", "S"]:
        card = card_color + str(card_type)
        if not card in implementation.player_hands[player]:
            # adds only cards which are not owned by the ai
            cards_to_ask_for.append(card)
    shuffle(cards_to_ask_for)
    # returns one of the cards that could be asked for at random
    return implementation.ask_for_card(player, asked_player, cards_to_ask_for[0])