From 6790bf06fdf684df23e38b72973a679d9db3fbc6 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 7 Jul 2019 22:32:35 +0000 Subject: [PATCH] Just stop when we reach the goal, since we always find a min-cost path --- LayoutLink.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/LayoutLink.js b/LayoutLink.js index 7e4e6b4..fd0940c 100644 --- a/LayoutLink.js +++ b/LayoutLink.js @@ -28,13 +28,6 @@ class LayoutLink { ++iter; let pos = next.path[next.path.length - 1]; - if (cheapestCostToGoal && next.cost >= cheapestCostToGoal) { - // Can't possibly find a cheaper route via this path - // We check this twice (again below), to avoid excessive queueing but - // to handle cheapestCostToGoal changing while we're in queue. - break; - } - let prevCost = cheapestCostByPos.get(pos); if (prevCost && prevCost <= next.cost) { // Reached a previous pos via a higher- or equal-cost path @@ -43,10 +36,8 @@ class LayoutLink { cheapestCostByPos.set(pos, next); if (pos[0] == this.to_.pos[0] && pos[1] == this.to_.pos[1]) { - // Reached the goal - cheapestCostToGoal = next.cost; this.path = next.path; - continue; + break; } //// Calculate cost for next hop @@ -65,12 +56,6 @@ class LayoutLink { newCost += 5; } - if (cheapestCostToGoal && newCost >= cheapestCostToGoal) { - // Can't possibly find a cheaper route via this path - // See duplicate check note above - continue; - } - for (let xOff of [-1, 0, 1]) { for (let yOff of [-1, 0, 1]) { if (xOff == 0 && yOff == 0) {