static IBoardStorage <int> PopulateLandmark(this IBoard <IHex> board, StepCost directedStepCost, Func <Queue> queueGenerator, IHex landmark ) { TraceNewLine($"Find distances from {landmark.Coords}"); var costs = new BlockedBoardStorage32x32 <int>(board.MapSizeHexes, c => - 1); var queue = queueGenerator(); queue.Enqueue(0, landmark); while (queue.TryDequeue(out var item)) { var here = item.Value; var key = item.Key; if (costs[here.Coords] > 0) { continue; } Trace($"Dequeue Path at {here} w/ cost={key,4}."); costs.SetItem(here.Coords, key); void SetHexside(Hexside hexside) => board.ExpandNode(directedStepCost, costs, queue, here, key, hexside); Hexside.ForEach(SetHexside); } return(costs); }
public bool IsFinished() { if (Queue.TryDequeue(out var item)) { var path = item.Value; var coords = path.PathStep.Coords; OpenSet.Remove(coords); if (!ClosedSet.Contains(coords)) { PathfinderExtensions.TraceFindPathDequeue(GetType().Name, coords, path, item.Key, 0); if (item.Key < BestSoFar) { Partner.Heuristic(coords).IfHasValueDo(heuristic => { if (path.TotalCost + Partner.FrontierMinimum() - heuristic < BestSoFar) { Hexside.ForEach(hexside => ExpandHex(path, hexside)); } }); } ClosedSet.Add(coords); } return(!Queue.Any()); } return(true); }
public override BoardStorage <short?> Fill() { // Reduce field references by keeping all these on stack. var queue = _queue; var store = _store; var tryDirectedStepCost = _tryDirectedStepCost; HexKeyValuePair <int, HexCoords> item; while (queue.TryDequeue(out item)) { var here = item.Value; var key = item.Key; Tracing.FindPathDetail.Trace("Dequeue Path at {0} w/ cost={1,4}.", here, key); Hexside.ForEach(hexside => Action(queue, store, tryDirectedStepCost, here, key, hexside)); } return(store); }
#pragma warning restore 3008 /// <inheritdoc/> public void ForAllNeighbours(HexCoords coords, Action <T, Hexside> action) => Hexside.ForEach(hexside => action(this[coords.GetNeighbour(hexside)], hexside) );