#include "vision.h"
#include <iostream>
#include <set>
using namespace std;

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

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

std::vector<std::vector<int>> getVisionPattern2d()
{
    return {
        {2, 1, 1, 3},
        {1, 1, 3, 2},
        {1, 3, 2, 1},
        {3, 2, 1, 1}
    };
}

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{   
    int idy = v.size() / 2;
    int idx = v[0].size() / 2;
    pair <int, int> ans = {idy, idx};

    [&]()->void {
        vector <int> a (v[0].size());
        for (int i = 0; i < v[0].size(); i++)
            a[i] = v[idy][i];
        ans.second = getMove1d (a);
    }();

    if (v[idy][idx] == 3)
        [&]()->void {
            vector <int> a (v.size());
            for (int i = 0; i < v.size(); i++)
                a[i] = v[i][idx];
            ans.first = getMove1d (a);
        }();

    return ans;
}
