#include "vision.h"

using namespace std;

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

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

std::vector<std::vector<int>> getVisionPattern2d() {
	vector<vector<int>> mat(8, vector<int>(8, 1));
	mat[6][6] = 2;
	mat[7][7] = 3;
	
	mat[2][2] = 2;
	mat[3][3] = 3;
	
	mat[2][6] = 2;
	mat[3][7] = 2;
	
	mat[6][2] = 2;
	mat[7][3] = 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 {0, 1};
	 } else if (v.size() == 5) {
		 for (int i = 0; i < 5; i ++) {
			 for (int j = 0; j < 5; j ++) {
				 if (v[i][j] == 3) {
					 return {i, j};
				 }
			 }
		 }
		 if (v[3][3] != 2 && v[3][1] != 2) {
			 return {5, 2};
		 } else {
			 return {0, 2};
		 }
	 } else {
		 for (auto i : {0, 6}) {
			 for (auto j : {0, 6}) {
				 if (v[i][j] == 2) {
					 return {i, j};
				 }
			 }
		 }
		 return {0, 0};
	 }
}
