diff --git a/main.cpp b/main.cpp index 899d815..8ba3ea8 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include #define pt cout << #define nl '\n' @@ -36,11 +39,13 @@ bool assert_alloc() { struct Move { char player; - int moveX, moveY; + int moveX; + int moveY; }; struct Moves { - int x{}, y{}; + int x; + int y; vector moves; }; @@ -48,6 +53,8 @@ Moves serialize(const string &s) { Moves result; istringstream iss(s); iss >> result.x >> result.y; + result.x <<= 1; + result.y <<= 1; string player; int x, y; @@ -58,18 +65,46 @@ Moves serialize(const string &s) { return result; } -void solve(const string& fileInp) { - Moves moves = serialize(fileInp); + +void initBoard(char **board, int x, int y) { + for (int i = 0; i < x; ++i) { + for (int j = 0; j < y; j++) { + board[i][j] = (j&1 || i&1) ? ' ': '.'; + } + } +} + +char **allocAndInitBoard(int x, int y) { + char **board = static_cast(alloc(sizeof(char *) * x)); + for (int i = 0; i < x; ++i) { + board[i] = static_cast(alloc(sizeof(char) * y)); + } + initBoard(board, x, y); + return board; +} + +void deallocBoard(char **board, int x) { + for (int i = 0; i < x; ++i) { + dealloc(board[i]); + } + dealloc(board); +} + +void printBoard(char **board, int x, int y) { + for (int i = 0; i < x; ++i) { + for (int j = 0; j < y; ++j) { + pt board[i][j]; + } + pt nl; + } +} + +void solve(Moves moves, char **board) { } -int main(int argc, char **argv) { - if (argc != 2) { - cerr << "Usage: " << argv[0] << " " << nl; - return 1; - } - char* fileName = argv[1]; - +int init(char *fileName) { + // --- IO START --- FILE *inp = fopen(fileName, "r"); if (inp == nullptr) { cerr << "File not found" << endl; @@ -77,7 +112,7 @@ int main(int argc, char **argv) { } fseek(inp, 0L, SEEK_END); - long sz = ftell(inp); + const long sz = ftell(inp); fseek(inp, 0L, SEEK_SET); char *fileInpPtr = static_cast(alloc(sz + 1 * sizeof(char))); @@ -86,16 +121,31 @@ int main(int argc, char **argv) { for (int i = 0; i < sz; ++i) { fscanf(inp, "%c", &fileInpPtr[i]); } + // --- IO END --- - solve(fileInpPtr); + // --- ALGORITHM START --- + Moves moves = serialize(fileInpPtr); + char **board = allocAndInitBoard(moves.x, moves.y); + solve(moves, board); + // --- ALGORITHM END --- + // --- CLEANUP START --- dealloc(fileInpPtr); + deallocBoard(board, moves.x); fclose(inp); if (!assert_alloc()) { cerr << "Memory leak detected" << endl; return 1; } - + // --- CLEANUP END --- return 0; } + +int main(int argc, char **argv) { + if (argc < 2) { + cerr << "No input file provided" << endl; + return 1; + } + return init(argv[1]); +}