示例#1
0
            // miniDict['&'] unique char
            private static void findWords(Coord a, wWrap mini, HashSet <Coord> seen, char[,] board, HashSet <string> sol, string current)
            {
                char letter = board[a.x, a.y];

                if (mini.miniDict.ContainsKey(letter) == false)
                {
                    return;
                }

                current += letter;
                wWrap next = mini.miniDict[letter];

                if (next.miniDict.ContainsKey('&'))
                {
                    sol.Add(current);
                }

                var adjCoords = Coord.getADJ(a.x, a.y);

                foreach (var coord in adjCoords)
                {
                    if (seen.Contains(coord))
                    {
                        continue;
                    }

                    var copy = seen;
                    copy.Add(coord);
                    findWords(coord, next, copy, board, sol, current);
                }
            }
示例#2
0
                public void addWord(string word)
                {
                    if (word.Length == 0)
                    {
                        miniDict['&'] = null; return;
                    }
                    char letter = word[0];

                    wWrap val = new wWrap();

                    if (miniDict.ContainsKey(letter))
                    {
                        val = miniDict[letter];
                    }
                    else
                    {
                        miniDict[letter] = val;
                    }

                    size++;
                    val.addWord(word[1..]);
示例#3
0
            public static List <string> solveBoggle(char[,] board, List <string> dict)
            {
                wWrap miniDict = new wWrap();

                foreach (string word in dict)
                {
                    miniDict.addWord(word);
                }

                HashSet <string> solutions = new HashSet <string>();

                for (int i = 0; i < 4; ++i)
                {
                    for (int ii = 0; ii < 4; ++ii)
                    {
                        findWords(new Coord(i, ii), miniDict, Coord.getHS(i, ii), board, solutions, "");
                    }
                }

                return(solutions.ToList());
            }