""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Seth Morrison Date: THE DATE YOU COMPLETED THE CODE Python: 3.5 ------------------------------------------------- """ #Players get to input there names. while True: opponent1 = input("What is Player 1's name? ") if opponent1.isalpha(): break print("That is not an acceptable name, please try again.") while True: opponent2 = input("What is Player 2's name? ") if opponent2.isalpha(): break print("That is not an acceptable name, please try again.") #players pick how many rounds they want to play. while True: try: num_rounds = int(input("How many rounds do you want to play? (1-5): ")) if 1 <= num_rounds <= 5: break print("Please choose a number between 1 and 5.") except ValueError: print("You didn't even put in a number, how am I supposed to process that bro?") #The Loop, Tells python how many chip to takeaway from base value and when to change round. def play_round(opponent1, opponent2): cookies = 21 turn = 0 print("Starting round with", cookies, "cookies.") while cookies > 0: current_player = opponent1 if turn % 2 == 0 else opponent2 print("\n", current_player, "'s turn. Cookies remaining:", cookies) while True: try: take = int(input(current_player + ", take (1-3 cookies): ")) if 1 <= take <= min(3, cookies): break except ValueError: pass print("Invalid choice. Try again.") cookies -= take turn += 1 # Switch turns winner = opponent1 if turn % 2 != 0 else opponent2 #Tells the Ai if 1 player has 2 wins to stop the game. print("\n", winner, "wins the round!") return winner #Tells us what the scores are. scores = {opponent1: 0, opponent2: 0} for round_num in range(1, num_rounds + 1): print("\n--- Round", round_num, "---") winner = play_round(opponent1, opponent2) scores[winner] += 1 print("Score:", opponent1, "-", scores[opponent1], ",", opponent2, "-", scores[opponent2]) #Finnish of game, tells the player who won. print("\nGame Over!") print("Final Score:", opponent1, "-", scores[opponent1], ",", opponent2, "-", scores[opponent2]) if scores[opponent1] != scores[opponent2]: print(max(scores, key=scores.get), "is the overall winner!") else: print("It's a tie!")