-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtictactoe.py
More file actions
113 lines (96 loc) · 2.24 KB
/
tictactoe.py
File metadata and controls
113 lines (96 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
for _ in range(int(input())):
arr=[0]*3
arr[0]= input()
arr[1]= input()
arr[2]= input()
X_=0
O_=0
__=0
row_wise=0
X_count=0
O_count=0
for i in range(3):
word= arr[i]
for i in range(3):
if word[i]=="X":
X_+=1
X_count+=1
elif word[i]=="O":
O_+=1
O_count+=1
elif word[i]=="_":
__+=1
if X_count==3 or O_count==3:
row_wise+=1
# print("X_count = ", X_count, "O_count = ", O_count)
X_count=0
O_count=0
if abs(X_ - O_)>1 or (row_wise>=2 ):
print("3")
continue
for i in range(3):
if arr[0][i]=="X":
X_count+=1
if arr[0][i]=="O":
O_count+=1
if arr[1][i]=="X":
X_count+=1
if arr[1][i]=="O":
O_count+=1
if arr[2][i]=="X":
X_count+=1
if arr[2][i]=="O":
O_count+=1
if X_count==3 or O_count==3:
row_wise+=1
X_count=0
O_count=0
if (row_wise>=2 ):
print("3")
continue
#for i in range(1):
if arr[0][0]=="X":
X_count+=1
if arr[0][0]=="O":
O_count+=1
if arr[1][1]=="X":
X_count+=1
if arr[1][1]=="O":
O_count+=1
if arr[2][2]=="X":
X_count+=1
if arr[2][2]=="O":
O_count+=1
if X_count==3 or O_count==3:
row_wise+=1
X_count=0
O_count=0
#for i in range(1):
if arr[0][2]=="X":
X_count+=1
if arr[0][2]=="O":
O_count+=1
if arr[1][1]=="X":
X_count+=1
if arr[1][1]=="O":
O_count+=1
if arr[2][0]=="X":
X_count+=1
if arr[2][0]=="O":
O_count+=1
if X_count==3 or O_count==3:
row_wise+=1
X_count=0
O_count=0
# print("row_wise = ", row_wise)
if (row_wise>=2):
print("3")
continue
if row_wise==1:
print("1")
continue
if __==0:
print("1")
continue
if __>0:
print("2")