#include "vision.h"
#include <stdio.h>

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

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

std::vector<std::vector<int>> getVisionPattern2d() {
    int idk[3][3] = {{1, 1, 1}, {1, 1, 2}, {1, 2, 3}};
    for(int l = 0; l < 30; l++) {
        for(int c = 0; c < 30; c++) {
            printf("%d ", idk[l % 3][c % 3]);
        }
        printf("\n");
    }
    return {{1, 1, 1}, {1, 1, 2}, {1, 2, 3}};
}

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