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

vector<int> getVisionPattern1d() {
    return { 1, 1, 2, 1, 3, 1 };
}
int getMove1d(vector<int> v) {
    int V = (v.size() - 1) / 2;
    if (V == 3) {
        return (v[1] == 2 ? v.size() - 1 : 0);
    }
    if (V == 2) {
        return (v.back() == 3 ? v.size() - 1 : 0);
    }
    if (V == 2) {
        return (v.back() == 3 ? v.size() - 1 : 0);
    }
    if (V == 1) {
        if (v[0] == 3)  { return 0; }
        if (v[2] == 3)  { return 2; }
        if (v[0] == 2)  { return 0; }
        if (v[2] == 2)  { return 2; }
        return 0;
    }
    assert(false);
}

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

pair<int, int> getMove2d(vector<vector<int>> v) {
    int V = (v.size() - 1) / 2;
    if (V == 1) {
        for (int i = 0; i < v.size(); i++) {
            for (int j = 0; j < v.size(); j++) {
                if (v[i][j] == 2) { return { i, j }; }
            }
        }
        return { 0, 0 };
    }
    if (V == 2) {
        pair<int, int> knightMove = { V, V }, diagMove = { V, V };
        for (int i = 0; i < v.size(); i++) {
            for (int j = 0; j < v.size(); j++) {
                if (v[i][j] == 2) {
                    int manDist = abs(i - V) + abs(j - V);
                    if (manDist == 3) { knightMove = { i, j }; }
                    if (manDist == 2) { diagMove = { i, j }; }
                }
            }
        }
        if (knightMove.first == V) { return diagMove; }
        if (diagMove.first == V) {
            pair<int, int> relMove = { V - knightMove.first, V - knightMove.second };
            return { V + relMove.first, V + relMove.second };
        }
        return knightMove;
    }

    return {0, 0};
}
