From 0e44cea2f5bb89c57897792ada47aa3759609f8d Mon Sep 17 00:00:00 2001 From: = Date: Mon, 8 Sep 2014 14:17:29 -0700 Subject: [PATCH] slightly better pathfinding. --- desktop/src-common/advent/pathfind.clj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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)))