#include "vision.h"
#include "bits/stdc++.h"

#define pb push_back

using namespace std;

vector<int> getVisionPattern1d()
{
    return {1, 2, 2, 1, 1, 2};
}

int getMove1d(std::vector<int> v) {
    int n = v.size();

    if (n == 3) {
        for (int i = 0; i < n; i++) {
            if (v[i] == 2) {
                return i;
            }
        }
    }
    else {
        vector<int> v1{2, 1, 2, 2, 1}, v2{1, 2, 2, 1, 1}, v3{1, 1, 2, 1, 2};

        if (v == v1 || v == v2 || v == v3) {
            return 4;
        }
        else {
            return 0;
        }
    }
}

vector<std::vector<int>> getVisionPattern2d() {
    vector<int> v(getVisionPattern1d());

    int n = v.size();

    vector<vector<int>> ret(n);

    for (int i = 0; i < n; i++) {
        ret[i] = v;

        rotate(v.begin(), v.begin() + 1, v.end());
    }

    return ret;
}

pair<int, int> getMove2d(std::vector<std::vector<int>> v) {
    int n = v.size();

    if (n == 3) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (v[i][j] == 2) {
                    return {i, j};
                }
            }
        }
    }

    int x, y;

    {
        vector<int> a;

        for (int i = 0; i < n; i++) {
            a.pb(v[i][n / 2]);
        }

        x = n - getMove1d(a) - 1;
    }

    {
        vector<int> a;

        for (int j = 0; j < n; j++) {
            a.pb(v[n / 2][j]);
        }

        y = getMove1d(a);
    }

    return {x, y};
}
