示例#1
0
        private static void OptimalAndQuickSolveUI()
        {
            while (true)
            {
                Cube cube = new Cube();

                Console.WriteLine(Cube.ToFriendlyString(Cube.Scramble(12, 12, cube)));

                Console.WriteLine(cube.ToString());

                char key;
                do
                {
                    Console.WriteLine("\nPress 'S' for Optimal Solve or 'Q' for Quick Solve.");
                    key = Console.ReadKey().KeyChar;
                } while ((key != 's') && (key != 'q'));

                DateTime now = DateTime.Now;
                Console.WriteLine("\nSolve started at: " + now.ToShortTimeString());

                if (key == 's')
                {
                    Console.WriteLine(Cube.ToFriendlyString(Cube.OptimalSolve(cube)));
                }
                else
                {
                    Cube.Move[] moves = Cube.QuickSolve(cube, false);
                    Console.WriteLine(Cube.ApplyMoves(cube, moves));
                    Console.WriteLine(Cube.ToFriendlyString(moves));
                }

                double subTotMilSec = (DateTime.Now - now).TotalMilliseconds;
                int    subMin       = (int)Math.Floor(subTotMilSec / 60000);
                subTotMilSec = subTotMilSec - (subMin * 60000);
                int subSec    = (int)Math.Floor(subTotMilSec / 1000);
                int subMilSec = (int)Math.Floor(subTotMilSec - (subSec * 1000));

                Console.WriteLine("Solved in " + subMin + " minute(s), " + subSec + " second(s) and " + subMilSec + " millisecond(s)");
                Console.ReadKey();
            }
        }
示例#2
0
        public static Move[] QuickSolve(Cube cube, bool feedBack = true)
        {
            Cube        testCube = new Cube(cube);
            List <Move> moves    = new List <Move>();

            if (feedBack)
            {
                Console.WriteLine("Solving up face...");
            }

            moves.AddRange(Cube.OptimalSolve(cube, true, false));

            ApplyMoves(testCube, moves.ToArray());

            int colorBottom = testCube.Faces[5].Tiles[0];
            int colorTop    = colorBottom < 4 ? (colorBottom - 2) : (colorBottom < 5 ? 5 : 4);

            colorTop = colorTop < 0 ? (4 + colorTop) : colorTop;

            if (feedBack)
            {
                Console.WriteLine("\nColor down: " + colorBottom);
                Console.WriteLine("Color up: " + colorTop);
                Console.WriteLine("\nSolving up face...");
            }

            DoOLL(testCube, moves, colorTop);
            DoPLL(testCube, moves);

            while (!testCube.IsSolved())
            {
                testCube.RotateUClock();
                moves.Add(Move.U);
            }

            List <Move> orginalMoves = new List <Move>(moves);

            FixSymmetry(moves, feedBack);

            return(moves.ToArray());
        }
示例#3
0
        private static void OptimalVsQuickSolveUI()
        {
            while (true)
            {
                Console.Clear();
                Cube cube = new Cube();

                Console.WriteLine(Cube.ToFriendlyString(Cube.Scramble(20, 30, cube)));

                Console.WriteLine(cube.ToString());
                Console.WriteLine("\nPress any key to begin.");
                Console.ReadKey();

                DateTime beginTimeOptimal = DateTime.Now;

                Console.WriteLine("\n" + beginTimeOptimal.ToLongTimeString() + " - Optimal Solve starting now...");

                Cube.Move[] optimalMoves = Cube.OptimalSolve(cube, false, true);

                DateTime beginTimeQuick  = DateTime.Now;
                int[]    durationOptimal = GetTimeDiff(beginTimeOptimal, beginTimeQuick);

                Console.WriteLine("\n" + beginTimeQuick.ToLongTimeString() + " - Quick Solve starting now...");

                Cube.Move[] quickMoves = Cube.QuickSolve(cube, true);

                DateTime endTime       = DateTime.Now;
                int[]    durationQuick = GetTimeDiff(beginTimeQuick, endTime);

                Console.WriteLine("\nOptimal solved in:\t" + durationOptimal[0] + " minute(s), " + durationOptimal[1] + " second(s) and " + durationOptimal[2] + " millisecond(s)");
                Console.WriteLine("Quick solved in:\t" + durationQuick[0] + " minute(s), " + durationQuick[1] + " second(s) and " + durationQuick[2] + " millisecond(s)");

                Console.WriteLine("\nSolutions:");
                Console.WriteLine("Optimal Solve:\t" + Cube.ToFriendlyString(optimalMoves));
                Console.WriteLine("Quick Solve:\t" + Cube.ToFriendlyString(quickMoves));

                Console.ReadKey();
            }
        }