public Boolean readFromFile(RubikFileReader p_reader) { int l_int; l_int = p_reader.read(); //Console.Write("%d ",l_int); while ((l_int == ' ') || (l_int == 13 /*'\r'*/)) { l_int = p_reader.read(); // Console.Write("%d ",l_int); } if ((l_int == /*'\n'*/ 10) || (l_int == -1 /*EOF*/) || (l_int != '(')) { return(false); } else { c_face = FaceHandler.getFace((int)Char.GetNumericValue((char)(p_reader.read()))); p_reader.read(); c_direction = DirectionHandler.getDirection((int)Char.GetNumericValue((char)(p_reader.read()))); p_reader.read(); return(true); } }
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); }
public bool readFromFile(RubikFileReader p_reader) { Rotation l_rotation = new Rotation(); c_array.Clear(); while (l_rotation.readFromFile(p_reader)) { c_array.Add((new Rotation(l_rotation.getFace(), l_rotation.getDirection()))); } return(!(c_array.Count == 0)); }
public void writeToFileXLevelsSecondAndThird() { RotationTreeLoader.findGoodRotationLinks("tstFirstFloor.txt", "tstSecondFloor.txt" , "tstThirdFloor.txt", 2); RotationTree firstFloorTree = new RotationTree(); RotationTree secondFloorTree = new RotationTree(); RotationTree thirdFloorTree = new RotationTree(); RubikFileReader readFirstFloor = new RubikFileReader("tstFirstFloor.txt"); RubikFileReader readSecondFloor = new RubikFileReader("tstSecondFloor.txt"); RubikFileReader readThirdFloor = new RubikFileReader("tstThirdFloor.txt"); RotationTreeLoader.loadRotationTreeFromFile(readFirstFloor, firstFloorTree); RotationTreeLoader.loadRotationTreeFromFile(readSecondFloor, secondFloorTree); RotationTreeLoader.loadRotationTreeFromFile(readThirdFloor, thirdFloorTree); }
public void write() { RubikFileWriter myWriter = new RubikFileWriter("Test.txt"); myWriter.write("testWrite"); myWriter.close(); RubikFileReader myReader = new RubikFileReader(("Test.txt")); int l_int; String l_readString = ""; while ((l_int = myReader.read()) != -1) { l_readString += (char)l_int; } Assert.AreEqual("testWrite", l_readString); }
public void testWriteRead() { RotationLinkedList myList = new RotationLinkedList(); myList.addRotation(new Rotation(Face.F, Direction.CW)); myList.addRotation(new Rotation(Face.U, Direction.CCW)); RubikFileWriter myWriter = new RubikFileWriter("writeLinked.txt"); myList.writeToFile(myWriter); myWriter.close(); RubikFileReader myReader = new RubikFileReader("writeLinked.txt"); RotationLinkedList mySecondList = new RotationLinkedList(); mySecondList.readFromFile(myReader); Assert.AreEqual(true, myList.get(0).equals(mySecondList.get(0)), "first"); Assert.AreEqual(true, myList.get(1).equals(mySecondList.get(1)), "first"); }
static void Main(string[] args) { //long beginningTime = System.nanoTime(); Cube myRubik = new Cube(); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.LEFT, Direction.CW); myRubik.rotateFace(Face.FRONT, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.LEFT, Direction.CW); myRubik.rotateFace(Face.FRONT, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.LEFT, Direction.CW); myRubik.rotateFace(Face.FRONT, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.LEFT, Direction.CW); myRubik.rotateFace(Face.FRONT, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.LEFT, Direction.CW); myRubik.rotateFace(Face.FRONT, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.LEFT, Direction.CW); myRubik.rotateFace(Face.FRONT, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.LEFT, Direction.CW); myRubik.rotateFace(Face.FRONT, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); myRubik.rotateFace(Face.BACK, Direction.CW); myRubik.rotateFace(Face.LEFT, Direction.CW); myRubik.rotateFace(Face.FRONT, Direction.CW); myRubik.rotateFace(Face.RIGHT, Direction.CW); Solver mySolver = new Solver(); RubikFileReader readFirstFloor = new RubikFileReader("..\\..\\..\\Resources\\FirstFloor.txt"); RubikFileReader readSecondFloor = new RubikFileReader("..\\..\\..\\Resources\\SecondFloor.txt"); RubikFileReader readThirdFloor = new RubikFileReader("..\\..\\..\\Resources\\ThirdFloor.txt"); RotationTree firstFloorTree = RotationTree.getRotationTreeFromFile(readFirstFloor); RotationTree secondFloorTree = RotationTree.getRotationTreeFromFile(readSecondFloor); RotationTree thirdFloorTree = RotationTree.getRotationTreeFromFile(readThirdFloor); Solution mySolution = mySolver.solve(myRubik, firstFloorTree, secondFloorTree, thirdFloorTree); mySolution.applyToRubik(myRubik); mySolution.print(); if (myRubik.equals(new Cube())) { Console.WriteLine("Solved!"); } else { Console.WriteLine("Not Solved :-("); } Console.ReadLine(); }