Exemple #1
0
 private int getDistance(int floor, Point fromLoc, Direction direction)
 {
     var toLoc = fromLoc.Add(direction.DirectionAsPoint());
     return PlayingField.CanMoveHere(ref floor, fromLoc, toLoc, true)
         ? Distance[floor, toLoc.Y, toLoc.X]
         : int.MaxValue;
 }
Exemple #2
0
        public void Explore(int floor, Point fromLoc, int distance, Direction direction)
        {
            var toLoc = fromLoc.Add(direction.DirectionAsPoint());
            if (!PlayingField.CanMoveHere(ref floor, fromLoc, toLoc, true))
                return;

            var here = Distance[floor, toLoc.Y, toLoc.X];
            if (here != 0 && here < distance)
                return; // already know shorter path

            Distance[floor, toLoc.Y, toLoc.X] = distance;

            foreach (var newDirection in Direction.AllDirections)
                Explore(floor, toLoc, distance + 1, newDirection);
        }
 public static Point Add(this Point p1, Direction dir)
 {
     return p1.Add(dir.DirectionAsPoint());
 }