Example #1
0
        static void Main(string[] args)
        {
            var field = GenerateField(8, 8);

            DumpField(field);

            var filename = "woorden.txt";

            Console.WriteLine("Reading {0}", filename);
            var words = File.ReadAllLines(filename);

            Console.WriteLine("Loading dictionary {0}", filename);
            var time       = Stopwatch.StartNew();
            var dictionary = BoggleUtilities.LoadWords(words, UniqueCharsIn(field));

            Console.WriteLine("Loaded {0} words in {1} ms", words.Length, time.ElapsedMilliseconds);

            Console.WriteLine("Press enter to show words");
            Console.ReadLine();
            time = Stopwatch.StartNew();
            var wordsInField = BoggleUtilities.FindWords(field, dictionary).ToArray();

            Console.WriteLine("Word finding took {0} ms", time.ElapsedMilliseconds);
            Console.WriteLine("Found {0} words", wordsInField.Length);

            foreach (var foundword in wordsInField.Select(w => w.Word).OrderBy(w => w))
            {
                Console.WriteLine(foundword);
            }

            string word;

            do
            {
                word = Console.ReadLine();
                var wordToDisplay = wordsInField.FirstOrDefault(w => w.Word == word);
                if (wordToDisplay == null) // word is not in field
                {
                    // either its not a word or its not in field.
                    Console.WriteLine("Sorry, '{0}' is not a word in the field.", word);
                }
                else
                {
                    DisplayWord(wordToDisplay, field);
                }
            } while (!String.IsNullOrEmpty(word));
        }
Example #2
0
        void Test()
        {
            var dictionary = BoggleUtilities.LoadWords(new[] {
                "aap",   // 2
                "aapje", // 0
                "art",   // 1
                "gaap",  // 2
                "raapt", // 1
                "rat",   // 1
            });

            /*
             *  The dictionary is now:
             * a
             *  a
             *   p*
             *    j
             *     e*
             *  r
             *   t*
             * g
             *  a
             *   a
             *    p*
             * r
             *  a
             *   a
             *    p
             *     t*
             *   t*
             */
            foreach (var word in
                     BoggleUtilities.FindWords(
                         new[, ]
            {
                { 'a', 'a', 'p' },
                { 'g', 'a', 't' },
                { 'g', 'r', 't' },
            }
                         , dictionary))
            {
                Console.WriteLine(word);
            }

            Console.ReadLine();
        }