/// <summary> /// Expands the maze size by a factor and then connects all new rooms that appeared from the expansion. /// </summary> private IGrid <GridPoint2, RectFEV.MazeType> ExpandMaze(IGrid <GridPoint2, RectFEV.MazeType> maze, int factor) { int r1 = (maze.Bounds.Size.X + 1) / 2 * factor; var one = -GridPoint2.One; var newShape = ImplicitShape.Func <GridPoint2>(p => maze.Contains((p - one).FloorDiv(factor * GridPoint2.One)) && maze[(p - one).FloorDiv(factor * GridPoint2.One)] == RectFEV.MazeType.Open).ToExplicit( new GridRect(new GridPoint2(1 - r1, 1 - r1), new GridPoint2(2 * r1 - 1, 2 * r1 - 1))); var maze2 = RectFEV.GenerateMaze(newShape, symmetry); var maze3 = maze2.Bounds.ToGrid <RectFEV.MazeType>(); foreach (var point in maze3.Points) { maze3[point] = maze2.Contains(point) && maze2[point] == RectFEV.MazeType.Open ? RectFEV.MazeType.Open : RectFEV.MazeType.Close; } RectFEV.ContinueMaze(maze3, symmetry); return(maze3); }
/// <summary> /// A Product maze creates small mazes and disposition them on the points of the repeat grid. /// </summary> private IGrid <GridPoint2, RectFEV.MazeType> ProductGrid() { var repeatShape = ImplicitShape.Square(GridPoint2.Zero, repeatGridRadius).ToExplicit(new GridRect(new GridPoint2(1 - repeatGridRadius, 1 - repeatGridRadius), new GridPoint2(2 * repeatGridRadius - 1, 2 * repeatGridRadius - 1))); var smallGridShape = ImplicitShape.Square(GridPoint2.Zero, smallGridRadius).ToExplicit(new GridRect(new GridPoint2(1 - smallGridRadius, 1 - smallGridRadius), new GridPoint2(2 * smallGridRadius - 1, 2 * smallGridRadius - 1))); var bigMaze = Grid.CloneStructure <GridPoint2, RectFEV.MazeType>(p => RectFEV.MazeType.Close); foreach (var iter in repeatShape.Points) { var maze = RectFEV.GenerateMaze(smallGridShape, iter.GetColor(2, 1, 1) == 0 ? RectFEV.Symmetry.Reflection : RectFEV.Symmetry.Rotation); foreach (var point in maze.Points) { var newPoint = iter * new GridPoint2(2 * smallGridRadius - 2, 2 * smallGridRadius - 2) + point; if (maze.Contains(point) && bigMaze.Contains(newPoint)) { bigMaze[newPoint] = maze[point] == RectFEV.MazeType.Open ? RectFEV.MazeType.Open : RectFEV.MazeType.Close; } } } RectFEV.ContinueMaze(bigMaze, symmetry); return(bigMaze); }