All pastes #382033 Raw Edit

ShadeS

public java v1 · immutable
·published 2007-03-05 07:24 UTC
rendered paste body
Program out put:Starting 4x4 game, words from enable1.txt, min word length 3.Reading word list from file enable1.txt... Read 172823 words.Building this game's lexicon... done. Stringpos 0word to check: doewordToCheck.length 3 Cur Center:  0 NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 0  row is: 0 col is: 0row: 0 and col: 0 row is: 0 col is: 0Grid[row][col] V SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 1  row is: 0 col is: 0row: 0 and col: 1 row is: 0 col is: 1Grid[row][col] I SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 2  row is: 0 col is: 1row: 0 and col: 2 row is: 0 col is: 2Grid[row][col] M SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 3  row is: 0 col is: 2row: 0 and col: 3 row is: 0 col is: 3Grid[row][col] P SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 4  row is: 0 col is: 3row: 1 and col: 0 row is: 1 col is: 0Grid[row][col] E SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 5  row is: 1 col is: 0row: 1 and col: 1 row is: 1 col is: 1Grid[row][col] E SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 6  row is: 1 col is: 1row: 1 and col: 2 row is: 1 col is: 2Grid[row][col] S SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 7  row is: 1 col is: 2row: 1 and col: 3 row is: 1 col is: 3Grid[row][col] H SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 8  row is: 1 col is: 3row: 2 and col: 0 row is: 2 col is: 0Grid[row][col] O SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 9  row is: 2 col is: 0row: 2 and col: 1 row is: 2 col is: 1Grid[row][col] E SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 10  row is: 2 col is: 1row: 2 and col: 2 row is: 2 col is: 2Grid[row][col] M SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 11  row is: 2 col is: 2row: 2 and col: 3 row is: 2 col is: 3Grid[row][col] H SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 12  row is: 2 col is: 3row: 3 and col: 0 row is: 3 col is: 0Grid[row][col] A SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 0word to check: doeLooking for letter : dwordToCheck.length 3 Cur Center:  0 X is : 13  row is: 3 col is: 0row: 3 and col: 1 row is: 3 col is: 1Grid[row][col] D SelectedSquare[row][col] == unselected if false: false  row is: 3 col is: 1Found & not selected Next row: 3Next col 1 Looking for Letter To Check  dFound letter at 13Found letter at row: 3 and col: 1  Selected squre should be true: trueAt Spot DNext Letter is: oCurrent Row and Column : 3 1Found lettertocheck: oFound it at: 121next center: 13List with Locations in order -_-__-_-== List with Locations in order: 13locaTions in order 13WordToCheck doe  Stringpos 1word to check: doewordToCheck.length 3 Cur Center:  13 NotABaseCase:  Stringpos 1word to check: doeLooking for letter : owordToCheck.length 3 Cur Center:  13 X is : 0  row is: 3 col is: 0row: 0 and col: 0 row is: 0 col is: 0Grid[row][col] V SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 1word to check: doeLooking for letter : owordToCheck.length 3 Cur Center:  13 X is : 1  row is: 0 col is: 0row: 0 and col: 1 row is: 0 col is: 1Grid[row][col] I SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 1word to check: doeLooking for letter : owordToCheck.length 3 Cur Center:  13 X is : 2  row is: 0 col is: 1row: 0 and col: 2 row is: 0 col is: 2Grid[row][col] M SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 1word to check: doeLooking for letter : owordToCheck.length 3 Cur Center:  13 X is : 3  row is: 0 col is: 2row: 0 and col: 3 row is: 0 col is: 3Grid[row][col] P SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 1word to check: doeLooking for letter : owordToCheck.length 3 Cur Center:  13 X is : 4  row is: 0 col is: 3row: 1 and col: 0 row is: 1 col is: 0Grid[row][col] E SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 1word to check: doeLooking for letter : owordToCheck.length 3 Cur Center:  13 X is : 5  row is: 1 col is: 0row: 1 and col: 1 row is: 1 col is: 1Grid[row][col] E SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 1word to check: doeLooking for letter : owordToCheck.length 3 Cur Center:  13 X is : 6  row is: 1 col is: 1row: 1 and col: 2 row is: 1 col is: 2Grid[row][col] S SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 1word to check: doeLooking for letter : owordToCheck.length 3 Cur Center:  13 X is : 7  row is: 1 col is: 2row: 1 and col: 3 row is: 1 col is: 3Grid[row][col] H SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 1word to check: doeLooking for letter : owordToCheck.length 3 Cur Center:  13 X is : 8  row is: 1 col is: 3row: 2 and col: 0 row is: 2 col is: 0Grid[row][col] O SelectedSquare[row][col] == unselected if false: false  row is: 2 col is: 0Found & not selected Next row: 2Next col 0 Looking for Letter To Check  oFound letter at 8Found letter at row: 2 and col: 0  Selected squre should be true: trueAt Spot ONext Letter is: eCurrent Row and Column : 2 0Found lettertocheck: eFound it at: 80next center: 8List with Locations in order -_-__-_-== List with Locations in order: 13List with Locations in order: 8locaTions in order 8WordToCheck doe  Stringpos 2word to check: doewordToCheck.length 3 Cur Center:  8 NotABaseCase:  Stringpos 2word to check: doeLooking for letter : ewordToCheck.length 3 Cur Center:  8 X is : 0  row is: 1 col is: 3row: 0 and col: 0 row is: 0 col is: 0Grid[row][col] V SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 2word to check: doeLooking for letter : ewordToCheck.length 3 Cur Center:  8 X is : 1  row is: 0 col is: 0row: 0 and col: 1 row is: 0 col is: 1Grid[row][col] I SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 2word to check: doeLooking for letter : ewordToCheck.length 3 Cur Center:  8 X is : 2  row is: 0 col is: 1row: 0 and col: 2 row is: 0 col is: 2Grid[row][col] M SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 2word to check: doeLooking for letter : ewordToCheck.length 3 Cur Center:  8 X is : 3  row is: 0 col is: 2row: 0 and col: 3 row is: 0 col is: 3Grid[row][col] P SelectedSquare[row][col] == unselected if false: false  NotABaseCase:  Stringpos 2word to check: doeLooking for letter : ewordToCheck.length 3 Cur Center:  8 X is : 4  row is: 0 col is: 3row: 1 and col: 0 row is: 1 col is: 0Grid[row][col] E SelectedSquare[row][col] == unselected if false: false  row is: 1 col is: 0Found & not selected Next row: 1Next col 0 Looking for Letter To Check  eFound letter at 4Found letter at row: 1 and col: 0  Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 3	at java.lang.String.charAt(Unknown Source)	at b0ggleLayout.FindWord(b0ggleLayout.java:107)	at b0ggleLayout.FindWord(b0ggleLayout.java:126)	at b0ggleLayout.FindWord(b0ggleLayout.java:126)	at BogglePlayer.isOnBoard(BogglePlayer.java:26)	at BoggleGUI.checkAndAddWordHuman(BoggleGUI.java:127)	at BoggleGUI$WordEntryField$1.actionPerformed(BoggleGUI.java:682)	at javax.swing.JTextField.fireActionPerformed(Unknown Source)	at javax.swing.JTextField.postActionEvent(Unknown Source)	at javax.swing.JTextField$NotifyAction.actionPerformed(Unknown Source)	at javax.swing.SwingUtilities.notifyAction(Unknown Source)	at javax.swing.JComponent.processKeyBinding(Unknown Source)	at javax.swing.JComponent.processKeyBindings(Unknown Source)	at javax.swing.JComponent.processKeyEvent(Unknown Source)	at java.awt.Component.processEvent(Unknown Source)	at java.awt.Container.processEvent(Unknown Source)	at java.awt.Component.dispatchEventImpl(Unknown Source)	at java.awt.Container.dispatchEventImpl(Unknown Source)	at java.awt.Component.dispatchEvent(Unknown Source)	at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)	at java.awt.Component.dispatchEventImpl(Unknown Source)	at java.awt.Container.dispatchEventImpl(Unknown Source)	at java.awt.Window.dispatchEventImpl(Unknown Source)	at java.awt.Component.dispatchEvent(Unknown Source)	at java.awt.EventQueue.dispatchEvent(Unknown Source)	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)	at java.awt.EventDispatchThread.run(Unknown Source)______import java.util.ArrayList;import java.util.List;public class b0ggleLayout {		private String[][] Grid;	private String[] Board;	private boolean[][] SelectedSquare;	List<String> IntRepofStringOnBoard;	List<Integer> LocationsInOrder = new ArrayList<Integer>();		//sets up the boggle board for use	//this method works for sure		public String[][] AssignGrid(String[] letterArray){		Board = letterArray;		SelectedSquare = new boolean[Board.length][Board.length];		double sideLengthdbl = Math.sqrt(letterArray.length);		int sideLengthint = (int)sideLengthdbl;			Grid = new String[sideLengthint][sideLengthint];		for (int x = 0; x < letterArray.length; x++){			int row=x/4;			int col=x%4;			Grid[row][col]=letterArray[x];		} 				return Grid;	}		public List FindWord(String wordToCheck, int StringPos, int NextCenter, int BoardPosition, int row, int col){		System.out.println(" ");		System.out.println("Stringpos " + StringPos);		System.out.println("word to check: " + wordToCheck);		System.out.println("wordToCheck.length " + wordToCheck.length());		System.out.println(" Cur Center:  " + NextCenter);		 		for(int x = 0; x < BoardPosition; x++){ 			System.out.println(" "); //finding the first letter linearly 	 			if(wordToCheck.length()+1<StringPos ){  //base case when the StringPosition to be checked is beyond the length of the Word To Check.  				System.out.println("Base Case!: ");				 				for(int y = 0; y < LocationsInOrder.size(); y++){ /* simple loop to see				       	                                           * if the int representations				       	                                           * of the string locations are				       	                                           * being added in the 'correct 				       	                                           * order				       	                                           *  */								System.out.println("List with Locations in order: " + LocationsInOrder.get(y));				}				System.out.println("locaTions in order "  + LocationsInOrder.get(StringPos));							System.out.println("WordToCheck " + wordToCheck);				System.out.println(" "); 								return LocationsInOrder; 			}  			else{ 				System.out.println("NotABaseCase: "); 				System.out.println(" "); 				System.out.println("Stringpos " + StringPos); 				System.out.println("word to check: " + wordToCheck); 				System.out.println("Looking for letter : "  +  wordToCheck.charAt(StringPos)); 				System.out.println("wordToCheck.length " + wordToCheck.length()); 				System.out.println(" Cur Center:  " + NextCenter); 				System.out.println(" X is : " + x); 				System.out.println(" "); 				System.out.println(" row is: " + row); 				System.out.println(" col is: " + col); // I beleive the problem lays somewhere here 				int oldrow = row;                      // I can't quite think the recursion out correctly here 				int oldcol = col; 				String LetterToCheck = wordToCheck.charAt(StringPos)+"";	 			row = x/Grid.length;				col = x%Grid.length;				int CurrentPosition = row * Grid.length+col;					int nextrow = CurrentPosition/Grid.length; // trying to work some magic					int nextcol = CurrentPosition%Grid.length;				System.out.println("row: " + row + " and col: " + col);				System.out.println(" row is: " + row); 				System.out.println(" col is: " + col); 								System.out.println("Grid[row][col] " + Grid[row][col]);				System.out.println(" ");				System.out.println("SelectedSquare[row][col] == unselected if false: " + SelectedSquare[row][col] );				System.out.println(" ");	 			if (LetterToCheck.equalsIgnoreCase(Grid[row][col]) == true && SelectedSquare[row][col] == false ){   //found letter & not previously selected	 				System.out.println(" row is: " + row);	 				System.out.println(" col is: " + col);	 	 					System.out.println("Found & not selected");	 						 					System.out.println(" Next row: " + nextrow);	 					System.out.println("Next col " + nextcol); 	 					System.out.println(" ");	 					System.out.println("Looking for Letter To Check  " + LetterToCheck);						System.out.println("Found letter at " + CurrentPosition);						System.out.println("Found letter at row: " + row + " and col: " + col);						LocationsInOrder.add(CurrentPosition); // add spot to List of ints to be returned						System.out.println(" ");												SelectedSquare[row][col]=true; // mark unselectable												System.out.println(" ");						if (wordToCheck.charAt(StringPos+1)+""!=null){							String NextLetterToCheck = wordToCheck.charAt(StringPos+1)+""; // get the next letter to check							NextCenter = FindAround(CurrentPosition, NextLetterToCheck, nextrow, nextcol) ; //next center is the next center to 						}						//check around for the next letter						System.out.println("next center: " + NextCenter);							if (NextCenter < -50){ // failure case 								System.out.println("Not Found Around!"); // the next letter is not around this value								LocationsInOrder.remove(LocationsInOrder.size()-1);							}							else{							System.out.println("List with Locations in order -_-__-_-== ");							for(int y = 0; y < LocationsInOrder.size(); y++){ // same loop as earlier to check for validity								System.out.println("List with Locations in order: " + LocationsInOrder.get(y));							}							System.out.println("locaTions in order "  + LocationsInOrder.get(StringPos));										System.out.println("WordToCheck " + wordToCheck);							System.out.println(" ");												FindWord(wordToCheck, StringPos+1, NextCenter, BoardPosition, oldrow, oldcol); // recursive search for finding the next value							}						}			} 		}		return LocationsInOrder;	}		public int FindAround(int CenterTile, String NextLetter, int row, int col){			System.out.println("Selected squre should be true: " + SelectedSquare[row][col]);		System.out.println("At Spot " + Board[CenterTile]);		System.out.println("Next Letter is: " + NextLetter);		/*positions to test		 * 1 row,col-1     left		 * 2 row-1,col-1   left & up		 * 3 row-1,col     up		 * 4 row-1,col+1   up & right		 * 5 row,col+1     right		 * 6 row+1,col+1   right & down 		 * 7 row+1,col     down		 * 8 row+1,col-1   down & left		 * 		 */		System.out.println("Current Row and Column : " + row + " " + col);				if(row<0 || row > 3 || col <0 || col > 3 ){				System.out.println("not on board");				return -101;			}			if( ((row >= 0) && (col-1 >=0)) && NextLetter.equalsIgnoreCase(Grid[row][col-1])==true){				System.out.println("Found lettertocheck: " + NextLetter);				System.out.println("Found it at: " + row * Grid.length+col);				return row * Grid.length+col;			}						if( ((row-1) >=0 && (col-1 >=0)) && NextLetter.equalsIgnoreCase(Grid[row-1][col-1])==true){				System.out.println("Found lettertocheck: " + NextLetter);				System.out.println("Found it at: " + row * Grid.length+col);				return row * Grid.length+col;			}			if( ((row-1) >= 0 && (col <= 3)) && NextLetter.equalsIgnoreCase(Grid[row-1][col])==true){				System.out.println("Found lettertocheck: " + NextLetter);				System.out.println("Found it at: " + row * Grid.length+col);				return row * Grid.length+col;			}				if( ((row-1) >= 0 && (col+1 <=3 )) && NextLetter.equalsIgnoreCase(Grid[row-1][col+1])==true){				System.out.println("Found lettertocheck: " + NextLetter);				System.out.println("Found it at: " + row * Grid.length+col);				return row * Grid.length+col;			}				if( ((row >= 0) && (col+1 <= 3)) && NextLetter.equalsIgnoreCase(Grid[row][col+1])==true){				System.out.println("Found lettertocheck: " + NextLetter);				System.out.println("Found it at: " + row * Grid.length+col);				return row * Grid.length+col;			}				if( ((row+1 <=3 ) && (col >=0 )) && NextLetter.equalsIgnoreCase(Grid[row+1][col])==true){				System.out.println("Found lettertocheck: " + NextLetter);				System.out.println("Found it at: " + row * Grid.length+col);				return row * Grid.length+col;			}				if(  ((row+1 <= 3) && (col-1 >= 0)) && Grid[row+1][col-1]==NextLetter){				System.out.println("Found lettertocheck: " + NextLetter);				System.out.println("Found it at: " + row * Grid.length+col);				return row * Grid.length+col;			}					if( ((row+1 <= 3) && (col+1 <= 3)) && Grid[row+1][col+1]==NextLetter){				System.out.println("Found lettertocheck: " + NextLetter);				System.out.println("Found it at: " + row * Grid.length+col);				return row * Grid.length+col;			}		else 			System.out.println("LetterToCheck: " + NextLetter);			System.out.println("LetterToCheck is not found In FindAround");				return -100;	}}