So for now I have written a simple Tic tac toe game. I haven't even used all the functions I made but here is my question: How can I determine if the player places a 1 or 2 where there already is one, I think I know how to do this, but how can I then put them back at the "Input your number" prompt if they enter an illegal character or they try to overwrite an already placed 1 or 2.
Also is there a more compact way to do this?
Here is the code for the game:
nr = [0,0,0,0,0,0,0,0,0]
keepGoing = True
def checkP1():
if nr[0] and nr[1] and nr[2] or nr[3] and nr[4] and nr[5] or nr[6] and nr[7] and nr[8] or nr[0] and nr[3] and \
nr[6] or nr[1] and nr[4] and nr[7] or nr[2] and nr[5] and nr[8] or nr[0] and nr[4] and nr[8] or nr[2] and nr[4] and nr[6] == 1:
print("P1 Wins")
keepGoing = False
return keepGoing
def checkP2():
if nr[0] and nr[1] and nr[2] or nr[3] and nr[4] and nr[5] or nr[6] and nr[7] and nr[8] or nr[0] and nr[3] and \
nr[6] or nr[1] and nr[4] and nr[7] or nr[2] and nr[5] and nr[8] or nr[0] and nr[4] and nr[8] or nr[2] and nr[4] and nr[6] == 2:
print("P2 Wins")
keepGoing = False
return keepGoing
def Game():
while keepGoing:
PrintBoard()
in1 = 0
in2 = 0
in1 = input("Please enter the number of the position you want to put your symbol P1.")
nr[int(in1)-1] = 1
check = checkP1()
if check == 0:
PrintBoard()
break
in2 = input("Please enter the number of the position you want to put your symbol P2.")
check = checkP2()
if check == 0:
PrintBoard()
break
nr[int(in2)-1] = 2
def PrintBoard():
print("",nr[0],nr[1],nr[2],"\n",nr[3],nr[4],nr[5],"\n",nr[6],nr[7],nr[8])
def Reset():
nr = [0,0,0,0,0,0,0,0,0]
keepGoing = True