単語検索ゲームを作成していますが、アルゴリズムにこだわっています。データ構造のようなテーブルで単語の出現を見つける必要があります。長さと高さがわかっている 2 次元配列を使用することにしました。私の考えは、単語の最初の文字を探し、見つかった場合はあらゆる方向を調べることです。私が把握できないのは、最初の文字を見つけた後に検索を開始する方法です。すべての方向を検索するメソッドに、最初の文字の位置を渡したいと思います。これが私がこれまでに持っているものです:
public void SearchWord(char[,] input, string name)
{
//1. loop through the array and look for the first letter of the string
//2. if found search in all directions "iterative"
//3. if one direction doesn't find it break out of the method and continue to search in other directions
//4. if found mark the positions so you don't find the same word more than once
char firstLetter = name[0];
//go look for it in the 2d array
for (int y = 0; y < 5; y++)
{
for (int x = 0; x < 4; x++)
{
if (results[x, y] == firstLetter)//found the letter
{
Console.WriteLine("Found it " + " " + firstLetter);
Console.WriteLine(x + " " + y);
SearchRightDirection(x, y);
SearchLeftDirection(x, y);
}
}
}
}
SearchRightDirection(char[,], int x, int y){} のようなパラメーターとして場所を渡そうとしましたが、この正確な場所の行と列から配列を続行することはできません。
提案はありますか?また、構造が正しい場合は?