private bool isWinner(string playerSymbol) { // Check Rows if (GameBoard.Any(Row => Row.All(Cell => Cell == playerSymbol))) { return(true); } // Check Columns for (int i = 0; i <= 2; i++) { if (GameBoard.All(Row => Row[i] == playerSymbol)) { return(true); } } // Check Diagonals string[][] Diagonals = new string[2][] { new string[3], new string[3] }; for (int i = 0; i <= 2; i++) { Diagonals[0][i] = GameBoard[i][i]; Diagonals[1][i] = GameBoard[i][2 - i]; } if (Diagonals.Any(Diagonal => Diagonal.All(Cell => Cell == playerSymbol))) { return(true); } return(false); }
private int getState() { // Check if user won if (isWinner(USER_SYMBOL)) { return(USER_WON); } // Check if AI won if (isWinner(AI_SYMBOL)) { return(AI_WON); } if (GameBoard.Any(Row => Row.Contains(string.Empty))) { return(INCOMPLETE); } return(TOE); }