1 Replies - 4375 Views - Last Post: 14 July 2012 - 11:37 AM Rate Topic: -----

#1 esludds  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 02-July 12

Creating a word search in java

Posted 14 July 2012 - 11:11 AM

I'm trying to create a word search in java i'm not going to put a gui or anything on it i'm just trying to do something simple. I have the list of words and the letters in the word search itself so that doesn't have to be randomly generated or anything like that. I'm wondering how i would go about it? ie setting up a grid for the word search. and what search method would be effective?
Is This A Good Question/Topic? 0
  • +

Replies To: Creating a word search in java

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5072
  • View blog
  • Posts: 13,696
  • Joined: 18-April 07

Re: Creating a word search in java

Posted 14 July 2012 - 11:37 AM

Well one method you could do is loop through each row of the word search looking for matching words from the list. Second you would do the same thing with columns, diagonals etc. If you are supporting reverse words of course you would need to look for those as well.

//Pseudocode for horizontal searching

for each line in search grid
   for each word in word list
       does line contain word or does line contain word reversed
           yes, remove word from list
   end for
end of



Diagonal is a little bit trickier, but if you first start from a corner and work you way across constructing a line using a nested loop through the grid, you can construct a line and then do the same "word is in line" checking.

:)

Edit: A second method would be to isolate a letter in the grid, then search for matching characters adjacent to it that matches a word. For instance if I have "a" in the grid I would look at the 8 letters around it to see if it has a "t" to match the word "hat"

This is a little more complex. Could be done using recursion etc.

This post has been edited by Martyr2: 14 July 2012 - 11:39 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1