Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Wordsearch probleeemo!

 
Paul Patter
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was hoping you would be able to help with a program I'm writing.
It's basically a word search composing of a square region 10x10 of jumbled letters, containing related(either vertically, horizontally, or diagonally) words.
The letters can be selected until a complete word has been highlighted, etc.

Problem is, I'm unable to find a suitable graphical interface for this. Initially I thought of using a table with cells, however the Java API doesnt allow selection of unrelated cells, it only lets me select whole rows or coloumns.
Would you have any other idea of a way to do this?

Help greatly appreciated! Thanks!
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at GridLayout?
 
Rob Camick
Ranch Hand
Posts: 2703
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe a GridLayout of JToggleButtons.
 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob's suggestion sounds good.

Or, it wouldn't be too hard just draw it from scratch using lines, filled rectangles, etc. You can easily work out which letter has been clicked from the co-ordinates of the click on the panel. It might be a bit easier this way if you want to allow things like clicking and dragging to highlight and select multiple letters.
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch!
 
Paul Patter
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! I've fiddled with it and went with the Rob's suggestion, implemented and works out great!

However I've run into another obstacle which I'd like do more efficiently.

I am using a 2D array to handle the characters which will map to the graphical interface.
I will place words pulled from a text file, onto the interface vertically, horizontally, and diagonally, and then fill the gaps with random letters. For simplicities sake and time, I wont be having words overlap each-other.
I'm looking for the most efficient logic to as to placing these words into this 2D array from the text file.

I've got a rough idea, however working that approach would be like writing a series of novels for what can be a 2 page pamphlet.

Insight appreciated!

Great forum by the way!


 
Luigi Plinge
Ranch Hand
Posts: 441
IntelliJ IDE Scala Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends what you mean by "efficient". Presumably you're not just trying to pack the most words into the smallest space, because then you'd end up with most of the the words lined up next to each other.

I would probably do something like this:

For each word
1) Create a map of all the possible positions (the grid dimensions plus an extra dimension for direction)

2) Give each position a score according to some criteria such as
- Number of times a direction has already been used
- Distance from existing words
- Number of times it crosses existing words

3) Select a position at random in proportion to some power of the score (i.e. do you want a position with a score of 10 to be twice as likely to be selected as one with a score of 5, or six times more likely, or 1.5 times as likely?)

It would barely add any complication at all to allow words to cross, since you need to check each square in a potential position for occupancy already, you just take it as valid if the square's letter matches the word you're placing.
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!