Beispiel #1
0
        void paths(int xStart, int yStart, int xEnd, int yEnd, string str)
        {
            if (xStart >= 0 && yStart >= 0 && xStart < (letters.GetLength(0)) && yStart < (letters.GetLength(0)))
            {
                if (!board[xStart, yStart])
                {
                    board[xStart, yStart] = true;
                    str += letters[xStart, yStart];
                    WordPrefix prefix = new WordPrefix(WordList);
                    prefix.add(str);

                    if (xStart == xEnd && yStart == yEnd && prefix.isWord())
                    {
                        words.Add(str);
                    }

                    else if (prefix.isPrefix())
                    {
                        paths(xStart + 1, yStart, xEnd, yEnd, str);
                        paths(xStart, yStart + 1, xEnd, yEnd, str);
                        paths(xStart + 1, yStart + 1, xEnd, yEnd, str);
                        paths(xStart, yStart - 1, xEnd, yEnd, str);
                        paths(xStart + 1, yStart - 1, xEnd, yEnd, str);
                        paths(xStart - 1, yStart, xEnd, yEnd, str);
                        paths(xStart - 1, yStart + 1, xEnd, yEnd, str);
                        paths(xStart - 1, yStart - 1, xEnd, yEnd, str);
                    }

                    board[xStart, yStart] = false;
                }
            }
        }
 public WordPrefix(WordPrefix src)
 {
     this.WordList = src.WordList;
     prefix = "";
 }
        void paths(int xStart, int yStart, int xEnd, int yEnd, string str)
        {
            if (xStart >= 0 && yStart >= 0 && xStart < (letters.GetLength(0)) && yStart < (letters.GetLength(0)))
            {
                if (!board[xStart, yStart])
                {
                    board[xStart, yStart] = true;
                    str += letters[xStart, yStart];
                    WordPrefix prefix = new WordPrefix(WordList);
                    prefix.add(str);

                    if (xStart == xEnd && yStart == yEnd && prefix.isWord())
                    {
                        words.Add(str);
                    }

                    else if (prefix.isPrefix())
                    {
                        paths(xStart + 1, yStart, xEnd, yEnd, str);
                        paths(xStart, yStart + 1, xEnd, yEnd, str);
                        paths(xStart + 1, yStart + 1, xEnd, yEnd, str);
                        paths(xStart, yStart - 1, xEnd, yEnd, str);
                        paths(xStart + 1, yStart - 1, xEnd, yEnd, str);
                        paths(xStart - 1, yStart, xEnd, yEnd, str);
                        paths(xStart - 1, yStart + 1, xEnd, yEnd, str);
                        paths(xStart - 1, yStart - 1, xEnd, yEnd, str);
                    }

                    board[xStart, yStart] = false;
                }
            }
        }
Beispiel #4
0
 public WordPrefix(WordPrefix src)
 {
     this.WordList = src.WordList;
     prefix        = "";
 }