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

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

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

vector<vector<int>> getVisionPattern2d()
{
    return {{3,4,5},{2,2,2},{1,1,1}};
}

pair<int, int> getMove2d(vector<vector<int>> v)
{
    int n=(v[0].size()-1)/2;
    int curr=v[n][n];
    if(curr==1)
    {
        if(v[n][n+1]==2)return {n,n+1};//r
        if(v[n][n-1]==2)return {n,n-1};//l
        if(v[n-1][n]==2)return {n-1,n};//u
        return {n+1,n};//d
    }
    else if(curr==2)
    {
        if(v[n][n+1]==3)return {n,n+1};//r
        if(v[n][n-1]==3)return {n,n-1};//l
        if(v[n-1][n]==3)return {n-1,n};//u
        return {n+1,n};//d
    }
    else if(curr==3)
    {
        if(v[n][n+1]==4)return {n,n+1};//r
        if(v[n][n-1]==4)return {n,n-1};//l
        if(v[n-1][n]==4)return {n-1,n};//u
        return {n+1,n};//d
    }
    else if(curr==4)
    {
        if(v[n][n+1]==5)return {n,n+1};//r
        if(v[n][n-1]==5)return {n,n-1};//l
        if(v[n-1][n]==5)return {n-1,n};//u
        return {n+1,n};//d
    }
    else
    {
        pair<int,int> get1;
        if(v[n][n+1]==3)get1={n,n+1};//r
        else if(v[n][n-1]==3)get1={n,n-1};//l
        else if(v[n-1][n]==3)get1={n-1,n};//u
        else get1={n+1,n};//d

        int x=get1.first,y=get1.second;
        if(v[x][y+1]==1)return {x,y+1};//r
        if(v[x][y-1]==1)return {x,y-1};//l
        if(v[x-1][y]==1)return {x-1,y};//u
        return {x+1,y};//d
    }
    return {0, 0};
}