Пример #1
0
        public void searchTree(int minimumValueToReach, RotationTree searchTree,
                               Cube cubeToSolve, SolutionManager solutionManager,
                               Solution previousSolution, int targetFloorToSortInCube, int depth)
        {
            if (minimumValueToReach < 2)
            {
                minimumValueToReach = 2;
            }
            for (int rotationSequenceIndex = 0; rotationSequenceIndex < searchTree.getSize(); rotationSequenceIndex++)
            {
                RotationSequence rotationSequence = searchTree.getRotationSequence(rotationSequenceIndex);
                if (rotationSequence != null)
                {
                    Cube cubeAfterRotationSequence = getCubeAfterApplyingSequence(new Cube(cubeToSolve), rotationSequence);

                    addSequenceToSolutionIfHigherValue(minimumValueToReach, solutionManager, previousSolution,
                                                       targetFloorToSortInCube, rotationSequence, cubeAfterRotationSequence);
                    if (targetFloorToSortInCube == 3 && depth == 0)
                    {
                        this.searchTree(minimumValueToReach, searchTree, cubeAfterRotationSequence, solutionManager,
                                        new Solution(rotationSequence, cubeAfterRotationSequence, previousSolution), targetFloorToSortInCube, 1);
                    }
                }
            }
        }
Пример #2
0
 public void addSolution(RotationSequence p_rotationLinkedList, Cube p_permutation, Solution p_prevSolution,
                         int p_value, int p_floor)
 {
     if (/*(p_value>=32 && getBestValue()>=36) ||*/ c_solutionList[p_value].Count < 40)
     {
         c_solutionList[p_value].Add(new SolutionNode(new Solution(p_rotationLinkedList.getCopy(), p_permutation.getCopy(), p_prevSolution)));
     }
 }
Пример #3
0
        public static RotationTree getRotationTreeFromFile(RubikFileReader p_File)
        {
            RotationTree     myTree = new RotationTree();
            RotationSequence l_rotationLinkedList = new RotationSequence();

            while (l_rotationLinkedList.readFromFile(p_File))
            {
                myTree.addRotationLinkedList(l_rotationLinkedList);
            }
            return(myTree);
        }
Пример #4
0
        private Cube getCubeAfterApplyingSequence(Cube cubeForExperimentation, RotationSequence rotationSequence)
        {
            for (int rotationIndex = 0; rotationIndex < rotationSequence.size(); rotationIndex++)
            {
                cubeForExperimentation.rotateFace(rotationSequence.getRotation(rotationIndex).getFace(),
                                                  rotationSequence.getRotation(rotationIndex).getDirection());
            }
            Cube cubeAfterRotationSequence = Cube.getPermutationFromCube(cubeForExperimentation).getCopy();

            return(cubeAfterRotationSequence);
        }
Пример #5
0
        public RotationSequence getCopy()
        {
            RotationSequence l_rotationLinkedList = new RotationSequence();



            foreach (var l_itr in c_array)
            {
                l_rotationLinkedList.addRotation(l_itr as Rotation);
            }

            return(l_rotationLinkedList);
        }
Пример #6
0
        public Solution solve(Cube p_rubik, RotationTree p_firstTree, RotationTree p_secondTree, RotationTree p_thirdTree)
        {
            int             l_numberOfCubicleInPlace;
            Cube            l_permutation     = new Cube(p_rubik);
            SolutionManager l_solutionManager = new SolutionManager();
            Solution        l_solutionToDev;

            RotationSequence l_rotationLinkedList = new RotationSequence();

            int l_floor = getTargetFloor(l_permutation);

            l_numberOfCubicleInPlace = Cube.getValue(l_permutation, 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}...", Cube.getValue(l_solutionToDev.getPermutation(), targetFloor));
                if (l_solutionManager.getBestValue() > Cube.getValue(l_solutionToDev.getPermutation(), 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());
            }

            return(l_solutionManager.getBest());
        }
Пример #7
0
 public void addRotationLinkedList(RotationSequence p_list)
 {
     //Console.Write("FFFFF");
     c_array.Add(p_list.getCopy());
 }
Пример #8
0
 private void addSequenceToSolutionIfHigherValue(int minimumValueToReach, SolutionManager solutionManager,
                                                 Solution previousSolution, int targetFloorToSortInCube, RotationSequence rotationSequence,
                                                 Cube cubeAfterRotationSequence)
 {
     if (Cube.getValue(cubeAfterRotationSequence, targetFloorToSortInCube) >= minimumValueToReach)
     {
         solutionManager.addSolution(rotationSequence, cubeAfterRotationSequence, previousSolution,
                                     Cube.getValue(cubeAfterRotationSequence, targetFloorToSortInCube), targetFloorToSortInCube);
     }
 }
Пример #9
0
 public Solution(RotationSequence p_rotationLinkedList, Cube p_permutation, Solution p_prevSolution)
 {
     c_rotationLinkedList = p_rotationLinkedList.getCopy();
     c_permutation        = p_permutation.getCopy();
     c_prevSolution       = p_prevSolution;
 }