4conq/Strategy/Strategy.cpp
szdytom 02eadae4ca
Add framework
Signed-off-by: szdytom <szdytom@qq.com>
2024-01-30 20:46:18 +08:00

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]] >= 4) {
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]] >= 4) {
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};
}