コード例 #1
0
ファイル: SigmaIndex.cs プロジェクト: penguin-of-linux/homm
        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)));
        }
コード例 #2
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))));
 }
コード例 #3
0
ファイル: MapGenerator.cs プロジェクト: penguin-of-linux/homm
        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));
        }
コード例 #4
0
ファイル: SigmaIndex.cs プロジェクト: penguin-of-linux/homm
        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));
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
ファイル: VoronoiMap.cs プロジェクト: penguin-of-linux/homm
 public TLabel this[SigmaIndex index]
 {
     get
     {
         return(labels
                .Argmin(kv => kv.Value.ManhattanDistance(index.AboveDiagonal(size)))
                .Key);
     }
 }
コード例 #7
0
        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));
        }
コード例 #8
0
        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;
        }
コード例 #9
0
        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);
                }
            }
        }
コード例 #10
0
        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)))
        {
        }
コード例 #11
0
        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)));
        }
コード例 #12
0
 public IEnumerator <SigmaIndex> GetEnumerator()
 {
     return(SigmaIndex
            .Square(Size)
            .Where(s => this[s] != null).GetEnumerator());
 }
コード例 #13
0
 public override TCell this[SigmaIndex index]
 {
     get { return(cells[index.Y, index.X]); }
 }
コード例 #14
0
 public override TCell this[SigmaIndex location]
 {
     get { return(cells.ContainsKey(location) ? cells[location] : defaultValue); }
 }
コード例 #15
0
 private bool IsBorderIndex(SigmaIndex index, MapSize size)
 {
     return(index.AboveDiagonal(size).ManhattanDistance(SigmaIndex.Zero) > size.X - 2);
 }
コード例 #16
0
 public override TCell this[SigmaIndex location]
 {
     get { return(default(TCell)); }
 }
コード例 #17
0
 public abstract TCell this[SigmaIndex location] {
     get;
 }