We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,389 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Search words from arrays?

Hiya, I wasn't really sure if this goes under Java or Game Development forums, so I decided to post it here.

I'm making a simple "Scrabble" game, which checks letters placed on the table and tries to find if they form proper nouns. I have a list of words, and two-dimensional array which contains all the letters on the table. Words are only recognized "across and down", so there's no need for diagonal word search.

I really don't have a clue how to check if the letters form any words that are in the list. Any help? :)

For the sake of making my point a bit more clear, here's some code:

Vector<String> wordList = loadWordsFromFile(); // List of words
Letter[][] table = new Letter[10][10]; // 10x10 table

// Game Loop
placeLetter(..); // Places a letter(!)
checkTableForWords(); // <-- THIS, how to do it? :)
2
Contributors
2
Replies
1 Hour
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
bleedi
Junior Poster in Training
84 posts since Jul 2010
Reputation Points: 13
Solved Threads: 2
Skill Endorsements: 0

wordList.contains(myWord);
doesn't work for you?

stultuske
Industrious Poster
4,379 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 24

wordList.contains(myWord);
doesn't work for you?

It does work, but my problem was, how to form 'myWord'. Well, it doesn't really matter anymore, since I found a solution. I just take the x, y coordinates of the letter placed, and start a linear search to the right from X, then from X-1, then from X-2 etc. until I find a word. :)

bleedi
Junior Poster in Training
84 posts since Jul 2010
Reputation Points: 13
Solved Threads: 2
Skill Endorsements: 0
Question Answered as of 1 Year Ago by stultuske

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0577 seconds using 2.66MB