fix printBoard

This commit is contained in:
Sandipsinh Rathod 2024-10-11 12:01:47 -04:00
parent 6f8eb0f0ac
commit 3008c1c2cb
No known key found for this signature in database

@ -11,6 +11,9 @@
using namespace std; using namespace std;
// TODO: drop pair
// remove global def of std
// -------- START RAII HELPERS-------- // -------- START RAII HELPERS--------
unsigned long allocatedMem = 0; unsigned long allocatedMem = 0;
@ -62,6 +65,12 @@ public:
length = 0; length = 0;
} }
myVec(size_t size) {
capacity = size;
length = 0;
data = static_cast<T *>(malloc(size * sizeof(T)));
}
void push_back(const T &val) { void push_back(const T &val) {
resize(); resize();
data[length++] = val; data[length++] = val;
@ -203,12 +212,68 @@ void deallocBoard(char **board, int x) {
} }
void printBoard(char **board, int x, int y) { void printBoard(char **board, int x, int y) {
int boardX = x + 2;
int boardY = y + 2;
myVec<myVec<char>> ans(boardX);
for (int i = 0; i < boardX; ++i) {
for (int j = 0; j < boardY; ++j) {
ans[i].push_back(' ');
}
}
for (int i = 0; i < y; ++i) {
if (!(i % 10)) {
ans[0][i] = (i / 10) + '0';
}
ans[1][i] = (i % 10) + '0';
}
for (int i = 0; i < x; ++i) {
if (!(i % 10)) {
ans[i + 2][0] = (i / 10) + '0';
}
ans[i + 2][1] = (i % 10) + '0';
}
for (int i = 0; i < x; ++i) { for (int i = 0; i < x; ++i) {
for (int j = 0; j < y; ++j) { for (int j = 0; j < y; ++j) {
pt board[i][j]; ans[i + 2][j + 2] = board[i][j];
}
}
// Calculate the maximum length of the row numbers plus two spaces
int maxLength = 0;
for (int i = 0; i < x; ++i) {
int length = 2 + (i >= 10 ? 2 : 1);
if (length > maxLength) {
maxLength = length;
}
}
// Print the first two rows with the calculated spaces
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < maxLength; ++j) {
pt ' ';
}
for (int j = 0; j < y; ++j) {
pt ans[i][j];
} }
pt nl; pt nl;
} }
// Print the rest of the board
for (int i = 2; i < boardX; ++i) {
for (int j = 0; j < boardY; ++j) {
if (j == 2) {
pt ' ';
}
pt ans[i][j];
if (j == boardY - 1) {
pt nl;
}
}
}
pt endl; pt endl;
} }
@ -267,7 +332,7 @@ void printScores(int *points, char blacklist) {
bubbleSort(arr); bubbleSort(arr);
for (int i = 0; i < 26; i++) { for (int i = 25; i > -1; i--) {
if (arr[i].second.first != -1) { if (arr[i].second.first != -1) {
pt arr[i].first << ": " << arr[i].second.first << " boxes" << ( pt arr[i].first << ": " << arr[i].second.first << " boxes" << (
(i == 25 || arr[i].second.second) && arr[i].first != blacklist (i == 25 || arr[i].second.second) && arr[i].first != blacklist