Ejemplo n.º 1
0
        /// <summary>
        /// Converts a rubik to a pattern
        /// </summary>
        /// <param name="r">Rubik </param>
        /// <returns>The pattern of the given rubik</returns>
        public static Pattern FromRubik(Rubik r)
        {
            Pattern            p        = new Pattern();
            List <PatternItem> newItems = new List <PatternItem>();

            foreach (CubePosition pos in Positions)
            {
                Cube cube = r.Cubes.First(c => r.GetTargetFlags(c) == pos.Flags);
                newItems.Add(new PatternItem(cube.Position, Solvability.GetOrientation(r, cube), pos.Flags));
            }
            p.Items = newItems;
            return(p);
        }
Ejemplo 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();
                if (OnSolutionStepCompleted != null)
                {
                    OnSolutionStepCompleted(this, new SolutionStepCompletedEventArgs(this.Name, true, this.Algorithm, (int)sw.ElapsedMilliseconds));
                }
                solvingThread.Abort();
            }
            else
            {
                this.BroadcastOnSolutionError(this.Name, "Unsolvable cube");
            }
        }