Results 1 to 3 of 3
  1. #1
    gandalf5166 is offline Member
    Join Date
    Feb 2010
    Posts
    75
    Rep Power
    0

    Default 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.
    Java 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);
            }

  2. #2
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    195
    Rep Power
    5

    Default

    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.
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  3. #3
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    Try the Feynman Algorithm:

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

Similar Threads

  1. Replies: 1
    Last Post: 03-04-2010, 12:19 PM
  2. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 12:14 PM
  3. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 02:21 PM
  4. Why doesn't this code accept my code?
    By PeterFeng in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 02:39 PM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •