static bool FindWordStartingFromCharacter(int lineInSearch, int positionInSearch, char[][] grid, int foundCharacters, string wordToFind)
{
if (foundCharacters == wordToFind.Length)
{
//we're at the end, found them all
return true;
}
int startingLineInSearch = lineInSearch;
int startingPositionInSearch = positionInSearch;
//look above, even, below lines
for (int x = -1; x <= 1; x++)
{
lineInSearch = startingLineInSearch + x;
//look left center right
for (int y = -1; y <= 1; y++)
{
positionInSearch = startingPositionInSearch + y;
if (x == 0 && y == 0)
{
//searching the same character, skip it
continue;
}
if (grid[lineInSearch][positionInSearch] == wordToFind[foundCharacters])
{
//found the second character, check from this point on recursively
bool result = CheckLine(grid, lineInSearch, positionInSearch, x, y, foundCharacters + 1,
wordToFind);
if (result)
return true;
}
}
}
return false;
}