Advertisement
Spocoman

05. Tic-Tac-Toe

Jan 24th, 2022
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. Решение с матрица:
  2.  
  3. matrix = []
  4. for i in range(3):
  5.     matrix.append(input().split())
  6.  
  7. if matrix[0][0] == matrix[0][1] == matrix[0][2] == '1' \
  8.         or matrix[1][0] == matrix[1][1] == matrix[1][2] == '1' \
  9.         or matrix[2][0] == matrix[2][1] == matrix[2][2] == '1' \
  10.         or matrix[0][0] == matrix[1][0] == matrix[2][0] == '1' \
  11.         or matrix[0][1] == matrix[1][1] == matrix[2][1] == '1' \
  12.         or matrix[0][2] == matrix[1][2] == matrix[2][2] == '1' \
  13.         or matrix[0][0] == matrix[1][1] == matrix[2][2] == '1' \
  14.         or matrix[0][2] == matrix[1][1] == matrix[2][0] == '1': print("First player won")
  15.  
  16. elif matrix[0][0] == matrix[0][1] == matrix[0][2] == '2' \
  17.         or matrix[1][0] == matrix[1][1] == matrix[1][2] == '2' \
  18.         or matrix[2][0] == matrix[2][1] == matrix[2][2] == '2' \
  19.         or matrix[0][0] == matrix[1][0] == matrix[2][0] == '2' \
  20.         or matrix[0][1] == matrix[1][1] == matrix[2][1] == '2' \
  21.         or matrix[0][2] == matrix[1][2] == matrix[2][2] == '2' \
  22.         or matrix[0][0] == matrix[1][1] == matrix[2][2] == '2' \
  23.         or matrix[0][2] == matrix[1][1] == matrix[2][0] == '2': print("Second player won")
  24. else:
  25.     print("Draw!")
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement