-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathP18992_ca_Othello.cc
57 lines (46 loc) · 1.73 KB
/
P18992_ca_Othello.cc
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
#include <bits/stdc++.h>
using namespace std;
bool recorre(const int& x, const int& y, vector<string>& taulell, const char& fitxa, const pair<int, int>& dir, int& blanques, int& negres, bool first=true) {
int n = taulell.size();
if (x < 0 or y < 0 or x >= n or y >= n) return false;
if (first) return recorre(x+dir.first, y+dir.second, taulell, fitxa, dir, blanques, negres, false);
if (taulell[x][y] == fitxa) return true;
if (taulell[x][y] == '.') return false;
if (recorre(x+dir.first, y+dir.second, taulell, fitxa, dir, blanques, negres, false)) {
if (fitxa=='B') ++blanques, --negres, taulell[x][y]='B';
else ++negres, --blanques, taulell[x][y]='N';
return true;
} else return false;
}
int main () {
const vector<pair<int, int> > direccions = {
{-1, -1}, {-1, 0}, {-1, 1},
{0, -1}, {0, 1},
{1, -1}, {1, 0}, {1, 1}};
int n;
cin >> n;
vector<string> taulell (n, string(n, '.'));
int negres=2, blanques=2;
taulell[n/2][n/2-1] = taulell[n/2-1][n/2] = 'N';
taulell[n/2][n/2] = taulell[n/2-1][n/2-1] = 'B';
for (int i=0; i < n; ++i) {
for (int j=0; j < n; ++j) cout << taulell[i][j];
cout << endl;
}
cout << negres << ':' << blanques << endl << endl;
char fitxa;
int x, y;
while(cin >> fitxa >> x >> y) {
--x, --y;
taulell[x][y] = fitxa;
(fitxa == 'B')? ++blanques : ++negres;
for (const auto& dir: direccions) {
recorre(x, y, taulell, fitxa, dir, blanques, negres);
}
for (int i=0; i < n; ++i) {
for (int j=0; j < n; ++j) cout << taulell[i][j];
cout << endl;
}
cout << negres << ':' << blanques << endl << endl;
}
}