-
Notifications
You must be signed in to change notification settings - Fork 0
/
Batman and Tick-tack-toe
205 lines (205 loc) · 6.02 KB
/
Batman and Tick-tack-toe
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include<stdio.h>
int main()
{
int i,j,k=0,chance,n,t,x,dot,o,m;
char arr[4][4];
scanf("%d",&t);
int arr2[t];
for(m=0;m<t;m++)
arr2[t]=0;
for(m=0;m<t;m++)
{
x=0,dot=0,o=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
scanf("%c",&arr[i][j]);
if(arr[i][j]=='x')
x++;
else if(arr[i][j]=='.')
dot++;
else
o++;
}
}
if(x<=o)
chance=1;//1 represents x's turn
else
chance=0;//0 reprsents o's turn
if(chance==1)
{
i=0;
//first we are gonna check columnwise
k=0;//k is basically the parameter that decides whether or not the arrangement will be favourable
for(j=0;j<4;j++)
{
while(arr[i][j]!='o' && i<4)
{
if(arr[i][j]=='x')
k++;
k++;
i++;
}
if(k>=5)//i wrote 5 because there must be 3 spaces and 2 'x's to win
{
arr2[m]=1;//1 represents that we have YES
break;
}
else
k=0;
}
//now we'll check row wise
if(k==0)
{
j=0;
for(i=0;i<4;i++)
{
while(arr[i][j]!='o' && j<4)
{
if(arr[i][j]=='x')
k++;
k++;
j++;
}
if(k>=5)
{
arr2[m]=1;//1 represents that we have YES
break;
}
else
k=0;
}
}
//now we'll check diagonally
if(k==0)
{
i=0,j=0;
{
while(arr[i][j]!='o' && j<4 && i<4)
{
if(arr[i][j]=='x')
k++;
k++;
j++,i++;
}
if(k>=5)
{
arr2[m]=1;//1 represents that we have YES
break;
}
else
k=0;
}
if(k==0){
i=4,j=0;
while(arr[i][j]!='o' && j<4 && i<4)
{
if(arr[i][j]=='x')
k++;
k++;
j++,i--;
}
if(k>=5)
{
arr2[m]=1;//1 represents that we have YES
break;
}
else
k=0;
}
}
}
else
{
i=0;
//first we are gonna check columnwise
k=0;
int temp1=i,temp2=j;
for(j=0;j<4;j++)
{
while(arr[i][j]!='x' && i<4)
{
if(arr[i][j]=='o')
k++;
k++;
i++;
}
if(k>=5)
{
arr2[m]=1;//1 represents that we have YES
break;
}
else
k=0;
}
//now we'll check row wise
if(k==0)
{
j=0;
for(i=0;i<4;i++)
{
while(arr[i][j]!='x' && j<4)
{
if(arr[i][j]=='o')
k++;
k++;
j++;
}
if(k>=5)
{
arr2[m]=1;//1 represents that we have YES
break;
}
else
k=0;
}
}
//now we'll check diagonally
if(k==0)
{
i=0,j=0;
{
while(arr[i][j]!='x' && j<4 && i<4)
{
if(arr[i][j]=='o')
k++;
k++;
j++,i++;
}
if(k>=5)
{
arr2[m]=1;//1 represents that we have YES
break;
}
else
k=0;
}
if(k==0){
i=4,j=0;
while(arr[i][j]!='x' && j<4 && i<4)
{
if(arr[i][j]=='o')
k++;
k++;
j++,i--;
}
if(k>=5)
{
arr2[m]=1;//1 represents that we have YES
break;
}
else
k=0;
}
}
}
}
for(m=0;m<t;m++)
{
if(arr2[m]==1)
printf("YES\n");
else
printf("NO\n");
}
}