#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 {{1, 2, 3}, {4, 5, 6}, {5, 7, 3}};
}
std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    vector<int> go = {0, 5, 6, 1, 7, 7, 7, 3};
    int po = v.size() / 2;
    if (po == 3){
        int iss = 0;
        for (int i = -1; i <= 1; i++){
            for (int j = -1; j <= 1; j++){
                if (abs(i) + abs(j) != 1) continue;
                if (v[po + i][po + j] == 7) iss = 1;
            }
        }
        if (iss == 0){
            for (int i = -1; i <= 1; i++){
                for (int j = -1; j <= 1; j++){
                    if (abs(i) + abs(j) == 0) continue;
                    if (v[po + i][po + j] == 6) return {po + i, po + j};
                }
            }
        }
    }
    for (int i = -1; i <= 1; i++){
        for (int j = -1; j <= 1; j++){
            if (abs(i) + abs(j) == 0) continue;
            if (v[po + i][po + j] == go[po]) return {po + i, po + j};
        }
    }
    while (1) po++;
}
