コード例 #1
0
        List <string> IBoggleService.GetBoggleAnswers(BoggleDataContract input)
        {
            // NOTE: Here is where there should be a large amount of logic for error handling and other checking
            // Because this is a code sample, I chose not to include it for the sake of time. In a production service
            // There would be a large number of checks looking for propper inputs and responding appropriatelyj

            // This isn't thread safe, I need to look further into how WCF services handle threads and locking
            if (dictionary == null)
            {
                dictionary = BoggleLibraryUtils.BuildDictionary(CodeSampleCoreUtils.ReturnWordList());
            }

            return(BoggleSolver.SolveBoggle(input.Height, input.Width, input.Board, input.MinWordSize, dictionary));
        }
コード例 #2
0
        public void TestBoggleSolverAgainstBungieKnownGood()
        {
            var dictionary = BoggleLibraryUtils.BuildDictionary(CodeSampleCoreUtils.ReturnWordList());

            char[][] board = new char[3][]
            {
                new char[] { 'y', 'o', 'x' },
                new char[] { 'r', 'b', 'a' },
                new char[] { 'v', 'e', 'd' }
            };

            string[] bungieWords =
            {
                "bred",
                "yore",
                "byre",
                "abed",
                "oread",
                "bore",
                "orby",
                "robed",
                "broad",
                "byroad",
                "robe",
                "bored",
                "derby",
                "bade",
                "aero",
                "read",
                "orbed",
                "verb",
                "aery",
                "bead",
                "bread",
                "very",
                "road"
            };

            var foundWords = BoggleSolver.SolveBoggle(3, 3, board, 4, dictionary);

            foreach (string word in bungieWords)
            {
                Assert.IsTrue(foundWords.Contains(word), "We should have found, but didn't: " + word);
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: schnappischnap/BoggleSolver
        /// <summary>
        /// Organises the input, solve the board and returns the results.
        /// </summary>
        /// <param name="input">The 16-character Boggle board string.</param>
        /// <returns>The results of the Boggle solver.</returns>
        SolverResults SolveBoard(string input)
        {
            string[,] board = new string[4, 4];

            for (int i = 0; i < 16; ++i)
            {
                int x = i % 4;
                int y = i / 4;

                string letter = input[i].ToString().ToUpper();
                // There is no 'Q' in Boggle, only 'QU'.
                if (letter == "Q")
                {
                    letter = "QU";
                }

                board[y, x] = letter;
            }

            BoggleSolver solver = new BoggleSolver(trie, board);

            return(solver.Solve());
        }