Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.AWTException;
- import java.util.Arrays;
- import java.util.Random;
- import java.util.Scanner;
- import java.awt.AWTException;
- import java.awt.Robot;
- import java.awt.event.KeyEvent;
- import java.awt.AWTException;
- import java.awt.Robot;
- import java.io.File;
- import java.io.FileNotFoundException;
- //Steven Burrell
- //Date Created 5/1/2012 in (Aprox 3-4 hours)
- //Letterblox/Scrabble word generator and enterer.
- public class Typer {
- public static void main(String[] args) throws AWTException {
- SmartRobot sr = new SmartRobot();
- Scanner keyboard = new Scanner(System.in);
- //QUERY//
- int decision = 0;
- while(decision != 1 && decision != 2 && decision != 3){System.out.println("(1)Try all possible combinations? (2)Crossreference with dictionary? (3)Smartguess?" );decision = keyboard.nextInt();}
- int combos = 0;
- String raw = "";
- if(decision == 2){
- combos = 6;System.out.println("Enter your six characters");raw = keyboard.next();
- }
- else if (decision == 1){
- System.out.println("Enter your six characters and how many combos (3-6) to check (Ex. abcdef 4)");
- raw = keyboard.next();
- combos = keyboard.nextInt();
- }
- else if (decision == 3){
- combos = 6;System.out.println("Enter your six characters");raw = keyboard.next();
- }
- int slot = 0;
- switch (combos){
- case 3:
- slot = 150;
- break;
- case 4:
- slot = 510;
- break;
- case 5:
- slot = 1230;
- break;
- case 6:
- slot = 1950;
- break;
- }
- String testedWord[] = new String[slot];
- int T = 0;
- String rawArray[] = new String[6];
- for(int i = 0; i < 6;i++)
- {rawArray[i] = raw.substring(i,(i+1));}
- //2
- for(int j = 0; j < rawArray.length;j++){
- for(int i = 0; i < rawArray.length; i++){
- if(i ==j){}
- else{
- //System.out.print(rawArray[j].concat(rawArray[i]) + " ");
- testedWord[T] = rawArray[j].concat(rawArray[i]);T++;}
- }
- //System.out.println();
- }
- if(combos == 3 || combos == 4 || combos == 5 || combos == 6){
- //3
- for(int q = 0; q < rawArray.length;q++){
- for(int j = 0; j < rawArray.length;j++){
- for(int i = 0; i < rawArray.length; i++){
- if(q == i || q == j || j ==i){}
- else{
- //System.out.print(rawArray[j].concat(rawArray[i]).concat(rawArray[q]) + " ");
- testedWord[T] = rawArray[j].concat(rawArray[i]).concat(rawArray[q]);T++;}
- }
- //System.out.println();
- }
- }}
- if(combos == 4 || combos == 5 || combos == 6){
- //4
- for(int k = 0; k < rawArray.length;k++){
- for(int q = 0; q < rawArray.length;q++){
- for(int j = 0; j < rawArray.length;j++){
- for(int i = 0; i < rawArray.length; i++){
- if(q == i || q == j || j ==i || k == q || k == j || k == i){}
- else{
- //System.out.print(rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]) + " ");
- testedWord[T] = rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]);T++;}
- }
- //System.out.println();
- }
- }
- }}
- if (combos == 6 || combos == 5){
- //5
- for(int p = 0; p < rawArray.length;p++){
- for(int k = 0; k < rawArray.length;k++){
- for(int q = 0; q < rawArray.length;q++){
- for(int j = 0; j < rawArray.length;j++){
- for(int i = 0; i < rawArray.length; i++){
- if(q == i || q == j || j ==i || k == q || k == j || k == i || p == k || p == q || p == j || p == i){}
- else{
- //System.out.print(rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]).concat(rawArray[p]) + " ");
- testedWord[T] = rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]).concat(rawArray[p]);T++;}
- }
- //System.out.println();
- }
- }
- }
- }}
- if(combos == 6){
- //6
- for(int w = 0; w < rawArray.length;w++){
- for(int p = 0; p < rawArray.length;p++){
- for(int k = 0; k < rawArray.length;k++){
- for(int q = 0; q < rawArray.length;q++){
- for(int j = 0; j < rawArray.length;j++){
- for(int i = 0; i < rawArray.length; i++){
- 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){}
- else{
- //System.out.print(rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]).concat(rawArray[p]) + " ");
- testedWord[T] = rawArray[j].concat(rawArray[i]).concat(rawArray[q]).concat(rawArray[k]).concat(rawArray[p]).concat(rawArray[w]);T++;}
- }
- //System.out.println();
- }
- }
- }
- }
- }}
- if(decision == 2 || decision == 3){
- String fileName = args[0];
- Scanner fileScanner = null;
- String dictArray[] = new String[28838];
- int dictWords = 0;
- //finds filename//
- try{fileScanner = new Scanner(new File(fileName));}
- catch (FileNotFoundException e) {
- System.out.println("Error: "+ fileName + " does not exist.");
- System.exit(0);
- }
- //Reads in each word and assigns it to an element in the array//
- while(fileScanner.hasNext()){
- dictArray[dictWords] = fileScanner.next();
- dictWords++;
- }
- int FA = 0;
- for(int i = 0; i < 28838; i++){
- for(int j = 0; j < testedWord.length;j++){
- if(testedWord[j].equalsIgnoreCase(dictArray[i]))
- {
- FA++;
- }
- }
- }
- String finalArray[] = new String[FA];
- int correctWordCount = 0;
- for(int i = 0; i < 28838; i++){
- for(int j = 0; j < testedWord.length;j++){
- if(testedWord[j].equalsIgnoreCase(dictArray[i]))
- {
- finalArray[correctWordCount] = testedWord[j];
- correctWordCount++;
- }
- }
- }
- //for(int u = 0; u < finalArray.length;u++){
- // System.out.println(finalArray[u]);
- //}
- Robot rb = new Robot();
- System.out.println("Prepare to type words...");
- sr.delay(4000);
- int counter = 0;
- for(int i = 0; i < finalArray.length;i++)
- {
- counter++;
- sr.type(finalArray[i]);
- rb.keyPress(KeyEvent.VK_ENTER);
- rb.keyRelease(KeyEvent.VK_ENTER);
- }
- if (decision == 2){System.out.println("Cross-referenced with Scrabble dictionary for " + raw + ".");}
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- if(decision == 1 || decision == 3){
- Robot rb = new Robot();
- if(decision == 1){System.out.println("Prepare to type words...");
- sr.delay(4000);
- }
- int bruteGuessLength = 0;
- if(decision == 3){bruteGuessLength = 510;}
- if(decision == 1){bruteGuessLength = testedWord.length;}
- for(int i = 0; i < bruteGuessLength;i++)
- {
- sr.type(testedWord[i]);
- rb.keyPress(KeyEvent.VK_ENTER);
- rb.keyRelease(KeyEvent.VK_ENTER);
- }
- if(decision== 1){System.out.println("Tryed all possible combinations for " + combos + " " + raw + ".");}
- if(decision == 3){System.out.println("Smartguessed for " + raw);}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement