public static void main(String[] args) {
Dictionary d = new Dictionary();
BoggleBoard b = new BoggleBoard();
Scanner key = new Scanner(System.in);
String word = "";
boolean testContinue = true;
boolean testOnBoard = false;
boolean testInDict = false;
int i = 0;
while (testContinue) {
b.printBoard();
System.out.println("Enter a word (enter \"asdf\" to quit): ");
word = key.nextLine();
if (word.equalsIgnoreCase("asdf")) testContinue = false;
else {
testInDict=d.wordSearch(word.toLowerCase());
while (!testOnBoard && testInDict && i < b.getSize()*b.getSize()) {
testOnBoard = b.onBoard(word);
i++;
}
System.out.println("inDict = " + testInDict);
System.out.println("onBoard = " + testOnBoard);
testOnBoard = false;
testInDict = false;
}
}
public boolean onBoard(String word) {
for(int i = 0;i < size;i++){
for(int j = 0;j < size; j++)
searched[i][j] = false;
}
return onBoard(word,0,0,0);
}
private boolean onBoard(String word, int index, int r, int c) {
//check to see if [r,c] is on the board, and has not been searched
if (c >= 0 && c < size && r >= 0 && r<size && searched[r][c]==false){
searched[r][c] = true;
//check to see if the letter at [r,c] is the next letter in the word
if (board[r][c].equalsIgnoreCase(word.substring(index,index+1))) {
//return true if it is the last letter in the word
if (index == word.length()-1) {
return true;
}
//search each surrounding letter
else if (
(onBoard(word,index+1,r,c+1)) ||
(onBoard(word,index+1,r+1,c+1)) ||
(onBoard(word,index+1,r-1,c+1)) ||
(onBoard(word,index+1,r,c-1)) ||
(onBoard(word,index+1,r+1,c-1)) ||
(onBoard(word,index+1,r-1,c-1)) ||
(onBoard(word,index+1,r-1,c)) ||
(onBoard(word,index+1,r+1,c)) ) return true;
}
else {
searched[r][c] = false;
}
}
return false;
}