Oct-12-2019, 10:13 AM
I am coding tic tac toe with lists (not 2d lists, this project was suggested by my teacher) and I want to go above and beyond, so I want to optimize my program as much as possible.
Right now, the part of the program that sticks out like a sore thumb, the checker.
Here is the code
If anyone can point me in the right direction, that would be great! Thanks in advance.
Right now, the part of the program that sticks out like a sore thumb, the checker.
Here is the code
def check(): #will check if Player One/Two has won R1CX = Row1.count("X") #side check R2CX = Row2.count("X") R3CX = Row3.count("X") R1CO = Row1.count("O") R2CO = Row2.count("O") R3CO = Row3.count("O") if R1CX == 3 or R2CX == 3 or R3CX == 3: print("X Wins!") if R1CO == 3 or R2CO == 3 or R3CO == 3: print("O Wins!") if Row1[2] == "X" and Row2[1] == "X" and Row3[0] == "X": #dia check print("X Wins!") if Row1[0] == "X" and Row2[1] == "X" and Row3[2] == "X": print("X Wins!") if Row1[2] == "O" and Row2[1] == "O" and Row3[0] == "O": print("O Wins!") if Row1[0] == "O" and Row2[1] == "O" and Row3[2] == "O": print("O Wins!") if Row1[0] == "X" and Row2[0] == "X" and Row3[0] == "X": #upanddown check print("X Wins!") if Row1[1] == "X" and Row2[1] == "X" and Row3[1] == "X": print("X Wins!") if Row1[2] == "X" and Row2[2] == "X" and Row3[2] == "X": print("X Wins!") if Row1[0] == "O" and Row2[0] == "O" and Row3[0] == "O": print("O Wins!!") if Row1[1] == "O" and Row2[1] == "O" and Row3[1] == "O": print("O Wins!") if Row1[2] == "O" and Row2[2] == "O" and Row3[2] == "O": print("O Wins!")By using count I saved myself a few lines but I don't think there is any way to check across lists (again, I have to use regular lists)
If anyone can point me in the right direction, that would be great! Thanks in advance.