diff --git a/astar/Astar.cs b/astar/Astar.cs index 568df6c..becd61c 100644 --- a/astar/Astar.cs +++ b/astar/Astar.cs @@ -43,22 +43,18 @@ namespace astar ValueTuple? meetingEnds = null; while (toVisitStart.Count > 0 && toVisitEnd.Count > 0) { - ulong closestEndNodeId = toVisitEnd.UnorderedItems - .MinBy(n => graph.Nodes[n.Element].DistanceTo(startNode.Value)).Element; - Node closestEndNode = graph.Nodes[closestEndNodeId]; - if (toVisitStart.Count >= toVisitEnd.Count && meetingEnds is null) + for (int i = 0; i < Math.Min(toVisitStart.Count * 0.5, 50) && meetingEnds is null; i++) { - for(int i = 0; i < Math.Min(toVisitStart.Count * 0.5, 50) && meetingEnds is null; i++) - meetingEnds = ExploreSide(true, graph, toVisitStart, rl, priorityHelper, closestEndNode, car, DefaultPriorityWeights, pathing, logger); + ulong closestEndNodeId = toVisitEnd.UnorderedItems.MinBy(node => graph.Nodes[node.Element].DistanceTo(graph.Nodes[toVisitStart.Peek()])).Element; + Node closestEndNode = graph.Nodes[closestEndNodeId]; + meetingEnds = ExploreSide(true, graph, toVisitStart, rl, priorityHelper, closestEndNode, car, DefaultPriorityWeights, pathing, logger); } - ulong closestStartNodeId = toVisitStart.UnorderedItems - .MinBy(n => graph.Nodes[n.Element].DistanceTo(endNode.Value)).Element; - Node closestStartNode = graph.Nodes[closestStartNodeId]; - if (toVisitEnd.Count >= toVisitStart.Count && meetingEnds is null) + for (int i = 0; i < Math.Min(toVisitEnd.Count * 0.5, 50) && meetingEnds is null; i++) { - for(int i = 0; i < Math.Min(toVisitEnd.Count * 0.5, 50) && meetingEnds is null; i++) - meetingEnds = ExploreSide(false, graph, toVisitEnd, rl, priorityHelper, closestStartNode, car, DefaultPriorityWeights, pathing, logger); + ulong closestStartNodeId = toVisitStart.UnorderedItems.MinBy(node => graph.Nodes[node.Element].DistanceTo(graph.Nodes[toVisitEnd.Peek()])).Element; + Node closestStartNode = graph.Nodes[closestStartNodeId]; + meetingEnds = ExploreSide(false, graph, toVisitEnd, rl, priorityHelper, closestStartNode, car, DefaultPriorityWeights, pathing, logger); } if (meetingEnds is not null)