Exemple #1
0
        public static IEnumerable <SinglyLinkedList <Point> > FindPaths(Map map, Point start, Point[] chests)
        {
            var visitedPoints = new HashSet <Point>();
            var hashedChests  = new HashSet <Point>(chests);
            var queue         = new Queue <SinglyLinkedList <Point> >();

            queue.Enqueue(new SinglyLinkedList <Point>(start));

            while (queue.Count != 0)
            {
                var point = queue.Dequeue();
                foreach (var delta in Walker.PossibleDirections)
                {
                    var walker = new Walker(point.Value).WalkInDirection(map, Walker.ConvertOffsetToDirection(delta));
                    if (walker.PointOfCollision != null || visitedPoints.Contains(walker.Position))
                    {
                        continue;
                    }
                    var nextPoint = walker.Position;
                    visitedPoints.Add(nextPoint);
                    var nextNode = new SinglyLinkedList <Point>(nextPoint, point);
                    if (hashedChests.Contains(nextPoint))
                    {
                        yield return(nextNode);
                    }
                    queue.Enqueue(nextNode);
                }
            }
        }
Exemple #2
0
        public static MoveDirection[] ConvertToDirections(
            SinglyLinkedList <Point> fullPath, bool reverse = false)
        {
            var list = fullPath.ToList();

            if (reverse)
            {
                list.Reverse();
            }
            return(list
                   .Zip(list.Skip(1), (before, after) =>
                        Walker.ConvertOffsetToDirection(new Size(after.X - before.X, after.Y - before.Y)))
                   .ToArray());
        }
Exemple #3
0
        static MoveDirection[] MakeDirectionFromPath(SinglyLinkedList <Point> path)
        {
            if (path == null)
            {
                return(new MoveDirection[0]);
            }
            MoveDirection[]          result      = new MoveDirection[path.Length - 1];
            SinglyLinkedList <Point> currentNode = path;

            for (int i = path.Length - 2; i >= 0; i--, currentNode = currentNode.Previous)
            {
                Size offset = new Size(currentNode.Value) - new Size(currentNode.Previous.Value);
                result[i] = Walker.ConvertOffsetToDirection(offset);
            }
            return(result);
        }
        private static MoveDirection[] TransformToDirections(IEnumerable <Point> path)
        {
            var old  = path.First();
            var size = new Size();

            return(path.Skip(1).Select(
                       x =>
            {
                size.Width = x.X - old.X;
                size.Height = x.Y - old.Y;
                var w = Walker.ConvertOffsetToDirection(size);
                old = x;
                return w;
            })
                   .ToArray());
        }
Exemple #5
0
        private static MoveDirection[] TransformToDirection(IEnumerable <Point> path)
        {
            var previousPoint = path.First();

            return(path.Skip(1).Select(currentPoint =>
            {
                var size = new Size
                {
                    Width = currentPoint.X - previousPoint.X,
                    Height = currentPoint.Y - previousPoint.Y
                };

                var direction = Walker.ConvertOffsetToDirection(size);
                previousPoint = currentPoint;

                return direction;
            }).ToArray());
        }
Exemple #6
0
 private static IEnumerable <MoveDirection> ConvertPointsToDirections(List <Point> points)
 {
     return(points.Zip(points.Skip(1), (p1, p2) =>
                       Walker.ConvertOffsetToDirection(new Size(p2.X - p1.X, p2.Y - p1.Y))));
 }
Exemple #7
0
 private static IEnumerable <MoveDirection> PathConvertToMoveDirection(List <Point> path) =>
 path.Zip(path.Skip(1),
          (a, b) => Walker.ConvertOffsetToDirection(new Size(b) - new Size(a)));
Exemple #8
0
 private static MoveDirection[] ConvertPathToDirection(List <Point> pathList)
 {
     return(pathList.Zip(pathList.Skip(1), (current, next) => Walker.ConvertOffsetToDirection(new Size(next) - new Size(current))).ToArray());
 }
Exemple #9
0
 public static IEnumerable <MoveDirection> AsPathWalk(this Steps steps) =>
 steps.Zip(steps.Skip(1),
           (a, b) => Walker.ConvertOffsetToDirection(new Size(b) - new Size(a)));