""" ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Project: Take Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Nate Blackwell Date: 03/03/25 Python: 3.5 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- This game allows for 2 players to play a chip based game. The first player to insert there name will always start on the first round, alternating between even and odd rounds. The players are faced with the option to take from 1, 2 or 3 chips from a pile of 21. As chips dwindle down the player to take the last chip will gain a point. The amount of rounds are chosen by the player/s between 1 - 5 allowing for total domination, small wins or possible ties. The code is structured by importing features, defining variables / asking the player for input variables. This is quickly followed by the main section of the code where it inputs the actual game using while loops ensuring the game continues until they meet there maxed rounds chosen. The game then used greater than and less than features. I encountered multiple problems such as making my code wrong by giving the player who took the last chip not a point and the other person, dealing with while loops and other small bugs. Multiple limitations were found during the game such as, the first player to pick there chips will nearly always win as well with a very boring and repetitive game in general. I believe fixes for this may be made by using import random, random.randint for chips to create a more fair and stable game. Also you could randomise who starts and implement a feature where you could have more than 2 people if wanted to creating a more havoc game. Also having a AI feature to play against if you dont have any friends. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- """ from time import * from random import * import sys, os, random #To make my code print letter by letter making it look cool. def text_typer(List, Delay): print() for string in List: for letter in string: print(letter, end="",flush=True) sleep(Delay) sleep(1)#waits for a certain amount of time given by the value in the brakets return "" #inputs to choose two names of our players while True: try: Prounds = int(input(text_typer("how many rounds do you want to play? ", 0.05))) except ValueError: #if the number is not a number it'll tell you to try again text_typer("The input is not an suitable.", 0.05) else: #if number is a number then it'll keep going with the other code break while True: Text = ["Enter a name for player one: "] #allows me to print this string of letters again in a print using less code ext = ["Enter a name for player two: "] #allows me to print this string of letters again in a print using less code name1 = input(text_typer([Text[0]],0.05)) #Alowing player one to choose a name name2 = input(text_typer([ext[0]],0.05)) #Alowing player two to choose a name if name1.isalpha() and name2.isalpha() == True: break else: text_typer("That name is not suitable it cannont have numbers or special charectors in it. \nAnd now both of you need to re enter your names\n\n", 0.05) #values to make sure our fail safes work P1 = 0 P2 = 0 player = 1 Nmbertrue = 0 #Messages to make sure we can use them over and over without writing it multiple times thng = f"-"*7, name1, "-"*7 win = f"Congrats ", name1, " You win!!!!!" thng2 = f"-"*7, name2, "-"*7 win2 = f"Congrats ", name2, " You win!!!!!" #Loop to make sure we have a winner best out of two while P1 != Prounds and P2 != Prounds: MAXCHIPS = 21 #making the chips reaset to 21 player = 1 #making it start on player one every time #Loup to start every round while MAXCHIPS != 0: #to change player each turn. if player %2==0: text_typer(thng2,0.05) #To print the players name player += 1 else: text_typer(thng,0.05) #To print the players name player += 1 #To ask what amount we want to take away and to make sure it's in range Nmbertrue=0 while Nmbertrue != 1: #To make sure my number is a number not a letter while True: try: Nmber =["Enter a number between 1 and 3 "] take = int(input(text_typer([Nmber[0]], 0.05))) #asking for you to input a number except ValueError: #if the number is not a number it'll tell you to try again text_typer("The input is not an suitable.", 0.05) else: #if number is a number then it'll keep going with the other code break if MAXCHIPS - take <0 and 4> take and take >= 1: #If the number you take would make the amount of chips left less than zero it'll not let it text_typer("Sorry we can't let it go negitive. \nTry again", 0.05) elif 4> take and take >= 1: #if number is in the range we give it'll carry on with the code Nmbertrue = 1 break else: #if number is not in the range we give it'll tell them to change it text_typer("That is not in range \nTry again", 0.05) #To change how many chips there are after taking them away MAXCHIPS -= take #to make sure that my code never goes negitive and to change players after every turn if MAXCHIPS <= 0: MAXCHIPS == 0 #as a fail safe to make sure he amount of chips equal zero at the end of the round print("There are:",MAXCHIPS, "chip(s) remaining") player -=1 if player %2==0: text_typer(win2,0.05) P2 += 1 else : text_typer(win,0.05) P1 += 1 if P1 != 2 and P2 != 2: #To make sure the plyers haven't player more than the allowed games scores = (f"The scores are \n {name1} : {P1} \n {name2} : {P2}") #allows the players to see the score at the end of a round text_typer(scores, 0.05) break else: break else: print("There are:",MAXCHIPS, "chip(s) remaining") #To show how many chips are remaining #end print to see who wins scores = (f"-------The final scores are------- \n {name1} : {P1} \n {name2} : {P2}") text_typer(scores, 0.05)