AdvancedAlgorithms.WheresWaldorf.CheckLine C# (CSharp) Method

CheckLine() static private method

Recursively checks a line in a certain direction
static private CheckLine ( char grid, int lineInSearch, int positionInSearch, int lineModifier, int positionModifier, int foundCharacters, string wordToFind ) : bool
grid char
lineInSearch int
positionInSearch int
lineModifier int
positionModifier int
foundCharacters int
wordToFind string
return bool
        static bool CheckLine(char[][] grid, int lineInSearch, int positionInSearch, int lineModifier,
            int positionModifier, int foundCharacters, string wordToFind)
        {
            if (foundCharacters == wordToFind.Length)
            {
                //we're at the end, found them all
                return true;
            }

            //add the line modifiers to the positions to keep it going in the same direction
            lineInSearch += lineModifier;
            positionInSearch += positionModifier;

            //check for going off edge
            if (lineInSearch == grid.Length || positionInSearch == grid[lineInSearch].Length)
                return false;

            //see if we have a match
            char currentChar = grid[lineInSearch][positionInSearch];
            if (currentChar == wordToFind[foundCharacters])
            {
                //found it, continue on
                return CheckLine(grid, lineInSearch, positionInSearch, lineModifier, positionModifier,
                                 foundCharacters + 1, wordToFind);
            }
            //no match
            return false;
        }