Beispiel #1
0
 private static void TryAddPosition(Map map, Direction direction, InternalPoint position, int xOffset, int yOffset)
 {
     var availableDirections = map.AvailableDirectionsByCoordinates[position.X, position.Y];
     var point = new InternalPoint(position.X + xOffset, position.Y + yOffset, direction);
     if ( (availableDirections & direction)!= 0 && !handled.Contains(point))
     {
         AddPoint(point);
         parents.SafeAdd(point, position);
     }
 }
Beispiel #2
0
        private static void TryAddPosition(Map map, Direction direction, InternalPoint position, int xOffset, int yOffset)
        {
            var availableDirections = map.AvailableDirectionsByCoordinates[position.X, position.Y];
            var point = new InternalPoint(position.X + xOffset, position.Y + yOffset, direction);

            if ((availableDirections & direction) != 0 && !handled.Contains(point))
            {
                AddPoint(point);
                parents.SafeAdd(point, position);
            }
        }
Beispiel #3
0
 public static Direction[] FindPath(Map map, Point from, Point to)
 {
     var lastDirection = Bfs(map, from, to);
     var directions = new List<Direction>();
     var currentPoint = new InternalPoint(to.X, to.Y, lastDirection);
     while (parents.ContainsKey(currentPoint))
     {
         directions.Add(currentPoint.Direction);
         currentPoint = parents[currentPoint];
     }
     directions.Reverse();
     return directions.ToArray();
 }
Beispiel #4
0
        public static Direction[] FindPath(Map map, Point from, Point to)
        {
            var lastDirection = Bfs(map, from, to);
            var directions    = new List <Direction>();
            var currentPoint  = new InternalPoint(to.X, to.Y, lastDirection);

            while (parents.ContainsKey(currentPoint))
            {
                directions.Add(currentPoint.Direction);
                currentPoint = parents[currentPoint];
            }
            directions.Reverse();
            return(directions.ToArray());
        }
Beispiel #5
0
 protected bool Equals(InternalPoint other)
 {
     return X == other.X && Y == other.Y;
 }
Beispiel #6
0
 private static void AddPoint(InternalPoint point)
 {
     queue.Enqueue(point);
     handled.Add(point);
 }
Beispiel #7
0
 protected bool Equals(InternalPoint other)
 {
     return(X == other.X && Y == other.Y);
 }
Beispiel #8
0
 private static void AddPoint(InternalPoint point)
 {
     queue.Enqueue(point);
     handled.Add(point);
 }