miscellaneous

This commit is contained in:
Sandipsinh Rathod 2024-10-10 18:16:59 -04:00
parent 415ed299e9
commit 8ff786df97
No known key found for this signature in database

@ -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<char, int> *a) {
void printScores(int *points) {
pair<char, int> *arr = static_cast<pair<char, int> *>(alloc(26 * sizeof(pair<char, int>)));
for (int i = 0; i < 26; i++) {
arr[i] = {static_cast<char>(i + 'a'), points[i]};
pair<char, int> p;
p.first = static_cast<char>(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<int *>(alloc(26));
for (int i = 0; i < 26; i++) {
points[i] = 0;
}#1#
map<char, int> 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<pair<char, int> > ranking(points.begin(), points.end());
sort(ranking.begin(), ranking.end(), [](const pair<char, int> &a, const pair<char, int> &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;
}