#include "vision.h"
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

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

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

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

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    int n = v.size() - 1, m = v[0].size() - 1;
    int mid = (v.size() - 1) / 2;
    if(v[mid] == 1)
    {
        if(v[mid][mid - 1] == 2)
        {
            if(v[mid - 1][mid] == 2) return {0, m};
            else return {n, m};
        }
        else if(v[mid + 1][mid] == 2)
        {
           return {n, 0};
        }
        else if (v[mid][mid + 1] == 2)
        {
            return {0, 0};
        }

        if(v[mid][mid - 1] == 3)
        {
            if(v[mid - 1][mid] == 3) return {0, m};
            else return {n, m};
        }
        else if(v[mid + 1][mid] == 3)
        {
           return {n, 0};
        }
        else if (v[mid][mid + 1] == 3)
        {
            return {0, 0};
        }
    }
    else if(v[mid] == 2)
    {
        if(v[mid][mid - 1] == 3)
        {
            if(v[mid - 1][mid] == 3) return {0, m};
            else return {n, m};
        }
        else if(v[mid + 1][mid] == 3)
        {
           return {n, 0};
        }
        else if (v[mid][mid + 1] == 3)
        {
            return {0, 0};
        }
    }
    else
    {
        if(v[mid][mid - 1] == 1)
        {
            if(v[mid - 1][mid] == 1) return {0, m};
            else return {n, m};
        }
        else if(v[mid + 1][mid] == 1)
        {
           return {n, 0};
        }
        else if (v[mid][mid + 1] == 1)
        {
            return {0, 0};
        }
    }
}
}
