# Decipher this bit of code for me?

• 05-04-2010, 08:33 PM
gandalf5166
Decipher this bit of code for me?
This bit of code is completely indecipherable to me. It's for a Boggle application, it searches the board for a word. Problem: It doesn't work. I realize that its impossible to decipher, but that's my problem. My teacher gave it to me, and it doesn't work. It invariably returns false. So if anyone could tell me what this code is doing, or even find out what the problem is, it would be much appreciated. And to clarify, my assignment is to make Boggle. So this is a small part of it, that my teacher gave to me. I just don't understand what it's doing.
Code:

```    private static void findWord(int row, int col, char[] word, int startLetterIndex) { char saveChar; if (startLetterIndex == word.length) { wordFound = true; } else if (row >= 0 && row < ROWS && col >= 0 && col < COLS && board[row][col] == word[startLetterIndex]) { saveChar = board[row][col]; board[row][col] = ' '; findWord(row+1, col, word, startLetterIndex+1); if (!wordFound) findWord(row-1, col, word, startLetterIndex+1); if (!wordFound) findWord(row, col+1, word, startLetterIndex+1); if (!wordFound) findWord(row, col-1, word, startLetterIndex+1); if (!wordFound) findWord(row-1, col-1, word, startLetterIndex+1); if (!wordFound) findWord(row+1, col-1, word, startLetterIndex+1); if (!wordFound) findWord(row-1, col+1, word, startLetterIndex+1); if (!wordFound) findWord(row+1, col+1, word, startLetterIndex+1); board[row][col] = saveChar; } else { wordFound = false; } }     public static boolean checkWord(String word) {                 boolean found = false;                 int row, col;                 char[] wordLetters;                 wordLetters = word.toCharArray();                 row = 0;                 while (row < ROWS && !found) {                                                        //find the first letter of word                         col =0;                         while (col < COLS && !found) {                                 if (wordLetters[0] == board[row][col]) {                                         findWord(row, col, wordLetters, 0);                        //check around first letter for word                                         found = wordFound;                                 }                                 if (!found) {                                         col += 1;                                 }                         }                         if (!found) {                                 row += 1;                         }                 }                 return(found);         }```
• 05-04-2010, 09:25 PM
Sno
attempt the old school way, grab a piece of paper, and read each line of code and figure out what statements mean, than you will have a pseudo version of the code.

I would do it, but I do not have that much time in the day to spare.
• 05-04-2010, 09:44 PM
iluxa
Try the Feynman Algorithm:

1. Write down the problem.
2. Think real hard.
3. Write down the solution.