#include "vision.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define pii pair<int,int>
using namespace std;

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

int getMove1d(vector<int> v)
{
	int n=v.size();
	int ind=n/2;
	if (v[ind]==3) {
		if (v[ind+1]==1) return n-1;
		return 0;
	}
	if (v[ind]==2) {
		if (v[ind+1]==3) return ind+1;
		return ind-1;
	}
	if (v[ind]==1) {
		if (v[ind+1]==v[ind-1]) return ind+1;
		if (v[ind+1]!=1) return ind+1;
		return ind-1;
	}
}

vector<vector<int>> getVisionPattern2d()
{
    return 
   {{1,1,1,1,1,1},
	{1,2,1,2,1,2},
	{1,1,1,1,1,1},
	{1,2,1,3,1,1},
	{1,1,1,1,2,1},
    {1,2,1,1,1,1}};
}
pair<int, int> getMove2d(vector<vector<int>> v)
{
	int n=v.size();
	int ind=n/2;
	
	int val=v[ind][ind];
	
	int dx[4]={1,1,-1,-1},dy[4]={-1,1,-1,1};
	
	if (val==3) {
		for (int j=0; j<4; j++) {
			int xx=ind+dx[j],yy=ind+dy[j];
			if (v[xx][yy]==2) return {ind+3*dx[j],ind+3*dy[j]};
		}
	}
	
	if (val!=3) {
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				if (v[i][j]==3) return {i,j};
			}
		}
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) {
				if (v[i][j]==2) return {i,j};
			}
		}
		return {ind+1,ind+1};
	}
}
