-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathterminal state check.cpp
59 lines (59 loc) · 1.27 KB
/
terminal state check.cpp
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
char check(board b)
{
for(int i=0;i<3;i++)
{
int count=0;
for(ll j=0;j<3;j++)
{
if(b.arr[i][j]=='X')
count++;
}
if(count==3)
return 'X';
count=0;
for(ll j=0;j<3;j++)
{
if(b.arr[i][j]=='O')
count++;
}
if(count==3)
return 'O';
count=0;
for(ll j=0;j<3;j++)
{
if(b.arr[j][i]=='O')
count++;
}
if(count==3)
return 'O';
count=0;
for(ll j=0;j<3;j++)
{
if(b.arr[j][i]=='X')
count++;
}
if(count==3)
return 'X';
}
if(b.arr[0][0]=='X' && b.arr[1][1]=='X' && b.arr[2][2]=='X')
return 'X';
if(b.arr[0][0]=='O' && b.arr[1][1]=='O' && b.arr[2][2]=='O')
return 'O';
if(b.arr[0][2]=='X' && b.arr[1][1]=='X' && b.arr[2][0]=='X')
return 'X';
if(b.arr[0][2]=='O' && b.arr[1][1]=='O' && b.arr[2][0]=='O')
return 'O';
int count=0;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(b.arr[i][j]=='-')
count++;
}
}
if(count==0)
return 'D';
else
return '-';
}