Esempio n. 1
0
        private static void RunSearch(UnscrambleOptions options, PrefixTreeDictionary dictionary)
        {
            if (options.MinWordLength < 0)
            {
                options.MinWordLength = options.Letters.Length;
            }

            Console.WriteLine("Looking for words...");
            var foundWords = WordFinder.FindUnscrambledWords(
                options.Letters,
                options.MinWordLength,
                dictionary
                );

            if (foundWords.Count == 0)
            {
                Console.WriteLine("Sorry, we didn't find any words :(");
            }
            else
            {
                Console.WriteLine($"Done! Found {foundWords.Count} words:");
                foreach (string word in foundWords)
                {
                    Console.WriteLine(word);
                }
            }
        }
Esempio n. 2
0
        public WordFinder(PrefixTreeDictionary dictionary, Grid <Tile> puzzleGrid)
        {
            Validate.IsNotNull(dictionary, "dictionary");
            Validate.IsNotNull(puzzleGrid, "puzzleGrid");

            Dictionary   = dictionary;
            PuzzleGrid   = puzzleGrid;
            AllWordPaths = new Dictionary <string, WordamentPath>();
        }
Esempio n. 3
0
        public static List <string> FindUnscrambledWords(
            string scrambledWord,
            int minWordLength,
            PrefixTreeDictionary dictionary)
        {
            var wordFinder = new WordFinder(
                scrambledWord,
                minWordLength,
                dictionary);

            return(wordFinder.FindAllWords());
        }
Esempio n. 4
0
        public WordSearchState(
            Tile startingTile,
            PrefixTreeDictionary dictionary,
            bool useAlternate = false)
        {
            Validate.IsNotNull(startingTile, "startingTile");
            Validate.IsNotNull(dictionary, "dictionary");

            CurrentString  = useAlternate ? startingTile.AlternateLetters : startingTile.Letters;
            LastTileAdded  = startingTile;
            DictionaryNode = dictionary.FindNode(CurrentString);
        }
Esempio n. 5
0
        public WordFinder(
            string scrambledWord,
            int minWordLength,
            PrefixTreeDictionary dictionary)
        {
            Validate.IsNotNullOrEmpty(scrambledWord);
            Validate.IsNotNull(dictionary, "dictionary");
            Validate.IsTrue(minWordLength >= 1 && minWordLength <= scrambledWord.Length,
                            "Minimum word length must be at least 1 and at most the length of the input string.");

            ScrambledWord = scrambledWord;
            MinWordLength = minWordLength;
            Dictionary    = dictionary;
        }
Esempio n. 6
0
        static bool BuildDictionaryFromFile(string filename)
        {
            Dictionary = new PrefixTreeDictionary();
            using (StreamReader inputFile = new StreamReader(filename))
            {
                while (!inputFile.EndOfStream)
                {
                    string word = inputFile.ReadLine().Trim().ToLower();
                    if (!string.IsNullOrEmpty(word))
                    {
                        Dictionary.Add(word);
                    }
                }
            }

            return(Dictionary.Count > 0);
        }
Esempio n. 7
0
        private static PrefixTreeDictionary ParseDictionary(string dictionaryFilename)
        {
            var dictionary = new PrefixTreeDictionary();

            using (var dictionaryFile = new StreamReader(dictionaryFilename))
            {
                while (!dictionaryFile.EndOfStream)
                {
                    string word = dictionaryFile.ReadLine().Trim().ToLower();
                    if (!string.IsNullOrEmpty(word))
                    {
                        dictionary.Add(word);
                    }
                }
            }

            return(dictionary);
        }