i am a beginner of using python,and i am doing an project about "Tic-Tac-Toe".
well,the project needs very basci code.....however,i could not get it....
The following conditons are the project requested:
1.When the computer randonm selected a available number,so which means computer doesn have logic....the winner are user.....
2.user and computer can tie...we dont care computer wins.
3.use "List"
:confused:
However,i only can not figure out.....am I stupid??stupid logic??:S
can anyone help me?It is urgent.....:(
Thank you guys!:sweat:
import random
L=['1','2','3','4','5','6','7','8','9']
AL=['1','2','3','4','5','6','7','8','9']
s='-------\n|1|2|3|\n-------\n|4|5|6|\n-------\n|7|8|9|\n-------'
print(s)
u='O'
c='X'
first= random.randint(1,2)
while True:
if first ==1:
uc=input("Enter your number,your number will be changed to sign 'o': ")
L[int(uc)-1]=u
AL.remove(uc)
print(AL)
print(L)
s=s.replace(uc,u)
print(s)
cc=random.randint(0,len(AL)-1)
print("Computer Choice: ",cc)
L[int(cc)-1]=c
AL.remove (AL[cc])
#AL.pop(int(cc)-1)
print(AL)
print(L)
s=s.replace(L[cc],c)
print(s)
else:
cc=random.randint(0,len(AL)-1)
L[int(cc)-1]=c
AL.remove(AL[cc])
print(AL)
s=s.replace(L[cc],c)
print(s)
uc=input("Enter your number,your number will be changed to sign 'o': ")
L[int(uc)-1]=u
AL.remove(int(uc)-1)
print(AL)
s=s.replace(uc,u)
print(s)
if L[0]==L[1]==L[2]:
print("Congraduation!You have won the game!")
break
elif L[3]==L[4]==L[5]:
print("Congraduation!You have won the game!")
break
elif L[6]==L[7]==L[8]:
print("Congraduation!You have won the game!")
break
elif L[0]==L[3]==L[6]:
print("Congraduation!You have won the game!")
break
elif L[1]==L[4]==L[7]:
print("Congraduation!You have won the game!")
break
elif L[2]==L[5]==L[8]:
print("Congraduation!You have won the game!")
break
elif L[0]==L[4]==L[8]:
print("Congraduation!You have won the game!")
break
elif L[2]==L[4]==L[6]:
print("Congraduation!You have won the game!")
break