What's the most efficient way to check a value against a large list of items?
Hello all, I am making a word game (like Scrabble) which requires players to use tiles to make words. I am trying to make it so that the words are checked for validity against a database of words (the entire english dictionary) when played. I was wondering if there some way of simply asking if the value exists in the database without having to loop through every word to find out? Would TMaps help out in this instance? The english language as a text file is around 1.6mb so I imagine it would be quite inefficient to be looping through this every time.
And secondly, would it be possible to populate the word database with an external text file via blueprints?
Any help would be greatly appreciated :)
asked May 16 '16 at 06:57 AM in Blueprint Scripting
you can separate your data alphabetically, so if your word begins with an S, you only check through the list of words beginning with the letter S. that way, instead of checking a million entries, you only check 30,000. if you want things to be more efficient, you can break the data down into smaller arrays. so put all the words that begin with "Sh" into its own list, and that will bring that 30,000 items to check, down to about 2,000, which should be fast enough.
if you want to automatically organize your data into an alphabetical tree that can be searched quickly, you might want to look into Btrees:
answered May 16 '16 at 10:08 AM
First of all, if you are that much worried about efficiency you should not be using blueprints but c++ instead. Secondly, you should consider using a integrated database solution such as SQlite 3. Implementation and tutorial on forums. (Porting txt to database is pretty easy.)
Scrabble is much more complex with it's point system, you do not need to add these on the database. Instead, make each tile have a 'point'>1 integer variable and then calculate the total points if the word exists and is valid for submission.
answered May 16 '16 at 09:40 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here