fix logical err in win/tie
This commit is contained in:
parent
8a0445f6e2
commit
489c43b953
11
main.cpp
11
main.cpp
@ -7,6 +7,7 @@
|
|||||||
#define pter cerr <<
|
#define pter cerr <<
|
||||||
#define nl "\n"
|
#define nl "\n"
|
||||||
#define in cin >>
|
#define in cin >>
|
||||||
|
#define all(x) x.begin(), x.end()
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -99,12 +100,14 @@ bool isValidPlayer(char c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string toString(int x) {
|
string toString(int x) {
|
||||||
|
if (!x) return "0";
|
||||||
|
|
||||||
string result;
|
string result;
|
||||||
while (x) {
|
while (x) {
|
||||||
result.push_back(x % 10 + '0');
|
result.push_back(x % 10 + '0');
|
||||||
x /= 10;
|
x /= 10;
|
||||||
}
|
}
|
||||||
reverse(result.begin(), result.end());
|
reverse(all(result));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,6 +188,7 @@ void printBoard(char **board, int x, int y) {
|
|||||||
}
|
}
|
||||||
pt nl;
|
pt nl;
|
||||||
}
|
}
|
||||||
|
pt endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
char toLowerCase(char c) {
|
char toLowerCase(char c) {
|
||||||
@ -224,7 +228,7 @@ void printScores(int *points, char blacklist) {
|
|||||||
|
|
||||||
int prev = -1;
|
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++) {
|
for (int i = 0; i < 26; i++) {
|
||||||
if (arr[i].second != -1) {
|
if (arr[i].second != -1) {
|
||||||
@ -235,6 +239,7 @@ void printScores(int *points, char blacklist) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dealloc(arr);
|
dealloc(arr);
|
||||||
|
pt endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValidMove(int x, int y, char **board) {
|
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)]);
|
points[normalize(player)] = max(0, points[normalize(player)]);
|
||||||
|
|
||||||
if (!isValidMove(moveX, moveY, board)) {
|
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';
|
board[moveX][moveY] = 'X';
|
||||||
printBoard(board, moves.x, moves.y);
|
printBoard(board, moves.x, moves.y);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user