import random # variables turns = 0 active_card = "" chosen_card = "" player_hand = [] cpu_hand1 = [] cpu_hand2 = [] cpu_hand3 = [] play_turn = 1 skipped = False reverse = False skipped_turns = False pickup = 0 plus_two = False plus_four = False deck = [ "red 0", "red 1", "red 1", "red 2", "red 2", "red 3", "red 3", "red 4", "red 4", "red 5", "red 5", "red 6", "red 6", "red 7", "red 7", "red 8", "red 8", "red 9", "red 9", "yellow 0", "yellow 1", "yellow 1", "yellow 2", "yellow 2", "yellow 3", "yellow 3", "yellow 4", "yellow 4", "yellow 5", "yellow 5", "yellow 6", "yellow 6", "yellow 7", "yellow 7", "yellow 8", "yellow 8", "yellow 9", "yellow 9", "green 0", "green 1", "green 1", "green 2", "green 2", "green 3", "green 3", "green 4", "green 4", "green 5", "green 5", "green 6", "green 6", "green 7", "green 7", "green 8", "green 8", "green 9", "green 9", "blue 0", "blue 1", "blue 1", "blue 2", "blue 2", "blue 3", "blue 3", "blue 4", "blue 4", "blue 5", "blue 5", "blue 6", "blue 6", "blue 7", "blue 7", "blue 8", "blue 8", "blue 9", "blue 9", "blue reverse","green reverse","blue reverse","green reverse","yellow reverse","red reverse","yellow reverse", "red reverse", "blue +2","green +2","blue +2","green +2","yellow +2","red +2","yellow +2", "red +2", "blue skip","green skip","blue skip","green skip","yellow skip","red skip","yellow skip", "red skip", "wild card", "wild card", "wild card", "wild card", "wild +4", "wild +4", "wild +4", "wild +4" ] # I put the fun in dysfunctional (functions) def rules(): while True: rules = input("would you like to read the rules?").lower() if rules in ("yes", "y"): instructions() break elif rules in ("no", "n"): print("Okay then") print("") break else: print("Please answer with either yes or no") continue def instructions(): print(" RULES") print("its uno go read uno rules fool") def deal(player, number): for i in range(number): player.append(deck[random.randint(0, len(deck) - 1)]) def start_game(cards_deal): global active_card active_card = (deck[random.randint(0, len(deck) - 33)]) deal(player_hand, cards_deal) deal(cpu_hand1, cards_deal) deal(cpu_hand2, cards_deal) deal(cpu_hand3, cards_deal) def int_check_cards_dealt(value1, value2): error = f"please enter an integer between {value1} & {value2}." while True: try: response = int(input(f"How many cards would you like to be dealt? (pick between {value1} and {value2})")) if response < value1 or response > value2: print(error) else: return response except ValueError: print(error) def player_choose_card(): global active_card global chosen_card global reverse global skipped global pickup global plus_four global plus_two print("It's your turn") print(f"Current card: {active_card}") print("") print(" Your hand:") print(player_hand) print("") while True: chosen_card = input("What card would you like to play, or type draw to pickup if you can't play any: ").lower() print(chosen_card) split_chosen_card = chosen_card.split(" ") split_active_card = active_card.split(" ") if chosen_card in player_hand: #check if card is the right colour if split_chosen_card[0] == split_active_card[0] or split_chosen_card[1] == split_active_card[1]: if split_chosen_card[1] == "reverse": reverse = not reverse elif split_chosen_card[1] == "skip": skipped = True elif split_chosen_card[1] == "+2": pickup +=2 plus_two = True else: pass print(f"you chose a {chosen_card}") active_card = chosen_card player_hand.remove(chosen_card) break #checks if the card is wild elif chosen_card == "wild card": while True: wild_colour = input("What colour would you like the wild card to be?").lower() if wild_colour in ["red", "blue", "green", "yellow"]: active_card_split = [wild_colour, "wild"] active_card = " ".join(active_card_split) player_hand.remove(chosen_card) break else: print("please answer with a colour (red, yellow, green, blue)") continue break elif chosen_card == "wild +4": pickup += 4 plus_four = True wild_colour = input("What colour would you like the wild card to be?").lower() while True: if wild_colour in ["red", "blue", "green", "yellow"]: active_card_split = [wild_colour, "wild"] active_card = " ".join(active_card_split) player_hand.remove(chosen_card) break else: print("please answer with a colour (red, yellow, green, blue)") continue break else: print(f"You can't play this card on a {active_card}. Please pick another card") continue elif chosen_card == "draw": print("You drew one card, here is your hand now:") print("") deal(player_hand, 1) print(player_hand) break else: print("Please enter the name of one of your cards, or draw") continue def cpu_choose_card(cpu_hand_num): global active_card global reverse global skipped global pickup global plus_four global plus_two active_card_split = active_card.split(" ") valid_cards = [] #cpu_choose card for i in range(len(cpu_hand_num)): cpu_card_split = cpu_hand_num[i].split(" ") if cpu_card_split[0] == active_card_split[0]: valid_cards.append(cpu_hand_num[i]) elif cpu_card_split[1] == active_card_split[1]: valid_cards.append(cpu_hand_num[i]) elif cpu_card_split[0] == "wild": valid_cards.append(cpu_hand_num[i]) #checks if the cpu can play any cards & then plays a card from the set it can play if len(valid_cards) >= 1: cpu_chosen_card = valid_cards[random.randint(0, len(valid_cards) - 1)] cpu_chosen_card_split = cpu_chosen_card.split(" ") cpu_hand_num.remove(cpu_chosen_card) if cpu_chosen_card_split[0] == "wild" and cpu_chosen_card_split[1] == "card": cpu_wild_list = ["red", "green", "yellow", "blue"] cpu_wild = cpu_wild_list[random.randint(0, len(cpu_wild_list) - 1)] cpu_chosen_card = f"{cpu_wild} wild" #print played card print(f"Player {play_turn} chose a wild card and changed the colour to {cpu_wild}") active_card = cpu_chosen_card elif cpu_chosen_card_split[0] == "wild" and cpu_chosen_card_split[1] == "+4": #plus four bit pickup += 4 plus_four = True #wild card part cpu_wild_list = ["red", "green", "yellow", "blue"] cpu_wild = cpu_wild_list[random.randint(0, len(cpu_wild_list) - 1)] cpu_chosen_card = f"{cpu_wild} +4" #print played card print(f"Player {play_turn} chose a wild +4 and changed the colour to {cpu_wild}") active_card = cpu_chosen_card elif cpu_chosen_card_split[1] == "reverse": #print played card print(f"Player {play_turn} chose a {cpu_chosen_card}") #changes reverse to true/false depending on what it was active_card = cpu_chosen_card reverse = not reverse elif cpu_chosen_card_split[1] == "skip": print(f"Player {play_turn} chose a {cpu_chosen_card}") print("the next players turn is skipped") active_card = cpu_chosen_card skipped = True elif cpu_chosen_card_split[1] == "+2": pickup +=2 plus_two = True print(f"Player {play_turn} chose a {cpu_chosen_card}") active_card = cpu_chosen_card else: print(f"Player {play_turn} chose a {cpu_chosen_card}") active_card = cpu_chosen_card else: print(f"Player {play_turn} drew a card") deal(cpu_hand_num, 1) if cpu_hand_num == 1: print(f"Player {play_turn} has uno") print(f"They now have {len(cpu_hand_num)} cards left") print("") def skipped_turn(): global skipped_turns if skipped_turns: pass else: input("press enter to go to the next turn") print("") def cpu_skip(cpu_hand): #checks if the cpu was skipped then plays their turn global skipped global play_turn if skipped: print(f"Player {play_turn} was skipped") skipped = False else: cpu_choose_card(cpu_hand) def player_pickup(chosen_card, player_hand): global plus_four global plus_two global pickup global active_card allowed_cards = ["green +2", "red +2", "blue +2", "yellow +2", "wild +4"] if plus_four: print("the player before you played a +4.") print("") print(f"your hand:") print(player_hand) while True: pickup_ans = "" pickup_ans = input(f"would you like to play a +4 to make the next person draw, or draw {pickup} cards?").lower() if pickup_ans in ["yes", "y", "+4", "wild +4"]: if "wild +4" in player_hand: player_hand.remove("wild +4") pickup += 4 while True: colour = input("you played a +4, what colour would you like it to be?").lower() if colour in ["red", "yellow", "blue", "green"]: active_card = f"{colour} +4" break else: print("Please enter a colour, out of Red, Yellow, Blue, and Green") continue break else: print("You don't have that in your hand") continue elif pickup_ans in "n" "no" "draw" "pickup" "pick up": deal(player_hand, pickup) print("") print(f"you drew {pickup} cards") pickup = 0 plus_four = False plus_two = False break else: print("Please type yes or pickup to play") elif plus_two: print("the player before you played a +2.") print("") print(f"your hand:") print(player_hand) print("") while True: pickup_ans = "" pickup_ans = input(f"would you like to play a +2 or +4 to make the next person draw, or draw {pickup} cards?").lower() if pickup_ans in "n" "no" "draw" "pickup" "pick up": deal(player_hand, pickup) print("") print(f"you drew {pickup} cards") pickup = 0 plus_four = False plus_two = False break elif pickup_ans in player_hand and pickup_ans in allowed_cards: pickup_ans = chosen_card split_chosen_card = chosen_card.split(" ") split_active_card = active_card.split(" ") if split_chosen_card[1] == "+2": player_hand.remove(chosen_card) print(f"you played a {chosen_card}") break elif split_chosen_card[1] == "+4": player_hand.remove("wild +4") pickup += 4 plus_four = True while True: colour = input("you played a +4, what colour would you like it to be?").lower() if colour in ["red" "yellow" "blue" "green"]: active_card = f"{colour} +4" break else: print("Please enter a colour, out of Red, Yellow, Blue, and Green") continue break else: print("Please enter one of your cards, or pickup to draw") continue # im pr loopy (regular game loop) print("Welcome to UNO") print("") #checks if the player want to read the rules rules() #checks if the player enters an integer between 5-10 cards_dealt = int_check_cards_dealt(5, 10) print("dealing out the cards...") #calls start game function start_game(cards_dealt) #space print("") while True: # Checks whose turn it is if play_turn == 1: #player turn if len(player_hand) > 1: pass elif len(player_hand) > 0: print("you have UNO") if skipped: print("Your turn was skipped") skipped = False elif plus_four or plus_two: player_pickup(chosen_card, player_hand) else: player_choose_card() #asks if the player wants to skip turns skipped_turns = False while True: skip_logic = input("Would you like to watch the other players turns? (yes/no) ").lower() if skip_logic in ("yes", "y"): skipped_turns = False break elif skip_logic in ("no", "n"): skipped_turns = True break else: print("Please answer with either yes or no") continue print("") if reverse: play_turn = 4 else: play_turn += 1 elif play_turn == 2: #cpu 1 turn cpu_skip(cpu_hand1) if reverse: play_turn += -1 else: play_turn += 1 skipped_turn() elif play_turn == 3: #cpu 2 turn cpu_skip(cpu_hand2) skipped_turn() if reverse: play_turn += -1 else: play_turn += 1 elif play_turn == 4: #cpu 3 turn cpu_skip(cpu_hand3) skipped_turn() if reverse: play_turn += -1 else: play_turn = 1 else: for i in range(256): print("game loop error type shi") exit()