Public feed
#377886
//finds the first value in a 4x4 grid or XxX grid for that matter
public int FindFirst(String wordToCheck, int StringPos){
System.out.println("wordToCheck's first letter : " + wordToCheck.substring(0, 1));
int LocOfFirstLetter = 23;
for (int x = 0; x < Board.length; x++){
// System.out.println("grid @ pos " + x + " is: String: " + Grid[(x/4)][(x%4)] + " row: " + x/4 + " col: " + x%4);
String LetterToCheck = wordToCheck.charAt(StringPos)+"";
System.out.println("Checking Letter : " + LetterToCheck);
if (LetterToCheck.equalsIgnoreCase(Grid[(x/4)][(x%4)]) == true){
System.out.println("First char isOnBoard at location " + Grid[(x/Grid.length)][(x%Grid.length)] + " at r/c : " + x/4 + " " + x%4 );
LocOfFirstLetter = x;
SelectedSquare[x]=true;
FindNext(wordToCheck, StringPos+1, x, (x/Grid.length),(x%Grid.length) );
}
}
return LocOfFirstLetter;
}
// suppose to find the next value of the word
public int FindNext(String wordToCheck, int StringPos, int StartLoc, int row, int col){
String LetterToCheck = wordToCheck.charAt(StringPos)+"";
System.out.println("Selected squre should be true: " + SelectedSquare[StartLoc]);
System.out.println("Next Letter is: " + LetterToCheck);
System.out.println("First letter at pos: " + StringPos + " row: " + row + " col : " + col); // is there a way to do this w/o 8 if statements, recursively?
/*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
*/
if(row<0 || row > 4 || col <0 || col > 4 ){
System.out.println("not on board");
}
return 0;
}
}