Exemplo n.º 1
0
        protected void GetSolution()
        {
            Stopwatch sw = new Stopwatch();

            foreach (var step in this.SolutionSteps)
            {
                sw.Restart();
                step.Value();
                sw.Stop();

                var alg = new Algorithm(null);
                alg.Moves = _movesOfStep;

                OnSolutionStepCompleted?.Invoke(this,
                                                new SolutionStepCompletedEventArgs(
                                                    step.Key,
                                                    false,
                                                    alg,
                                                    (int)sw.ElapsedMilliseconds
                                                    )
                                                );

                _movesOfStep.Clear();
            }
        }
Exemplo n.º 2
0
        private void SolveAsync(Rubik rubik)
        {
            bool solvable = Solvability.FullTest(rubik);

            if (solvable)
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                Solve(rubik);
                sw.Stop();

                Algorithm = Algorithm.RemoveUnnecessaryMoves(Algorithm);
                var args = new SolutionStepCompletedEventArgs(Name, true, Algorithm, (int)sw.ElapsedMilliseconds);
                OnSolutionStepCompleted?.Invoke(this, args);

                solvingThread.Abort();
            }
            else
            {
                this.BroadcastOnSolutionError(this.Name, "Unsolvable cube");
            }
        }