/// <summary>.</summary> /// <param name="pathHalves"></param> /// <param name="isForward"></param> public AltPathfinder(IPathHalves <THex> pathHalves, bool isForward) { int exitCost(IHex hex, Hexside hexside) => hex.ExitCost(hexside); int entryCost(IHex hex, Hexside hexside) => hex.EntryCost(hexside); PathHalves = pathHalves; Board = pathHalves.Board; ClosedSet = pathHalves.ClosedSet; Start = isForward ? pathHalves.Source : pathHalves.Target; Goal = isForward ? pathHalves.Target : pathHalves.Source; StepCost = isForward ? (StepCost)exitCost : entryCost; Potential = isForward ? (Potential)((l, c) => l.DistanceFrom(c)) : ((l, c) => l.DistanceTo(c)); SetBestSoFar = isForward ? (SetBest)((s, p) => PathHalves.SetBestSoFar(p, s)) : ((s, p) => PathHalves.SetBestSoFar(s, p)); HexsideDirection = isForward ? (Func <Hexside, Hexside>)(hexside => hexside) : (hexside => hexside.Reversed); OpenSet = new Dictionary <HexCoords, IDirectedPath>(); Queue = HotPriorityQueue.New <IDirectedPath>(0, 256); $"ALT {(isForward?"Fwd":"Rev")}".TraceFindPathDetailDirection(Goal.Coords - Start.Coords); StartPath(Start); }
// Common settings for both directions /// <param name="board">Board on which this path search is taking place.</param> /// <param name="start">Start hex for this half of the bidirectional path search.</param> /// <param name="goal">Goal hex for this this half of the bidirectional path search.</param> /// <param name="pathHalves"></param> protected DirectionalPathfinder(INavigableBoard <IHex> board, IHex start, IHex goal, IPathHalves pathHalves) : base(board, start, goal, pathHalves.ClosedSet) { PathHalves = pathHalves; OpenSet = new Dictionary <HexCoords, IDirectedPath>(); Queue = new HotPriorityQueue <IDirectedPath>(0, 256); }
/// <param name="pathHalves"></param> /// <param name="isForward"></param> public AltPathfinder(IPathHalves pathHalves, bool isForward) { IsForward = isForward; ClosedSet = pathHalves.ClosedSet; StartCoords = pathHalves.Start; GoalCoords = pathHalves.Goal; Landmarks = pathHalves.Board.Landmarks; OpenSet = new Dictionary <HexCoords, IDirectedPath>(); Queue = HotPriorityQueue.New <IDirectedPath>(0, 256); TryStepCost = IsForward ? (StepCost)pathHalves.Board.TryEntryCost : pathHalves.Board.TryExitCost; PathHalves = pathHalves; PathfinderExtensions.TraceFindPathDetailDirection(Direction, GoalCoords - StartCoords); StartPath(IsForward ? StartCoords : GoalCoords); }
BidirectionalPathfinder(IHex start, IHex goal, LandmarkCollection landmarks, HashSet <HexCoords> closed, Func <int> getBestSoFar ) { _start = start; _goal = goal; _getBestSoFar = getBestSoFar; _vectorGoal = goal.Coords.Canon - start.Coords.Canon; _open = new Dictionary <HexCoords, DirectedPath>(); _closed = closed; _queue = new HotPriorityQueue <DirectedPath>(16); _landmark = landmarks .OrderByDescending(l => l.HexDistance(goal.Coords) - l.HexDistance(start.Coords)) .FirstOrDefault(); _heuristic = c => _landmark.HexDistance(c) - _landmark.HexDistance(start.Coords); var path = new DirectedPath(goal); _open.Add(goal.Coords, path); _queue.Enqueue(0, path); }
/// <summary>TODO</summary> internal static IPriorityQueue <int, TValue> NewHotPriorityQueue <TValue>(int initialSize) // where TValue : class { return(HotPriorityQueue.New <TValue>(0, initialSize)); }
/// <summary>Returns a new <see cref="HotPriorityQueue"/> with size <paramref name="initialSize"/>.</summary> internal static IPriorityQueue <int, TValue> NewHotPriorityQueue <TValue>(int initialSize) => HotPriorityQueue.New <TValue>(0, initialSize);