Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ArrayList<ArrayList<String>> myPossibilities = new ArrayList<>();//array of permutations seperated in characters
- ArrayList<String> myHand = LetterList(string);//get list of letters from user
- myPossibilities.add(myHand);
- Permutation(myHand, myPossibilities, 0);//find every permutation of input letters
- final ArrayList<String> myFinalHand = Merger(myPossibilities); //convert words that were broken down to characters to an array of strings
- return Single.fromCallable(new Callable<String>() {
- @Override
- public String call() throws Exception {
- int currentvalue = 0;
- String currentword = "";
- ArrayList<String> validwords = new ArrayList<String>();
- for (String word : myFinalHand) {
- retrofit2.Response<WordResponse> response = oxford.lookupword(word).execute();
- if (response.isSuccessful()) {
- int tempvalue = Calculator(word);
- if(tempvalue > currentvalue){
- currentvalue = tempvalue;
- currentword = word;
- }
- }
- }
- return currentword;
- }
- });
- // ArrayList myDictionary = Dictionary();//get words for text file
- //String Solution = DeScramble(myFinalHand, myDictionary);//find matches between user input and text file, and output highest value word
- //ArrayList Solution = DictionaryAPI(myPossibilities, 0);
- /*
- if(Solution.isEmpty()){
- return "No word can be created";
- }
- else{
- return Solution + " " + Calculator(Solution);
- //System.out.println("The highest value word you can make is:" + Solution + " " + "with a value of " + Calculator(Solution));
- }
- */
- //return Solution;
- /*
- static ArrayList<String> LetterList(String string) {
- ArrayList<String> Hand = new ArrayList<>();
- Scanner scan = new Scanner(System.in);
- //System.out.println("Enter all of the desired letter. Press ENTER when finished.");
- // String s = scan.nextLine();
- string = string.replaceAll("\\d+", ""); //remove numbers
- string = string.toLowerCase(); //convert all to lowercase
- String[] splitStrings = string.split("(?!^)");
- for (int i = 0; i < splitStrings.length; i++) {
- if (splitStrings[i].equals(",") || splitStrings[i].equals(" ")) { //remove objects other than letters
- } else {
- Hand.add(splitStrings[i]);
- }
- }
- return Hand;
- }
- static void Permutation(ArrayList hand, ArrayList possibilities, int start) {
- for (int i = 0; i < hand.size() - 1; i++) {
- ArrayList tempArray = new ArrayList(hand);
- Object tempValue = tempArray.get(start);
- tempArray.set(start, tempArray.get(i));
- tempArray.set(i, tempValue);
- if (possibilities.indexOf(tempArray) == -1) {
- possibilities.add(tempArray);
- }
- if (start < hand.size() - 1) {
- Permutation(tempArray, possibilities, start + 1);
- }
- }
- }
- static ArrayList<String> Merger(ArrayList<ArrayList<String>> list) {
- ArrayList<String> mergedHand = new ArrayList<>(); //array of every permutation in seperate strings
- for (int i = 0; i < list.size(); i++) {
- ArrayList tempArray = (ArrayList) list.get(i);
- String tempString = "";
- for (int j = 0; j < tempArray.size(); j++) {
- tempString += tempArray.get(j);
- }
- mergedHand.add(tempString);
- }
- return mergedHand;
- }
- public static Single<String> getValidWords(final ArrayList<String> list) {
- return Single.fromCallable(new Callable<String>() {
- @Override
- public String call() throws Exception {
- int currentvalue = 0;
- String currentword = "";
- ArrayList<String> validwords = new ArrayList<String>();
- for (String word : list) {
- retrofit2.Response<WordResponse> response = oxford.lookupword(word).execute();
- if (response.isSuccessful()) {
- //check if word is better than current answer
- }
- }
- return currentword;
- }
- });
- }
- /*
- ArrayList Dictionary(){ //function to test input with WordList.txt
- ScrabbleHelper context = ScrabbleHelper.this;
- InputStream is = context.getResources().openRawResource(R.raw.wordlist);
- ArrayList Dictionary = new ArrayList();
- //File WordList = new File("WordList.txt");
- String[] splitStrings;
- Scanner line = new Scanner(is);
- while (line.hasNextLine()) {
- String i = line.nextLine();
- splitStrings = i.split("");
- Dictionary.add(i);
- }
- line.close();
- return Dictionary;
- }
- /*
- static String DeScramble(ArrayList list, ArrayList list2) {
- String PossibleAnswer = "";
- String TrueAnswer = "";
- ArrayList CheckedLetters = new ArrayList();
- int TrueValue = 0;
- for (int i = 0; i < list.size(); i++) {
- String word = (String) list.get(i);
- if (list2.contains(word)) {
- if (Calculator(word) > TrueValue) {
- TrueAnswer = word;
- TrueValue = Calculator(word);
- }
- }
- }
- return TrueAnswer;
- }
- }
- */
- /*
- anagramica.findBest(string).enqueue(new Callback<WordResponse>() {
- @Override
- public void onResponse(Call<WordResponse> call, retrofit2.Response<WordResponse> response) {
- ArrayList<String> mypossibilities = new ArrayList<>(response.body().getBest());
- String solution = "";
- String possiblesolution = "";
- int solvalue = 0;
- int possiblesolvalue = 0;
- for (String word : mypossibilities) {
- possiblesolvalue = Calculator(word);
- if (possiblesolvalue > solvalue) {
- solvalue = possiblesolvalue;
- solution = word;
- }
- }
- }
- @Override
- public void onFailure (Call < WordResponse > call, Throwable t){
- solution = "No Words Found";
- }
- }
- );
- return solution;
- */
- /*
- ArrayList<ArrayList<String>> myPossibilities = new ArrayList<>();//array of permutations seperated in characters
- ArrayList<String> myHand = LetterList(string);//get list of letters from user
- myPossibilities.add(myHand);
- Permutation(myHand, myPossibilities, 0);//find every permutation of input letters
- final ArrayList<String> myFinalHand = Merger(myPossibilities); //convert words that were broken down to characters to an array of strings
- return Single.fromCallable(new Callable<String>() {
- @Override
- public String call() throws Exception {
- int currentvalue = 0;
- String currentword = "";
- ArrayList<String> validwords = new ArrayList<String>();
- for (String word : myFinalHand) {
- retrofit2.Response<WordResponse> response = oxford.lookupword(word).execute();
- if (response.isSuccessful()) {
- int tempvalue = Calculator(word);
- if(tempvalue > currentvalue){
- currentvalue = tempvalue;
- currentword = word;
- }
- }
- }
- return currentword;
- }
- });
- // ArrayList myDictionary = Dictionary();//get words for text file
- //String Solution = DeScramble(myFinalHand, myDictionary);//find matches between user input and text file, and output highest value word
- //ArrayList Solution = DictionaryAPI(myPossibilities, 0);
- /*
- if(Solution.isEmpty()){
- return "No word can be created";
- }
- else{
- return Solution + " " + Calculator(Solution);
- //System.out.println("The highest value word you can make is:" + Solution + " " + "with a value of " + Calculator(Solution));
- }
- */
- //return Solution;
- /*
- static void init() {
- OkHttpClient client = new OkHttpClient.Builder()
- .addInterceptor(new Interceptor() {
- @Override
- public Response intercept(Chain chain) throws IOException {
- Request request = chain.request().newBuilder()
- .addHeader("app_id", "7ddb00d8")
- .addHeader("app_key", "9b38e8c1685a64d7b05dfb07c0666559")
- .build();
- return chain.proceed(request);
- }
- })
- .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
- .build();
- Retrofit retrofit = new Retrofit.Builder()
- .baseUrl("https://od-api.oxforddictionaries.com/api/v1/")
- .client(client)
- .addConverterFactory(GsonConverterFactory.create())
- .build();
- oxford = retrofit.create(Oxford.class);
- }
- */
- /*oxford.lookupword("fish").enqueue(new Callback<WordResponse>() {
- @Override
- public void onResponse(Call<WordResponse> call, retrofit2.Response<WordResponse> response) {
- if (response.isSuccessful()) {
- Snackbar.make(root, "word exists", Snackbar.LENGTH_SHORT).show();
- } else {
- Snackbar.make(root, "nope", Snackbar.LENGTH_SHORT).show();
- }
- }
- @Override
- public void onFailure(Call<WordResponse> call, Throwable t) {//if person has no internet connection
- Snackbar.make(root, "failure", Snackbar.LENGTH_SHORT).show();
- t.printStackTrace();
- }
- });*/
- /*
- ScrabbleHelper.solve(message)
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(new SingleObserver<String>() {
- @Override
- public void onSubscribe(Disposable d) {
- }
- @Override
- public void onSuccess(String bestword) {
- Intent intent = new Intent(MainActivity.this, DisplayMessageActivity.class);
- intent.putExtra(EXTRA_MESSAGE, bestword);
- startActivity(intent);
- //Snackbar.make(root, "Best scoring word is " + bestword, Snackbar.LENGTH_SHORT).show();
- }
- @Override
- public void onError(Throwable e) {
- Snackbar.make(root, "failure", Snackbar.LENGTH_SHORT).show();
- e.printStackTrace();
- }
- });
- */
- //use solver function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement