diff --git a/main.cpp b/main.cpp index 1fd3bf7..5ea87b8 100644 --- a/main.cpp +++ b/main.cpp @@ -69,7 +69,11 @@ Moves serialize(const string &s) { string err = "Invalid player: " + player; throw invalid_argument(err); } - result.moves.push_back({player[0], x, y}); + Move move; + move.player = player[0]; + move.moveX = x; + move.moveY = y; + result.moves.push_back(move); } return result; @@ -140,7 +144,10 @@ void bubbleSort(pair *a) { void printScores(int *points) { pair *arr = static_cast *>(alloc(26 * sizeof(pair))); for (int i = 0; i < 26; i++) { - arr[i] = {static_cast(i + 'a'), points[i]}; + pair p; + p.first = static_cast(i + 'a'); + p.second = points[i]; + arr[i] = p; } bubbleSort(arr); @@ -159,8 +166,7 @@ void printScores(int *points) { } bool isValidMove(int x, int y) { - // TODO: simplify this - return !(x & 1 != y & 1 && !(x & 1)); + return (x & 1) != (y & 1); } void addPoint( @@ -252,7 +258,9 @@ void solve(Moves moves, char **board) { points[i] = -1; } - for (Move &move: moves.moves) { + for (int i = 0; i < moves.moves.size(); i++) { + Move move = moves.moves[i]; + int moveX = move.moveX; int moveY = move.moveY; char player = move.player; @@ -290,55 +298,6 @@ void solve(Moves moves, char **board) { dealloc(points); } -/* -void solve(Moves moves, char **board) { - /* - TODO: use custom arr for points over map - *int *points = static_cast(alloc(26)); - for (int i = 0; i < 26; i++) { - points[i] = 0; - }#1# - map points; - - for (const auto &move: moves.moves) { - int moveX = move.moveX; - int moveY = move.moveY; - char player = move.player; - - board[moveX][moveY] = toLowerCase(player); - - if (moveX % 2 == 0 && moveY % 2 == 1) { - if (moveX > 0 && board[moveX - 1][moveY] == '|' && board[moveX - 1][moveY - 1] == '-' && board[moveX - 1][moveY + 1] == '-') { - points[player]++; - } - if (moveX < moves.x - 1 && board[moveX + 1][moveY] == '|' && board[moveX + 1][moveY - 1] == '-' && board[moveX + 1][moveY + 1] == '-') { - points[player]++; - } - } else if (moveX % 2 == 1 && moveY % 2 == 0) { - if (moveY > 0 && board[moveX][moveY - 1] == '-' && board[moveX - 1][moveY - 1] == '|' && board[moveX + 1][moveY - 1] == '|') { - points[player]++; - } - if (moveY < moves.y - 1 && board[moveX][moveY + 1] == '-' && board[moveX - 1][moveY + 1] == '|' && board[moveX + 1][moveY + 1] == '|') { - points[player]++; - } - } - } - - vector > ranking(points.begin(), points.end()); - sort(ranking.begin(), ranking.end(), [](const pair &a, const pair &b) { - return a.second < b.second; - }); - - for (const auto &rank: ranking) { - pt rank.first << ": " << rank.second << " boxes" << nl; - } - printBoard(board, moves.x, moves.y); - - - // dealloc(points); -} -*/ - int init(char *fileName) { // --- IO START --- FILE *inp = fopen(fileName, "r"); @@ -381,6 +340,7 @@ int init(char *fileName) { int main(int argc, char **argv) { if (argc < 2) { pter "No input file provided" << nl; + pter "Usage: dotsandboxes /path/to/input.txt" << nl; return 1; }