fix printBoards

This commit is contained in:
Sandipsinh Rathod 2024-10-11 13:31:02 -04:00
parent 5bfef3f9dd
commit e3a728e10b
No known key found for this signature in database

@ -213,31 +213,32 @@ 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 boardX = x + 2;
int boardY = y + 2; int boardY = y + 2;
myVec<myVec<char> > ans(boardX); myVec<myVec<string> > ans(boardX);
for (int i = 0; i < boardX; ++i) { for (int i = 0; i < boardX; ++i) {
ans[i] = myVec<string>(boardY);
for (int j = 0; j < boardY; ++j) { for (int j = 0; j < boardY; ++j) {
ans[i].push_back(' '); ans[i][j] = " ";
} }
} }
for (int i = 0; i < y; ++i) { for (int i = 0; i < y; ++i) {
if (!(i % 10)) { if (!(i % 10)) {
ans[0][i] = (i / 10) + '0'; ans[0][i] = toString((i / 10));
} }
ans[1][i] = (i % 10) + '0'; ans[1][i] = toString((i % 10));
} }
for (int i = 0; i < x; ++i) { for (int i = 0; i < x; ++i) {
if (!(i % 10)) { if (!(i % 10)) {
ans[i + 2][0] = (i / 10) + '0'; ans[i + 2][0] = toString((i / 10));
} }
ans[i + 2][1] = (i % 10) + '0'; ans[i + 2][1] = toString((i % 10));
} }
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) {
ans[i + 2][j + 2] = board[i][j]; ans[i + 2][j + 2] = string(1, board[i][j]);
} }
} }
@ -245,10 +246,13 @@ void printBoard(char **board, int x, int y) {
int maxLength = 0; int maxLength = 0;
for (int i = 0; i < x; ++i) { for (int i = 0; i < x; ++i) {
int length = 2 + (i >= 10 ? 2 : 1); int length = 2 + (i >= 10 ? 2 : 1);
if (length > maxLength) { for(int j = 0; j < y; ++j) {
maxLength = length; if (ans[i + 2][j + 2].size() > length) {
length = ans[i + 2][j + 2].size();
} }
} }
maxLength = max(maxLength, length);
}
// Print the first two rows with the calculated spaces // Print the first two rows with the calculated spaces
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
@ -268,11 +272,9 @@ void printBoard(char **board, int x, int y) {
pt ' '; pt ' ';
} }
pt ans[i][j]; pt ans[i][j];
if (j == boardY - 1) { }
pt nl; pt nl;
} }
}
}
pt endl; pt endl;
} }