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

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

int getMove1d(std::vector<int> v)
{
    return 67;
}

std::vector<std::vector<int>> getVisionPattern2d()
{
    vector<vector<int>> ans(0);
    vector<int> wut(5,1);
    for(int i = 0; i < 5; i++) {
        ans.push_back(wut);
    }
    for(int i = 1; i < 4; i++) {
        ans[i][1] = 2;
        ans[1][i] = 2;
    }
    return ans;
}

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    if(v.size() == 3) {
        pair<int,int> wut[8] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,-1},{-1,1}};
        for(pair<int,int> t: wut) {
            if(v[1+t.first][1+t.second] == 2) {
                return {1+t.first,1+t.second};
            }
        }
        return {2,1};
    }
    vector<pair<int,int>> wut(0);
    if(v[1][2] == 2) {
        wut.push_back({-1,0});
    }
    if(v[2][1] == 2) {
        wut.push_back({0,-1});
    }
    if(v[3][2] == 2) {
        wut.push_back({1,0});
    }
    if(v[2][3] == 2) {
        wut.push_back({0,1});
    }
    if(wut.size() == 2) {
        if(wut[0].second == 0) {
            if(v[1][1] == 2 || v[1][3] == 2) {
                return {3,2};
            }
            else {
                return {1,2};
            }
        }
        else {
            if(v[1][1] == 2 || v[3][1] == 2) {
                return {2,3};
            }
            else {
                return {2,1};
            }
        }
    }
    int dx = wut[0].first,dy = wut[0].second;
    int x = 2-2*dx,y = 2-2*dy;
    if(dy == 0) {
        if(v[2+2*dx][3] == 2) {
            y = 3;
        }
        else {
            y = 1;
        }
    }
    else {
        if(v[3][2+2*dy] == 2) {
            x = 3;
        }
        else {
            x = 1;
        }
    }
    return {x,y};
}
