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)))); }
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)); }
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))); }
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); }
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))); }
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()); }
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); }
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)); }
public ModifiedMapWrapper(ISigmaMap <TCell> parent, SigmaIndex modLocation, TCell modCell) { ParentMaze = parent; ModifiedLocation = modLocation; ModifiedCell = modCell; }
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])); }