#include "vision.h"
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
#define f(i, s, n) for(int i=s; i<n; i++)

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

int getMove1d(std::vector<int> v)
{
    if (v.size() == 7) {
        if (v[1] == 2) return 6;
        else return 0;
    }
    if (v.size() == 5) {
        if (v[0] == 3) return 0;
        else return 4;
    }
    if (v[0] == 3) return 0;
    if (v[2] == 3) return 2;
    if (v[0] == 2) return 0;
    return 2;
}

std::vector<std::vector<int>> getVisionPattern2d()
{
    vector<vector<int>> numbers(15, vector<int>(15, 1));
    f(i, 0, 15) f(j, 0, 15) numbers[3 * i][3 * j] = 2;
    numbers[2][5] = 2;
    numbers[5][11] = 2;
    numbers[8][2] = 2;
    numbers[11][8] = 2;
    numbers[14][14] = 2;
    return numbers;
}

std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
{
    if (v.size() == 3) {
        f(i, 0, 3) f(j, 0, 3) if (v[i][j] == 2) return { i, j };
    }
    int count = -25;
    f(i, 0, 5) f(j, 0, 5) count += v[i][j];
    if (count == 5) f(i, 1, 4) f(j, 1, 4) if (v[i][j] == 2 and (i != 2 or j != 2)) return { i, j };
    f(i, 1, 4) f(j, 1, 4) if (v[i][j] == 2 and (i != 2 or j != 2)) return { 6 - 2 * i, 6 - 2 * j };
    f(i, 0, 5) f(j, 0, 5) if (v[i][j] == 2 and (i != 2 or j != 2)) return { i, j };
    return { 0, 2 };
}
