Beispiel #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] + " ");
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
 public void SolveMaze(string mazeName)
 {
     if (IsMazeExists(mazeName))
     {
         if (!IsSolutionExists(mazeName))
         {
             new Thread(() =>
             {
                 Maze3d maze3d           = m_mazes[mazeName];
                 ISearchable maze        = new SearchableMaze3d(maze3d);
                 AState startState       = maze.GetStartState();
                 ASearchingAlgorithm bfs = new BreadthFirstSearch();
                 Solution solution       = bfs.Solve(maze);
                 m_solutions.Add(mazeName, solution);
                 controller.output("solution for " + mazeName + " is ready");
             }).Start();
         }
         else
         {
             controller.output("solution for " + mazeName + " is ready");
         }
     }
     else
     {
         throw new Exception("maze " + mazeName + " dosen't exist!");
     }
 }
Beispiel #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);
        }
Beispiel #5
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();
        }
    void Start()
    {
        theMaze = new Maze3d(nCellsX, nCellsY, wallBlock);
        GameObject baseFloor = GameObject.CreatePrimitive(PrimitiveType.Cube);

        baseFloor.transform.position   = new Vector3(theMaze.Length / 2, 0, theMaze.Width / 2);
        baseFloor.transform.localScale = new Vector3(theMaze.Length, 0.2f, theMaze.Width);
        Quaternion zeroRot = new Quaternion(0, 0, 0, 1);

        for (int x = 0; x < theMaze.Length; x++)
        {
            for (int z = 0; z < theMaze.Width; z++)
            {
                if ((x & 1) == 0 || (z & 1) == 0)
                {
                    Vector3 pos = new Vector3((float)x, 0.6f, (float)z);
                    // wallBlock.transform.localScale = new Vector3(0.9f, 1.0f, 0.9f);
                    Instantiate(wallBlock, pos, zeroRot);
                }
            }
        }


        StartCoroutine(createMaze());
    }
Beispiel #7
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");
        }
Beispiel #8
0
        /// <summary>
        /// constructor of maze canvas
        /// </summary>
        /// <param name="maze">Maze maze 3d</param>
        public MazeCanvas(Maze3d maze)
        {
            InitializeComponent();
            m_maze  = maze;
            Start_x = m_maze.getStartPosition().X;
            Start_y = m_maze.getStartPosition().Y;
            //m_row = 0;
            //m_column = 0;
            m_row      = Start_x;
            m_column   = Start_y;
            x          = m_maze.MX * 2 - 1;
            y          = m_maze.MY * 2 - 1;
            z          = m_maze.MZ;
            goal_layer = z - 1;
            cur_layer  = 0;

            CreateTheMaze();
            // CreatePlayer();
            RestaerPlayer();

            //for zoom in/out
            m_ZoomX = 1;
            m_ZoomY = 1;

            //this.MouseWheel += new MouseWheelEventHandler(prevMouseWheel);
            this.PreviewMouseWheel += PrevMouseWheel;
            checkWindow             = true;

            //
            dragged      = false;
            ScrollerView = new ScrollViewer();//
        }
Beispiel #9
0
        /// <summary>
        /// click  up button
        /// </summary>
        /// <param name="sender">object sender</param>
        /// <param name="e">EventArgs e</param>
        private void button_up_Click(object sender, RoutedEventArgs e)
        {
            Maze3d maze = m_maze as Maze3d;

            if (m_layer == m_maze.MZ - 1 || m_maze.MZ == 0 || m_maze.MZ == 1)
            {
                MessageBox.Show("This is the Maximun level!");
                return;
            }
            else
            {
                m_layer++;
                DockP_MSOL.Children.Clear();
                if (m_layerOfGrid.ContainsKey(m_layer))
                {
                    DockP_MSOL.Children.Add(m_layerOfGrid[m_layer]);
                    TextB_MazeSol.Text = "You are in level " + m_layer;
                }
                else
                {
                    CreateMazeGrid(m_maze.MX, m_maze.MY, m_layer);
                    colorMazeWall(m_layerOfGrid[m_layer], ((Maze2d)maze.MAZE3dArray[m_layer]), m_layer, m_maze.MZ, m_solution);
                    TextB_MazeSol.Text = "You are in level " + m_layer;
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Save Maze - Creates a compression of the maze and
        /// saves the file on the disk with a given file path
        /// </summary>
        /// <param name="mazeName">Maze name</param>
        /// <param name="path">File Name</param>
        /// <returns>True if successful saving the maze</returns>
        public bool saveMaze(string mazeName, string filePath)
        {
            //MessageBox.Show("save: " + mazeName);
            WinMaze winMaze     = m_currentWinMaze;
            Maze3d  currentMaze = winMaze.getMaze();

            add3dMaze(mazeName, currentMaze);
            if (isSolutionExists)
            {
                m_solutionsDictionary[mazeName] = mCurrentSolution;
            }

            if (currentMaze == null)
            {
                return(false);
            }
            using (FileStream fileOutStream = new FileStream(filePath, FileMode.Create))
            {
                using (Stream outStream = new MyCompressorStream(fileOutStream))
                {
                    outStream.Write(currentMaze.toByteArray(), 0, currentMaze.toByteArray().Length);
                    outStream.Flush();
                }
            }
            return(true);
        }
Beispiel #11
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 fileName = Path.GetFileName(filePath);
            string mazeName = fileName.Substring(0, fileName.IndexOf('.'));

            try
            {
                using (FileStream input = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    byte[] bytes          = new byte[input.Length];
                    int    numBytesToRead = (int)input.Length;
                    int    numBytesRead   = 0;
                    while (numBytesToRead > 0)
                    {
                        int n = input.Read(bytes, numBytesRead, numBytesToRead); // Read may return anything from 0 to numBytesToRead.
                        if (n == 0)                                              // Break when the end of the file is reached.
                        {
                            break;
                        }

                        numBytesRead   += n;
                        numBytesToRead -= n;
                    }
                    Maze3d maze = new Maze3d(bytes);
                    m_DicOfMazes[mazeName] = maze;
                }
                ModelChanged("MazeLoaded", mazeName);
            }
            catch
            {
                ModelChanged("ErrorInLoadMaze", mazeName);
            }
        }
Beispiel #12
0
        /// <summary>
        /// uploade the maze
        /// </summary>
        /// <param name="fileName">name of file</param>
        private void uploadMaze(string fileName)
        {
            using (FileStream input = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                byte[] bytes          = new byte[input.Length];
                int    numBytesToRead = (int)input.Length;
                int    numBytesRead   = 0;
                while (numBytesToRead > 0)
                {
                    // Read may return anything from 0 to numBytesToRead.
                    int n = input.Read(bytes, numBytesRead, numBytesToRead);

                    // Break when the end of the file is reached.
                    if (n == 0)
                    {
                        break;
                    }

                    numBytesRead   += n;
                    numBytesToRead -= n;
                }
                Maze3d maze = new Maze3d(bytes);
                m_DicOfMazes[fileName] = maze;
            }
        }
Beispiel #13
0
 /// <summary>
 /// save the maze to disk
 /// </summary>
 /// <param name="maze_name">name of the file</param>
 /// <param name="filePath">path of the file</param>
 public void SaveMazeToDisk(string maze_name, string filePath)
 {
     if (!checkIfNameExist(maze_name))
     {
         ModelChanged("NameIsntExists", maze_name);
     }
     else
     {
         try
         {
             Maze3d maze3d      = (Maze3d)m_DicOfMazes[maze_name];
             byte[] inputSource = maze3d.toByteArray();
             using (MemoryStream input = new MemoryStream(inputSource))
             {
                 using (FileStream outputStream = new FileStream(filePath, FileMode.Create))
                 {
                     byte[] byteArray = new byte[100];
                     int    r         = 0;
                     while ((r = input.Read(byteArray, 0, byteArray.Length)) != 0)
                     {
                         outputStream.Write(byteArray, 0, r);
                         outputStream.Flush();
                         byteArray = new byte[100];
                     }
                 }
             }
             ModelChanged("MazeSaved", maze_name);
         }
         catch (Exception e)
         {
             ModelChanged("ErrorInSaveMaze", maze_name);
         }
     }
 }
Beispiel #14
0
 /// <summary>
 /// click play option button
 /// </summary>
 /// <param name="sender">object sender</param>
 /// <param name="e">event args e</param>
 private void playmaze_Click(object sender, RoutedEventArgs e)
 {
     string[] parameters = new string[1];
     m_name = NameMaze.Text;
     if (m_name == "")
     {
         MessageBox.Show("The name is empty!");
     }
     else
     {
         parameters[0] = m_name;
         m_view.startEvent(sender, new EventArgMaze(parameters));
         Maze new_maze = m_view.GetMaze();
         if (new_maze != null)
         {
             Maze3d maze3d = new_maze as Maze3d;
             maze_canv = new MazeCanvas(maze3d);
             maze_canv.Focus();
             display.Children.Clear();
             display.Children.Add(maze_canv);
             TextB_MazeWall.Text = maze_canv.writeMazeSLevel(); //"You are in level 0";
             TextB_GoalPois.Text = maze_canv.writeFinalLevel();
             TextB_SizeMaze.Text = maze_canv.writeMazeSizes();
         }
     }
 }
Beispiel #15
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();
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// click down button
        /// </summary>
        /// <param name="sender">object sender</param>
        /// <param name="e">EventArgs e</param>
        private void button_down_Click(object sender, RoutedEventArgs e)
        {
            Maze3d maze = m_maze as Maze3d;

            if (m_layer == 0)
            {
                MessageBox.Show("This is the Minimum level!");
            }
            else
            {
                m_layer--;
                DockP_Mwall.Children.Clear();
                if (m_layerOfGrid.ContainsKey(m_layer))
                {
                    TextB_MazeWall.Text = "You are in level " + m_layer;
                    DockP_Mwall.Children.Add(m_layerOfGrid[m_layer]);
                }
                else
                {
                    CreateMazeGrid(m_maze.MX, m_maze.MY, m_layer);
                    colorMazeWall(m_layerOfGrid[m_layer], ((Maze2d)maze.MAZE3dArray[m_layer]), m_layer, m_maze.MZ);
                    TextB_MazeWall.Text = "You are in level " + m_layer;
                }
            }
        }
Beispiel #17
0
 public void AddToGeneratedMazesDictionary(string mazeName, Maze3d maze)
 {
     try { m_generatedMazes.Add(mazeName, maze); }
     catch (Exception)
     {
         ModelChanged("this maze was already generated");
     }
 }
 /// <summary>
 /// constructs maze control
 /// </summary>
 /// <param name="maze">maze data</param>
 /// <param name="x">maze start position x axis</param>
 /// <param name="y">maze start position y axis</param>
 /// <param name="layer">current layer of the maze</param>
 /// <param name="solutionOn">flag of display solution</param>
 /// <param name="sol">maze solution</param>
 /// <param name="width">control width</param>
 /// <param name="height">control height</param>
 public MazeDisplayer(Maze3d maze, int x, int y, int layer, bool solutionOn, Solution sol, double width, double height)
 {
     InitializeComponent();
     m_maze = maze;
     DrawMaze(maze, x, y, layer, solutionOn, sol);
     m_width  = width;
     m_height = height;
 }
Beispiel #19
0
        /// <summary>
        /// Generates a 3d maze and adds it to the dictionary.
        /// </summary>
        /// <param name="size">array[3] : [0]columns [1] rows [2] levels - as maze dimensions </param>
        /// <param name="mazeName">the maze name - maze ID</param>
        private void threadGenerateMaze(int[] size, string mazeName)
        {
            IMazeGenerator mazeGenerator3d = new MyMaze3dGenerator();
            Maze3d         maze            = (Maze3d)mazeGenerator3d.generate(size);

            addMaze(mazeName, maze);
            m_controller.Output("maze " + mazeName + " is ready!\n");
        }
Beispiel #20
0
 public void generate()
 {
     dim      = floorSize;
     div_dim  = dim / 2.0F;
     m_maze3d = new Maze3d(heigth, depth, width, exitsInFloor, exitsInWalls);
     m_maze3d.generate(randWallsExits, randFloorExits);
     pop_maze_3d(m_maze3d, new Vector3(0, 0, 0));
 }
        /// <summary>
        /// redraws maze
        /// </summary>
        /// <param name="maze">maze to draw</param>
        /// <param name="x">player x position</param>
        /// <param name="y">player y position</param>
        /// <param name="layer">player layer position</param>
        private void reDrawMaze(Maze3d maze, int x, int y, int layer)
        {
            cnvs_main.Children.Clear();
            MazeDisplayer mazeDisplayer = new MazeDisplayer(maze, x, y, layer, solutionOn, m_sol, 400, 400);

            cnvs_main.Children.Add(mazeDisplayer);
            Canvas.SetLeft(mazeDisplayer, 0);
            Canvas.SetTop(mazeDisplayer, 0);
        }
Beispiel #22
0
        /// <summary>
        /// get the size of the maze
        /// </summary>
        /// <param name="maze_name">name of the maze</param>
        /// <returns>get the size of the maze</returns>
        public int MazeSize(string maze_name)
        {
            int    size_maze;
            Maze   maze   = m_DicOfMazes[maze_name];
            Maze3d maze3d = maze as Maze3d;

            size_maze = maze3d.toByteArray().Length;
            return(size_maze);
        }
Beispiel #23
0
 public void genarateMaze(string mazeName, int x, int y, int z)
 {
     new Thread(() =>
     {
         MyMaze3dGenerator mg = new MyMaze3dGenerator();
         Maze3d maze          = (Maze3d)mg.generate(x, y, z);
         AddMaze(mazeName, maze);
         controller.output("Maze " + mazeName + " genarated!");
     }).Start();
 }
Beispiel #24
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="maze3d"></param>
        public SearchableMaze3D(AMaze maze3d)
        {
            m_maze3d = (Maze3d)maze3d;
            Position3D statrPosition = (Position3D)maze3d.getStartPosition();

            m_initialState = new MazeState(null, statrPosition.Col, statrPosition.Row, statrPosition.Level);
            Position3D goalPosition = (Position3D)maze3d.getGoalPosition();

            m_goalState = new MazeState(null, goalPosition.Col, goalPosition.Row, goalPosition.Level);
        }
Beispiel #25
0
        /// <summary>
        /// solve the maze in new Thread
        /// </summary>
        /// <param name="name">mame of the thread</param>
        /// <param name="new_alg">alg of solving</param>
        private void SolveMazeInNewThread(string name, ASearchingAlgorithm new_alg)
        {
            Maze             m_from_dic    = m_DicOfMazes[name];
            Maze3d           m_3d          = m_from_dic as Maze3d;
            SearchableMaze3d maze3dS       = new SearchableMaze3d(m_3d);
            Solution         maze_solution = new_alg.Solve(maze3dS); // solve the maze

            IfSolutionExist(name);                                   // if the solution exist with identical name - remove it.
            m_solutions.Add(name, maze_solution);                    // add to dictionary of solutions
        }
Beispiel #26
0
        /// <summary>
        /// check if there is a wall in the cell
        /// </summary>
        /// <param name="p">get the position to check about</param>
        /// <returns>true if there is a wall</returns>
        public bool checkIfThereIsAWall(Position p)
        {
            Maze3d m3d = (Maze3d)(m_maze);
            Maze2d m2d = (Maze2d)(m3d.MAZE3dArray[p.Z]);

            if (m2d.MAZE2d[p.X, p.Y] == 1)
            {
                return(true);
            }
            return(false);
        }
 public void TestBadArguments()
 {
     try
     {
         var    mg   = new MyMaze3dGenerator();
         Maze3d maze = (Maze3d)mg.generate(2, -10, 2);
         Assert.Fail("Test Bad Arguments Faild");
     }
     catch (OverflowException)
     {
     }
 }
Beispiel #28
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();
        }
Beispiel #29
0
        private static void testMeze3dGenerator(MyMaze3dGenerator mg)
        {
            ArrayList s = new ArrayList();

            s.Add(20);
            s.Add(20);
            s.Add(4);

            Console.WriteLine(mg.MeasureAlgorithmTime(s));
            AMaze    maze  = mg.generate(s);
            Position start = maze.getStartPosition();

            start.print();
            maze.getGoalPosition().print();
            maze.Print();
            byte[]      dar  = (maze as Maze3d).toByteArray();
            Maze3d      hara = new Maze3d(dar);
            ICompressor car  = new MyMaze3DCompressor();

            byte[] hara1 = car.compress(dar);
            byte[] hara2 = car.decompress(hara1);
            Maze3d hara3 = new Maze3d(hara2);

            hara3.Print();


            /*using (FileStream fileOutStream = new FileStream("1.maze", FileMode.Create))
             * {
             *  using (Stream outStream = new MyCompressorStream(fileOutStream, 1))
             *  {
             *      outStream.Write((maze as Maze3d).toByteArray(),0,1);
             *      outStream.Flush();
             *  }
             * }
             * byte[] mazeBytes;
             * using (FileStream fileInStream = new FileStream("1.maze", FileMode.Open))
             * {
             *  using (Stream inStream = new MyCompressorStream(fileInStream,1))
             *  {
             *      mazeBytes = new byte[(maze as Maze3d).toByteArray().Count()];
             *      input.read(b);
             *  }
             * }
             * Maze3d loadedMaze = new Maze3d(mazeBytes);
             * System.out.println(loaded.equals(maze));*/



            Console.ReadKey();
        }
Beispiel #30
0
 /// <summary>
 /// Adds the given maze to the dictionary (memory)
 /// </summary>
 /// <param name="mazeName">Maze Name</param>
 /// <param name="currentMaze">Maze</param>
 private void add3dMaze(string mazeName, Maze3d currentMaze)
 {
     try
     {
         //m_solutionsDictionary.Remove("maze");
     }
     catch (Exception)
     {
         // Empty implementation
     }
     //MessageBox.Show("add");
     m_mazesDictionary["maze"]   = currentMaze;
     m_mazesDictionary[mazeName] = currentMaze;
 }