public static void loadRotationTreeFromFile(RubikFileReader p_File, RotationTree p_tree) { RotationLinkedList l_rotationLinkedList = new RotationLinkedList(); while (l_rotationLinkedList.readFromFile(p_File)) { p_tree.addRotationLinkedList(l_rotationLinkedList); } }
public void addSolution(RotationLinkedList p_rotationLinkedList, Permutation p_permutation, Solution p_prevSolution, int p_value, int p_floor) { if (/*(p_value>=32 && getBestValue()>=36) ||*/ (c_solutionList[p_value] as ArrayList).Count < 40) { (c_solutionList[p_value] as ArrayList).Add(new SolutionNode(new Solution(p_rotationLinkedList.getCopy(), p_permutation.getCopy(), p_prevSolution))); // Console.Write("Added Solution Value={0}, Index={0}\n", p_value, p_value); } }
public RotationLinkedList getCopy() { RotationLinkedList l_rotationLinkedList = new RotationLinkedList(); foreach (var l_itr in c_array) { l_rotationLinkedList.addRotation(l_itr as Rotation); } return(l_rotationLinkedList); }
static RotationTree loadSearchTree() { RotationLinkedList l_rotationLinkedList = new RotationLinkedList(); RotationTree l_tree = new RotationTree(); RubikFileReader l_fileReader = new RubikFileReader("C:\\DevProj\\RubikSolver\\permRubik.txt"); loadRotationTreeFromFile(l_fileReader, l_tree); loadRotationTreeFromStandard(l_tree, l_rotationLinkedList, 7); l_fileReader.close(); return(l_tree); }
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(); }
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 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); }
public static void loadRotationTreeFromStandard(RotationTree p_tree, RotationLinkedList p_rotationLinkedList, int p_depth) { if (p_depth == 0) { return; } foreach (Face face in Enum.GetValues(typeof(Face))) { foreach (Direction direction in Enum.GetValues(typeof(Direction))) { Rotation newRotation = new Rotation(face, direction); if (p_rotationLinkedList.isRedundant(newRotation)) { continue; } p_rotationLinkedList.addRotation(newRotation); p_tree.addRotationLinkedList(p_rotationLinkedList); loadRotationTreeFromStandard(p_tree, p_rotationLinkedList, p_depth - 1); p_rotationLinkedList.removeRotation(); } } }
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 void addRotationLinkedList(RotationLinkedList p_list) { c_array.Add(p_list.getCopy()); }
public Solution(RotationLinkedList p_rotationLinkedList, Permutation p_permutation, Solution p_prevSolution) { c_rotationLinkedList = p_rotationLinkedList.getCopy(); c_permutation = p_permutation.getCopy(); c_prevSolution = p_prevSolution; }