Aug-14-2020, 10:22 AM
Hi all,
Nice to be here :) I'm brand new to python so please be nice!
I have this 'last one loses' game to do. I cannot, for the life of me, get 1 player to be the computer so basically it's me against the computer. The computer choses a number randomly between 1 & 3. It's based on the game of nim. I have it working so both players require human input, but I want it so 1 is human and 1 is the computer. Any idea where i'm going wrong please?
Nice to be here :) I'm brand new to python so please be nice!
I have this 'last one loses' game to do. I cannot, for the life of me, get 1 player to be the computer so basically it's me against the computer. The computer choses a number randomly between 1 & 3. It's based on the game of nim. I have it working so both players require human input, but I want it so 1 is human and 1 is the computer. Any idea where i'm going wrong please?
#last one loses game #import random module import random #assign random play to the computer computer = (random.randint(1,3)) #set player to false player = False #set initial state state = 0 while state < 10 or state > 51: state = int(input("Enter counter number between 10 and 50 ")) #initial number of counters print ("The number of counters is ", state) #get valid move and set player to True while player == False: if state == 1: print("The computer has taken 1 counter") if state == 2: print("The computer taken 2 counters") if state == 3: print("The computer chosen 3 counters") remainingCounters(state) print("player ",player) while True: move=int(input("How many counters would you like to remove? ")) if move in [1,2,3] and move<state: break print("Please only choose up to 3 counters!") #update state state=state-move #show state print("The remaining number of counters is now ", state) #check win status - win or lose if state == 1: print("Player ",player, " wins!") break #switch players 2->1, 1->2 then go back to valid move line ##if player==1: ## player=2 ## else: ## player=1 print("Game over")