#include "vision.h"
#include <bits/stdc++.h>
using namespace std;

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

int getMove1d(vector<int> v)
{
    if(v.size()==3){
        if(v[0]>v[2]) return 0;
        else return 2;
    }
    if(v.size()==5){
        if(v[0]>v[4]) return 0;
        else return 4;
    }
    if(v.size()==7){
        if(v[1]>v[5]) return 6;
        else return 0;
    }
    return 0;
}

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

pair<int,int> check(vector<vector<int> > v){
    int ful=v.size();
    int hal=v.size()/2;
    for(int i=0;i<ful;i++){
        for(int j=0;j<ful;j++){
            if(v[i][j]>v[hal][hal]) return {i,j};
        }
    }
    if(ful==3) return {0,1};
    if(v[2][0]==2 and v[0][3]==2 and v[4][4]==2) return {4,4};
    if(v[0][1]==2 and v[4][1]==2 and v[1][4]==2) return {4,1};
    if(v[0][0]==2 and v[3][4]==2) return {4,4};
    if(v[1][0]==2 and v[2][4]==2) return {2,4};
    if(v[0][3]==2 and v[3][4]==2) return {3,4};
    if(v[0][0]==2 and v[4][1]==2 and v[2][4]==1) return {4,1};
    if(v[3][0]==2 and v[4][4]==2) return {4,4};
    if(v[1][0]==2 and v[4][3]==2) return {4,3};
    return {-1,-1};
}
vector<vector<int> > flipx(vector<vector<int> > v){
    int sz=v.size();
    for(int i=0;i<sz/2;i++){
        for(int j=0;j<sz;j++){
            swap(v[i][j],v[sz-1-i][j]);
        }
    }
    return v;
}
vector<vector<int> > flipy(vector<vector<int> > v){
    int sz=v.size();
    for(int i=0;i<sz;i++){
        for(int j=0;j<sz/2;j++){
            swap(v[i][j],v[i][sz-1-j]);
        }
    }
    return v;
}
pair<int, int> getMove2d(vector<vector<int> > v)
{
    int ful=v.size();
    int hal=v.size()/2;
    pair<int,int> a = check(v);
    if(a!=make_pair(-1,-1)) return a;
    v=flipx(v);
    a = check(v);
    if(a!=make_pair(-1,-1)) return {ful-1-a.first,a.second};
    v=flipy(v);
    a = check(v);
    if(a!=make_pair(-1,-1)) return {ful-1-a.first,ful-1-a.second};
    v=flipx(v);
    a = check(v);
    if(a!=make_pair(-1,-1)) return {a.first,ful-1-a.second};
    return {0,0};
}