I'm trying to compare list's so that it will play TocTacToe till someone wins how ever when one of the columns, rows, or diagonals(or what ever u want to call them) is filled with 1's or 2's it does exit even though the while loop is only supposed to run while the columns and rows don't equal 1,1,1 or 2,2,2.
My code:
import random
import sys
import os
import time
clear = lambda: os.system('cls')
clear()
pWin = [1, 1, 1]
cWin = [2, 2, 2]
bV = ["1","2","3","4","5","6","7","8","9"]
squares = [0,0,0,0,0,0,0,0,0]
s1 = squares[0]
s2 = squares[1]
s3 = squares[2]
s4 = squares[3]
s5 = squares[4]
s6 = squares[5]
s7 = squares[6]
s8 = squares[7]
s9 = squares[8]
c1 = [s1,s4,s7]
c2 = [s2,s5,s7]
c3 = [s3,s6,s9]
r1 = [s1,s2,s3]
r2 = [s4,s5,s6]
r3 = [s7,s8,s9]
d1 = [s1,s5,s9]
d2 = [s3,s5,s7]
test = 4
board1 = [bV[0], bV[1], bV[2]]
board2 = [bV[3], bV[4], bV[5]]
board3 = [bV[6], bV[7], bV[8]]
while c1 or c2 or c3 or r1 or r2 or r3 or d1 or d2 != pWin or cWin:
clear()
skip = 0
choiceComplete = 0
nC = 0
print(c1)
print(c2)
print(c3)
print(r1)
print(r2)
print(r3)
print(d1)
print(d2)
print(pWin)
print(cWin)
while nC <= 8:
if squares[nC] == 1:
bV[nC] = "X"
nC = nC + 1
elif squares[nC] == 2:
bV[nC] = "O"
nC = nC + 1
elif squares[nC] == 0:
nC = nC + 1
board1 = [bV[0], bV[1], bV[2]]
board2 = [bV[3], bV[4], bV[5]]
board3 = [bV[6], bV[7], bV[8]]
print(board1)
print(board2)
print(board3)
uChoice = int(raw_input("Your turn, choose a spot: "))
'''
uChoice = test
'''
cN = uChoice - 1
if squares[cN] == 0:
squares[cN] = 1
elif squares[cN] == 1 or 2:
print("Sorry, that square has already been chosen.")
time.sleep(2)
skip = 1
if skip == 0:
while choiceComplete == 0:
cChoice = random.randrange(1,10)
gN = cChoice - 1
if squares[gN] == 0:
squares[gN] = 2
choiceComplete = 1
s1 = squares[0]
s2 = squares[1]
s3 = squares[2]
s4 = squares[3]
s5 = squares[4]
s6 = squares[5]
s7 = squares[6]
s8 = squares[7]
s9 = squares[8]
c1 = [s1,s4,s7]
c2 = [s2,s5,s7]
c3 = [s3,s6,s9]
r1 = [s1,s2,s3]
r2 = [s4,s5,s6]
r3 = [s7,s8,s9]
d1 = [s1,s5,s9]
d2 = [s3,s5,s7]
'''
test = test + 1
'''
if c1 or c2 or c3 or r1 or r2 or r3 or d1 or d2 == pWin:
print("You Won!")
if c1 or c2 or c3 or r1 or r2 or r3 or d1 or d2 == pWin:
print("You lost!")
The part I'm talking about:
while c1 or c2 or c3 or r1 or r2 or r3 or d1 or d2 != pWin or cWin:
P.S. As you can tell I'm very new to coding, I started 2 days ago, so any constructive criticism on my code is greatly appreciated.
No comments:
Post a Comment