Beispiel #1
0
 private ImmutableSigmaMap <MazeCell> FixConnectivity(ImmutableSigmaMap <MazeCell> maze)
 {
     return(IsConnected(maze) ? maze : maze
            .Insert(new SigmaIndex(0, maze.Size.X), MazeCell.Empty)
            .Insert(new SigmaIndex(maze.Size.Y, 0), MazeCell.Empty)
            .Insert(new SigmaIndex(1, maze.Size.X), MazeCell.Empty)
            .Insert(new SigmaIndex(maze.Size.Y, 1), MazeCell.Empty)
            .Insert(new SigmaIndex(0, maze.Size.X - 1), MazeCell.Empty)
            .Insert(new SigmaIndex(maze.Size.Y - 1, 0), MazeCell.Empty));
 }
Beispiel #2
0
        private ImmutableSigmaMap <MazeCell> InitAboveDiagonal(MapSize size)
        {
            // need a local variable here to put it into a closure
            ImmutableSigmaMap <MazeCell> maze = ArraySigmaMap.From(size, _ => MazeCell.Wall);

            return(Graph.DepthFirstTraverse(new SigmaIndex(0, 0),

                                            s => s.Neighborhood
                                            .Clamp(size)
                                            .OrderBy(_ => random.Next()),

                                            s => s.Neighborhood
                                            .Clamp(size)
                                            .Where(x => maze[x] == MazeCell.Empty)
                                            .Count() > emptyNeighborhood

                                            ).Aggregate(maze, (m, r) => maze = m.Insert(r.Node, MazeCell.Empty)));
        }
Beispiel #3
0
 private ImmutableSigmaMap <MazeCell> SymmetricallyComplete(ImmutableSigmaMap <MazeCell> maze)
 {
     return(maze.Where(s => maze[s] == MazeCell.Empty)
            .Aggregate(maze, (m, s) => m.Insert(s.DiagonalMirror(m.Size), MazeCell.Empty)));
 }