diff --git a/desktop/src-common/advent/pathfind.clj b/desktop/src-common/advent/pathfind.clj index 0a3455e3..323a3a50 100644 --- a/desktop/src-common/advent/pathfind.clj +++ b/desktop/src-common/advent/pathfind.clj @@ -43,8 +43,11 @@ (came-from current-node)))))) (defn heuristic [[goal-x goal-y] [current-x current-y]] - (+ (Math/abs (- goal-x current-x )) - (Math/abs (- goal-y current-y)))) + (let [dist-x (Math/abs (- goal-x current-x )) + dist-y (Math/abs (- goal-y current-y)) + d2 (Math/sqrt 2)] + (+ dist-x dist-y (* (- d2 1) + (min dist-x dist-y))))) (defn ->scale [loc] (vec (map (fn [x] (int (/ x 2))) loc)))