-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtictactoe-2.py
More file actions
148 lines (131 loc) · 3.18 KB
/
tictactoe-2.py
File metadata and controls
148 lines (131 loc) · 3.18 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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
O_jeeta= False
X_jeeta = False
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:
row_wise+=1
X_jeeta = True
if O_count==3:
row_wise+=1
O_jeeta= True
X_count=0
O_count=0
row_mein_khushi= row_wise
if O_jeeta and X_ != O_:
print("3")
continue
if X_jeeta and X_ - O_ != 1:
print(3)
continue
if (X_ - O_)>1 or (X_ - O_)<0:
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 :
row_wise+=1
X_jeeta = True
if O_count==3:
row_wise+=1
O_jeeta=True
X_count=0
O_count=0
coloumn_mein_khushi= row_wise - row_mein_khushi
if (O_jeeta and X_ != O_) or (X_jeeta and X_ - O_ != 1):
print("3")
continue
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:
row_wise+=1
X_jeeta = True
if O_count==3:
row_wise+=1
O_jeeta=True
X_count=0
O_count=0
if (O_jeeta and X_ != O_) or (X_jeeta and X_ - O_ != 1):
print("3")
continue
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 :
row_wise+=1
X_jeeta = True
if O_count==3:
row_wise+=1
O_jeeta=True
X_count=0
O_count=0
if (O_jeeta and X_ != O_) or (X_jeeta and X_ - O_ != 1):
print("3")
continue
diagnol_mein_khushi = row_wise - (row_mein_khushi + coloumn_mein_khushi)
if row_mein_khushi>1 or coloumn_mein_khushi>1:
print("3")
continue
if coloumn_mein_khushi==1 or row_mein_khushi==1:
print("1")
continue
if diagnol_mein_khushi==2 or diagnol_mein_khushi==1:
print("1")
continue
if row_wise==1:
print("1")
continue
if __==0:
print("1")
continue
else:
print("2")