Пример #1
0
        private DirectionString WordSearch(char[,] arr, bool[,] visited, string word, int row, int col, Dictionary <Pair, DirectionString> dict, ref bool found)
        {
            if (arr == null || row > arr.GetLength(0) - 1 || col > arr.GetLength(1) - 1 || col < 0 || row < 0 || found)
            {
                return(null);
            }

            char c = arr[row, col];

            Pair p = new Pair(row, col);

            if (visited[row, col])
            {
                return(dict.ContainsKey(p) ? dict[p] : null);
            }

            visited[row, col] = true;

            DirectionString str = new DirectionString();

            str.Str = c.ToString();

            var top = WordSearch(arr, visited, word, row - 1, col, dict, ref found);

            str.Left = top != null ?
                       top.Str + c.ToString() :
                       null;

            var left = WordSearch(arr, visited, word, row, col - 1, dict, ref found);

            str.Left = left != null ?
                       left.Str + c.ToString() :
                       null;

            var bottom = WordSearch(arr, visited, word, row + 1, col, dict, ref found);

            str.Bottom = bottom != null ?
                         bottom.Str + c.ToString() :
                         null;

            var right = WordSearch(arr, visited, word, row, col + 1, dict, ref found);

            str.Right = right != null ?
                        right.Str + c.ToString() :
                        null;


            if (str.Top == word || str.Bottom == word || str.Left == word || str.Right == word)
            {
                Console.WriteLine($"found word {word}");
                found = true;
            }

            if (!dict.ContainsKey(p))
            {
                dict.Add(p, str);
            }

            return(str);
        }
Пример #2
0
 public virtual void MakeSchemaCompliant()
 {
     DirectionVector.MakeSchemaCompliant();
     DirectionDescription.MakeSchemaCompliant();
     DirectionKeyword.MakeSchemaCompliant();
     DirectionString.MakeSchemaCompliant();
 }