diff --git a/main.cpp b/main.cpp index e65fd86..114b0f8 100644 --- a/main.cpp +++ b/main.cpp @@ -210,8 +210,8 @@ void printScores(int *points) { dealloc(arr); } -bool isValidMove(int x, int y) { - return (x & 1) != (y & 1); +bool isValidMove(int x, int y, char **board) { + return (x & 1) != (y & 1) && board[x][y] == ' '; } void addPoint( @@ -310,7 +310,7 @@ void solve(Moves moves, char **board) { int moveY = move.moveY; char player = move.player; - if (!isValidMove(moveX, moveY)) { + if (!isValidMove(moveX, moveY, board)) { pt "Invalid move by: " << player << " at (x, y): (" << moveX << ", " << moveY << ")" << nl; board[moveX][moveY] = 'X'; printBoard(board, moves.x, moves.y); @@ -323,9 +323,9 @@ void solve(Moves moves, char **board) { board[moveX][moveY] = toLowerCase(player); // TODO: - if (moveX % 2 == 0 && moveY % 2 == 1) { + if (!(moveX&1) && (moveY&1)) { solveVertical(moveX, moveY, board, points, moves.x, moves.y, player); - } else if (moveX % 2 == 1 && moveY % 2 == 0) { + } else if ((moveX&1) && !(moveY&1)) { solveHorizontal(moveX, moveY, board, points, moves.y, player); } else { pt "Invalid move by: " << player << " at (x, y): (" << moveX << ", " << moveY << ")" << nl;