Results 1 to 3 of 3
- 05-04-2010, 07:33 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
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); }
- 05-04-2010, 08:25 PM #2
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 ~-'
- 05-04-2010, 08:44 PM #3
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
Similar Threads
-
can any one pls send me a sample code for calling a jsp code in swings
By sniffer139 in forum AWT / SwingReplies: 1Last Post: 03-04-2010, 11:19 AM -
Convert java code to midlet code
By coldvoice05 in forum New To JavaReplies: 1Last Post: 08-12-2009, 11:14 AM -
Convert java code to midlet code
By coldvoice05 in forum Advanced JavaReplies: 1Last Post: 08-09-2009, 01:21 PM -
Why doesn't this code accept my code?
By PeterFeng in forum New To JavaReplies: 5Last Post: 02-03-2009, 01:39 PM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks