From 489c43b953a62f95dda8999266faef1d330368e7 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Thu, 10 Oct 2024 19:36:22 -0400 Subject: [PATCH] fix logical err in win/tie --- main.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index a6c3d31..400c492 100644 --- a/main.cpp +++ b/main.cpp @@ -7,6 +7,7 @@ #define pter cerr << #define nl "\n" #define in cin >> +#define all(x) x.begin(), x.end() using namespace std; @@ -99,12 +100,14 @@ bool isValidPlayer(char c) { } string toString(int x) { + if (!x) return "0"; + string result; while (x) { result.push_back(x % 10 + '0'); x /= 10; } - reverse(result.begin(), result.end()); + reverse(all(result)); return result; } @@ -185,6 +188,7 @@ void printBoard(char **board, int x, int y) { } pt nl; } + pt endl; } char toLowerCase(char c) { @@ -224,7 +228,7 @@ void printScores(int *points, char blacklist) { int prev = -1; - string win = arr[0].second == arr[1].second ? " (tie)\n" : " (win)\n"; + string win = arr[25].second == arr[24].second ? " (tie)\n" : " (win)\n"; for (int i = 0; i < 26; i++) { if (arr[i].second != -1) { @@ -235,6 +239,7 @@ void printScores(int *points, char blacklist) { } dealloc(arr); + pt endl; } bool isValidMove(int x, int y, char **board) { @@ -340,7 +345,7 @@ void solve(Moves moves, char **board) { points[normalize(player)] = max(0, points[normalize(player)]); if (!isValidMove(moveX, moveY, board)) { - pt "Invalid move by: " << player << " at (x, y): (" << moveX << ", " << moveY << ")" << nl; + pt "Invalid or Repeated move by: " << player << " at (x, y): (" << moveX << ", " << moveY << ")" << nl; board[moveX][moveY] = 'X'; printBoard(board, moves.x, moves.y);