60 lines
1.1 KiB
C++
60 lines
1.1 KiB
C++
#include "Strategy.h"
|
|
#include <cstring>
|
|
using namespace std;
|
|
|
|
int N;
|
|
vector<vector<int>> B;
|
|
int ctl[2][15];
|
|
|
|
void initStrategy(int n, const std::vector<std::vector<int>> &board) {
|
|
N = n;
|
|
B = board;
|
|
memset(ctl, 0, sizeof(ctl));
|
|
}
|
|
|
|
std::tuple<int, int> getMove(int lstX, int lstY) {
|
|
if (lstX != -1) {
|
|
ctl[0][B[lstX][lstY]] += 1;
|
|
int t = B[lstX][lstY];
|
|
if (ctl[0][B[lstX][lstY]] >= (N + 1) / 2) {
|
|
for (int i = 0; i < N; ++i) {
|
|
for (int j = 0; j < N; ++j) {
|
|
if (B[i][j] == t)
|
|
B[i][j] = -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
B[lstX][lstY] = -1;
|
|
}
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
for (int j = 0; j < N; ++j) {
|
|
bool flag = false;
|
|
if (i == 0 || i == N - 1 || j == 0 || j == N - 1)
|
|
flag = true;
|
|
if (flag || B[i - 1][j] == -1 || B[i + 1][j] == -1
|
|
|| B[i][j - 1] == -1 || B[i][j + 1] == -1)
|
|
flag = true;
|
|
|
|
if (flag && B[i][j] != -1) {
|
|
ctl[1][B[i][j]] += 1;
|
|
|
|
if (ctl[1][B[i][j]] >= (N + 1) / 2) {
|
|
int t = B[i][j];
|
|
for (int i = 0; i < N; ++i) {
|
|
for (int j = 0; j < N; ++j) {
|
|
if (B[i][j] == t)
|
|
B[i][j] = -1;
|
|
}
|
|
}
|
|
}
|
|
B[i][j] = -1;
|
|
return {i, j};
|
|
}
|
|
}
|
|
}
|
|
return {-1, -1};
|
|
}
|
|
|