#include "toonsplat.h"
#include <cstdio>
#include <vector>
#include <deque>
#include <cstdlib>
#include <time.h>
#include <cstring>
void init(){
    srand(time(NULL));
    return;
}

int ax[4] = {1,0,-1,0};
int ay[4] = {0,1,0,-1};


void printboard(vector<vector<int>> &board){
    for (int y = BOARD_SIZE-1; y >= 0; y--){
        for (int x = 0; x < BOARD_SIZE; x++){
            printf("%d", board[x][y]);
        }
        printf("\n");
    }
}

// Check toonsplat.h to see what all these arguments are
void tick(vector<vector<int>> board, vector<Position> player_botlets, 
vector<deque<Operation>> operation_queues, vector<Position> enemy_botlets, 
int current_tick, double remaining_compute_time){
    if (current_tick == 1){
        // Don't worry! You can just print like normal and you will be able to see stuff.
        // iostream works too, don't worry about my preference in cstdio
        printf("Hello! We are currently at tick %d\n", current_tick);
    }

    // Demonstration of how to issue commands, and put them on the queue
    if (current_tick == 1){
        move(0,{9,9},0);        
        move(1,{9,9},1);
        move(2,{9,9},2);
        move(2,{0,0},2);
    }

    // Make the botlets that don't have anything to do move in a random direction.
    for (int i = 0; i < INITIAL_BOTLETS; i++){
        if (operation_queues[i].empty()){
            int dir = rand() % 4;
            int cx = player_botlets[i].x + ax[dir];
            int cy = player_botlets[i].y + ay[dir];

            if (max(cx,cy) >= BOARD_SIZE || min(cx,cy) < 0){
                continue;
            }
            move(i,{cx,cy},0);
        }
    }

    // I even left in a cute helper function to help you print the board.
    if (current_tick == 58){
        printboard(board);

    }

    return;
};
