getting rid of pain makes everything run much smoother.

This commit is contained in:
=
2014-09-11 22:54:51 -07:00
parent 1d46fbf527
commit dfc534a8a9

View File

@@ -43,7 +43,7 @@
current-node (vec target-loc)]
(if (or (= current-node play-loc)
(nil? current-node))
(reverse (map (fn [[x y]] [x y]) (conj path current-node)))
(reverse (conj path current-node))
(recur
(conj path current-node)
(came-from (vec current-node))))))))
@@ -59,19 +59,26 @@
^long (+ dist-x dist-y (* ^double d2
^long (min dist-x dist-y)))))
(def my-count (atom 0))
(def cost-comparator (comparator (fn [{^long a :cost} {^long b :cost}] (do (swap! my-count inc) (< a b)))))
(defn visit-all [my-map play-loc target-loc]
(reset! my-count 0)
(let [play-loc (vec play-loc)
target-log (vec target-loc)]
(if (= 0 (get-in my-map target-loc))
nil
(let [cost-so-far ^java.util.HashMap (java.util.HashMap. {play-loc 0})
came-from ^java.util.HashMap (java.util.HashMap.)
fronteir ^java.util.PriorityQueue (java.util.PriorityQueue. 100 (comparator (fn [a b] (< (:cost a) (:cost b)))))]
fronteir ^java.util.PriorityQueue (java.util.PriorityQueue. 100 cost-comparator)]
(.offer fronteir {:cost 0 :loc play-loc})
(loop [current-loc (.poll fronteir)]
(if (or (nil? current-loc)
(= (:loc current-loc) target-loc))
(resolve-path came-from play-loc target-loc)
(do (println @my-count)
(resolve-path came-from play-loc target-loc))
(do (doseq [neighbor (neighbors (:loc current-loc) my-map)]
(let [cost-for-neighbor (.get cost-so-far neighbor)
new-cost (+ (.get cost-so-far (:loc current-loc)) (get-in my-map neighbor))]
@@ -111,5 +118,5 @@
:let [current-color (color (pixmap! pm :get-pixel x y))]]
(cond
(color! current-color :equals black) 0
(color! current-color :equals painful) 10
(color! current-color :equals painful) 1
:else 1)))))))