Exemplo n.º 1
0
        public static void findGoodRotationLinks(String p_firstFloorFile
                                                 , String p_secondFloorFile, String p_thirdFloorFile, int p_levels)
        {
            RubikFileWriter    l_firstWriter        = new RubikFileWriter(p_firstFloorFile);
            RubikFileWriter    l_secondWriter       = new RubikFileWriter(p_secondFloorFile);
            RubikFileWriter    l_thirdWriter        = new RubikFileWriter(p_thirdFloorFile);
            Rubik              l_rubik              = new Rubik();
            Permutation        l_initialPermutation = l_rubik.getPermutation();
            RotationLinkedList l_rotationLinkedList = new RotationLinkedList();

            BuildFilesForRotation(l_firstWriter, l_secondWriter, l_thirdWriter
                                  , l_rubik, l_initialPermutation, l_rotationLinkedList, p_levels, "");
            l_firstWriter.close();
            l_secondWriter.close();
            l_thirdWriter.close();
        }
Exemplo n.º 2
0
        public Solution solve(Rubik p_rubik, RotationTree p_firstTree, RotationTree p_secondTree, RotationTree p_thirdTree)
        {
            int             l_numberOfCubicleInPlace;
            Permutation     l_permutation     = p_rubik.getPermutation();
            SolutionManager l_solutionManager = new SolutionManager();
            Solution        l_solutionToDev;

            RotationLinkedList l_rotationLinkedList = new RotationLinkedList();

            int l_floor = getTargetFloor(l_permutation);

            l_numberOfCubicleInPlace = l_permutation.getValue(l_floor);

            l_solutionManager.addSolution(l_rotationLinkedList, l_permutation, null, l_numberOfCubicleInPlace, l_floor);
            while ((l_solutionToDev = l_solutionManager.getBestUndeveloped()) != null &&
                   l_solutionManager.getBestValue() < 40)
            {
                int targetFloor = getTargetFloor(l_solutionToDev.getPermutation());
                Console.Write("Searching {0}", l_solutionToDev.getPermutation().getValue(targetFloor));
                if (l_solutionManager.getBestValue() > l_solutionToDev.getPermutation().getValue(targetFloor) + 14)
                {
                    Console.WriteLine("Couldn't Find a Solution");
                    return(l_solutionManager.getBest());
                }
                if (targetFloor == 1)
                {
                    findBetterSolution(l_solutionToDev, p_firstTree, l_solutionManager, targetFloor);
                }
                if (targetFloor == 2)
                {
                    findBetterSolution(l_solutionToDev, p_secondTree, l_solutionManager, targetFloor);
                }
                if (targetFloor == 3)
                {
                    findBetterSolution(l_solutionToDev, p_thirdTree, l_solutionManager, targetFloor);
                }

                l_floor = getTargetFloor(l_solutionManager.getBestValue());

                //  Console.Write("Floor={0}, Best yet:{1}\n", l_floor, l_solutionManager.getBestValue());
                // l_solutionManager.getBest().print();
            }

            var toReturn = l_solutionManager.getBest();

            return(toReturn);
        }
Exemplo n.º 3
0
        public void searchTree(int p_minimumValue, RotationTree p_tree,
                               Rubik p_rubik, SolutionManager p_solutionManager,
                               Solution p_prevSolution, int p_floor, int depth)
        {
            if (p_minimumValue < 2)
            {
                p_minimumValue = 2;
            }
            Permutation l_permutation = p_rubik.getPermutation().getCopy();
            Rubik       l_rubik       = new Rubik();

            for (int i = 0; i < p_tree.getSize(); i++)
            {
                RotationLinkedList l_rotationLinkedList = p_tree.getRotationLinkedList(i);
                if (l_rotationLinkedList != null)
                {
                    l_rubik.setPermutation(l_permutation);
                    for (int j = 0; j < l_rotationLinkedList.size(); j++)
                    {
                        l_rubik.rotateFace(l_rotationLinkedList.get(j));
                    }
                    Permutation l_resultPermutation = l_rubik.getPermutation().getCopy();

                    if (l_resultPermutation.getValue(p_floor) >= p_minimumValue)
                    {
                        p_solutionManager.addSolution(l_rotationLinkedList, l_resultPermutation, p_prevSolution, l_resultPermutation.getValue(p_floor), p_floor);
                    }
                    if (p_floor == 3 && depth == 0)
                    {
                        //  Console.WriteLine("Hi");
                        searchTree(p_minimumValue, p_tree, l_rubik, p_solutionManager,
                                   new Solution(l_rotationLinkedList, l_resultPermutation, p_prevSolution), p_floor, 1);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void Main(String[] args)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            Rubik myRubik = new Rubik();

            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.B, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.L, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.F, Direction.CW));
            myRubik.rotateFace(new Rotation(Face.R, Direction.CW));
            Solver          mySolver        = new Solver();
            RotationTree    firstFloorTree  = new RotationTree();
            RotationTree    secondFloorTree = new RotationTree();
            RotationTree    thirdFloorTree  = new RotationTree();
            RubikFileReader readFirstFloor  = new RubikFileReader("..\\..\\..\\Resources\\FirstFloor.txt");
            RubikFileReader readSecondFloor = new RubikFileReader("..\\..\\..\\Resources\\SecondFloor.txt");
            RubikFileReader readThirdFloor  = new RubikFileReader("..\\..\\..\\Resources\\ThirdFloor.txt");

            RotationTreeLoader.loadRotationTreeFromFile(readFirstFloor, firstFloorTree);
            RotationTreeLoader.loadRotationTreeFromFile(readSecondFloor, secondFloorTree);
            RotationTreeLoader.loadRotationTreeFromFile(readThirdFloor, thirdFloorTree);

            Solution mySolution = mySolver.solve(myRubik, firstFloorTree, secondFloorTree, thirdFloorTree);

            mySolution.applyToRubik(myRubik);
            mySolution.print();
            stopWatch.Stop();
            TimeSpan ts          = stopWatch.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                 ts.Hours, ts.Minutes, ts.Seconds,
                                                 ts.Milliseconds / 10);

            Console.Write("Elapsed Time={0} seconds", elapsedTime);
            //27-12-2017: started 11:39 PM, Failed
            myRubik.getPermutation().print();
        }