#include "vision.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;

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

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

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

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    if(v.size()==3){
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(v[i][j]>1) return {i, j};
            }
        }
        return {2, 1};
    }
    //now 2
    if(v[3][2]==2 || v[1][2]==2){
        //If no sides, move to it
        if(v[2][0]==v[2][4] && v[2][0]==1){
            if(v[3][2]==2) return {3, 2};
            if(v[1][2]==2) return {1, 2};
        }
        if(v[2][0]==2) return {2, 0};
        return {2, 4};
    }
    if(v[2][0]==2){
        if(v[3][4]==2) return {3, 4};
        return {1, 4};
    }
    if(v[3][0]==2) return {3, 0};
    return {1, 0};        
}
