예제 #1
0
 private HashSet <SigmaIndex> FindRoad(SigmaIndex from, SigmaIndex to, ISigmaMap <MazeCell> maze)
 {
     return(new HashSet <SigmaIndex>(Graph.BreadthFirstSearch(from,
                                                              s => s.Neighborhood.Where(n => n.IsInside(maze.Size) && maze[n] == MazeCell.Empty),
                                                              s => s == to)
                                     .Select(x => x.AboveDiagonal(maze.Size))));
 }
예제 #2
0
        public ISigmaMap <TileObject> Spawn(ISigmaMap <List <TileObject> > map, ISigmaMap <MazeCell> maze)
        {
            var locationsToSpawn = new HashSet <Location>(locations(maze));

            return(SparseSigmaMap.From(map.Size,
                                       loc => locationsToSpawn.Contains(loc) ? factory(map, maze, loc) : null));
        }
예제 #3
0
        public ISigmaMap <TileTerrain> Construct(ISigmaMap <MazeCell> maze)
        {
            var road = FindRoad(SigmaIndex.Zero, new SigmaIndex(maze.Size.X - 1, maze.Size.Y - 1), maze);

            return(new ArraySigmaMap <TileTerrain>(maze.Size,
                                                   i => road.Contains(i.AboveDiagonal(maze.Size)) ? roadTile : null));
        }
        public ISigmaMap <TileTerrain> Construct(ISigmaMap <MazeCell> maze)
        {
            var terrains = generators
                           .Select(g => g.Construct(maze))
                           .ToArray();

            return(new ArraySigmaMap <TileTerrain>(maze.Size,
                                                   s => terrains.Select(t => t[s]).FirstOrDefault(t => t != null)));
        }
예제 #5
0
        private bool IsGoodPlaceForBuilding(
            ISigmaMap <List <TileObject> > map, ISigmaMap <MazeCell> maze, Location placeToCheck)
        {
            var isWall              = maze[placeToCheck] == MazeCell.Wall;
            var isOccupiedByOther   = map[placeToCheck] != null && map[placeToCheck].Count != 0;
            var hasPlaceForBuilding = FindPlaceForBuilding(map, maze, placeToCheck) != null;

            return(!isWall && !isOccupiedByOther && hasPlaceForBuilding);
        }
예제 #6
0
 private bool IsConnected(ISigmaMap <MazeCell> maze)
 {
     return(Graph.DepthFirstTraverse(new SigmaIndex(0, 0), s => s.Neighborhood
                                     .Where(n => n.IsInside(maze.Size))
                                     .Where(n => maze[n] == MazeCell.Empty)
                                     )
            .Select(x => x.Node)
            .Contains(new SigmaIndex(maze.Size.Y - 1, maze.Size.X - 1)));
 }
예제 #7
0
        private Location FindPlaceForBuilding(
            ISigmaMap <List <TileObject> > map, ISigmaMap <MazeCell> maze, Location location)
        {
            Func <Location, IEnumerable <Location> > neighbors = loc => loc.Neighborhood.Inside(map.Size);

            Func <Location, bool> isBuilding = loc => neighbors(loc)
                                               .Any(neighbor => map[neighbor].Any(x => (x is IBuilding && ((IBuilding)x).BuildingLocation == loc)));

            return(neighbors(location)
                   .Where(neighbor => maze[neighbor] == MazeCell.Wall && !isBuilding(neighbor))
                   .FirstOrDefault());
        }
예제 #8
0
        private TileObject SpawnObject(Dictionary <Location, TileObject> spawnedObjects,
                                       ISigmaMap <List <TileObject> > map, ISigmaMap <MazeCell> maze, Location location)
        {
            var mirror = location.DiagonalMirror(map.Size);

            if (spawnedObjects.ContainsKey(mirror) && symmetricFactory != null)
            {
                return(symmetricFactory(spawnedObjects[mirror], location));
            }

            var spawnedObject = factory(map, maze, location);

            spawnedObjects[location] = spawnedObject;

            return(spawnedObject);
        }
예제 #9
0
        public ISigmaMap <TileObject> Spawn(ISigmaMap <MazeCell> maze)
        {
            var potentialLocations = getSpawnLocations(maze).ToArray();

            var spawnPoints = new HashSet <Location>();

            while (potentialLocations.Length != 0)
            {
                var i = random.Next(potentialLocations.Length);

                var spawnPoint = potentialLocations[i];
                spawnPoints.Add(spawnPoint);

                potentialLocations = potentialLocations
                                     .Where(s => s.EuclideanDistance(spawnPoint) >= config.SpawnDistance)
                                     .ToArray();
            }

            return(SparseSigmaMap.From(maze.Size,
                                       s => IsSpawnPoint(spawnPoints, s, maze.Size) ? factory(s) : null));
        }
예제 #10
0
 public ModifiedMapWrapper(ISigmaMap <TCell> parent, SigmaIndex modLocation, TCell modCell)
 {
     ParentMaze       = parent;
     ModifiedLocation = modLocation;
     ModifiedCell     = modCell;
 }
예제 #11
0
        public ISigmaMap <TileTerrain> Construct(ISigmaMap <MazeCell> maze)
        {
            var voronoiMap = new VoronoiMap <TileTerrain>(maze.Size, terrains, random);

            return(new ArraySigmaMap <TileTerrain>(maze.Size, i => voronoiMap[i]));
        }