#define _GLIBCXX_FILESYSTEM
#include<bits/stdc++.h>
#include "vision.h"
using namespace std;
vector<int> getVisionPattern1d() {
    return {1, 2, 1, 1, 2, 2};
}

int getMove1d(vector<int> v) {
    if (v.size() == 3) {
        if (v[0] == 2) return 0;
        else return 2;
    }
    int br2 = 0;
    for (int i = 0; i < v.size(); i++) if (v[i] == 2) br2++;
    if (br2 == 3) {
        if (v[0] == 2) return 0;
        else return 4;
    }
    if (v[1] == 2) return 1;
    else if (v[3] == 2) return 3;
    else if (v[0] == 2) return 4;
    else return 0;

}

vector<vector<int>> getVisionPattern2d() {
    vector<vector<int>> p;
    for (int i = 0; i < 4; i++) {
        p.push_back({});
        for (int j = 0; j < 8; j++) {
            if (i == 1 && j == 2) p[i].push_back(2);
            else if (i == 1 && j == 4) p[i].push_back(2);
            else if (i == 2 && j == 6) p[i].push_back(2);
            else if (i == 3 && j == 7) p[i].push_back(2);
            else p[i].push_back(1);
        }
    }
    return p;
}

pair<int, int> getMove2d(vector<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] == 2) return {i, j};
            }
        }
        return {0, 1};
    }
    vector<pair<int, int>> p;
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            if (i == 2 && j == 2) continue;
            if (v[i][j] == 2) p.push_back({i, j});
        }
    }
    if (p.size() == 2) {
        if (p[0].first == 2) return p[1];
        else if (p[1].first == 2) return p[0];
        else if (p[0].second == 0 || p[0].second == 4) return p[0];
        else return p[1];
    }
    else if (p[0].first == 2) return p[0];
    else if (p[0].first == 1 && p[0].second == 1) return {4, 4};
    else if (p[0].first == 1 && p[0].second == 3) return {4, 0};
    else if (p[0].first == 3 && p[0].second == 1) return {0, 4};
    else if (p[0].first == 3 && p[0].second == 3) return {0, 0};
}
