Exemple #1
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());
        }
Exemple #2
0
        public static Move[] OptimalSolve(Cube cube, bool onlyBottomFace = false, bool feedBack = true)
        {
            Move maxMoveIndex;

            if (onlyBottomFace)
            {
                maxMoveIndex = Enum.GetValues(typeof(Move)).Cast <Move>().Max();
            }
            else
            {
                maxMoveIndex = (Move)Enum.GetValues(typeof(MoveOptimalSolve)).Cast <MoveOptimalSolve>().Max();
            }
            //maxMoveIndex = (Move)Enum.GetValues(typeof(MoveOptimalSolve)).Cast<MoveOptimalSolve>().Max(); // TEST

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

            int amountChecked = 0;
            List <List <Move> > movesChecked = new List <List <Move> >();

            //Console.WriteLine("Solved: " + cube.IsSolved());

            if ((!onlyBottomFace && cube.IsSolved()) || (onlyBottomFace && cube.Faces[5].IsOneColor() != -1))
            {
                return(moves.ToArray());
            }

            for (int i = 0; i <= 11; i++)
            {
                moves.Add((Move)0);

                int j = 0;

                do
                {
                    Cube testCube = new Cube(cube);
                    Cube.ApplyMoves(testCube, moves.ToArray());

                    if ((!onlyBottomFace && testCube.IsSolved()) || (onlyBottomFace && testCube.Faces[5].IsOneColor() != -1))
                    {
                        return(moves.ToArray());
                    }

                    amountChecked++;

                    //Console.WriteLine(testCube);
                    //Console.WriteLine(ToFriendlyString(moves.ToArray()) + " " + testCube.IsSolved());
                    //Console.Write(ToFriendlyString(moves.ToArray()) + "\t\t");

                    bool isDecentMove;
                    j = -1;
                    do
                    {
                        isDecentMove = true;
                        j++;
                        if (0 < j)
                        {
                            moves[j - 1] = (Move)0;
                        }
                        moves[j]++;

                        // Console.Write(j.ToString() + i.ToString()  + " ");

                        if (j < i)
                        {
                            isDecentMove = IsDecentNextMove(moves[j], moves[j + 1]);
                        }

                        while (j < i && moves[j] < maxMoveIndex && !isDecentMove)
                        {
                            moves[j]++;
                            isDecentMove = IsDecentNextMove(moves[j], moves[j + 1]);
                        }

                        if (!isDecentMove)
                        {
                            //Console.WriteLine("Not decent: " + moves[j]);
                            moves[j]++;
                        }

                        //Console.Write(":" + moves[j] + " " + (j < i ? moves[j + 1].ToString() : "") + " " + isDecentMove + "\n");
                    } while (j < i && maxMoveIndex < moves[j]);
                    // Console.WriteLine("DAMN");
                } while (moves[j] <= maxMoveIndex);
                moves[j] = (Move)0;

                if (feedBack)
                {
                    Console.WriteLine("Amount Checked: " + amountChecked);
                    //Console.ReadKey();
                }
            }

            return(null);
        }