""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Shia Abdul-Coley Date: 17/03/2025 Python: 3.5 ------------------------------------------------- This program plays a takeaway game. The program asks how many players are amongst them, name themselves, tell how many rounds they would like to play, and then the game starts. The game consists of you taking 1~3 "chips" from a pile of 21. The winner of that round is the player that takes the last one (the 21st one), leaving none remaining in the pile. This code allows for players to customize their experience a lot, allowing them to state how many players, as opposed to a standard game where you are limited to two. The main caveat with this game is that Player 1 in a 2 player game is always guaranteed to win. They can accomplish this by always aiming to change the chip amount to a multiple of 4, securing the win. There is no way to circumvent this flaw, as the only solution, that being changing the number of chips to an unknown number, would defeat the purpose of the game, therefore not being a sufficient solution. Despite this disadvantage, this game is very fun if people do not realize this specific strategy, allowing for a fun experience from all players. ------------------------------------------------- """ # Import libraries and define variables/constants import time currentround = 0 players = [] wins = [] winner = [] MAX_CHIPS = 21 # Basic greeting print("Hello!") time.sleep(1) # Input number of players while True: try: playercount = int(input("How many players will be playing? (2+) ")) if playercount < 2: print("Invalid number!") else: break except: print("Invalid input!") # Name the players, puts all players (and their win counts) in an array for i in range(playercount): # Checks if the name is taken or not while True: player = str(input(f"Player {i + 1}'s name? ")) if player in players: print("That name is already taken!") else: break # Appends the player name to an array, along with their number of wins that is to be changed laters players.append(player) wins.append(0) # Input number of rounds while True: try: rounds = int(input("Greetings fellow players. How many rounds would you like to play of this game? (1-5) ")) if rounds < 1 or rounds > 5: print("Invalid number!") else: break except: print("Invalid input!") # Start of game loop while currentround < rounds: # Sets up the round currentround += 1 turn = 0 chips = MAX_CHIPS # Start of round loop while chips > 0: # Increases the turn count by 1, sets the current player turn += 1 currentplayer = players[(turn - 1) % playercount] # Input takeaway while True: try: takeaway = int(input(f"\nPlayer {currentplayer}'s turn\n{chips}/{MAX_CHIPS} chips left\nHow much would you like to takeaway? (1-3) ")) if takeaway < 1 or takeaway > 3: print("Invalid number!") elif takeaway > chips: print("You took more than what was offered. How do you act when you come across a bowl on Halloween with a sign that says 'take one candy'? It's a small test of your character, isn't it? The temptation to take more is often strong, especially when you feel no one is watching. But what does that say about you? Do you follow the rules, or do you give in to the urge for more, knowing that it's a moment that could go unnoticed? It’s a simple choice, but it reflects something much bigger about your integrity and respect for boundaries, even when they seem insignificant.") turn += 1 currentplayer = players[(turn - 1) % playercount] time.sleep(5) else: break except: print("Invalid input!") # Takes the input away from the total amount of chips chips -= takeaway # States winner and gives them a win print(f"\nRound {currentround} winner: {currentplayer}") wins[(turn - 1) % playercount] += 1 # Calculates winner based off wins, and sends the winner(s) to an array for i in range(playercount): if wins[i] == max(wins): winner.append(players[i]) # Adds suspense for the winner print("\nThe winner is...") time.sleep(1) # Prints the winner(s), if there is a draw, all winners get added to an array and are printed one by one, otherwise, the sole winner is shown as a string for i in winner: print(i) time.sleep(1) # Shows the number of wins the winner(s) had, exits the program once done print(f"\nWho had {max(wins)} win(s)!") time.sleep(2) exit()