/// <summary> /// Constructor /// </summary> /// <param name="maze">maze board</param> /// <param name="start">start position</param> /// <param name="end">goal position</param> public Maze3d(int[,,] maze, Position3D start, Position3D end) : base(start, end) { m_maze = maze; }
/// <summary> /// Generates a maze (size is determined by a list of dimensions given as argument) /// </summary> /// <param name="boardSize"></param> /// <returns></returns> public override AMaze generate(int[] boardSize) { if (boardSize.Length < 2) { //error Console.WriteLine("Illegal Dimensions"); } initiateMaze(boardSize[0], boardSize[1], boardSize[2]); Random random = new Random(); row = random.Next(1, boardSize[1] - 1); cellStack.Push(new Position3D(floor, row, col)); start = new Position3D(floor, row, col); maze[floor, row, col] = 5; while (visitedCells < totalCells * 2) { check = false; int[] order = generateRandomDirections(6); for (int i = 0; i < 6; i++) { switch (order[i]) { case 1: //Left goLeft(); break; case 2: //Down goDown(); break; case 3: //Right goRight(); break; case 4: //Up goUp(); break; case 5: //Descend Descend(); break; case 6: //Ascend Ascend(); break; } //If theres no where to go from the current position //go back to the previous position if (!check) { if (cellStack.Count > 0) { current = (Position3D)cellStack.Pop(); } floor = current.Level; row = current.Row; col = current.Col; } } } if (!legalMaze) { return(generate(boardSize)); } return(new Maze3d(maze, start, end)); }