public void applyToRubik(Rubik p_rubik) { foreach (var l_itr in c_array) { p_rubik.rotateFace(l_itr as Rotation); } }
public static void BuildFilesForRotation(RubikFileWriter p_firstFloorFile, RubikFileWriter p_secondFloorFile, RubikFileWriter p_thirdFloorFile , Rubik p_rubik , Permutation p_initialPermutation, RotationLinkedList p_rotationLinkedList, int p_level, String p_progressString) { if (p_level == 0) { return; } if (p_level > 5) { Console.WriteLine(p_progressString); } int i = 0; foreach (Face face in Enum.GetValues(typeof(Face))) { foreach (Direction direction in Enum.GetValues(typeof(Direction))) { i++; String myProgressString = p_progressString + String.Format(".{0}", i); Rotation newRotation = new Rotation(face, direction); if (p_rotationLinkedList.isRedundant(newRotation)) { continue; } p_rotationLinkedList.addRotation(newRotation); p_rubik.rotateFace(newRotation); if (p_rubik.isDifferentItemsInFirstFloorLessThanThree(p_initialPermutation)) { p_rotationLinkedList.writeToFile(p_firstFloorFile); } if (p_rubik.isDifferentItemsOnlyInSecondFloorLessThanThree(p_initialPermutation)) { p_rotationLinkedList.writeToFile((p_secondFloorFile)); } if (p_rubik.changesOnlyInThirdFloor(p_initialPermutation)) { p_rotationLinkedList.writeToFile(p_thirdFloorFile); } BuildFilesForRotation(p_firstFloorFile, p_secondFloorFile, p_thirdFloorFile, p_rubik, p_initialPermutation, p_rotationLinkedList, p_level - 1, myProgressString); p_rotationLinkedList.removeRotation(); p_rubik.rotateFace(newRotation.getReverse()); } } }
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); } } } }
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(); }