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

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

int getMove1d(std::vector<int> v)
{
    int tot = v.size();
    int mid = tot / 2;
    int val = v[mid];
    if (val == 1) {
        if (v[mid-1] == 2 && v[mid+1] == 3) return mid+1;
        else if (v[mid-1] == 3 && v[mid+1] == 2) return mid-1;
        else if (v[mid+1] == 2) return mid+1;
        else if (v[mid-1] == 2) return mid-1;
        else if (v[mid-1] == 3) return mid+1;
        else if (v[mid+1] == 3) return mid-1;
    }
    else if (val == 2) {
        if (v[mid+2] == 3) return mid+2;
        else if (v[mid-2] == 3) return mid-2;
    }
    else if (val == 3) {
        if (v[mid-2] == 2) return mid+1;
        else return mid-1;
    }
    assert(false);
    return -1;
}

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

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    int tot = v.size();
    int mid = tot / 2;
    vector<int> vv = v[mid];
    int val = vv[mid];
    if (val == 1) {
        if (vv[mid-1] == 2 && vv[mid+1] == 3) return {0, mid+1};
        else if (vv[mid-1] == 3 && vv[mid+1] == 2) return {0, mid-1};
        else if (vv[mid+1] == 2) return {0, mid+1};
        else if (vv[mid-1] == 2) return {0, mid-1};
        else if (vv[mid-1] == 3) return {0, mid+1};
        else if (vv[mid+1] == 3) return {0, mid-1};
    }
    else if (val == 2) {
        if (vv[mid+2] == 3) return {0, mid+2};
        else if (vv[mid-2] == 3) return {0, mid-2};
    }
    else if (val == 3) {
        if (vv[mid-2] == 2) return {0, mid+1};
        else return {0, mid-1};
    }
    assert(false);
    return {0, 0};
}
