示例#1
0
        public static IPathSearch FromPoints(World world, Locomotor locomotor, Actor self, IEnumerable <CPos> froms, CPos target, BlockedByActor check)
        {
            var graph  = new PathGraph(LayerPoolForWorld(world), locomotor, self, world, check);
            var search = new PathSearch(graph);

            search.heuristic = search.DefaultEstimator(target);

            // The search will aim for the shortest path by default, a weight of 100%.
            // We can allow the search to find paths that aren't optimal by changing the weight.
            // We provide a weight that limits the worst case length of the path,
            // e.g. a weight of 110% will find a path no more than 10% longer than the shortest possible.
            // The benefit of allowing the search to return suboptimal paths is faster computation time.
            // The search can skip some areas of the search space, meaning it has less work to do.
            // We allow paths up to 25% longer than the shortest, optimal path, to improve pathfinding time.
            search.heuristicWeightPercentage = 125;

            search.isGoal = loc =>
            {
                var locInfo = search.Graph[loc];
                return(locInfo.EstimatedTotal - locInfo.CostSoFar == 0);
            };

            foreach (var sl in froms)
            {
                if (world.Map.Contains(sl))
                {
                    search.AddInitialCell(sl);
                }
            }

            return(search);
        }
示例#2
0
        public static IPathSearch Search(World world, Locomotor locomotor, Actor self, BlockedByActor check, Func <CPos, bool> goalCondition)
        {
            var graph  = new PathGraph(LayerPoolForWorld(world), locomotor, self, world, check);
            var search = new PathSearch(graph);

            search.isGoal    = goalCondition;
            search.heuristic = loc => 0;
            return(search);
        }
示例#3
0
        public static IPathSearch Search(World world, MobileInfo mi, Actor self, bool checkForBlocked, Func <CPos, bool> goalCondition)
        {
            var graph  = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
            var search = new PathSearch(graph);

            search.isGoal    = goalCondition;
            search.heuristic = loc => 0;
            return(search);
        }
示例#4
0
        public static IPathSearch Search(World world, MobileInfo mi, Actor self, bool checkForBlocked, Func <CPos, bool> goalCondition)
        {
            var graph  = new PathGraph(LayerPoolForWorld(world), mi, self, world, checkForBlocked);
            var search = new PathSearch(graph);

            search.isGoal    = goalCondition;
            search.heuristic = loc => 0;
            return(search);
        }
示例#5
0
        public static IPathSearch FromPoints(IWorld world, IMobileInfo mi, IActor self, IEnumerable <CPos> froms, CPos target, bool checkForBlocked)
        {
            var graph  = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
            var search = new PathSearch(graph)
            {
                heuristic = DefaultEstimator(target)
            };

            foreach (var sl in froms.Where(sl => world.Map.Contains(sl)))
            {
                search.AddInitialCell(sl);
            }

            return(search);
        }
示例#6
0
        public static IPathSearch FromPoint(IWorld world, IMobileInfo mi, IActor self, CPos from, CPos target, bool checkForBlocked)
        {
            var graph  = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
            var search = new PathSearch(graph)
            {
                heuristic = DefaultEstimator(target)
            };

            if (world.Map.Contains(from))
            {
                search.AddInitialCell(from);
            }

            return(search);
        }
示例#7
0
        public static PathSearch ToTargetCellByPredicate(
            World world, Locomotor locomotor, Actor self, IEnumerable <CPos> froms, Func <CPos, bool> targetPredicate, BlockedByActor check,
            Func <CPos, int> customCost = null)
        {
            var graph  = new PathGraph(LayerPoolForWorld(world), locomotor, self, world, check, customCost, null, false, DefaultLaneBias);
            var search = new PathSearch(graph, loc => 0, DefaultHeuristicWeightPercentage, targetPredicate);

            foreach (var sl in froms)
            {
                if (world.Map.Contains(sl))
                {
                    search.AddInitialCell(sl);
                }
            }

            return(search);
        }
示例#8
0
        public static IPathSearch FromPoints(World world, MobileInfo mi, Actor self, IEnumerable <CPos> froms, CPos target, bool checkForBlocked)
        {
            var graph  = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);
            var search = new PathSearch(graph)
            {
                heuristic = DefaultEstimator(target)
            };

            search.isGoal = loc =>
            {
                var locInfo = search.Graph[loc];
                return(locInfo.EstimatedTotal - locInfo.CostSoFar == 0);
            };

            foreach (var sl in froms.Where(sl => world.Map.Contains(sl)))
            {
                search.AddInitialCell(sl);
            }

            return(search);
        }
示例#9
0
        public static IPathSearch FromPoint(World world, MobileInfo mi, Actor self, CPos from, CPos target, bool checkForBlocked)
        {
            var graph  = new PathGraph(LayerPoolForWorld(world), mi, self, world, checkForBlocked);
            var search = new PathSearch(graph)
            {
                heuristic = DefaultEstimator(target)
            };

            search.isGoal = loc =>
            {
                var locInfo = search.Graph[loc];
                return(locInfo.EstimatedTotal - locInfo.CostSoFar == 0);
            };

            if (world.Map.Contains(from))
            {
                search.AddInitialCell(from);
            }

            return(search);
        }
示例#10
0
        public static PathSearch ToTargetCell(
            World world, Locomotor locomotor, Actor self, IEnumerable <CPos> froms, CPos target, BlockedByActor check,
            Func <CPos, int> customCost = null,
            Actor ignoreActor           = null,
            bool inReverse                = false,
            bool laneBias                 = DefaultLaneBias,
            Func <CPos, int> heuristic    = null,
            int heuristicWeightPercentage = DefaultHeuristicWeightPercentage)
        {
            var graph = new PathGraph(LayerPoolForWorld(world), locomotor, self, world, check, customCost, ignoreActor, inReverse, laneBias);

            heuristic = heuristic ?? DefaultCostEstimator(locomotor, target);
            var search = new PathSearch(graph, heuristic, heuristicWeightPercentage, loc => loc == target);

            foreach (var sl in froms)
            {
                if (world.Map.Contains(sl))
                {
                    search.AddInitialCell(sl);
                }
            }

            return(search);
        }
示例#11
0
        public static IPathSearch Search(IWorld world, IMobileInfo mi, IActor self, bool checkForBlocked)
        {
            var graph = new PathGraph(CellInfoLayerManager.Instance.NewLayer(world.Map), mi, self, world, checkForBlocked);

            return(new PathSearch(graph));
        }