Created
May 28, 2024 00:16
-
-
Save Qubik65536/d0ae9ef64cc82386f88342f5a27cbaab to your computer and use it in GitHub Desktop.
TTT-CSharp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static bool checkForObviousMove(char[,] board) { | |
| int rows = board.GetLength(0); | |
| int cols = board.GetLength(1); | |
| int x; | |
| int y; | |
| int obviousCount; | |
| int blankCount; | |
| for (int i = 0; i < rows; i++) | |
| { | |
| x = -1; | |
| y = -1; | |
| obviousCount = 0; | |
| blankCount = 0; | |
| for (int j = 0; j < cols; j++) | |
| { | |
| if (board[i, j] == 'o') | |
| { | |
| obviousCount++; | |
| } | |
| if (board[i, j] == ' ') | |
| { | |
| x = i; | |
| y = j; | |
| blankCount++; | |
| } | |
| } | |
| if (obviousCount == cols - 1 && blankCount == 1) | |
| { | |
| writeOnBoard(board, 'o', x, y); | |
| return true; | |
| } | |
| } | |
| for (int j = 0; j < cols; j++) | |
| { | |
| x = -1; | |
| y = -1; | |
| obviousCount = 0; | |
| blankCount = 0; | |
| for (int i = 0; i < rows; i++) | |
| { | |
| if (board[i, j] == 'o') | |
| { | |
| obviousCount++; | |
| } | |
| if (board[i, j] == ' ') | |
| { | |
| x = i; | |
| y = j; | |
| blankCount++; | |
| } | |
| } | |
| if (obviousCount == rows - 1 && blankCount == 1) | |
| { | |
| writeOnBoard(board, 'o', x, y); | |
| return true; | |
| } | |
| } | |
| x = -1; | |
| y = -1; | |
| obviousCount = 0; | |
| blankCount = 0; | |
| for (int i = 0, j = 0; i < rows && j < cols; i++, j++) | |
| { | |
| if (board[i, j] == 'o') | |
| { | |
| obviousCount++; | |
| } | |
| if (board[i, j] == ' ') | |
| { | |
| x = i; | |
| y = j; | |
| blankCount++; | |
| } | |
| } | |
| if (obviousCount == rows - 1 && blankCount == 1) | |
| { | |
| writeOnBoard(board, 'o', x, y); | |
| return true; | |
| } | |
| x = -1; | |
| y = -1; | |
| obviousCount = 0; | |
| blankCount = 0; | |
| for (int i = rows - 1, j = 0; i >= 0 && j < cols; i--, j++) | |
| { | |
| if (board[i, j] == 'o') | |
| { | |
| obviousCount++; | |
| } | |
| if (board[i, j] == ' ') | |
| { | |
| x = i; | |
| y = j; | |
| blankCount++; | |
| } | |
| } | |
| if (obviousCount == rows - 1 && blankCount == 1) | |
| { | |
| writeOnBoard(board, 'o', x, y); | |
| return true; | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment