#include "vision.h"
#include<vector>
using namespace std;
std::vector<int> getVisionPattern1d()
{
    return {1, 1, 2, 2, 1, 2};

}

int getMove1d(std::vector<int> v)
{
    vector<int> a = {1, 2, 2, 1, 2}, b = {2, 1, 2, 1, 1}, c = {1, 1, 2, 2, 1};
    if (v.size() == 3) {
        if (v[0] == 2) {
            return 0;
        }
        return 2;
    }
    if (v == a || v == b || v == c) {
        return 4;
    }
    return 0;
}

std::vector<std::vector<int>> getVisionPattern2d()
{
    vector<int> a = {1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2};
    vector<vector<int>> a2;
    for (int i = 0; i < a.size(); i++) {
        if (i % 2 == 1) {
            a[(i + 9) % a.size()] = 1;
        }
        a2.push_back(a);
        if (i % 2 == 1) {
            a[(i + 9) % a.size()] = 2;
        }
        vector<int> x = {a.back()};
        for (int i = 0; i + 1 < a.size(); i++) {
            x.push_back(a[i]);
        }
        a = x;
    }
    return a2;
}

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    if (v.size() == 3) {
        pair<int, pair<int, int>> mx = {-1, {-1, -1}};
        for (int i = 0; i < v.size(); i++) {
            for (int j = 0; j < v.size(); j++) {
                mx = max(mx, {v[i][j], make_pair(i, j)});
            }
        }
        if (mx.first != 1) {
            return mx.second;
        }
        return {0, 1};
    }
    if (v.size() == 5) {
        long long cnt_2 = 0;
        pair<int, pair<int, int>> mx = {-1, {-1, -1}};
        for (int i = 0; i < v.size(); i++) {
            for (int j = 0; j < v.size(); j++) {
                if (v[i][j] == 2) {
                    cnt_2++;
                }
                mx = max(mx, {v[i][j], make_pair(i, j)});
            }
        }
        if (cnt_2 == 6) {
            long long x, y;
            if (v[3][1] == 1) {
                x = 4;
                y = 0;
            } else {
                x = 0;
                y = 0;
            }
            if (v[x][y] == 2) {
                return {x, y};
            }
            return {4 - x, 4 - y};
        } else if (cnt_2 == 9) {
            if (v[1][2] == 2) {
                return {1, 2};
            }
            return {3, 2};
        } else if (cnt_2 == 3) {
            long long x, y;
            if (v[4][0] == 1) {
                x = 4;
                y = 0;
            } else {
                x = 0;
                y = 0;
            }
            return {x, y};
        }
        long long x, y;
        if (v[1][2] == 1) {
            x = 4;
        } else {
            x = 0;
        }
        if (v[2][1] == 2) {
            y = 4;
        } else {
            y = 0;
        }
        return {x, y};
    }
}
