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


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


int getMove1d(std::vector<int> v)
{
    int vi = v.size()/2;
    if(v[vi] == 1)
    {
        if(v[vi+1] >= v[vi-1]) return vi+1;
        return vi-1;
    }

    if(v[vi] == 2)
    {
        for(int j = 0; j < v.size(); j++) if(v[j] == 3) return j;
    }

    ///ost samo 3
    if(v[0] == 2) return 0;
    else return v.size()-1;

    return -1;
}


std::vector<std::vector<int>> getVisionPattern2d()
{
    vector<vector<int> >v;
    v.resize(3);
    int idx = 0;
    for(int i = 0; i < 3; i++)
    {
        v[i].resize(3);
        for(int j = 0; j < 3; j++)
        {
            v[i][j] =  ++idx;
        }
    }
    return v;
}


std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    pair<int,int> dir[4] = {{-1,-1},{-1,1},{1,1},{1,-1}};
    int ans[10];
    ans[1] = 5;
    ans[5] = 9;
    ans[9] = 1;

    ans[2] = 6;
    ans[6] = 7;
    ans[7] = 2;

    ans[3] = 4;
    ans[4] = 8;
    ans[8] = 3;
    int xi = v.size()/2;
    int yi = v[xi].size()/2;

    for(int i = 0; i < 4; i++)
    {
        pair<int,int> p = {xi + dir[i].first, yi + dir[i].second};
        if(v[p.first][p.second] == ans[v[xi][yi]]) return p;
    }
    return {-1,-1};
}
