Exemple #1
0
        private static void testCompression()
        {
            MyMaze3dGenerator smg = new MyMaze3dGenerator();
            Maze maze             = smg.generate(9, 6, 5);

            byte[] byets = ((Maze3d)maze).toByteArray();
            using (FileStream fileOutStream = new FileStream("1.maze", FileMode.Create))
            {
                using (MyCompressorStream outStream = new MyCompressorStream(fileOutStream, MyCompressorStream.Compress))
                {
                    outStream.Write(byets, 0, byets.Length);
                    outStream.Flush();
                }
            }
            byte[] mazeBytes;
            using (FileStream fileInStream = new FileStream("1.maze", FileMode.Open))
            {
                using (MyCompressorStream inStream = new MyCompressorStream(fileInStream, MyCompressorStream.Decompress))
                {
                    mazeBytes = new byte[byets.Length];
                    inStream.Read(mazeBytes, 0, mazeBytes.Length);
                }
            }
            Maze3d loadedMaze = new Maze3d(mazeBytes);

            Console.WriteLine(loadedMaze.equals(maze));

            Console.WriteLine("*******************************");
            Console.WriteLine("Press any key to continue");
            Console.WriteLine();
            Console.ReadKey();
        }
Exemple #2
0
        /// <summary>
        /// load the maze from the disk
        /// </summary>
        /// <param name="filePath">path of the file</param>
        /// <param name="maze_name">name of the maze</param>
        public void LoadMazeFromDisk(string filePath, string maze_name)
        {
            string fullPath = filePath + maze_name;

            byte[]      byteFromFile     = new byte[100];
            List <byte> byteMazeFromFile = new List <byte>();

            using (Stream stream = new FileStream(fullPath, FileMode.Open))
            {
                using (Stream file_s = new MyCompressorStream(stream, 2))
                {
                    MyCompressorStream file_Str = file_s as MyCompressorStream;
                    int read_f = 0;
                    while ((read_f = file_Str.Read(byteFromFile, 0, 100)) != 0)
                    {
                        if (read_f < 100)
                        {
                            addToList(byteMazeFromFile, byteFromFile, read_f);
                        }
                        else
                        {
                            byteMazeFromFile.AddRange(byteFromFile);
                        }
                        byteFromFile = new byte[100];
                    }
                    byte[] b = byteMazeFromFile.ToArray();
                    m_DicOfMazes[maze_name] = new Maze3d(b);
                    file_Str.Flush();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Load Maze - Loads a maze to the memory with a given file path
        /// from the user.
        /// </summary>
        /// <param name="path">Directory path</param>
        /// <param name="mazeName">Name of the maze</param>
        public void loadMaze(string path, string mazeName)
        {
            int numberOfBytes;

            byte[]      compressionArray = new byte[100];
            List <byte> compressedList   = new List <byte>();

            using (FileStream fileInStream = new FileStream(path, FileMode.Open))
            {
                using (Stream compressor = new MyCompressorStream(fileInStream))
                {
                    while ((numberOfBytes = compressor.Read(compressionArray, 0, 100)) != 0)
                    {
                        for (int i = 0; i < numberOfBytes; i++)
                        {
                            compressedList.Add(compressionArray[i]);
                        }
                    }
                }
            }
            Maze3d loadedMaze = new Maze3d(compressedList.ToArray());

            add3dMaze(mazeName, loadedMaze);
            WinMaze winMaze = new WinMaze(loadedMaze, "maze", 50);

            //if (!winMaze.isSolutionExists())
            //    isSolutionExists = false;
            m_currentWinMaze = winMaze;
            m_winMazesDictionary.Remove("maze");
            m_winMazesDictionary["maze"] = winMaze;
            m_instructions.Clear();
            m_instructions.Add("display");
            m_instructions.Add("maze");
        }
Exemple #4
0
        public void Load(string path, string mazename)
        {
            if ((m_controller as MyController).mazes.ContainsKey(mazename))
            {
                (m_controller as MyController).M_view.Output("maze name already exists");
                return;
            }
            if (!File.Exists(path))
            {
                (m_controller as MyController).M_view.Output("File does not exsits");
                return;
            }
            byte[] todecompress = File.ReadAllBytes(path);
            byte[] buffer       = new byte[todecompress[0] * todecompress[1] * todecompress[2] + 3];

            using (FileStream fileInStream = new FileStream(path, FileMode.Open))
            {
                using (Stream inStream = new MyCompressorStream(fileInStream, 2))
                {
                    byte[] mazeBytes = new byte[inStream.Read(buffer, 0, 0)];
                }
            }
            AMaze maze = new Maze3d(buffer);

            (m_controller as MyController).mazes.Add(mazename, maze);
        }
Exemple #5
0
        /// <summary>
        /// Load Maze - Loads a maze to the memory with a given file path
        /// from the user.
        /// </summary>
        /// <param name="path">Directory path</param>
        /// <param name="mazeName">Name of the maze</param>
        public void loadMaze(string path, string mazeName)
        {
            mazeName        = mazeName.Substring(0, mazeName.Length - 5);
            currentMazeName = mazeName;
            int numberOfBytes;

            byte[]      compressionArray = new byte[100];
            List <byte> compressedList   = new List <byte>();

            using (FileStream fileInStream = new FileStream(path, FileMode.Open))
            {
                using (Stream compressor = new MyCompressorStream(fileInStream))
                {
                    while ((numberOfBytes = compressor.Read(compressionArray, 0, 100)) != 0)
                    {
                        for (int i = 0; i < numberOfBytes; i++)
                        {
                            compressedList.Add(compressionArray[i]);
                        }
                    }
                }
            }
            Maze3d loadedMaze = new Maze3d(compressedList.ToArray());

            add3dMaze(mazeName, loadedMaze);
            WinMaze winMaze = new WinMaze(loadedMaze, "maze", 50);

            m_currentWinMaze = winMaze;
            m_winMazesDictionary.Remove("maze");
            m_winMazesDictionary["maze"] = winMaze;
            printMaze(winMaze, winMaze.PosZ);
        }
Exemple #6
0
 public void LoadFromDisk(string mazeName, string path)
 {
     using (Stream compressed = new FileStream(path, FileMode.Open))
     {
         using (Stream mydecompressor = new MyCompressorStream(compressed, MyCompressorStream.Decompress))
         {
             byte[] size = new byte[3];
             mydecompressor.Read(size, 0, size.Length);
             byte[] mazebytes = new byte[3 + (size[0] * size[1] * size[2])];
             for (int i = 0; i < 3; mazebytes[i] = size[i], i++)
             {
                 ;
             }
             mydecompressor.Read(mazebytes, 3, mazebytes.Length - 3);
             Maze3d newMaze = new Maze3d(mazebytes);
             m_mazes.Add(mazeName, newMaze);
         }
     }
 }
Exemple #7
0
        private static void TestMyCompressorStream()
        {
            IMazeGenerator mg   = new MyMaze3dGenerator();
            Maze           maze = mg.generate(10, 14, 5);

            Console.WriteLine("Test - My Stream Compressor");
            string filePath = @"compressedFile.txt";

            using (FileStream fileOutStream = new FileStream(filePath, FileMode.Create))
            {
                using (MyCompressorStream c = new MyCompressorStream(fileOutStream, 1))
                {
                    byte[] byteArray = ((Maze3d)maze).toByteArray();
                    int    length    = byteArray.Length;
                    Console.WriteLine();
                    for (int i = 0; i < byteArray.Length; i++)
                    {
                        Console.Write(byteArray[i]);
                    }
                    Console.WriteLine();

                    Console.WriteLine();
                    c.Write(byteArray, 0, length);
                }
            }
            Console.WriteLine();
            byte[] mazeBytes;
            using (FileStream fileInStream = new FileStream(filePath, FileMode.Open))
            {
                using (MyCompressorStream inStream = new MyCompressorStream(fileInStream, 2))
                {
                    mazeBytes = new byte[(((Maze3d)maze).toByteArray()).Length];
                    int length = mazeBytes.Length;
                    inStream.Read(mazeBytes, 0, length);
                    Console.WriteLine();
                    Console.WriteLine("*** Data Bytes after reading from the file ***");
                    for (int i = 0; i < mazeBytes.Length; i++)
                    {
                        Console.Write(mazeBytes[i]);
                    }
                    Console.WriteLine();
                }
            }
            Console.WriteLine();
            Console.WriteLine("*******Before writing to the file*******");
            maze.print();
            Console.WriteLine("*******After reading from the file*******");
            Maze3d mazeAfterReading = new Maze3d(mazeBytes);

            mazeAfterReading.print();
        }
Exemple #8
0
 private static void DecompressFile(string compressedFilePath, string decompressedFilePath)
 {
     // decompress bart_compressed.txt => bart_decompressed.txt
     using (FileStream compressesFileStream = new FileStream(compressedFilePath, FileMode.Open))
     {
         using (FileStream decompressedFileStream = new FileStream(decompressedFilePath, FileMode.Create))
         {
             using (MyCompressorStream myCompressorStream = new MyCompressorStream(compressesFileStream))
             {
                 byte[] data = new byte[100];
                 int    r    = 0;
                 while ((r = myCompressorStream.Read(data, 0, 100)) != 0)
                 {
                     decompressedFileStream.Write(data, 0, data.Length);
                 }
             }
         }
     }
 }
Exemple #9
0
        /// <summary>
        /// Loads a compressed maze from the given path ,decompress it and adds it to the dictionary
        /// also - if theres a previous existing solution for a maze with the same name - delete it
        /// </summary>
        /// <param name="path">path of the file to load</param>
        /// <param name="mazeName">maze name</param>
        public void loadMaze(string path, string mazeName)
        {
            int numOfBytes;

            byte[]      arrayCmp  = new byte[100];
            List <byte> totalComp = new List <byte>();

            using (FileStream fileInStream = new FileStream(path, FileMode.Open))
            {
                using (Stream compressor = new MyCompressorStream(fileInStream))
                {
                    while ((numOfBytes = compressor.Read(arrayCmp, 0, 100)) != 0)
                    {
                        for (int i = 0; i < numOfBytes; i++)
                        {
                            totalComp.Add(arrayCmp[i]);
                        }
                    }
                }
            }
            addMaze(mazeName, new Maze3d(totalComp.ToArray()));
        }
Exemple #10
0
 /// <summary>
 /// Loads maze from given path and saves it in app memory by given name
 /// </summary>
 /// <param name="path">path</param>
 /// <param name="mazeName">maze name</param>
 public void LoadMaze(string path, string mazeName)
 {
     if (!m_savedMazes.ContainsKey(path))
     {
         ModelChanged("path doesnt exit");
     }
     else //file path exist
     {
         Maze3d savedMaze = m_savedMazes[path];
         byte[] mazeBytes = new byte[savedMaze.toByteArray().Length];
         using (FileStream fileInStream = new FileStream(path, FileMode.Open))
         {
             using (Stream inStream = new MyCompressorStream(fileInStream, ATP2016Library.Compression.CompressionMode.Decompress))
             {
                 inStream.Read(mazeBytes, 0, mazeBytes.Length);
             }
         }
         Maze3d loadedMaze = new Maze3d(mazeBytes);
         AddToGeneratedMazesDictionary(mazeName, loadedMaze);
         ModelChanged("maze " + mazeName + " was loaded successfully");
     }
 }
Exemple #11
0
        private static void testMyCompressorStream()
        {
            Console.WriteLine("*******  testMyCompressorStream  *******\n");
            int[]          size3D          = { 3, 6, 7 }; // (z,y,x)
            IMazeGenerator mazeGenerator3d = new MyMaze3dGenerator();
            Maze3d         maze            = (Maze3d)mazeGenerator3d.generate(size3D);

            // save the maze to a file – compressed
            using (FileStream fileOutStream = new FileStream(@"D:\1.maze.txt", FileMode.Create))
            {
                using (Stream outStream = new MyCompressorStream(fileOutStream))
                {
                    outStream.Write(maze.toByteArray(), 0, maze.toByteArray().Length);
                    outStream.Flush();
                }
            }
            byte[] mazeBytes;
            using (FileStream fileInStream = new FileStream(@"D:\1.maze.txt", FileMode.Open))
            {
                using (Stream inStream = new MyCompressorStream(fileInStream))
                {
                    mazeBytes = new byte[maze.toByteArray().Length];
                    inStream.Read(mazeBytes, 0, mazeBytes.Length);
                }
            }
            Maze3d loadedMaze = new Maze3d(mazeBytes);

            Console.WriteLine("The original maze : ");
            maze.print();
            maze.getStartPosition().print();
            maze.getGoalPosition().print();

            Console.WriteLine("The decompress maze : ");
            loadedMaze.print();
            loadedMaze.getStartPosition().print();
            loadedMaze.getGoalPosition().print();
            Console.WriteLine(loadedMaze.Equals(maze));
        }