#include "vision.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;

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

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

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

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    int n = v.size();
    int m = v[0].size();
    if(n*m==9)
    {
        for(int i = 0; i < n; i++)
            for(int j = 0;j < m; j++)
                if(v[i][j]==2)return {i,j};
        return {2,2};
    }
    int s = 0;
    pii neg = {2,2};
    if(v[2][1]==2)
        neg = {2,1},s++;
    if(v[2][3]==2)
        neg = {2,3},s++;
    if(v[1][2]==2)
        neg = {1,2},s++;
    if(v[3][2]==2)
        neg = {3,2},s++;
    int h = 4,ver = 4;
    if(s==2)
    {
        if(v[2][1]==2)
            h = 0;
        if(v[1][2]==2)
            ver = 0;
        return {ver,h};
    }
    return neg;
}
