#include "vision.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> getVisionPattern1d()
{
    return {3, 2, 1, 1};
}

int getMove1d(std::vector<int> v)
{
    int po = (int)v.size() / 2;
    if (po != 1){
        int go = po - 1;
        if (go == 0) go = 3;
        if (v[po + 1] == go) return po + 1;
        else return po - 1;
    }
    else{
        if (v[po + 1] % 3 < v[po - 1] % 3) return po + 1;
        return po - 1;
    }
}

std::vector<std::vector<int>> getVisionPattern2d()
{
    return {{3, 1, 1}, {1, 2, 1}, {1, 1, 1}};
}
int po;
vector<vector<int>> al;
int check(int x, int y){
    if (al[x][y] != 2) return -1;
    int cnt = 0;
    for (int i = -1; i <= 1; i++){
        for (int j = -1; j <= 1; j++){
            if (abs(i) + abs(j) != 1) continue;
            if (x + i < 0 || x + i >= 2 * po + 1 || y + j < 0 || y + j >= 2 * po + 1) continue;
            if (al[x + i][y + j] == 2) cnt++;
        }
    }
    return cnt;
}
std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    al = v;
    vector<int> go = {0, 3, 7, 5, 7, 6, 7, 1};
    po = v.size() / 2;
    if (po != 2){
        for (int i = -1; i <= 1; i++){
            for (int j = -1; j <= 1; j++){
                if (v[po + i][po + j] == 2) return {po + i, po + j};
            }
        }
    }
    int d1 = 0, d2 = 0;
    for (int i = -1; i <= 1; i++){
        for (int j = -1; j <= 1; j++){
            if (abs(i) + abs(j) < 2) continue;
            if (v[po + i][po + j] == 3){
                d1 = i, d2 = j;
                d1 = -d1, d2 = -d2;
                return {po + d1 * 2, po + d2 * 2};
            }
        }
    }
    //while (1) po++;
}