Hi there,
I’m writing a Scrabble prototype for fun just to learn the ropes of scripting and I’m stuck at checking the spelled word against a dictionary.
I’ve got a text document with a list of words separated by a new line. My original thought was to create an array of strings and have the game check the word spelled on the game board against these strings. At first when I was researching, I thought to use Array.Contains, but that function does not exist for the built-in array as I’ve found out, so I decided to have it check them manually.
//Variable assignment
public static string[] wordArray = new string[];
public TextAsset dict; //assigned in inspector
//In Start()
wordArray = dict.text.Split("
"[0]);
//In other script
if (tilesPlaced)
{
for (int i=0; i<gameMaster.wordArray.Length;i++)
{
if (gameMaster.wordArray *== wordOnBoard)*
{
AddScore();
break;
}
}
}
This whole thing works, but is especially slow. I’m writing and testing with a computer running around 2.4GHz with four cores, and the search through the array takes almost 90 seconds. I realize it’s a lot of strings to search, but I imagine there must be a better way to implement this kind of check, similar to the way Words With Friends or Scrabble itself may do it.
I’ve tried to use ArrayList, List, and Dictionary but I’m not sure I’m implementing them correctly. I also can’t add them straight from the Split() command. The only way I can think to do it is to add an array, then transfer the information from the array to the List using a for loop in the Start function, but that would still require a lengthy initial load.
Does any code gurus out there have any ideas to help me get this together?