Goal:
My goal is to set up a function that will find all possible combinations of letters that make words (assuming you can combine the letters in any direction, without using the same object twice or combining objects that are not next to each other).
Context:
I have a grid of objects with randomly picked letters as children. Each object has a script attached that has the other letters immediately around it stored in a GameObject variable. Like this:
0------1------2
7------X------3
6------5------4
I already have way to check against the letter combinations to see if they are actual words.
The “allLetters” variable below is an array of all the letter objects.
void FindPossibleWords()
{
foreach(GameObject al in allLetters)
{
string word = al.GetComponent<Letter>().letter;
for(int i = 0; i < 7; i++)
{
word += al.GetComponent<Letter>().near*.GetComponent<Letter>().letter;*
-
if("Letters can still potentially make a real word")*
-
{*
-
// Repeat? *
-
}*
-
}*
-
}*
-
}*
I’m not looking for someone to write the code for me. I just can’t get my brain around a method/strategy for looping through an “unknown” number of times.
I can already see that this will not work the way I am going about it. Essentially I am looking for a way for it to loop through an unknown number of letter combinations and then store the ones that are real words.
I apologize for the minimal amount of code, mostly I am stuck on what strategy to use to get the result. I feel like I could get the result with a ridiculous amount of code, but there is usually some other option that I am missing.
I appreciate any help.
Thanks,
Howey