Exemplo n.º 1
0
        /// <summary>
        /// Find route from init locations to destination defined by IAstarTarget
        /// </summary>
        public static AStarResult Find(IEnumerable<IntVector3> initLocs, IAStarTarget target,
			int maxNodeCount = 200000, CancellationToken? cancellationToken = null)
        {
            var astar = new AStar(initLocs, target);
            astar.MaxNodeCount = maxNodeCount;
            if (cancellationToken.HasValue)
                astar.CancellationToken = cancellationToken.Value;

            var status = astar.Find();

            return new AStarResult(status, astar.LastNode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Find route from init locations to destination defined by IAstarTarget
        /// </summary>
        public static AStarResult Find(IEnumerable <IntVector3> initLocs, IAStarTarget target,
                                       int maxNodeCount = 200000, CancellationToken?cancellationToken = null)
        {
            var astar = new AStar(initLocs, target);

            astar.MaxNodeCount = maxNodeCount;
            if (cancellationToken.HasValue)
            {
                astar.CancellationToken = cancellationToken.Value;
            }

            var status = astar.Find();

            return(new AStarResult(status, astar.LastNode));
        }
Exemplo n.º 3
0
        public AStar(IEnumerable<IntVector3> initialLocations, IAStarTarget target)
        {
            this.MaxNodeCount = 200000;
            this.CancellationToken = CancellationToken.None;

            m_target = target;
            m_nodeMap = new Dictionary<IntVector3, AStarNode>();
            m_openList = new BinaryHeap<AStarNode>();

            foreach (var p in initialLocations)
            {
                ushort g = 0;
                ushort h = m_target.GetHeuristic(p);

                var node = new AStarNode(p, null);
                node.G = g;
                node.H = h;
                m_openList.Add(node);
                m_nodeMap.Add(p, node);
            }
        }
Exemplo n.º 4
0
        public AStar(IEnumerable <IntVector3> initialLocations, IAStarTarget target)
        {
            this.MaxNodeCount      = 200000;
            this.CancellationToken = CancellationToken.None;

            m_target   = target;
            m_nodeMap  = new Dictionary <IntVector3, AStarNode>();
            m_openList = new BinaryHeap <AStarNode>();

            foreach (var p in initialLocations)
            {
                ushort g = 0;
                ushort h = m_target.GetHeuristic(p);

                var node = new AStarNode(p, null);
                node.G = g;
                node.H = h;
                m_openList.Add(node);
                m_nodeMap.Add(p, node);
            }
        }
Exemplo n.º 5
0
        public static IEnumerable<AStarResult> FindMany(IEnvironmentObject env,
			IntVector3 src, DirectionSet srcPositioning, IAStarTarget target,
			int maxNodeCount = 200000, CancellationToken? cancellationToken = null)
        {
            var initLocs = env.GetPositioningLocations(src, srcPositioning);

            var astar = new AStar(initLocs, target);
            astar.MaxNodeCount = maxNodeCount;
            if (cancellationToken.HasValue)
                astar.CancellationToken = cancellationToken.Value;

            AStarStatus status;
            while ((status = astar.Find()) == AStarStatus.Found)
                yield return new AStarResult(status, astar.LastNode);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Find route from src to destination defined by IAstarTarget
        /// </summary>
        public static AStarResult Find(IAStarEnvironment environment, IntPoint3 src, DirectionSet srcPositioning, IAStarTarget target,
			int maxNodeCount = 200000, CancellationToken? cancellationToken = null)
        {
            var astar = new AStarImpl(environment, src, srcPositioning, target, maxNodeCount, cancellationToken);
            var status = astar.Find();
            return new AStarResult(astar.Nodes, astar.LastNode, status);
        }
Exemplo n.º 7
0
            public AStarImpl(IAStarEnvironment environment, IntPoint3 src, DirectionSet srcPositioning,
				IAStarTarget target, int maxNodeCount = 200000, CancellationToken? cancellationToken = null)
            {
                m_environment = environment;
                m_src = src;
                m_srcPositioning = srcPositioning;
                m_maxNodeCount = maxNodeCount;
                m_cancellationToken = cancellationToken.HasValue ? cancellationToken.Value : CancellationToken.None;

                m_target = target;
                m_nodeMap = new Dictionary<IntPoint3, AStarNode>();
                m_openList = new BinaryHeap<AStarNode>();

                AddInitialNodes();
            }
Exemplo n.º 8
0
        public static IEnumerable<AStarResult> FindMany(IAStarEnvironment environment,
			IntPoint3 src, DirectionSet srcPositioning, IAStarTarget target,
			int maxNodeCount = 200000, CancellationToken? cancellationToken = null)
        {
            var astar = new AStarImpl(environment, src, srcPositioning, target, maxNodeCount, cancellationToken);

            AStarStatus status;
            while ((status = astar.Find()) == AStarStatus.Found)
                yield return new AStarResult(astar.Nodes, astar.LastNode, status);
        }
Exemplo n.º 9
0
        public static IEnumerable <AStarResult> FindMany(IEnvironmentObject env,
                                                         IntVector3 src, DirectionSet srcPositioning, IAStarTarget target,
                                                         int maxNodeCount = 200000, CancellationToken?cancellationToken = null)
        {
            var initLocs = env.GetPositioningLocations(src, srcPositioning);

            var astar = new AStar(initLocs, target);

            astar.MaxNodeCount = maxNodeCount;
            if (cancellationToken.HasValue)
            {
                astar.CancellationToken = cancellationToken.Value;
            }

            AStarStatus status;

            while ((status = astar.Find()) == AStarStatus.Found)
            {
                yield return(new AStarResult(status, astar.LastNode));
            }
        }