Advertisement
Steezy

LetterBlox Solver

Jul 17th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.80 KB | None | 0 0
  1. import java.awt.AWTException;
  2. import java.util.Arrays;
  3. import java.util.Random;
  4. import java.util.Scanner;
  5. import java.awt.AWTException;
  6. import java.awt.Robot;
  7. import java.awt.event.KeyEvent;
  8. import java.awt.AWTException;
  9. import java.awt.Robot;
  10. import java.io.File;
  11. import java.io.FileNotFoundException;
  12. //Steven Burrell
  13. //Date Created 5/1/2012 in (Aprox 3-4 hours)
  14. //Letterblox/Scrabble word generator and enterer.
  15.  
  16.  
  17.  
  18. public class Typer {
  19.  
  20.     public static void main(String[] args) throws AWTException {
  21.         SmartRobot sr = new SmartRobot();
  22.         Scanner keyboard = new Scanner(System.in);
  23.        
  24.         //QUERY//
  25.         int  decision = 0;
  26.         while(decision != 1 && decision != 2 && decision != 3){System.out.println("(1)Try all possible combinations? (2)Crossreference with dictionary? (3)Smartguess?" );decision = keyboard.nextInt();}
  27.         int combos = 0;
  28.         String raw = "";
  29.        
  30.         if(decision == 2){
  31.         combos = 6;System.out.println("Enter your six characters");raw = keyboard.next();
  32.         }
  33.         else if (decision == 1){
  34.         System.out.println("Enter your six characters and how many combos (3-6) to check (Ex. abcdef 4)");
  35.         raw = keyboard.next();
  36.         combos = keyboard.nextInt();
  37.         }
  38.         else if (decision == 3){
  39.         combos = 6;System.out.println("Enter your six characters");raw = keyboard.next();
  40.         }
  41.    
  42.         int slot = 0;
  43.         switch (combos){
  44.         case 3:
  45.         slot = 150;
  46.         break;
  47.         case 4:
  48.         slot = 510;
  49.         break;
  50.         case 5:
  51.         slot = 1230;
  52.         break;
  53.         case 6:
  54.         slot = 1950;
  55.         break;
  56.         }
  57.        
  58.         String testedWord[] = new String[slot];
  59.        
  60.    
  61.         int T = 0;
  62.         String rawArray[] = new String[6];
  63.         for(int i = 0; i < 6;i++)
  64.         {rawArray[i] = raw.substring(i,(i+1));}
  65.        
  66.    
  67.         //2
  68.         for(int j = 0; j < rawArray.length;j++){
  69.         for(int i = 0; i < rawArray.length; i++){
  70.         if(i ==j){}
  71.         else{
  72.         //System.out.print(rawArray[j].concat(rawArray[i]) + " ");
  73.         testedWord[T] = rawArray[j].concat(rawArray[i]);T++;}
  74.        
  75.             }
  76.         //System.out.println();
  77.         }
  78.        
  79.        
  80.         if(combos == 3 || combos == 4 || combos == 5 || combos == 6){
  81.         //3
  82.         for(int q = 0; q < rawArray.length;q++){
  83.         for(int j = 0; j < rawArray.length;j++){
  84.         for(int i = 0; i < rawArray.length; i++){
  85.             if(q == i || q == j || j ==i){}
  86.             else{
  87.             //System.out.print(rawArray[j].concat(rawArray[i]).concat(rawArray[q]) + " ");
  88.             testedWord[T] = rawArray[j].concat(rawArray[i]).concat(rawArray[q]);T++;}
  89.                 }
  90.             //System.out.println();
  91.             }
  92.         }}
  93.        
  94.        
  95.        
  96.         if(combos == 4 || combos == 5 || combos == 6){
  97.         //4
  98.         for(int k = 0; k < rawArray.length;k++){
  99.         for(int q = 0; q < rawArray.length;q++){
  100.         for(int j = 0; j < rawArray.length;j++){
  101.         for(int i = 0; i < rawArray.length; i++){
  102.             if(q == i || q == j || j ==i || k == q || k == j || k == i){}
  103.             else{
  104.             //System.out.print(rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]) + " ");
  105.             testedWord[T] = rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]);T++;}
  106.                     }
  107.         //System.out.println();
  108.                 }
  109.             }
  110.         }}
  111.        
  112.        
  113.        
  114.        
  115.         if (combos == 6 || combos == 5){
  116.         //5
  117.         for(int p = 0; p < rawArray.length;p++){
  118.         for(int k = 0; k < rawArray.length;k++){
  119.         for(int q = 0; q < rawArray.length;q++){
  120.         for(int j = 0; j < rawArray.length;j++){
  121.         for(int i = 0; i < rawArray.length; i++){
  122.             if(q == i || q == j || j ==i || k == q || k == j || k == i || p == k || p == q || p == j || p == i){}
  123.             else{
  124.             //System.out.print(rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]).concat(rawArray[p]) + " ");
  125.             testedWord[T] = rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]).concat(rawArray[p]);T++;}
  126.                         }
  127.         //System.out.println();
  128.                     }
  129.                 }
  130.             }
  131.         }}
  132.    
  133.         if(combos == 6){
  134.         //6
  135.         for(int w = 0; w < rawArray.length;w++){
  136.         for(int p = 0; p < rawArray.length;p++){
  137.         for(int k = 0; k < rawArray.length;k++){
  138.         for(int q = 0; q < rawArray.length;q++){
  139.         for(int j = 0; j < rawArray.length;j++){
  140.         for(int i = 0; i < rawArray.length; i++){
  141.             if(q == i || q == j || j ==i || k == q || k == j || k == i || p == k || p == q || p == j || p == i || w == p || w == k || w == q || w == j || w == i){}
  142.             else{
  143.             //System.out.print(rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]).concat(rawArray[p]) + " ");
  144.             testedWord[T] = rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]).concat(rawArray[p]).concat(rawArray[w]);T++;}
  145.                         }
  146.         //System.out.println();
  147.                     }
  148.                 }
  149.             }
  150.         }
  151.     }}
  152.    
  153.         if(decision == 2 || decision == 3){
  154.        
  155.         String fileName = args[0];
  156.         Scanner fileScanner = null;
  157.         String dictArray[] = new String[28838];
  158.         int dictWords = 0;
  159.        
  160.         //finds filename//
  161.         try{fileScanner = new Scanner(new File(fileName));}
  162.         catch (FileNotFoundException e) {
  163.             System.out.println("Error: "+ fileName +  " does not exist.");
  164.             System.exit(0);
  165.         }  
  166.        
  167.         //Reads in each word and assigns it to an element in the array//
  168.         while(fileScanner.hasNext()){
  169.         dictArray[dictWords] = fileScanner.next();
  170.         dictWords++;
  171.         }
  172.        
  173.         int FA = 0;
  174.         for(int i = 0; i < 28838; i++){
  175.             for(int j = 0; j < testedWord.length;j++){
  176.                 if(testedWord[j].equalsIgnoreCase(dictArray[i]))
  177.                 {
  178.                     FA++;
  179.                 }
  180.             }
  181.            
  182.         }
  183.        
  184.        
  185.        
  186.        
  187.         String finalArray[] = new String[FA];
  188.         int correctWordCount = 0;
  189.        
  190.         for(int i = 0; i < 28838; i++){
  191.             for(int j = 0; j < testedWord.length;j++){
  192.                 if(testedWord[j].equalsIgnoreCase(dictArray[i]))
  193.                 {
  194.                 finalArray[correctWordCount] = testedWord[j];
  195.                 correctWordCount++;
  196.                 }
  197.             }
  198.            
  199.         }
  200.        
  201.         //for(int u = 0; u < finalArray.length;u++){
  202.         //  System.out.println(finalArray[u]);
  203.         //}
  204.        
  205.    
  206.        
  207.         Robot rb = new Robot();
  208.         System.out.println("Prepare to type words...");
  209.         sr.delay(4000);
  210.         int counter = 0;
  211.        
  212.        
  213.         for(int i = 0; i < finalArray.length;i++)
  214.         {
  215.            
  216.    
  217.             counter++;
  218.             sr.type(finalArray[i]);
  219.             rb.keyPress(KeyEvent.VK_ENTER);
  220.             rb.keyRelease(KeyEvent.VK_ENTER);
  221.            
  222.        
  223.         }
  224.        
  225.         if (decision == 2){System.out.println("Cross-referenced with Scrabble dictionary for " + raw + ".");}
  226.         }
  227.        
  228. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  229.        
  230.         if(decision == 1 || decision == 3){
  231.            
  232.             Robot rb = new Robot();
  233.             if(decision == 1){System.out.println("Prepare to type words...");
  234.             sr.delay(4000);
  235.             }
  236.            
  237.             int bruteGuessLength = 0;
  238.             if(decision == 3){bruteGuessLength = 510;}
  239.             if(decision == 1){bruteGuessLength = testedWord.length;}
  240.  
  241.             for(int i = 0; i < bruteGuessLength;i++)
  242.             {
  243.                
  244.        
  245.                 sr.type(testedWord[i]);
  246.                 rb.keyPress(KeyEvent.VK_ENTER);
  247.                 rb.keyRelease(KeyEvent.VK_ENTER);
  248.                
  249.            
  250.             }
  251.            
  252.             if(decision== 1){System.out.println("Tryed all possible combinations for " + combos + " " + raw + ".");}
  253.             if(decision == 3){System.out.println("Smartguessed for " + raw);}
  254.         }
  255.        
  256.        
  257.  
  258.        
  259.     }
  260.  
  261.    
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement