public List isOnBoard(String wordToCheck) {
//isOnBoard: this function takes as argument a String and determines whether the String can be found in the board
//specified by the most recent call to setBoard(). The return type of this function is a List object containing
//Integer elements. If it is possible to find the word in the current board, the function returns a list of Integers
//representing the locations of the dice used to form the word, in order (using the same mapping from integers to
//locations required by setBoard()). If is is NOT possible to form the word, the function returns null. If setBoard()
//has not yet been called, the behavior of this method is undefined.
try {
if (boardArray != null) {
boolean[] booleanArray = new boolean[boardArray.length];
List<Integer> integerArray = new ArrayList<Integer>();
List<Integer> tempIntegerArray = new ArrayList<Integer>();
String[] stringArray;
if (wordToCheck.contains("q") == true) stringArray = new String[wordToCheck.length()-1];
else stringArray = new String[wordToCheck.length()];
for (int i = 0; i < stringArray.length; i++) {
if (wordToCheck.contains("q") == true) {
if (wordToCheck.substring(i,i+1).equalsIgnoreCase("q") == true) {
stringArray[i] = wordToCheck.substring(i,i+2);
}
else {
stringArray[i] = wordToCheck.substring(i+1,i+2);
}
}
else {
stringArray[i] = wordToCheck.substring(i,i+1);
}
}
for (int k = 0; k < stringArray.length; k++) {
for (int j = 0; j < boardArray.length; j++) {
if (stringArray[k].equalsIgnoreCase(boardArray[j])) {
if (integerArray.isEmpty() == false) {
if (isOnBoardCheck(j-1,j) == true && booleanArray[j] == false) {
booleanArray[j] = true;
integerArray.add(j);
}
}
else {
integerArray.add(j);
booleanArray[j] = true;
}
}
}
}
int wordCount = 0;
if (integerArray.size() != stringArray.length) {
System.err.println("Duplicate letters are found... New searches are processing...");
for (int m = 0; m < stringArray.length; m++) {
for (int n = 0; n < integerArray.size(); n++) {
if (stringArray[m].equals(boardArray[integerArray.get(n)])) {
System.out.println(n+"c");
tempIntegerArray.add(n);
if (wordCount == stringArray.length) {
return tempIntegerArray;
}
}
}
}
}
else {
return integerArray;
}
}
}
catch (Exception e) {
System.err.println("Error building ArrayList for wordToCheck integer elements...");
}
return null;
}