Esempio n. 1
0
        private static void HandleControl(ConsoleKeyInfo key, ref RubikCube cube)
        {
            var shiftPressed = (key.Modifiers & ConsoleModifiers.Shift) != 0;
            var solver       = new RubikSolver(cube);

            switch (key.Key)
            {
            case ConsoleKey.P:
                PerformanceTest();
                break;

            case ConsoleKey.Z:
                solver.SolveStep0();
                solver.SolveStep1();
                solver.SolveStep2();
                solver.SolveStep3();
                solver.SolveStep4();
                var rotations = solver.GetRotationsArray();
                if (rotations.Length > 0)
                {
                    for (var i = 0; i < rotations.Length - 1; i++)
                    {
                        Console.Write(RubikUtil.RotationCommandToText(rotations[i]) + " ");
                    }
                    Console.Write(RubikUtil.RotationCommandToText(rotations[rotations.Length - 1]) + "\n");
                }
                break;

            case ConsoleKey.Q:
                cube = new RubikCube();
                var r = new Random();

                for (var i = 0; i < 20; i++)
                {
                    var command = ((RSide)r.Next(0, 6), (RotationType)r.Next(0, 3));
                    cube.RotateSide(command);
                    Console.Write(RubikUtil.RotationCommandToText(command) + " ");
                }
                Console.WriteLine();
                break;

            case ConsoleKey.G:
                cube.RotateSide(RSide.Left, shiftPressed);
                break;

            case ConsoleKey.Y:
                cube.RotateSide(RSide.Front, shiftPressed);
                break;

            case ConsoleKey.J:
                cube.RotateSide(RSide.Right, shiftPressed);
                break;

            case ConsoleKey.N:
                cube.RotateSide(RSide.Back, shiftPressed);
                break;

            case ConsoleKey.T:
                cube.RotateSide(RSide.Up, shiftPressed);
                break;

            case ConsoleKey.M:
                cube.RotateSide(RSide.Down, shiftPressed);
                break;
            }
        }
Esempio n. 2
0
        private static void Main(string[] args)
        {
            try
            {
                var cube    = new RubikCube();
                var solver  = new RubikSolver(cube);
                var keyInfo = new ConsoleKeyInfo();

                if (args.Length != 0)
                {
                    cube.RotateByCommandSequence(args[0]);
                    solver.SolveStep0();
                    solver.SolveStep1();
                    solver.SolveStep2();
                    solver.SolveStep3();
                    solver.SolveStep4();

                    var rotations = solver.GetRotationsArray();
                    if (rotations.Length > 0)
                    {
                        for (var i = 0; i < rotations.Length - 1; i++)
                        {
                            Console.Write(RubikUtil.RotationCommandToText(rotations[i]) + " ");
                        }
                        Console.Write(RubikUtil.RotationCommandToText(rotations[rotations.Length - 1]) + "\n");
                    }
                    return;
                }

                Console.WriteLine("*DIRECT CONTROL MODE*\n");
                RubikUtil.PrintSidesData(cube);
                while (keyInfo.Key != ConsoleKey.Escape)
                {
                    keyInfo = Console.ReadKey();
                    Console.Clear();

                    if (keyInfo.Key != ConsoleKey.Tab)
                    {
                        Console.WriteLine("*DIRECT CONTROL MODE*\n");
                        HandleControl(keyInfo, ref cube);
                        RubikUtil.PrintSidesData(cube);
                    }
                    else
                    {
                        Console.WriteLine("*COMMAND SEQUENCE INPUT MODE*\n");
                        RubikUtil.PrintSidesData(cube);

                        cube.RotateByCommandSequence(Console.ReadLine());
                        Console.WriteLine("\nPress any key...\n");
                        Console.ReadKey();

                        Console.Clear();
                        Console.WriteLine("*DIRECT CONTROL MODE*\n");
                        RubikUtil.PrintSidesData(cube);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error happened! Error message: " + e);
            }
        }