public override PM_Maze Generate_Maze(
            Random randomness_provider,
            int width,
            int height
            )
        {
            // initialize maze
            PM_Maze maze = new PM_Maze(width, height);

            Vec2i          current_position = maze.RandomCell(randomness_provider);
            List <UEdge2i> expansion_edges  = maze.Cell_ExpansionEdges_List(current_position);

            expansion_edges.Shuffle(randomness_provider);

            while (expansion_edges.Count > 0)
            {
                UEdge2i selected_edge = expansion_edges.Pop_Last_Item(); // select & remove (draw) the last edge
                current_position = selected_edge.exit;
                if (maze.Q_Is_Cell_Unconnected(current_position))
                {
                    maze.OP_AddEdge(selected_edge);
                    List <UEdge2i> newEdges = maze.Cell_ExpansionEdges_List(current_position);
                    newEdges.Shuffle(randomness_provider);
                    expansion_edges.AddRange(newEdges);
                }
            }
            return(maze);
        }
        public static void Fill_Random_DFS(
            this PM_Maze maze,
            Random rand
            )
        {
            if (maze == null)
            {
                return;
            }
            List <UEdge2i> allPossibleEdges = maze.ConnectedCells_ExpansionEdges_List();

            // temporarily commented out
            allPossibleEdges.Shuffle(rand);

            while (allPossibleEdges.Count > 0)
            {
                UEdge2i edge = allPossibleEdges.Pop_Last_Item();
                if (maze.Q_Is_Cell_Unconnected(edge.exit))
                {
                    maze.OP_AddEdge(edge);
                    List <UEdge2i> newEdges = maze.Cell_ExpansionEdges_List(edge.exit);
                    newEdges.Shuffle(rand);
                    allPossibleEdges.AddRange(newEdges);
                }
            }
        }
        public static void OP_RemoveEdge(this PM_Maze maze, UEdge2i edge)
        {
            if (maze.Q_Is_Edge_InBounds(edge))
            {
                Directions_Ortho_2D origin_direction = edge.To_Direction();
                maze.LLOP_Remove_Cell_Directions(edge.origin, origin_direction);

                Directions_Ortho_2D exit_direction = edge.Reverse().ToDirection();
                maze.LLOP_Remove_Cell_Directions(edge.exit, exit_direction);
            }
        }
        public static UEdge2i[,] DeepCopy(this UEdge2i[,] originalArray)
        {
            int width  = originalArray.GetLength(0);
            int height = originalArray.GetLength(1);

            UEdge2i[,] arrayCopy = new UEdge2i[width, height];

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    arrayCopy[x, y] = originalArray[x, y];
                }
            }

            return(arrayCopy);
        }
        public static List <UEdge2i> Cell_InactiveEdges_InBounds_List(
            this PM_Maze maze,
            Vec2i pos
            )
        {
            List <UEdge2i> inactiveEdges_InBounds = new List <UEdge2i>();

            if (maze.Q_Cell_Directions(pos).HasFlag(Directions_Ortho_2D.U) == false)
            {
                UEdge2i upEdge = new UEdge2i(pos, pos.To_Up());
                if (maze.Q_Is_Edge_InBounds(upEdge))
                {
                    inactiveEdges_InBounds.Add(upEdge);
                }
            }
            if (maze.Q_Cell_Directions(pos).HasFlag(Directions_Ortho_2D.D) == false)
            {
                UEdge2i downEdge = new UEdge2i(pos, pos.To_Down());
                if (maze.Q_Is_Edge_InBounds(downEdge))
                {
                    inactiveEdges_InBounds.Add(downEdge);
                }
            }
            if (maze.Q_Cell_Directions(pos).HasFlag(Directions_Ortho_2D.L) == false)
            {
                UEdge2i leftEdge = new UEdge2i(pos, pos.To_Left());
                if (maze.Q_Is_Edge_InBounds(leftEdge))
                {
                    inactiveEdges_InBounds.Add(leftEdge);
                }
            }
            if (maze.Q_Cell_Directions(pos).HasFlag(Directions_Ortho_2D.R) == false)
            {
                UEdge2i rightEdge = new UEdge2i(pos, pos.To_Right());
                if (maze.Q_Is_Edge_InBounds(rightEdge))
                {
                    inactiveEdges_InBounds.Add(rightEdge);
                }
            }
            return(inactiveEdges_InBounds);
        }
        public static void Fill_RandomBFS(
            this PM_Maze maze,
            Random rand
            )
        {
            if (maze == null)
            {
                return;
            }
            // edges
            List <UEdge2i> edges = maze.ConnectedCells_ExpansionEdges_List();

            while (edges.Count > 0)
            {
                UEdge2i edge = edges.Pop_Random_Item(rand);
                if (maze.Q_Is_Cell_Unconnected(edge.exit))
                {
                    maze.OP_AddEdge(edge);
                    edges.AddRange(maze.Cell_ExpansionEdges_List(edge.exit));
                }
            }
        }
Example #7
0
        public override PM_Maze Generate_Maze(
            Random rand,
            int width,
            int height
            )
        {
            PM_Maze        maze                     = new PM_Maze(width, height);
            Vec2i          current_position         = new Vec2i(rand.Next(width), rand.Next(height));
            List <UEdge2i> possible_expansion_edges = maze.Cell_ExpansionEdges_List(current_position);

            while (possible_expansion_edges.Count > 0)
            {
                UEdge2i edge = possible_expansion_edges.Pop_Random_Item(rand);
                current_position = edge.exit;
                if (maze.Q_Is_Cell_Unconnected(current_position))
                {
                    maze.OP_AddEdge(edge);
                    List <UEdge2i> newEdges = maze.Cell_ExpansionEdges_List(current_position);
                    possible_expansion_edges.AddRange(newEdges);
                }
            }
            return(maze);
        }
 public static bool Q_Is_Edge_InBounds(this PM_Maze maze, UEdge2i edge)
 {
     return(maze.Q_Is_Cell_InBounds(edge.origin) && maze.Q_Is_Cell_InBounds(edge.exit));
 }