Exemplo n.º 1
0
 /// <summary>
 /// check if mazes are equal
 /// </summary>
 /// <param name="maze">maze to compre to</param>
 /// <returns>true if the mazes are equel</returns>
 public override bool equals(Maze maze)
 {
     if (maze is Maze3d)
     {
         Maze3d maze3d = (Maze3d)maze;
         if (mazeMap.Length == maze3d.mazeMap.Length)
         {
             for (int i = 0; i < mazeMap.Length; i++)
             {
                 if (!mazeMap[i].equals(maze3d.mazeMap[i]))
                 {
                     return(false);
                 }
             }
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Generate a 3D maze.
        /// </summary>
        /// <param name="mazesizes">Get the sizes of the maze</param>
        /// <returns>Returns a maze with a solution.</returns>
        /// <remarks>For each floor we build a 2D maze. First we fill the 0 floor all with 1s then for each floor, except the last,
        /// we call to generate2d that generates a 2D maze. The last floor will be filled with 1s and one 4 - the exit. Floor no. 1 will mark the start.</remarks>
        public override AMaze generate(ArrayList mazesizes)
        {
            Maze3d    maze3d = new Maze3d(mazesizes);
            int       floors = (int)mazesizes[2];
            ArrayList al2    = new ArrayList();

            al2.Add(mazesizes[0]);
            al2.Add(mazesizes[1]);

            for (int i = 0; i < (int)mazesizes[0]; i++)
            {
                for (int j = 0; j < (int)mazesizes[1]; j++)
                {
                    maze3d.maze3d[0].maze2d[i, j] = 1;
                }
            }

            for (int i = 1; i <= floors; i++)
            {
                maze3d.maze3d[i] = (Maze2d)generate2d(al2);
            }
            for (int i = 0; i < (int)mazesizes[0]; i++)
            {
                for (int j = 0; j < (int)mazesizes[1]; j++)
                {
                    if (maze3d.maze3d[maze3d.maze3d.Length - 2].maze2d[i, j] == 4)
                    {
                        maze3d.maze3d[floors + 1].maze2d[i, j] = 4;
                        maze3d.end = new Position(i, j, floors + 1);
                    }
                    else
                    {
                        maze3d.maze3d[floors + 1].maze2d[i, j] = 1;
                    }
                }
            }
            maze3d.start = maze3d.maze3d[1].start;
            maze3d.maze3d[1].maze2d[maze3d.start.x, maze3d.start.y] = 3;
            return(maze3d);
        }
Exemplo n.º 3
0
        /// <summary>
        ///  genarate maze with given size
        /// </summary>
        /// <param name="x"> widht </param>
        /// <param name="y"> length </param>
        /// <param name="z"> depth </param>
        /// <returns> maze</returns>
        public override Maze generate(int x, int y, int z)
        {
            if (x <= 2 || y <= 2 || z <= 2)
            {
                throw new NotSupportedException("cant genarate maze this size");
            }
            Position start = randomPosition(x, y, 0);

            Thread.Sleep(4);
            Position end = randomPosition(x, y, z - 1);

            Maze2d[] mazeMap = new Maze2d[z];
            mazeMap[0]     = fillSurface(x, y, start, Start);
            mazeMap[z - 1] = fillSurface(x, y, end, End);

            for (int i = 1; i < z - 1; i++)
            {
                mazeMap[i] = make2dMaze(x, y);
            }
            Maze maze = new Maze3d(start, end, mazeMap);

            return(maze);
        }
Exemplo n.º 4
0
        /// <summary>
        /// checks if an obj represents the same maze
        /// </summary>
        /// <param name="obj">object to compare</param>
        /// <returns>true if the mazes equals, else- false</returns>
        public override bool Equals(object obj)
        {
            if (!(obj is Maze3d))
            {
                return(false);
            }
            Maze3d other = (Maze3d)obj;

            for (int level = 0; level < m_maze.GetLength(0); level++)
            {
                for (int row = 0; row < m_maze.GetLength(1); row++)
                {
                    for (int col = 0; col < m_maze.GetLength(2); col++)
                    {
                        if (m_maze[level, row, col] != other.m_maze[level, row, col])
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 5
0
 /// <summary>
 /// constractor
 /// </summary>
 /// <param name="_maze"></param>
 public SearchableMaze3d(Maze3d _maze)
 {
     maze = _maze;
 }