Esempio n. 1
0
 public IEnumerable <Cubicle> Neighbors(Cubicle cubicle)
 {
     return
         (Steps.Select(xStep => new { x = cubicle.X + xStep, y = (int)cubicle.Y })
          .Concat(Steps.Select(yStep => new { x = (int)cubicle.X, y = cubicle.Y + yStep }))
          .Where(c => this.IsCubicle(c.x, c.y))
          .Select(c => new Cubicle((ushort)c.x, (ushort)c.y)));
 }
Esempio n. 2
0
        public ISet <Cubicle> Flood(Maze maze, Cubicle start, int rounds)
        {
            var flooded = new HashSet <Cubicle> {
                start
            };
            var wave = new Queue <Cubicle>(new[] { start });

            for (int i = 0; i < rounds; i++)
            {
                var nextWave = new Queue <Cubicle>();
                while (wave.Count > 0)
                {
                    var c = wave.Dequeue();
                    foreach (var neighbor in maze.Neighbors(c).Where(n => !flooded.Contains(n)))
                    {
                        flooded.Add(neighbor);
                        nextWave.Enqueue(neighbor);
                    }
                }
                wave = nextWave;
            }

            return(flooded);
        }
Esempio n. 3
0
 protected bool Equals(Cubicle other)
 {
     return(X == other.X && Y == other.Y);
 }
Esempio n. 4
0
 public ushort ManhattanDistance(Cubicle other)
 {
     return((ushort)(Math.Abs(this.X - other.X) + Math.Abs(this.Y - other.Y)));
 }
Esempio n. 5
0
 public IEnumerable <Cubicle> ShortestPath(Cubicle start, Cubicle destination)
 {
     return(AStarUtilities.FindMinimalPath(start, destination, cubicle => this.Maze.Neighbors(cubicle),
                                           (c1, c2) => 1, c => c.ManhattanDistance(destination)).Result);
 }