0

# How to simplify this Tic Tac Toe program ?

number = 3 matrix = [] for i in range(number): string = input().split() matrix.append(string) if (matrix == "O" and matrix == "O" and matrix == "O") or (matrix == "O" and matrix == "O" and matrix == "O") or (matrix == "O" and matrix == "O" and matrix) == "O": print("Abhinav Wins") elif (matrix == "X" and matrix == "X" and matrix == "X") or (matrix == "X" and matrix == "X" and matrix == "X") or (matrix == "X" and matrix == "X" and matrix) == "X": print("Anjali Wins") elif (matrix == "O" and matrix == "O" and matrix == "O") or (matrix == "O" and matrix == "O" and matrix == "O") or (matrix == "O" and matrix == "O" and matrix == "O"): print("Abhinav Wins") elif (matrix == "X" and matrix == "X" and matrix == "X") or (matrix == "X" and matrix == "X" and matrix == "X") or (matrix == "X" and matrix == "X" and matrix == "X"): print("Anjali Wins") elif (matrix == "O" and matrix == "O" and matrix == "O") or (matrix == "O" and matrix and matrix) == "O": print("Abhinav Wins") elif (matrix == "X" and matrix == "X" and matrix == "X") or (matrix == "X" and matrix and matrix) == "X": print("Anjali Wins") else: print("Tie")

16th Oct 2022, 3:37 PM
PRAVEEN + 1
Yeah there are a lot you can consider to make this more efficient. first, you should have a function to check if the game is finished and has a winning move. a winning game is three repeated character in a row, column or diagonal. so you can loop over each of those and validate if they are all identical I can't add much more right now but I hope this helps!
16th Oct 2022, 6:06 PM
Apollo-Roboto 0  