public double EuclideanDistance(SigmaIndex other) { var thisFixY = Y + 0.5 * (X % 2); var otherFixY = other.Y + 0.5 * (other.X % 2); return(Math.Sqrt(Math.Pow(X - other.X, 2) + Math.Pow(thisFixY - otherFixY, 2))); }
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 Map GenerateMap(int size) { if (size < 0) { throw new ArgumentException("Cannot create map of negative size"); } if (size % 2 == 1) { throw new ArgumentException("Cannot create map of odd size"); } var mapSize = new MapSize(size, size); var maze = mazeGenerator.Construct(mapSize); var terrainMap = terrainGenerator.Construct(maze); var entities = entitiesGenerators .Aggregate(SigmaMap.Empty <TileObject>(maze.Size), (m, g) => m.Merge(g.Spawn(maze))); var tiles = SigmaIndex.Square(mapSize) .Select(s => new Tile(s.X, s.Y, terrainMap[s], maze[s] == MazeCell.Empty ? entities[s] : new Impassable(s))); return(new Map(size, size, tiles)); }
public double ManhattanDistance(SigmaIndex other) { var thisFixY = Y + 0.5 * (X % 2); var otherFixY = other.Y + 0.5 * (other.X % 2); return(Math.Abs(X - other.X) + Math.Abs(thisFixY - otherFixY)); }
public ArraySigmaMap(MapSize size, Func <SigmaIndex, TCell> cellsFactory) { cells = new TCell[size.Y, size.X]; foreach (var index in SigmaIndex.Square(size)) { cells[index.Y, index.X] = cellsFactory(index); } }
public TLabel this[SigmaIndex index] { get { return(labels .Argmin(kv => kv.Value.ManhattanDistance(index.AboveDiagonal(size))) .Key); } }
public ImmutableSigmaMap <TCell> Insert(SigmaIndex location, TCell cell) { if (location.X < 0 || location.X > Size.X || location.Y < 0 || location.Y > Size.Y) { throw new ArgumentException("Modifying maze outside of its borders"); } return(new ModifiedMapWrapper <TCell>(this, location, cell)); }
public SpawnerConfig(SigmaIndex emitter, double startInclusive, double endExclusive, double density) { if (density > 1 || density <= 0) { throw new ArgumentException($"{nameof(density)} should be in range (0, 1]"); } EmitterLocation = emitter; StartRadius = startInclusive; EndRadius = endExclusive; SpawnDensity = density; }
public SparseSigmaMap(MapSize size, Func <SigmaIndex, TCell> cellsFactory, TCell defaultValue = default(TCell)) : this(size, new Dictionary <SigmaIndex, TCell>(), defaultValue) { foreach (var index in SigmaIndex.Square(size)) { var cell = cellsFactory(index); if (cell == null || !cell.Equals(defaultValue)) { cells.Add(index, cell); } } }
public MinDistanceSpawner( Random random, SpawnerConfig config, Func <Vector2i, TileObject> factory) : base(random, config, factory, maze => SigmaIndex.Square(maze.Size) .Where(s => maze[s] == MazeCell.Empty) .Select(s => new { Value = s, Distance = config.EmitterLocation.ManhattanDistance(s) }) .Where(s => s.Distance >= config.StartRadius) .Where(s => s.Distance < config.EndRadius) .Select(s => s.Value) .Where(s => s.IsAboveDiagonal(maze.Size))) { }
private bool IsSpawnPoint(HashSet <SigmaIndex> spawns, SigmaIndex index, MapSize size) { if (!IsBorderIndex(index, size)) { return(spawns.Contains(index.AboveDiagonal(size))); } if (index.X >= size.X / 2.0) { return(spawns.Contains(index)); } return(index.AboveDiagonal(size) == index ? false : spawns.Contains(index.AboveDiagonal(size))); }
public IEnumerator <SigmaIndex> GetEnumerator() { return(SigmaIndex .Square(Size) .Where(s => this[s] != null).GetEnumerator()); }
public override TCell this[SigmaIndex index] { get { return(cells[index.Y, index.X]); } }
public override TCell this[SigmaIndex location] { get { return(cells.ContainsKey(location) ? cells[location] : defaultValue); } }
private bool IsBorderIndex(SigmaIndex index, MapSize size) { return(index.AboveDiagonal(size).ManhattanDistance(SigmaIndex.Zero) > size.X - 2); }
public override TCell this[SigmaIndex location] { get { return(default(TCell)); } }
public abstract TCell this[SigmaIndex location] { get; }