From 55c753adb8a897ca0b0a4f32558bd960fd0742a7 Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 25 Jul 2024 01:54:53 +0200 Subject: [PATCH] Ends try to find closest node to one another. --- astar/Astar.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/astar/Astar.cs b/astar/Astar.cs index e2f438c..00113c1 100644 --- a/astar/Astar.cs +++ b/astar/Astar.cs @@ -44,21 +44,27 @@ 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 < toVisitStart.Count / 10 && meetingEnds is null; i++) - meetingEnds = ExploreSide(true, graph, toVisitStart, rl, priorityHelper, endNode.Value, car, DefaultPriorityWeights, pathing, logger); + meetingEnds = ExploreSide(true, graph, toVisitStart, rl, priorityHelper, closestEndNode, car, DefaultPriorityWeights, pathing, logger); } if(meetingEnds is null) - meetingEnds = ExploreSide(true, graph, toVisitStart, rl, priorityHelper, endNode.Value, car, DefaultPriorityWeights, pathing, logger); + 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 < toVisitEnd.Count / 10 && meetingEnds is null; i++) - meetingEnds = ExploreSide(false, graph, toVisitEnd, rl, priorityHelper, startNode.Value, car, DefaultPriorityWeights, pathing, logger); + meetingEnds = ExploreSide(false, graph, toVisitEnd, rl, priorityHelper, closestStartNode, car, DefaultPriorityWeights, pathing, logger); } if(meetingEnds is null) - meetingEnds = ExploreSide(false, graph, toVisitEnd, rl, priorityHelper, startNode.Value, car, DefaultPriorityWeights, pathing, logger); + meetingEnds = ExploreSide(false, graph, toVisitEnd, rl, priorityHelper, closestStartNode, car, DefaultPriorityWeights, pathing, logger); if (meetingEnds is not null) break;