#include "vision.h"

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

int getMove1d(std::vector<int> v)
{
    int n = v.size(), m = n / 2;
    if (v[m] == 1) {
        if (v[m - 1] == 2 && v[m + 1] == 3 || v[m - 1] == 1 && v[m + 1] == 2 || v[m - 1] == 3 && v[m + 1] == 1) return m + 1;
        else return m - 1;
    } else if (v[m] == 2) {
        if (v[m - 2] == 1) return m + 1;
        else return m - 1;
    } else {
        if (v[m - 2] == 2) return m + 1;
        else return m - 1;
    }
}

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

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    int n = v.size();
    int m = n / 2;
    int x = 0, y = 0;
    if (v[m][m] == 1) {
        if (v[m][m + 1] == 2) y = 1;
        else y = -1;
        if (v[m + 1][m] == 2) x = -1;
        else x = 1;
    } else if (v[m][m] == 2) {
        if (v[m][m + 1] == 3) y = 1;
        else y = -1;
        if (v[m + 1][m] == 3) x = -1;
        else x = 1;
    } else {
        if (v[m][m + 1] == 1) y = 1;
        else y = -1;
        if (v[m + 1][m] == 1) x = -1;
        else x = 1;
    }
    return {m - x, m + y};
}
