Exemple #1
0
        private static void testCompressor()
        {
            int[]          size3D          = { 3, 6, 6 }; // (z,y,x)
            IMazeGenerator mazeGenerator3d = new MyMaze3dGenerator();
            Maze3d         maze            = (Maze3d)mazeGenerator3d.generate(size3D);

            maze.print();
            Console.ReadKey();
            byte[] decomp = maze.toByteArray();
            for (int i = 0; i < decomp.Length; i++)
            {
                Console.Write(decomp[i] + " ");
            }
            ICompressor compressor = new MyMaze3DCompressor();

            Console.WriteLine("\ncompression : ");
            byte[] comp = compressor.compress(decomp);
            for (int i = 0; i < comp.Length; i++)
            {
                Console.Write(comp[i] + " ");
            }
            decomp = compressor.decompress(comp);
            Console.WriteLine("\ndecompression : ");
            for (int i = 0; i < decomp.Length; i++)
            {
                Console.Write(decomp[i] + " ");
            }
        }
Exemple #2
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 #3
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));
        }
Exemple #4
0
        /// <summary>
        /// display the maze on the screen
        /// </summary>
        /// <param name="m">the maze to print to screen</param>
        public void Display(Maze m)
        {
            Maze3d maze3d = m as Maze3d;

            maze3d.print();
        }
Exemple #5
0
 /// <summary>
 /// Prints the maze
 /// </summary>
 public void print()
 {
     m_maze3d.print();
 }