Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public bool readFromFile(RubikFileReader p_reader)
        {
            int l_int;

            l_int = p_reader.read();
            while ((l_int == ' ') || (l_int == 10))
            {
                l_int = p_reader.read();
            }
            if ((l_int == '\n') || (l_int == -1 /*EOF*/) || (l_int != '('))
            {
                return(false);
            }
            else
            {
                c_face = FaceFactory.getFaceByInt((int)Char.GetNumericValue((char)(p_reader.read())));
                p_reader.read();
                c_direction = DirectionFactory.getDirectionByInt((int)Char.GetNumericValue((char)(p_reader.read())));
                p_reader.read();
                return(true);
            }
        }
Exemplo n.º 5
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();
        }