Ejemplo n.º 1
0
        /// <summary>
        /// constructor of maze with byte array
        /// </summary>
        /// <param name="uncompressed">array byte uncompressed</param>
        public Maze3d(byte[] uncompressed) : base(uncompressed)
        {
            maze3d          = new ArrayList();
            m_startPosition = new Position(uncompressed[0], uncompressed[1], uncompressed[2]);
            m_goalPosition  = new Position(uncompressed[3], uncompressed[4], uncompressed[5]);
            m_mx            = uncompressed[6] / 2 + 1;
            m_my            = uncompressed[7] / 2 + 1;
            m_mz            = uncompressed[8];
            int i = 9;

            for (int layer = 0; layer < m_mz; layer++)
            {
                Maze2d maze2D = new Maze2d(m_mx, m_my, layer);
                if (layer == 0)
                {
                    maze2D.setStartPosition(m_startPosition);
                }
                if (layer == m_mz - 1)
                {
                    maze2D.setGoalPosition(m_goalPosition);
                }
                for (int row = 0; row < m_mx * 2 - 1; row++)
                {
                    for (int column = 0; column < m_my * 2 - 1; column++)
                    {
                        maze2D.MAZE2d[row, column] = uncompressed[i];
                        i++;
                    }
                }
                maze3d.Add(maze2D);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// build a maze2d that we can solve - break walls to get to the goal position
        /// </summary>
        /// <param name="maze"></param>
        /// <returns>maze2d</returns>
        ///
        ////IMaze maze in function
        public void generateMaze2d(Maze2d maze2d)
        {
            int      randomWallLocation;
            Position currentWall;
            Position pMaze;
            Position startPosition = new Position(0, 0, 0);

            positionsInMaze = new ArrayList();
            ArrayList neighborWallsList = new ArrayList();

            maze2d.setGoalPosition();
            Position goalPosition = maze2d.getGoalPosition();

            neighborWallsList.AddRange(maze2d.getOptionsToMove(goalPosition)); // add all the neighbors to neighborsWallList
            positionsInMaze.Add(goalPosition);                                 // add the goalPosition to List
            while (neighborWallsList.Count != 0)                               // while there is positions in neighborsWallsPOsitions
            {
                randomWallLocation = ran.Next(0, neighborWallsList.Count - 1); // random and get 1 of the walls in the List
                currentWall        = ((Position)neighborWallsList[randomWallLocation]);
                pMaze = getUnvisitedWallNeighborCell(currentWall);             // get all the UnvisitedNeighbors of the current wall
                if (pMaze != null)
                {
                    startPosition.setPosition(pMaze);                      // cheange the Position
                    maze2d.setMazeWallsCell(currentWall.X, currentWall.Y); // change the cell to 0 - we visited it
                    if (!isPositionExist(pMaze, positionsInMaze))
                    {
                        positionsInMaze.Add(pMaze); // add it to positionInMAze - all the position we have visited
                    }
                    neighborWallsList.AddRange(filterExistNeighbors(neighborWallsList, maze2d.getOptionsToMove(pMaze)));
                }
                neighborWallsList.RemoveAt(randomWallLocation); // remove the current wall from the neighborWallsList
            }
            maze2d.setStartPosition(startPosition);             // change the startPosition
        }
Ejemplo n.º 3
0
        /// <summary>
        /// build the maze 2d in a simple way,
        /// always start from the left side and have options to move (up,down,right), the goalPosition is in the right side
        /// </summary>
        /// <param name="x">dim X of the maze2d</param>
        /// <param name="y">dim Y of the maze2d</param>
        /// <param name="z">dim Z of the maze2d</param>
        /// <returns>a generated 2dMaze</returns>
        public override Maze generate(int x, int y, int z)
        {
            Position currentWall;
            Position startPosition = new Position(0, 0, 0);
            Maze2d   maze2d        = new Maze2d(x, y, z);

            maze2d.setGoalPosition();
            Position goalPosition = maze2d.getGoalPosition();

            startPosition.setPosition(goalPosition);

            while (startPosition.Y != maze2d.MY * 2 - 2)
            {
                currentWall = ((Position)MoveTONextPosition(startPosition, maze2d));   //get the wall to break
                currentWall.setFatherPosition(startPosition);
                maze2d.setMazeWallsCell(currentWall.X, currentWall.Y);                 //break the wall
                startPosition.setPosition(MoveToNextCell(startPosition, currentWall)); //get the prev position and the wall and move to the next cell
            }
            maze2d.setStartPosition(startPosition);
            breakMoreWalls(maze2d);
            return(maze2d);
        }