private void FindFailureX10000ToolStripMenuItem_Click(object sender, EventArgs e) { var stopwatch = Stopwatch.StartNew(); const int SearchCount = 10; for (int i = 0; i < SearchCount; i++) { var scramble = Scrambler.Scamble(); var solutionFinder = new ShortestSolutionFinder(WellKnownSolvers.Roux); var(foundSolution, description, states) = solutionFinder.FindSolution( Rotator.ApplyMoves(Puzzle.Solved, scramble)); if (!foundSolution) { this.txtScrambleMoves.Text = scramble; this.UpdateSolutionUI(description, states); return; } } stopwatch.Stop(); this.txtScrambleMoves.Text = string.Empty; this.txtSolutionMoves.Text = string.Empty; this.txtSolutionDescription.Text = $"{SearchCount} solutions found in {stopwatch.ElapsedMilliseconds}ms."; this.Refresh(); }
private void FindAlgorithmSolutionsToolStripMenuItem_Click(object sender, EventArgs e) { this.txtScrambleMoves.Text = string.Empty; this.txtSolutionMoves.Text = string.Empty; this.txtSolutionDescription.Text = string.Empty; this.Refresh(); var solver = WellKnownSolvers.Roux; var algorithm = solver.Algorithms["PairToRightFront.RightBackUp"]; var stopwatch1 = Stopwatch.StartNew(); Puzzle foundPuzzle = null; for (int i = 0; i < 10000; i++) { var initialPuzzle = Rotator.ApplyMoves(Puzzle.Solved, Scrambler.Scamble()); foundPuzzle = new AlgorithmUsageFinder(WellKnownSolvers.Roux, algorithm).FindUsage(initialPuzzle); if (foundPuzzle != null) { break; } } stopwatch1.Stop(); if (foundPuzzle == null) { this.txtSolutionDescription.Text = "No usage of this algorithm in this puzzle."; return; } this.txtSolutionDescription.Text = $"Found puzzle for algorithm in {stopwatch1.ElapsedMilliseconds.ToString()}ms"; var stopwatch2 = Stopwatch.StartNew(); var solutions = new SolutionSearch(4, SolutionSearch.AllRouxMoves, algorithm.FinishedState) .Search(foundPuzzle); stopwatch2.Stop(); var shortestLength = solutions.Min(value => value.Count()); var message = this.txtSolutionDescription.Text + Environment.NewLine + $"Found solutions in {stopwatch2.ElapsedMilliseconds.ToString()}ms\r\n" + string.Join( ", ", from solution in solutions where solution.Count() == shortestLength select NotationParser.FormatMoves(solution)); this.txtSolutionDescription.Text = message; }
private void ScramblePuzzle() { this.txtScrambleMoves.Text = Scrambler.Scamble(); this.txtScrambleMoves.SelectionStart = int.MaxValue; }