示例#1
0
        /// <summary>
        /// Fills in controls with Boggle results.
        /// </summary>
        /// <param name="results">The results of the Boggle solver.</param>
        void DisplayResults(SolverResults results)
        {
            if (results.Words.Length == 0)
            {
                outputTextBox.Text        = "No words found.";
                toolStripStatusLabel.Text = "No words found";
                return;
            }

            int    length     = results.Words[0].Length;
            string outputText = $"{length}-LETTER WORDS";

            foreach (string word in results.Words)
            {
                if (word.Length < length)
                {
                    length      = word.Length;
                    outputText += Environment.NewLine + Environment.NewLine + $"{length}-LETTER WORDS";
                }

                outputText += Environment.NewLine + word;
            }

            outputTextBox.Text        = outputText;
            toolStripStatusLabel.Text = $"Score: {results.Score}   Words: {results.Words.Length}";
        }
示例#2
0
        /// <summary>Attempts to solve the current puzzle, update the state in the grid, and return the results.</summary>
        /// <returns>The results from attempting to solve the puzzle.</returns>
        private SolverResults SolvePuzzle()
        {
            // If it's already solved, nothing to do
            if (State.Status == PuzzleStatus.Solved)
            {
                return(new SolverResults(PuzzleStatus.Solved, State, 0, null));
            }

            // Otherwise, try to solve it.
            SolverOptions options = new SolverOptions();

            options.MaximumSolutionsToFind = 1u;             // this means that if there are multiple solutions, we'll find and use the first
            options.AllowBruteForce        = true;
            options.EliminationTechniques  = new List <EliminationTechnique> {
                new NakedSingleTechnique()
            };

            SolverResults results = Solver.Solve(State, options);

            if (results.Status == PuzzleStatus.Solved && results.Puzzles.Count == 1)
            {
                SetUndoCheckpoint();
                State = results.Puzzle;
            }
            return(results);
        }
示例#3
0
 /// <summary>Creates a checkpoint used to determine where cells are invalid in the puzzle.</summary>
 public void SetOriginalPuzzleCheckpoint(PuzzleState original)
 {
     _originalState = original;
     if (original != null)
     {
         SolverOptions options = new SolverOptions();
         options.MaximumSolutionsToFind = 2;
         SolverResults results = Solver.Solve(original, options);
         if (results.Status == PuzzleStatus.Solved && results.Puzzles.Count == 1)
         {
             _solvedOriginalState = results.Puzzle;
         }
         else
         {
             _solvedOriginalState = null;
         }
     }
 }
示例#4
0
        private void solveButton_Click(object sender, EventArgs e)
        {
            // Check the trie was loaded.
            if (trie == null)
            {
                toolStripStatusLabel.Text = "Dictionary not loaded!";
                return;
            }

            // Check the input is valid.
            if (inputTextBox.Text.Length != 16)
            {
                toolStripStatusLabel.Text = "Invalid input!";
                return;
            }

            SolverResults results = SolveBoard(inputTextBox.Text);

            DisplayResults(results);
        }
        private async Task ExecuteSolveAsync(object p)
        {
            // copy the model data now, it could be changed before
            // the task is run maybe to an invalid value
            int target = Model.Target;

            int[] tiles = Model.Tiles.ToArray();

            SolverResults results = await Task.Run(() => Model.Solve(tiles, target));

            // process the results list
            if (results.Solutions.Count > 0)
            {
                results.Solutions.Add(new EquationItem());
                results.Solutions.Add(new EquationItem($"There are {results.Solutions.Count - 1} solutions."));
            }
            else if (results.ClosestMatch.Length > 0)
            {
                results.Solutions.Add(new EquationItem("There are no solutions."));
                results.Solutions.Add(new EquationItem($"The closest match is {Math.Abs(results.Difference)} away."));
                results.Solutions.Add(new EquationItem());
                results.Solutions.Add(new EquationItem($"{results.ClosestMatch} = {target - results.Difference}"));
            }
            else
            {
                results.Solutions.Add(new EquationItem("No solutions are 10 or less from the target"));
            }

            results.Solutions.Add(new EquationItem());

            // in case its running on a very fast multicore machine
            string fmtStr = (results.Elapsed < TimeSpan.FromMilliseconds(1)) ? "\\0\\.ffffff" : "s\\.fff";

            results.Solutions.Add(new EquationItem($"Evaluated in {results.Elapsed.ToString(fmtStr)} seconds."));

            results.Solutions.Add(new EquationItem($"Tiles are {tiles[0]}, {tiles[1]}, {tiles[2]}, {tiles[3]}, {tiles[4]}, {tiles[5]}"));
            results.Solutions.Add(new EquationItem($"Target is {target}"));

            // update the ui
            EquationList = results.Solutions;
        }