public static FindPathProcess <T> FindPath <T>(this iExplorer <T> explorer, FindPathOptions options, T start, params T[] goal) { // set default options if (options == null) { options = FindPathOptions.c_Default; } // create result var result = new FindPathProcess <T>(); // common sense check if (start == null || goal.Length == 0 || explorer == null) { result.Complete(FindPathResult.BadArguments); return(result); } // find only reachable goals goal = goal .Where(n => explorer.Reachable(start, n)) .ToArray(); // is reachable if (goal.Length == 0) { result.Complete(FindPathResult.NotReachable); return(result); } // init result inner data result.Init(options, explorer, start, goal); return(result); }
////////////////////////////////////////////////////////////////////////// public void Init(FindPathOptions options, iExplorer <T> exlorer, T start, T[] goal) { if (Result == FindPathResult.None) { // save data Options = options; Explorer = exlorer; Start = start; Goal = goal; // set running state Result = FindPathResult.Running; // allocate collections Path = new LinkedList <T>(); OpenSet = new FastPriorityQueue <PathNode <T> >(Pathfinder.c_AdaptiveBufferExperiance.Average); ClosedSet = new HashSet <T>(); ClosedNodes = new LinkedList <PathNode <T> >(); // create start node, add to open set var startNode = new PathNode <T>(start) { СameFrom = null, PathCost = 0.0f, PathCostEstimated = 0.0f, Cost = 0.0f }; OpenSet.Enqueue(startNode, startNode.Cost); } }
public static FindPathProcess <T> FindPath <T>(this iExplorer <T> explorer, out FindPathProcess <T> findPathProcess, FindPathOptions options, T start, params T[] goal) { findPathProcess = explorer.FindPath(options, start, goal); return(findPathProcess); }