-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.cpp
58 lines (51 loc) · 992 Bytes
/
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
#include <iostream>
using namespace std;
bool check(bool o[9], bool x[9], int d, string *first, string *second) {
int z = 0;
bool b = 0;
for (int i = 0; i < 9; i += 3) {
if (o[i] && o[i + 1] && o[i + 2]) {
b = 1;
z = 1;
}
if (x[i] && x[i + 1] && x[i + 2]) {
b = 1;
z = 2;
}
}
for (int i = 0; i < 3; i++) {
if (o[i] && o[i + 3] && o[i + 6]) {
b = 1;
z = 1;
}
if (x[i] && x[i + 3] && x[i + 6]) {
b = 1;
z = 2;
}
}
for (int i = 0; i < 2; i++) {
int k = 4 - 2 * i;
int j = 2 * i;
if (o[j] && o[j + k] && o[j + 2 * k]) {
b = 1;
z = 1;
}
if (x[j] && x[j + k] && x[j + 2 * k]) {
b = 1;
z = 2;
}
}
if (b == 1) {
if (z == 1) {
cout << *first << " wins\n";
} else if (z == 2) {
cout << *second << " wins\n";
}
return true;
}
if (b == 0 && d == 9) {
cout << "It's a draw\n";
return true;
}
return false;
}