#---------------------------------------------- # Project: Take-Away-Game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys' College # Author: Tristan Olckers # Date: 17/03/2025 # Python: 3.5 #---------------------------------------------- import random #importing functions incase in need import time MAX_CHIPS = 21 #setting starting variables PlayerOneScore = 0 PlayerTwoScore = 0 chipsLeft = 0 chipsTaken = 0 while True: #askiing for player 1's name player_1_name = input("Enter Player 1 name: ") if player_1_name.isalpha(): #input validation time.sleep(1) print("Hello",player_1_name ) break else: print("Invalid name. Please enter letters only. Name cannot contain numbers, special characters or space.") while True: #asking for player 2's name player_2_name = input("Enter Player 2 name: ") if player_2_name.isalpha(): #input validation time.sleep(1) print("Hello",player_2_name ) break else: print("Invalid name. Please enter letters only. Name cannot contain numbers, special characters or space.") while True: #asking for the round limit between 1 and 5 rounds = input("Enter the number of rounds 1-5: ") if rounds.isdigit() and 1 <= int(rounds) <= 5: rounds = int(rounds) time.sleep(0.5) print("Sweet, there will be", rounds, "rounds") time.sleep(0.5) break else: print("Invalid input. Please enter a number between 1 and 5.") while rounds > 0: # resets the chips when there are none left and the round ends chipsLeft = MAX_CHIPS while chipsLeft > 0: print("Chips left:", chipsLeft) while True: #player 1 chooses how many chips to take chipsTaken = input(player_1_name + ", how many chips will you take? 1-3 ") if chipsTaken.isdigit() and 1 <= int(chipsTaken) <= 3 and int(chipsTaken) <= chipsLeft: chipsTaken = int(chipsTaken) break else: print("Invalid, Please choose between 1-3, or no more than the chips left: ", chipsLeft) chipsLeft -= chipsTaken if chipsLeft < 1: #win validation print(player_1_name, "has won the round") PlayerOneScore += 1 break print("Chips left:", chipsLeft) while True: #player 2 chooses how many chips to take chipsTaken = input(player_2_name + ", how many chips will you take? 1-3: ") if chipsTaken.isdigit() and 1 <= int(chipsTaken) <= 3 and int(chipsTaken) <= chipsLeft: chipsTaken = int(chipsTaken) break else: print("Invalid, Please choose between 1-3, or no more than the chips left: ", chipsLeft) chipsLeft -= chipsTaken if chipsLeft < 1: print(player_2_name, "has won the round") PlayerTwoScore += 1 break rounds -= 1 print("Rounds left: ", rounds) if PlayerOneScore > PlayerTwoScore: print(player_1_name, "wins with", PlayerOneScore, "rounds!") elif PlayerTwoScore > PlayerOneScore: print(player_2_name, "wins with", PlayerTwoScore, "rounds!") else: print("It's a tie!")