/// <summary>Returns an <c>IPath</c> for the optimal path from coordinates <paramref name="source"/> to <paramref name="target"/>.</summary> /// <param name="board">An object satisfying the interface <c>INavigableBoardFwd</c>.</param> /// <param name="source">Coordinates for the <c>first</c> step on the desired path.</param> /// <param name="target">Coordinates for the <c>last</c> step on the desired path.</param> /// <returns>A <see cref="IPath{THex}"/> for the shortest path found, or null if no path was found.</returns> /// <remarks> /// <para>Note that the Heuristic provided by <paramref name="board"/> must be <b>consistent</b> /// in order for the algorithm to perform properly.</para> /// </remarks> public static IPath <THex> GetPathBiDiAlt <THex>(this ILandmarkBoard <THex> board, THex source, THex target) where THex : class, IHex { if (board?.Landmarks == null || source == null || target == null) { return(new Path <THex>(null, source, target, null, null)); } else { source.TraceFindPathDetailInit(target); var pathHalves = board.NewPathHalves(source, target); var pathfinderFwd = pathHalves.NewAltPathfinder(false); var pathfinderRev = pathHalves.NewAltPathfinder(true); // Alternate searching from each direction and calling the other direction pathfinderFwd.Partner = pathfinderRev; var pathfinder = pathfinderRev.Partner = pathfinderFwd; while (!pathfinder.IsFinished()) { pathfinder = pathfinder.Partner; } pathHalves.ClosedSet.Count.TraceFindPathDone(); return(new Path <THex>(pathHalves.PathFwd, source, target, pathHalves.ClosedSet, null)); } }
public PathHalves(ILandmarkBoard board, HexCoords start, HexCoords goal) { Board = board; Start = start; Goal = goal; ClosedSet = new HashSet <HexCoords>(); BestSoFar = int.MaxValue; }
/// <summary>.</summary> /// <param name="board">Board on which this path search is taking place.</param> /// <param name="source">Start hex for this half of the bidirectional path search.</param> /// <param name="target">Goal hex for this this half of the bidirectional path search.</param> public PathHalves(ILandmarkBoard <THex> board, THex source, THex target) { Board = board; Source = source; Target = target; ClosedSet = new HashSet <HexCoords>(); BestSoFar = int.MaxValue; }
/// <summary>.</summary> /// <typeparam name="THex"></typeparam> /// <param name="board"></param> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> internal static IPathHalves <THex> NewPathHalves <THex>(this ILandmarkBoard <THex> board, THex source, THex target) where THex : class, IHex => new PathHalves <THex>(board, source, target);
/// <summary>Calculates an <see cref="IDirectedPath"/> for the optimal path from coordinates.</summary> /// <param name="board">An object satisfying the interface <c>INavigableBoardFwd</c>.</param> /// <remarks> /// <para>Note that the Heuristic provided by <paramref name="board"/> <b>must</b> be monotonic /// in order for the algorithm to perform properly.</para> /// <seealso cref="StandardPathfinder"/> /// </remarks> public BidirectionalAltPathfinder(ILandmarkBoard board) => Board = board;