示例#1
0
        /// <summary>
        /// Expands both path searches until they intersect, and returns the path.
        /// Returned path is from the source of the first search to the source of the second search.
        /// </summary>
        public List <CPos> FindBidiPath(PathSearch first, PathSearch second)
        {
            while (first.CanExpand && second.CanExpand)
            {
                // make some progress on the first search
                var p     = first.Expand();
                var pInfo = second.Graph[p];
                if (pInfo.Status == CellStatus.Closed &&
                    pInfo.CostSoFar != PathGraph.PathCostForInvalidPath)
                {
                    return(MakeBidiPath(first, second, p));
                }

                // make some progress on the second search
                var q     = second.Expand();
                var qInfo = first.Graph[q];
                if (qInfo.Status == CellStatus.Closed &&
                    qInfo.CostSoFar != PathGraph.PathCostForInvalidPath)
                {
                    return(MakeBidiPath(first, second, q));
                }
            }

            return(NoPath);
        }
示例#2
0
        /// <summary>
        /// Expands the path search until a path is found, and returns that path.
        /// Returned path is *reversed* and given target to source.
        /// </summary>
        public List <CPos> FindPath(PathSearch search)
        {
            while (search.CanExpand)
            {
                var p = search.Expand();

                if (search.IsTarget(p))
                {
                    return(MakePath(search.Graph, p));
                }
            }

            return(NoPath);
        }